Skip to content

Load the browser run and the Codex transport only where a check or inference needs them - #7253

Merged
max-sixty merged 5 commits into
mainfrom
agent-a641a7a7d6f6dfb84
Nov 26, 2026
Merged

max-sixty merged 5 commits into
mainfrom
agent-a641a7a7d6f6dfb84

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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. Have the thread writes take the browser check from their callers, ending thread's backward import #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

`needs_browser` and `places_judged_widget` move from
`pages/render_gate/page_code.py` to a new `source/browser_judged.py`, which
owns the fact "whether this revision runs what only a browser can judge" and
reads only the document, the revision artifact and source-layer helpers. The
render runner's header keeps the run and points at the new module for what
needs one and why. Every caller is cut over: `page check`, `message_check`
and the plain-pages journey. The functions are moved unchanged.

Plain `page check` on a page that needs no browser (a heading and a
paragraph, `browser: null`) no longer imports the render runner, and with it
`serving.event_endpoint`, `agents.inference` and `agents.codex`, so it no
longer registers Codex's atexit handler. Measured in a fresh interpreter on
such a page: `check_page` loaded 306 modules before and 285 after (96 and 83
of them `leaf.*`), with no module newly loaded. The whole
`leaf page check` process went from 411 imported modules to 392
(`python -X importtime`). The report is unchanged.
… one

`message_check` and `message_page` move from `render_gate/command.py` and
`render_gate/page_code.py` to a new `render_gate/messages.py`, which decides
with `browser_judged.places_judged_widget` first and imports the browser run
(`page_snapshot`, `render_gate.command`) inside the function, on the branch
that runs it. Every caller of the check is cut over: `leaf thread create`,
`reply` and `edit`, the Codex adapter (`codex_run`), the website's hosted
turn, and the turn-follower test. The thread writes still take
`check: MessageCheck | None` from their commands. `message_page` moves
unchanged, and `message_check` only gains the deferred imports.

An agent runs these commands at every message. Measured on a fresh
interpreter running `leaf thread reply` on a claimed page:

- plain-text reply: 470 modules before, 440 after (105 and 83 of them
  `leaf.*`). The render runner, `serving`'s state and lifetime modules and
  `agents.codex` no longer load, and the process registers one atexit
  handler instead of two.
- reply whose HTML places no such widget: 484 before, 453 after (111 and 88).
- reply placing an `lf-diagram`: the same modules plus `messages`. A diagram
  that draws still posts after the browser run, and one with a Mermaid syntax
  error is still refused with "the HTML in the reply doesn't draw" and the
  same page report.

`test_a_session_holding_a_page_loads_only_the_dependencies_each_step_uses`
now also asserts that the Stop hook, the prompt hook and a plain reply load
neither `render_gate.command` nor `agents.codex`. Run against the previous
commit's code, only its reply case fails, naming the import chain through
`render_gate/command.py`.
…the message check's decision

`agents/inference.py` imported the App Server transport (`agents.codex`) at
its top, and importing that module registers `stop_private_app_servers` with
atexit. So every importer of inference loaded it: `thread_titles`,
`serving.event_endpoint`, and through it the render runner and every command
that reaches one, even where the harness is Claude Code or Pi. Each Codex call
site (`open_thread`, `ask`, `app_server_generate`, `codex_generate`) now
imports what it uses from `agents.codex`, and the module header says why.
Nothing else in inference needs the transport. The Codex title test patches
`private_app_server` on `agents.codex`, where the call site now reads it.

Which processes load `agents.codex`, measured in a fresh interpreter on a
claimed page (origin/main / previous commit / this commit):

- plain `thread reply`: yes / no / no
- `thread reply` with HTML that places no browser-judged widget: yes / no / no
- `page picture` on a message that doesn't exist: yes / yes / no
  (336 -> 334 modules, 2 -> 1 atexit handlers, same refusal)
- `page check` of a page that needs no browser: yes / no / no
- importing inference, thread_titles or event_endpoint, or choosing Claude
  Code's generator: now no

The hook-registration import test's reply now carries HTML
(`<em>Checking.</em>`), so it reaches `message_check` and its widget
predicate. A new test runs `page check` in a fresh process on a page that
needs no browser and asserts it loads neither the browser run
(`render_gate.page_code`) nor `agents.codex`. Against origin/main's code, the
reply case and the page-check test fail, naming the import chains. With the
browser run's imports moved above the predicate in `message_check`, the reply
case fails too.

The headers of `render_gate/messages.py` and `render_gate/page_code.py` now
say when a message runs the check: on HTML only, where
`places_judged_widget` selects its markup.
# Conflicts:
#	src/leaf/pages/render_gate/command.py
The header moved from page_code.py carried the counts of a widgets-draw-as-written
eval run: 5 of 6 Codex thread messages holding a Mermaid sequence diagram didn't
draw, and their authors never ran --render. #7247 drops them from page_code.py,
since the tree states what holds now and a measurement goes in the commit.
@max-sixty
max-sixty merged commit 225d93e into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-a641a7a7d6f6dfb84 branch November 26, 2026 07:23
max-sixty pushed a commit that referenced this pull request Nov 29, 2026
#7602)

Tonight's nightly review of the last day's commits and a survey of
existing files turned up text that now describes code that has moved or
changed, plus two exports nothing imports. This PR corrects them.
Nothing it touches changes behavior. `pnpm run check` and pre-commit
pass on the branch.

- **README:** the Claude Code band line now lists how much waits on the
user with the first item's name, the agent's status and the unread
threads, with a `more` button for On Me. #7560 dropped the open-threads
count the README still described, and #7566 added the button.
- **`docs/website.html`:** #7582 runs the plugin's hooks in the hosted
Codex, so a message sent during a turn now reaches that turn, as the
header of `worker/leaf_website/__init__.py` says. The page still said it
waits for the turn to end.
- **`packages/detail/defaults.css`,
`browser/runtime/readings/user-place.ts`:** these now point at
`dial.js`. Since #7591, `dial.js` holds the dial's layout, motion and
`holdPlace`, and `lf-dial.js` only registers the widget.
- **`lf-toc`:** it no longer exports `Toc` and `TocMessage`. Their only
importer outside the module was the story test that #7542 deleted.
- **Eval headers and `notes/agent-usability-evals.md`:** `needs_browser`
is now cited at `source/browser_judged.py` (#7253), not
`render_gate/page_code.py`. authoring-evidence.md's chart line is now
named by its subject, since that line no longer names `lf-chart`.
- **Small cleanups:**
- `src/leaf/commands/hooks.py` had the same `TYPE_CHECKING` import twice
in a row; one is removed.
- The docstring of `tests/browser/test_render_drafts.py` now says what
its one test protects.
- The header of `render-checks/scrollbars.js` no longer carries a
timing, which belongs in a commit message.

Co-authored-by: leaf-agent <[email protected]>
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