Skip to content

Studio: correct anyio<4.14 comments to the real #6483 cause (4.14/Py3.13 streaming cancel-scope bug) - #6581

Merged
danielhanchen merged 1 commit into
mainfrom
fix-anyio-comment-accuracy
Jun 23, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-anyio-comment-accuracy

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up correcting comments merged in #6579. Comments only, no version changes.

#6579 reworded the anyio<4.14 pin comments to say a clean 4.14 is fine on 3.13 and that the failure is just a half-resolved install. That is inaccurate. #6483 is a genuine anyio 4.14 + Python 3.13 regression, not an install artifact.

What actually breaks (#6483)

From the reporter's crash log (clean 4.14.0, Python 3.13, Apple Silicon), a streaming /v1/chat/completions raises:

RuntimeError: Attempted to exit a cancel scope that isn't the current task's current cancel scope
  starlette/responses.py: async with create_collapsing_task_group()   # StreamingResponse
  anyio/_core/_tasks.py:276  _run_coro:  with self._cancel_scope:
  anyio/_backends/_asyncio.py:472  __exit__ -> RuntimeError

anyio 4.14 added TaskHandle, and TaskHandle.__init__ creates a per-task CancelScope that _run_coro enters with with self._cancel_scope:. Under starlette's collapsing task group on the asyncio backend + Python 3.13, that scope is exited in a different task than it was entered, tripping anyio's host-task check. 4.13 has none of this code (no TaskHandle/_run_coro), so it is unaffected - the reporter confirmed anyio==4.13.0 fixes it. Same Py3.13 cancel-scope class seen upstream (e.g. encode/httpx#3728).

The TaskHandle ImportError seen in CI is a separate, secondary symptom: on macOS-arm the cap fights mlx's anyio>=4.14, leaving a half-resolved 4.14/4.13 anyio. That is real too, but it is not what #6483 is about.

Why the pin stays

The <4.14 cap is the correct mitigation for the real upstream bug; this PR only fixes the comments so the rationale is accurate (and so nobody un-pins thinking 4.14 is fine on 3.13). The actual fix belongs upstream in anyio.

#6579 reworded these comments to attribute the failure to a half-resolved
install and claimed a clean 4.14 is fine on 3.13. That is wrong: #6483 is a
genuine anyio 4.14 + Python 3.13 regression. 4.14 added a per-task cancel
scope in its asyncio backend (TaskHandle/_run_coro) that gets exited in the
wrong task under starlette's collapsing task group, raising the cancel-scope
RuntimeError on streaming; 4.13 has no such code and is unaffected (the
reporter confirmed 4.13.0 fixes it). The TaskHandle ImportError is only the
secondary macOS-arm symptom from the mlx-vs-cap version fight. Comments only.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the explanatory comments in the backend requirements and constraints files regarding the anyio<4.14.0 dependency cap. The updated comments clarify that anyio 4.14 causes a RuntimeError related to asyncio cancel scopes on Python 3.13 during streaming responses under Starlette. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@danielhanchen
danielhanchen merged commit 1ffffc1 into main Jun 23, 2026
46 of 50 checks passed
@danielhanchen
danielhanchen deleted the fix-anyio-comment-accuracy branch June 23, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants