Skip to content

Studio: correct the anyio<4.14 pin rationale (mixed-install ImportError, not a 4.14 cancel-scope bug) - #6579

Merged
danielhanchen merged 2 commits into
mainfrom
docs-anyio-414-root-cause
Jun 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
docs-anyio-414-root-cause

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Follow-up to #6546 / #6575. The anyio<4.14.0 pin comments attribute the failure to "anyio 4.14+ breaks cancel scope on Python 3.13". That is not what happens. This PR corrects the rationale (comments only). The pin itself stays.

What actually breaks

anyio 4.14.0 added a new symbol, TaskHandle, in anyio/_core/_tasks.py. Both anyio/__init__.py (line 73) and the asyncio backend anyio/_backends/_asyncio.py (line 95) now do from .._core._tasks import TaskHandle. 4.13.0 has no TaskHandle and no such import.

A clean 4.14.0 is fine, including on Python 3.13. The CI 500 (cannot import name 'TaskHandle' from anyio._core._tasks) only happens with a half-resolved install: a stale 4.13 _core/_tasks.py (no TaskHandle) sitting under 4.14's importers. That mix is produced on macOS-arm by the version fight between mlx-vlm/mlx-lm (which pull anyio>=4.14) and this <4.14 cap.

Reproduction (Python 3.13)

Clean installs, both versions:

TaskHandle in _core._tasks import _backends._asyncio move_on_after Event
anyio 4.13.0 absent OK cancelled_caught=True OK
anyio 4.14.0 present OK cancelled_caught=True OK

So neither clean version is broken on 3.13. Forcing the mix reproduces the exact CI error:

# overlay 4.13.0's _core/_tasks.py onto an otherwise-4.14.0 anyio, then:
python -c "import anyio"
ImportError: cannot import name 'TaskHandle' from 'anyio._core._tasks'

Restoring 4.14.0's _core/_tasks.py fixes it.

Why the pin still stands

Keeping anyio on one consistent <4.14 line avoids the mix. On macOS-arm the cap alone loses to mlx's >=4.14, so #6575 forces it via the uv override; Linux/Windows honor the constraint directly. (An alternative would be to allow a clean >=4.14, since clean 4.14 works - but the validated fix is the consistent <4.14.)

Change

Comments only, in constraints.txt and no-torch-runtime.txt. No version changes.

@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 comments in the requirements and constraints files to clarify the reasoning behind capping the anyio package version to <4.14.0. The updated comments explain that a half-resolved installation with a stale 4.13 _core/_tasks under 4.14's importers leads to an ImportError and server failures. There are no review comments, so I have no feedback to provide.

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.

The pin comments said "anyio 4.14+ breaks cancel scope on Python 3.13", but
a clean anyio 4.14.0 works on 3.13 (cancel scopes, Event, and the asyncio
backend import all pass). The actual failure is a half-resolved install:
anyio 4.14 added TaskHandle, imported by __init__.py and _backends/_asyncio
from _core/_tasks. When a stale 4.13 _core/_tasks (no TaskHandle) sits under
4.14's importers, the import raises ImportError and 500s the server. Correct
the rationale; the <4.14 pin still stands as the way to keep one consistent
anyio version.
@danielhanchen
danielhanchen force-pushed the docs-anyio-414-root-cause branch from 746f275 to 763dcd6 Compare June 22, 2026 15:51
@danielhanchen
danielhanchen merged commit c976174 into main Jun 22, 2026
45 of 49 checks passed
@danielhanchen
danielhanchen deleted the docs-anyio-414-root-cause branch June 22, 2026 16:05
danielhanchen added a commit that referenced this pull request Jun 23, 2026
#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.
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.

1 participant