Repository navigation
Move the imports a module already loads from its functions to its top - #7243
Merged
Merged
Conversation
leaf-agent
previously approved these changes
Nov 26, 2026
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…ference needs them (#7253) `page check` of a page that needs no browser, and every `leaf thread create`, `reply` and `edit`, loaded the whole render runner and the Codex transport, which registers an exit handler as it loads. The predicate that decides whether a browser is needed lived in the module that runs one, and `agents/inference.py` imported the transport at its top for every harness. - `needs_browser` and `places_judged_widget` move unchanged to a new `source/browser_judged.py`, which imports nothing of the browser run. - `message_check` and `message_page` move to a new `pages/render_gate/messages.py`. `message_check` decides with `places_judged_widget` first and imports the browser run only on the branch that runs it, as `src/AGENTS.md` now allows for start-up work. #7233's interface, where callers pass the check, is unchanged. - `inference.py`'s four Codex call sites import the transport themselves. Measured in a fresh interpreter on a claimed page: a plain `thread reply` loads 440 modules instead of 470, `page check` of a plain page 381 instead of 401, and neither, nor a `page picture` refusal, loads `agents.codex`. A reply placing a Mermaid diagram runs the browser and refuses with the same report as before. `test_hook_registration` now asserts that a reply with HTML and a plain `page check` load neither the browser run nor the Codex transport; both assertions fail on main. Found by Codex reviewing #7243. Tests: `lint-imports`, pre-commit, and 108 model and process tests over the moved functions, inference and titles. > _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.
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
leafmodule, a freshimportloads 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 theacyclic_siblingscontract (#7230) counts an import inside a function as it counts one at the top.src/AGENTS.mdnow 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 --runtimeandpage open, so only the moves no process can notice went in.deepcopystays insidestate_definition, since Python 3.15'sdataclassesno longer loadscopy.test_forkspatchedactive_enclosingwhere it is defined, whichforksused to look up at each call; it now patchesforks' copy.Tests:
lint-imports, eachleafmodule imported alone, the module probe of 34 processes, and 548 model tests of the touched modules.