Skip to content

Move the imports a module already loads from its functions to its top - #7243

Merged
max-sixty merged 7 commits into
mainfrom
deslop-please
Nov 26, 2026
Merged

max-sixty merged 7 commits into
mainfrom
deslop-please

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

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

leaf-agent
leaf-agent previously approved these changes Nov 26, 2026
@max-sixty
max-sixty merged commit cf0d718 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the deslop-please branch November 26, 2026 06:54
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_
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