Repository navigation
fix: defer core.compat imports in parallel.py to break config<->runtime<->compat cycle - #289
Open
raymondginger2018-sudo wants to merge 1 commit into
Conversation
…untime<->compat cycle core/compat/parallel.py imported core.compat.agent and core.compat.request_params at module level. Because core.compat.__init__ imports core.compat.parallel, and core.compat.agent imports core.compat.runtime which imports core.config (which imports core.agent_runtime.tools.mcp), a module-level import here closes the cycle and can turn 'import core.config' into an ImportError depending on which entrypoint is loaded first. Move both imports under TYPE_CHECKING (the module already has from __future__ import annotations, so all uses are annotation-only). Add core/agent_runtime/parallel.py as the public run_parallel_llm entry point (docstring already referenced it) with its core.compat.parallel import deferred into the function body, and re-export it from core.agent_runtime.__init__. Add tests/test_import_layering.py as a regression guard: three entrypoints must import in a fresh interpreter, and no module-level core.compat import may appear anywhere under core/agent_runtime/ (AST-scanned with parent pointer tracking so TYPE_CHECKING and function-body imports are allowed).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Break the
core.config ↔ core.agent_runtime ↔ core.compatcircular import by deferringcore.compatimports incore/compat/parallel.pytoTYPE_CHECKING, and extract a thincore/agent_runtime/parallel.pymodule with a single public entry pointrun_parallel_llm.Why
The module-level import graph contains a 3-way cycle:
Today the cycle doesn't detonate (import order happens to work), but it's fragile: any future module that imports
core.compat.parallelbeforecore.configis fully initialised will hit aPartiallyImportederror. This PR makes the dependency direction safe and adds a guard test to prevent regression.Changes
core/compat/parallel.py— movecore.compat.agent/core.compat.request_paramsimports underif TYPE_CHECKING:(already usesfrom __future__ import annotations, so all usages are annotation-only).core/agent_runtime/parallel.py(new) — thin public module withrun_parallel_llm; importsParallelLLMlazily inside the function body.core/agent_runtime/__init__.py— re-exportrun_parallel_llm.tests/test_import_layering.py(new) — guard test: 3 fresh-interpreter import checks + AST scan asserting no module-levelcore.compatimports undercore/agent_runtime/**.Verification
-p no:cacheproviderneeded on Windows due to pytest cache plugin + subprocess interaction).core.compatimport incore/agent_runtime/helpers.py→ guard correctly went RED → removed → GREEN.Notes