Skip to content

fix(5320): run graph commands without anyio installed - #5422

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-cli-without-anyio
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-cli-without-anyio

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Part of #5320. On 0.9.118, explain, query, path, affected and
benchmark crash on an install without the mcp extra:

  File ".../graphify/serve.py", line 14, in <module>
    import anyio
ModuleNotFoundError: No module named 'anyio'

anyio comes only with the mcp and all extras. These five commands import
helpers from serve.py, so a module-level import there has to work on a core
install. #5374 imported anyio inside the MCP function that uses it; e6d37d5
moved it to the top of the file. This PR moves it back, with a comment saying
why it is there.

fff446c2  test(5320): pin graph commands running without the mcp extra
d2e6a61e  fix(5320): import anyio only where the MCP server uses it

Until this is released, pip install anyio works around it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

The invariant: commands that only read a graph work on a core install. Only the
MCP server may need the mcp extra.

The dev environment has anyio, so the other tests can't see this. The new test
runs the CLI in a subprocess where anyio, mcp and starlette can't be
imported.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Merge Danger

Door: two-way. No persisted state, graph output or cache schema changes.

Blast radius: when anyio gets imported. The MCP server still uses it in
the same place.

Limitations

  • The test covers the five commands above, not every CLI command.
  • benchmark gets an exit-code check only, because it prints statistics.

How was this tested?

With PYTHONPATH set to the worktree:

pytest -q tests/test_cli_without_mcp_extra.py
    v8 (5ce8fcef)  -> 5 failed
    this branch    -> 5 passed
pytest -q tests/test_cli_without_mcp_extra.py tests/test_serve_reload_off_loop.py tests/test_serve.py
    this branch    -> 207 passed
pytest -q (full suite)
    this branch    -> 11902 passed, 1 failed, 122 skipped, 1 xfailed

The one failure is a file-watcher test,
test_watch_relative_roots_receive_config_events_without_rebasing_source_paths[src],
where graph.json did not exist yet when it was read. Run alone it passes 5/5
on this branch and 5/5 on v8, so it looks like timing; I did not find the cause.

Clean Python 3.12 environments without anyio (graphifyy[vbnet]):

0.9.114, 0.9.115  explain, query, path, affected run
0.9.118           the same four fail with ModuleNotFoundError
this branch       all five run

Not tested: Windows.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. (No trailer in the commit messages.)

explain, query, path, affected and benchmark only read a graph, so they must
work on a core install. Run each with anyio, mcp and starlette unimportable.
e6d37d5 moved the import to the top of serve.py. anyio ships only with the
mcp and all extras, but explain, query, path, affected and benchmark import
helpers from serve.py, so they failed with ModuleNotFoundError on a core
install of 0.9.118.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 23, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Nothing blocking · 4 possible issues to check · Merge confidence 5/5

4 possible issues to check · High impact

The server now imports anyio only when its asynchronous graph-loading helper runs, so importing the module for CLI graph commands no longer requires that optional dependency.

4 possible issues we couldn't confirm

They don't change the score.

Code graph · 883 functions depend on this change
  • 31 of 621 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed d2e6a61 · Full report in the Graphify check

safishamsi added a commit that referenced this pull request Nov 24, 2026
…batch

Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO
(#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54,
so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's
cwd-fragile `query` assertion to check the queried node (returncode==0 is the
real invariant). 0.9.119 changelog and version bump. The headline is the
#5320 anyio regression fix (graph commands broke on core installs in 0.9.118).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.119 via an authorship-preserving cherry-pick, so your commit keeps its credit. Thank you for catching and fixing this — the 0.9.118 anyio hoist broke query/path/explain/affected/benchmark on core installs without the mcp extra, and moving the import back inside the MCP server path restores them. (I fixed the query test's cwd-fragile assertion on merge.) Verified end-to-end on a core install. Thanks @Deepjyoti-Sarmah!

@safishamsi safishamsi closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants