Repository navigation
Check that each src/leaf package's modules import each other without a cycle - #7230
Merged
Merged
Conversation
…a cycle import-linter's layers contract checks only the imports between `src/leaf`'s eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224); this adds import-linter's `acyclic_siblings` contract over every package (`ancestors = leaf.*`), which recurses into subpackages, such as `served_state` and `render_gate`, so a new cycle fails pre-commit as an upward import does. A planted deferred import from `presence` into `delivery`, and one from `served_state.context` into `served_state.page`, each fail the contract, naming the import; the tree as it stands passes. The config's header says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle. `src/AGENTS.md` states the rule beside the layering one.
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…#7243) Moves 71 imports from inside functions to the top of their modules, in 19 files, so those modules' tops list what they depend on. Each one moved names a module that importing its own module already loads: for every `leaf` module, a fresh `import` loads the same modules on this branch as on main, so no process loads anything more. Many were placed inside functions to dodge an import cycle, which no longer works, since the `acyclic_siblings` contract (#7230) counts an import inside a function as it counts one at the top. `src/AGENTS.md` now says when an import belongs inside a function: where loading it with its module would add start-up work to a process started often, fail on a platform, or set off an effect. `source/registry/schema.py`'s header now says when pywhatwgurl loads. To weigh: the other 336 stay inside functions, each keeping a module out of some process that loads its module. A first version also moved 52 that no hook or common agent command needed deferred; Codex's review found six rarer processes that then loaded more, such as `page export --runtime` and `page open`, so only the moves no process can notice went in. `deepcopy` stays inside `state_definition`, since Python 3.15's `dataclasses` no longer loads `copy`. `test_forks` patched `active_enclosing` where it is defined, which `forks` used to look up at each call; it now patches `forks`' copy. Tests: `lint-imports`, each `leaf` module imported alone, the module probe of 34 processes, and 548 model tests of the touched modules. > _This was written by Claude Code on behalf of max-sixty_
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.
import-linter's layers contract checks only the imports between
src/leaf's eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224). This adds import-linter's ownacyclic_siblingscontract over every package (ancestors = leaf.*). It recurses into subpackages such asserved_stateandrender_gate, so a new cycle fails pre-commit as an upward import does, naming the import that closes it.A planted deferred import from
presenceintodelivery, and one fromserved_state.contextintoserved_state.page, each fail the contract; the tree as it stands passes. The config's header now says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle;src/AGENTS.mdstates the rule beside the layering one.The maintainer asked for the cycles inside
agentsto be broken; this widens that to every package and keeps them broken. The two allowances the layers contract still lists are cut by #7223 and the PR after it.Tests:
lint-imports(both contracts), pre-commit, and the two planted cycles above.