Skip to content

Have the thread writes take the browser check from their callers, ending thread's backward import - #7233

Merged
max-sixty merged 11 commits into
mainfrom
agent-a4429899afef4f1de
Nov 26, 2026
Merged

max-sixty merged 11 commits into
mainfrom
agent-a4429899afef4f1de

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Ends the backward import agents.thread -> pages.render_gate.command. The thread writes imported the render gate's message_check, which runs a message's widgets in a browser as a page of their own and refuses the message where one doesn't draw; it needs pages.hosting and the page snapshot, so it can't sit below agents.

Now the writes take the check from whoever calls them, as #7149 passed the handover pass the check it runs and as cmd_comment already takes drawn from the command. cmd_comment, post_reply, post_response and cmd_edit each take check: MessageCheck | None = None and call it where the import was, on the same normalized markup and before the page lease. The command layer supplies it: the CLI's thread create, reply and edit; leaf codex run, through TaskConnection and each TurnFold to the App Server reply stream's opening and answer; and the website's hosted Codex turn. A caller that passes none runs no browser check, as on a host with no browser, where the message posts unrun and reports a failure when its thread draws.

To weigh:

  • Default none, not required. Every production caller that ran the check still does; requiring it would put check=None on about 230 test call sites and break base-arm evals whose post_response lacks the keyword. The cost is that a future production caller that forgets it gets the no-browser behaviour.
  • The line fork's working line passes none. Its outcome can't change: an ephemeral line holding any lf- element is refused (ephemeral-content), and the check runs a browser only where markup places a widget. Only the refusal's wording in the page's diagnostics differs, for a line whose widget also failed to draw.

This is the last of the cuts the maintainer asked for to end src/leaf's backward imports. With #7223 landed, the layers contract now lists none, so its ignore_imports key goes and the config's header says neither contract takes exceptions.

Tests: lint-imports, pre-commit, 684 focused tests after the final merge, and the check's own CLI test. A probe on message_check showed no model or process test relied on the check running implicitly.

This was written by Claude Code on behalf of max-sixty

…selection beside delivery

Two `agents` modules reached up into `commands.session`. Both edges came from
code sitting a layer away from what it uses or what uses it.

The Codex adapter has no watch of its own: `run_adapter` builds a
`session.Watch` and drives `read_watch_pass`, as `leaf wait` and a hook
harness's watch between turns do. The watch revives a dead page server through
`hosting.start_server`, so it stands above `pages`, and its three runners
belong with it. `run_adapter` and `_hand_over`, the adapter's process and its
handover to a successor copy, move to `commands/codex_run.py`, named for
`leaf codex run`, the command they implement. What a claim, the hooks and the
loop read of the adapter stays in `agents/codex_adapter.py`: its transports,
`TaskConnection`, its lease record and its start. `_offer_queued_delivery` and
`_start_adapter`, now called across the two modules, lose their underscores.
Each header keeps the paragraphs about its own half.

`presence.nudge_interrupted` imported `session.wake_inputs` and
`delivery.deliverable` from inside the function. Its one caller is the page
server's row publisher, whose header already describes it, so it moves to
`serving/server_rows.py`. `wake_inputs`, which picks out of a deliverable
batch what can wake a session, moves beside `deliverable` in
`agents/delivery.py`; the between-turns watch, `session.nudge_pending` and
`nudge_interrupted` all call it there. `presence` now imports neither
`delivery` nor `commands`, which takes it out of the cycle among `codex`,
`codex_state`, `delivery` and `thread`.

The allowances `agents.codex_adapter -> commands.session` and
`agents.presence -> commands.session` go. `wake_inputs` keeps its deferred
`read_page`, now under delivery's existing allowance
`agents.delivery -> serving.served_state.context`.

A refactor: behaviour is unchanged. Tests that patched the loop's
collaborators on `codex_adapter` patch them on `codex_run`.
`codex_adapter.capture_batch` read three fields of `session.PageTick`, the
command layer's watch result, so `agents` still leaned on the shape of a
`commands` value. It now takes the page's transaction and the batch, and the
runner that holds the tick (`codex_run.run_adapter`) unpacks it. The tests that
built a tick only to hand it over pass the transaction and batch directly.

`wake_inputs`'s docstring said receipted input is absent from the batch; it now
names the exception, an update still owed whose owner holds no usable
`answer.ref`, which `deliverable` hands over again. `codex.py`'s header names
`codex_adapter.py` as the header that says how `TaskConnection` folds
notifications and handles failures, and the agent-journey reference sends a
change to `delivery.wake_inputs` through the Claude Code and Pi journeys.

A refactor: behaviour is unchanged.
Merges #7216 and #7217. #7217 took delivery's reads of the page's work to
`presence.read_work`; this branch had already taken `nudge_interrupted` out of
`presence` and `wake_inputs` out of `commands.session`, so the conflicts resolve
to this branch's homes for both, `read_work` beside presence's readings, and
neither `commands.session` allowance.

`wake_inputs` read and folded the page again for a batch `deliverable` had just
read by the same fold. It now takes that work reading, as `batch_data` does, and
reads no page itself. A watch pass reads each page's work once, hands it to
`deliverable` and keeps it on the tick (`PageTick.work`), so the between-turns
watch selects its wake input by it; `nudge_pending` and
`server_rows.nudge_interrupted` read the work once and pass it to both. A nudge,
and a pass over a page with a batch, folds the page once instead of twice.

The layers contract keeps three allowances, none of them a `commands.session`
one, and `agents` holds no import cycle. Behaviour is unchanged.
A watch pass already reads each page's work to find its batch and keeps it on
the tick, but `leaf wait`'s delivery (`session.delivery_record`) and the Codex
capture (`codex_run`, `codex_adapter.capture_batch`, `codex.append_batch`)
read and folded it again. Both now pass the tick's work on, as `batch_data`
takes it, so a pass folds a page once. `append_batch` and `capture_batch` read
the work themselves only where a caller hands none.

Behaviour is unchanged.
# Conflicts:
#	src/leaf/agents/codex_adapter.py
….thread's import of the render gate

`thread.cmd_comment`, `post_reply` and `cmd_edit` each imported
`pages.render_gate.command.message_check`, a browser run of the message's markup that
needs `pages.hosting` and the page snapshot, from below them. Each write now takes the
check from its caller, as a `check` argument of type `thread.MessageCheck`, and calls
it where it ran the import: on the same normalized markup, before it takes the page
lease. The command layer supplies it. The CLI's `thread create`, `reply` and `edit`
pass `message_check`, and so do the two processes that commit a Codex App Server
answer: `leaf codex run`, through `TaskConnection`, each `TurnFold` it makes and the
fold's `AppServerReplyStream`, and the website's `HostedTurn`.

`cmd_comment` already takes `drawn`, the drawn page's reading of its target, from the
command the same way: the render gate stands above the thread writes, and a host may
have no browser, where the message posts unrun. The writes now say what they need of
the gate without importing it, and the layers contract needs one allowance fewer.

The argument defaults to none, which runs no browser. About 200 test calls and 30 test
constructions of the fold, the stream and the connection post without one, and so do
two writers whose messages the check never decides: the line fork's working line and
the harness's failure receipts. The line is ephemeral progress, which
`_compose_and_append` refuses (`ephemeral-content`) whenever its markup holds an `lf-`
element, and the check runs a browser only where the markup places one. A failure
receipt's words are Leaf's constants and hold no markup.

Refactor: behaviour is unchanged, apart from the words of one refusal. A line fork's
line holding a widget is refused as before, but always as `ephemeral-content`, where
before a widget that also failed to draw was refused as HTML that doesn't draw; that
refusal reaches only the page's diagnostics (`fork_outcome`).

Tests: the website follower's stand-in reply stream takes the check and the test
asserts the hosted turn hands it `message_check`. A response test that unpacked a
`dict[str, str]` of options into `post_response` passes `title` directly, since the
type check reads such a dict as possibly reaching `check`.
# Conflicts:
#	.config/importlinter.ini
#	src/leaf/agents/codex.py
#	src/leaf/agents/codex_adapter.py
#	src/leaf/commands/codex_run.py
# Conflicts:
#	.config/importlinter.ini
#	src/leaf/agents/thread.py
leaf-agent
leaf-agent previously approved these changes Nov 26, 2026
With the clerk's and the thread's backward imports cut, the layers contract allows
none, so its ignore_imports key and the header's account of allowances go.
@max-sixty
max-sixty merged commit d4e0cab into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-a4429899afef4f1de branch November 26, 2026 05:34
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