Skip to content

test(agent_runtime): pin the layering rule and drop a stale docstring reference - #289

Merged
Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/compat-parallel-type-checking-import
Nov 16, 2026
Merged

Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/compat-parallel-type-checking-import

Conversation

@raymondginger2018-sudo

@raymondginger2018-sudo raymondginger2018-sudo commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pins one layering rule and removes a stale docstring reference, following the shape from the review on this PR.

core.agent_runtime is the current runtime; core.compat is the legacy shim that adapts the old mcp_agent surface. The dependency must not point back from the runtime into the shim.

  • tests/test_import_layering.py pins that direction statically: a module-level core.compat import anywhere under core/agent_runtime/ fails at the offending line, instead of surfacing later as an order-dependent ImportError at import time.
  • Drops the stale docstring line in core/agent_runtime/__init__.py that advertised core.agent_runtime.parallel, a module that has never existed.

What this is not

It does not claim an import cycle. There is none on main: core.config, core.compat, core.compat.parallel, core.compat.agent, core.compat.runtime, core.agent_runtime, core.events and app_server each import cleanly as the first import of a fresh interpreter, and the graph is core.compat -> {core.config, core.agent_runtime} plus core.config -> core.agent_runtime.

Changes

2 files, +72 / -1.

  • core/agent_runtime/__init__.py — remove the stale run_parallel_llm docstring line.
  • tests/test_import_layering.py — new. One test, an AST scan; deferred imports (if TYPE_CHECKING: or inside a function body) stay allowed.

Dropped from the earlier revision, as asked: core/agent_runtime/parallel.py, its re-export, and the TYPE_CHECKING change in core/compat/parallel.py.

Tests

  • tests/test_import_layering.py — 1 passed.
  • tests/test_config_layering.py — 24 passed (neighbour).

The rule was falsified in both directions: adding a module-level from core.compat.request_params import RequestParams to core/agent_runtime/hook.py fails the test naming hook.py:161, and removing it turns the test green again.

ruff 0.15.21 check and ruff 0.15.21 format --check clean.

Rebased onto 3dcb0fb4.

Dependency note

None. One new test file plus one docstring line removed; no new imports, no new runtime path.

@raymondginger2018-sudo
raymondginger2018-sudo force-pushed the fix/compat-parallel-type-checking-import branch from 830db3c to e6e4481 Compare November 15, 2026 02:32
@Zongwei9888

Copy link
Copy Markdown
Contributor

Thanks for looking at import layering. We tried to reproduce the cycle on main and couldn't.

There is no cycle on main. Each of these imports cleanly as the first import in a fresh interpreter:

  • core.config
  • core.compat, core.compat.parallel, core.compat.agent, core.compat.runtime
  • core.agent_runtime
  • core.events
  • app_server

Nothing under core/agent_runtime imports core.compat, so the graph is compat → {config, agent_runtime} and config → agent_runtime, with no loop. The new test also passes on main unchanged (4 passed), so the code changes aren't what makes it green.

The new code works against what the test protects. run_parallel_llm has no callers. Adding it makes the core runtime depend, lazily, on the legacy compat layer, which is what the test is meant to prevent. The actual problem is the stale docstring line in core/agent_runtime/__init__.py, which names a module that never existed.

What we'd accept:

  • Remove that docstring line.
  • Keep test_agent_runtime_has_no_module_level_compat_import as a layering rule. Give it a docstring that describes today accurately: there is no cycle, and the rule keeps core/agent_runtime from depending on core.compat.
  • Drop core/agent_runtime/parallel.py, the re-export, and the TYPE_CHECKING change in core/compat/parallel.py.

With that, it's a quick merge.

… reference

There is no import cycle on the current tree: each of core.config, core.compat,
core.agent_runtime, core.events and app_server imports cleanly as the first
import of a fresh interpreter, and the graph is
core.compat -> {core.config, core.agent_runtime} plus
core.config -> core.agent_runtime.

What remains is the layering rule itself: core.agent_runtime is the current
runtime and core.compat is the legacy shim, so the edge must not point back
from the runtime into the shim. This keeps that direction pinned statically --
a module-level core.compat import anywhere under core/agent_runtime/ fails at
the offending line, instead of surfacing later as an order-dependent
ImportError at import time.

Also drops the stale docstring line in core/agent_runtime/__init__.py that
advertised core.agent_runtime.parallel, a module that has never existed.

Deferred imports stay allowed (if TYPE_CHECKING: for annotations, or inside a
function body for call-time), because neither executes at module import time.

Tests: tests/test_import_layering.py (1 passed); neighbour
tests/test_config_layering.py (24 passed). The rule was falsified in both
directions: adding a module-level `from core.compat.request_params import
RequestParams` to core/agent_runtime/hook.py makes the test fail naming
hook.py:161, and removing it turns the test green again. ruff 0.15.21 check and
format --check clean.
@raymondginger2018-sudo
raymondginger2018-sudo force-pushed the fix/compat-parallel-type-checking-import branch from e6e4481 to 389f66d Compare November 16, 2026 11:13
@raymondginger2018-sudo raymondginger2018-sudo changed the title fix: defer core.compat imports in parallel.py to break config<->runtime<->compat cycle test(agent_runtime): pin the layering rule and drop a stale docstring reference Nov 16, 2026
@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

Thanks — all three points are done, and you were right that there is no cycle.

Removed the stale docstring line. core/agent_runtime/__init__.py no longer advertises core.agent_runtime.parallel.

Kept the layering rule with an accurate docstring. tests/test_import_layering.py now says exactly that: there is no cycle today, the graph is core.compat -> {core.config, core.agent_runtime} plus core.config -> core.agent_runtime, and the test exists so the edge cannot point back from the runtime into the legacy shim. The symptom test (test_entrypoints_import_in_fresh_interpreter) is gone, since it was guarding a cycle that does not exist.

Dropped the rest. core/agent_runtime/parallel.py, its re-export, and the TYPE_CHECKING change in core/compat/parallel.py are all gone.

Now 2 files, +72 / -1. Rebased onto 3dcb0fb4.

Two verification notes, since a rule test that cannot fail is worth nothing:

  • I reproduced your finding first: all eight entrypoints import cleanly as the first import of a fresh interpreter on 3dcb0fb4, and core/agent_runtime has zero module-level core.compat imports.
  • The rule is falsified in both directions: appending from core.compat.request_params import RequestParams to core/agent_runtime/hook.py fails the test with Offenders: ['core/agent_runtime/hook.py:161']; removing it turns it green. tests/test_config_layering.py (24) plus the new test (1) pass, and ruff 0.15.21 check / format --check are clean.

One thing I want to flag rather than hide: with the rule test alone, the diff is a bit thin — it is one guard plus a docstring fix. If you would rather take just the docstring line as its own tiny change and let the guard wait until there is a real edge to protect, say so and I will split it.

@Zongwei9888
Zongwei9888 merged commit 916bbb9 into HKUDS:main Nov 16, 2026
12 checks passed
@Zongwei9888

Copy link
Copy Markdown
Contributor

Merged in 916bbb9. Thank you. We kept it as one change: the layering rule is cheap to keep, and the docstring line is fixed.

Zongwei9888 added a commit that referenced this pull request Nov 17, 2026
Add the news entry and changelog for the 2026-11-16 community batch
(#289, #293, #303, #307) and fold the 2026-10-31 entry into the
earlier updates. The three points under "What Deep means" now match the
numbered parts of the framework figure, self-evolution is named as
planned, and "Why DeepCode" no longer repeats them.
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