Skip to content

Run the Leaf plugin's hooks in leaf.page's hosted Codex - #7582

Merged
max-sixty merged 2 commits into
mainfrom
website-installs-leaf
Nov 29, 2026
Merged

max-sixty merged 2 commits into
mainfrom
website-installs-leaf

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

leaf.page's container installs the Leaf plugin into Codex, but Codex runs a plugin's hooks only once its config records a trusted hash for each, and nothing there recorded one, so no Leaf hook ran on a hosted turn. The website now starts and resumes every thread with App Server's bypass_hook_trust request override. A visitor's comment sent while a turn runs then reaches that turn at its next tool call or as it would stop, instead of waiting for the next turn. The hooks cost about 1.2 s a turn on the website-adapter journey.

What the diff doesn't show: the override trusts every hook source in the container's Codex home, not only the plugin's; the thread already runs with full access to its per-visitor container, so persisting the plugin's hashes at image build would add a build step for no protection. Running the hooks exposed places where EmbeddedHarness answered as if no hook ran (the Stop guard held every hosted turn open; SessionEnd on an idle unload ended the page's claim), so the embedded session's lifetime is now its App Server process ({"app_server": pid}, which moves the session record's protocol since to 65). Hook offers made the website's reuse of a held delivery go wrong in several ways Codex's review found, so each website start now retires every unaccepted record and captures the page's input afresh, and a hosted turn's ending and every resume share one receipt function, which runs recover_codex_receipt and then receipts whatever the thread's ended turns left owed. The commit message has the detail.

Max asked for the hooks to be marked trusted in the container. Reviewed by Codex over seven rounds. Focused model and website tests and pre-commit pass, and leaf-dev journey run website-adapter passed against a real agent on this head (the release step took 27 s).

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

The website's container installs the Leaf plugin into Codex, but Codex runs a
plugin's hooks only once its config records a trusted hash for each, and nothing
in the container recorded one, so no Leaf hook ever ran on a hosted turn. The
website now starts and resumes every thread with `bypass_hook_trust`, an App
Server request override Codex 0.170 and 0.172 honour. A probe on 0.172 ran the
SessionStart, UserPromptSubmit, PostToolUse and Stop hooks with it, on a started
thread and on one a fresh App Server resumed, and none without it. The override
trusts every hook source rather than the plugin's alone; the thread already runs
with full access to its per-visitor container, so a hook can do nothing the
agent's own commands couldn't, and persisting the plugin's hashes at image build
would add a build step for no protection.

What the hosted agent gains: a comment the visitor sends while a turn runs reaches
that turn at its next tool call or as it would stop, as in a terminal Codex task,
where before it waited for the turn to end and a new one to start. The hooks cost
about 1.2 s a turn on the local website-adapter journey (SessionStart 0.1 s, each
PostToolUse 0.1-0.5 s, Stop 0.14 s). The follower logs each hook run as
`turn_hook_completed`, so its status and duration show in Workers Observability.

`EmbeddedHarness` had answered as if no hook ran in its sessions. Three of its
answers changed:

- Its Stop hook held each hosted turn open with "no embedded harness is holding
  this page": the watcher question fell to the base answer, a wait lease or hook
  delivery, which the host never has. The host starts a turn for each new input,
  and a hook runs only inside a turn it started, so `watcher_live` is now true
  and the unreachable `nothing_listening` is gone. The extra Stop round had
  stretched the journey's turn to 39.5 s; with the fix it ended on the agent's
  answer in 20.9 s and 27.5 s, against 15-33 s before hooks ran.
- App Server ends an idle thread's Codex session as it unloads it, and the
  SessionEnd hook that runs then ended the website's claim on the page, which
  then read its agent as gone until the visitor's next comment. The embedded
  lifetime is now `{"app_server": pid}`, a form of its own, so SessionEnd
  suspends the session as it does a desktop Codex chat's, and the claim lives as
  long as the App Server process. Codex's review found this with a shortened
  unload delay. The session record's schema gains the form, so its `since`
  moves to 65. A claim of a passed generation reads without its lifetime, so a
  harness rebuilt from one carries no pid; such a claim had raised KeyError for
  every reader that rebuilt its harness, as after a failed App Server restart.
- `turn_takes_input` read hook delivery, which embedded sessions lack. Every
  harness's tool and Stop hooks hand input into a running turn, so the base
  method now asks only whether Leaf's hooks ran for the session, and Codex's
  override is gone.

A hosted turn's ending receipts every update it picked up and left unanswered,
including those the hooks handed it mid-turn, where before it receipted only the
delivery it was started with. A comment the agent acknowledged mid-turn and then
didn't answer before the turn failed was left picked up by a gone turn, owed
forever, with nothing to deliver it again. The ending's `turn_failure_reported`
counts as outstanding only the receipts it couldn't write; it had also counted
updates the agent answered.

A hook's offer that no turn accepted outlives its turn, and the website's next
start reused it whatever had happened since. That went wrong three ways. An agent
can answer a comment a hook offered without running the delivery's `leaf delivery
ack`, and the next turn then asked again for the answered comment, ahead of the
visitor's newer one. After App Server died and the website started it again, the
old process's claim no longer read as live, so the start removed the offer and
refused, and the visitor got `startup_failed`. And an acknowledgement cut short
between accepting the offer and writing its pickup left the comment owed with no
pickup, held out of every later capture, so the next start refused or skipped it.
`prepare_codex_delivery` no longer reuses a held record: each start retires every
record no turn accepted and captures the page's input afresh, in log order, asking
for an answer only to what the page still owes. A page another session took still
refuses. A failed start no longer withdraws its offer itself, since the next
start retires it. The Worker's failure receipt retires the unaccepted record
holding the move it settles: an offer, which also frees a running turn's hooks to
offer the visitor's next comment, or input a hook collected behind one, which had
asked the agent to answer a comment the visitor was told wouldn't be. Terminal
Codex's adapter still re-queues an answered offer, and is left as it was.

A hosted turn's ending and every resume account for the thread's earlier turns
in one function, `receipt_unanswered`, which receipts each move the thread picked
up and still owes, whichever turn took it: a thread runs one turn at a time, and
the harness's lock keeps the next from starting until the receipts are written.
It first runs `recover_codex_receipt`, as the terminal adapter does before each
offer, so a cut-short acknowledgement's comment is receipted with the turn that
took it. A resume had receipted nothing, whether it stopped a turn a dead
follower left running or found that turn already ended: the comments the turn
had taken stayed owed with no turn coming for them.

Tests: the Stop guard's watcher case gains an embedded claim; a hosted turn's
PostToolUse and Stop hooks hand it a comment that arrived mid-turn; a failed turn
receipts a comment its hook handed it, whether the acknowledgement finished or was
cut short, and counts nothing outstanding; the next hosted turn asks only for the
comments still owed, after the agent answered part of a hook's offer; a restarted
App Server's first turn takes the old turn's unread offer; a repeated start
captures the same input in a new delivery, and one after a failed start asks only
for the visitor's retry; a comment the Worker turns away mid-turn, offered or
collected behind an offer, isn't asked of the agent and leaves the next one to
reach the turn; a resumed thread's unwatched turn, stopped or already ended, has
its unanswered comment receipted; SessionEnd keeps a hosted thread's claim; a passed
generation's claim still names its harness; the follower logs a hook run; and the
requests pinned for thread/start and thread/resume carry the override.
@max-sixty
max-sixty merged commit 8600ffd into main Nov 29, 2026
7 checks passed
@max-sixty
max-sixty deleted the website-installs-leaf branch November 29, 2026 02:20
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