Skip to content

Deliver a page's unanswered updates to its new owner - #3272

Merged
max-sixty merged 3 commits into
mainfrom
agent-ad627e1f40bf2147f
Oct 20, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-ad627e1f40bf2147f

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

When a session took a page whose earlier owner had received a comment but not answered it, the new owner had no way to answer it. Reproduced in process: session A received the comment's delivery, session B ran leaf page claim. The claim printed nothing; leaf page state showed the answer as {"kind": "reply", ..., "received": true} with no ref; leaf response reply <A's ref> refused with "response page claim no longer matches its delivery"; and leaf wait delivered nothing, because the cursor had passed the comment. Only the prompt and Stop hooks recovered it, by freezing a separate recovery delivery at the end of a turn.

What changes

  • delivery.deliverable now includes each update the cursor has passed that still owes an answer the owner holds no usable ref for (delivery.unreferenced). Every transport (leaf wait, the Claude Code and Pi hooks, the Codex adapter and its Stop hook, leaf codex start) hands such an update to the new owner the way it hands new input, so no new command or agent instruction is needed. The receipt records the new owner's ref, after which the update is no longer deliverable.
  • The hooks' separate recovery path goes (PagePlan.recovery), and so does the received answer binding. A refusal for such an update now names the leaf wait that delivers it.
  • A receipt records a usable ref over an unreadable one (record_pickup). Review found that an update whose ref named a delivery this Leaf can't read stayed deliverable after every receipt, so each hook handed it over again.
  • Codex's tool hook still offers only input past the cursor. Finding owed updates needs the page fold, whose imports cost about 70 ms of CPU, and that hook runs after every tool call (test_codex_tool_hook_reads_a_quiet_page_without_the_page_model). Codex's Stop hook offers the rest.

Tests

The new test_a_wait_hands_a_new_owner_the_update_its_predecessor_left_unanswered covers the transfer and the answer through leaf wait. On the base, its wait blocks with nothing to deliver. test_a_new_owners_prompt_delivers_the_update_its_predecessor_left_unanswered covers the same through the prompt hook and answers with the new ref. Codex's Stop test now expects the update as a Codex offer instead of a reminder pointer. The unreadable-delivery test now asserts that the update stops being deliverable, and it fails without the record_pickup fix. The stop-guard fixture for a queued pickup now records the refs a real queue receipt records.

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

max-sixty and others added 3 commits October 19, 2026 23:39
When a session took a page whose earlier owner had received a comment but not
answered it, the new owner had no way to answer it. The cursor had passed the
comment, so `leaf wait` never handed it out again, and its `answer.ref` named
the earlier claim, which `post_reply` refuses. `leaf page state` marked it
`received` with no ref, and the refusals named "`leaf response reply
<answer.ref>`" with no route to a ref. Only the prompt and Stop hooks recovered
it, by freezing a separate recovery delivery at the end of the turn.

`delivery.deliverable` now includes each update the cursor has passed that
still owes an answer the owner holds no usable ref for. Every transport (`leaf
wait`, the Claude Code and Pi hooks, the Codex adapter and Stop hook) hands it
to the new owner the way it hands new input, and the receipt records the new
owner's ref, after which it is no longer deliverable. The hooks' separate
recovery path (`PagePlan.recovery`) and the `received` answer binding go, and
a refusal for such an update names the `leaf wait` that delivers it.

Codex's tool hook still offers only input past the cursor: finding owed
updates needs the page fold, whose imports cost about 70 ms per call, so
Codex's Stop hook offers the rest.

Behavior changes the tests record: a new owner's first delivery carries the
update (new `leaf wait` test, rewritten prompt-hook test); Codex's Stop offers
it as a Codex record rather than a reminder pointer; the stop-guard fixture
for a queued pickup now records the refs a real queue receipt records.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tops coming back

Review found that an update whose ref names a delivery this Leaf cannot read
stayed deliverable after every receipt: record_pickup skipped the new ref
because a ref under the same claim was already on record, so each hook handed
the update over again. A receipt now records a ref wherever the claim's newest
one is unusable, the same test unreferenced applies.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	TODO.md
#	skills/leaf/scripts/leaf/hook_transport.py
@max-sixty
max-sixty merged commit b631e74 into main Oct 20, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-ad627e1f40bf2147f branch October 20, 2026 06:57
max-sixty added a commit that referenced this pull request Oct 22, 2026
…ver it again if the turn ends first (#3591)

Max's decision #2 on the overnight report: confirm a Claude Code hook
delivery at the turn's next hook (option B), so an update the turn never
read is delivered again.

### The defect

Claude Code reads a hook's output only once every hook of that event has
exited. Escape before then drops it. Leaf's hook recorded the receipt as
it returned, so the update read Picked up while no model had seen it,
and nothing offered it again. Reproduced on Claude Code 2.1.308 with the
new journey steps below, against the base:

- **A resolve** whose wake Escape interrupted never reached the agent
(no hook context carried it within 120 s).
- **A comment handed over at a tool boundary** (PostToolBatch) in a turn
a wake opened was not answered within 150 s. Escape cancelled the
boundary's hooks and ended the turn ("turn ended in error"), and no
watch or nudge followed. This also settles the TODO's untested guess
that PostToolBatch shares the window.
- On 2.1.308, Escape during a wake's prompt hooks makes Claude Code
submit the queued wake again at once. On the base the retry carried only
a reminder, so an owed comment still got answered, but an update that
owes nothing was lost.

### What changes

- **Handover and receipt are separate again.** A Claude Code hook
records only the opened pickup, so the page shows the update as
delivered at once, as before. The turn's next hook records the receipt
(`delivery.confirm_turn`). That hook is PreToolUse before a `leaf`
command, PostToolBatch, or Stop, and each runs only after the model has
read the context. Pi's extension commits a hook's context itself, so its
hooks still record the receipt with the pickup
(`Harness.commits_hook_context`).
- **One rule decides re-offering.** `delivery.deliverable` leaves out
what a hook handed into the owner's still-open turn
(`awaiting_receipt`). Once that turn reads ended, the update is
deliverable again, by the same path #3272's re-offer to a new owner
uses. A turn ends when Stop closes it without confirming, or when Claude
Code's record reads idle after an interrupt (`activity.claimant_turn`).
It is also deliverable again when a prompt opens the turn again. Claude
Code reuses Leaf's turn id after an Escape, so a handover counts only
from the turn's latest opening (`handed_into_turn`). That is how a
resubmitted wake's prompt hook hands it over anew. No new event kind or
record is added: the opened pickup is the handed state, and the existing
receipt is the confirmation.
- **The re-offer reaches a session with no watch.** An interrupted turn
runs no hook. The page's server already reads Claude Code's record every
presence interval, so when it reads an interrupted turn holding such
input and no watch, it nudges the session (`presence.nudge_interrupted`,
called from `server_rows`). A watch from before the turn wakes for the
input itself. As it wakes, the watch marks the ending as messaged
(`session.woke_after`), so the server doesn't also nudge in the moment
before the woken turn starts. An earlier journey run of this branch
caught that double wake.
- **"Picked up" becomes "Delivered"** in every visible string, and
"Waiting for pickup" becomes "Waiting for delivery". Under the new
contract, Leaf knows it delivered the update into a turn, and it
delivers the update again if that turn ends unread. The protocol ids
(`pickup` events, stage `picked_up`) are unchanged, so this needs no
protocol bump. The glossary records the stage id, and the docs,
references, examples, corpus and kernel follow.
- The TODO entry for this decision is removed.

### Tradeoff

A turn interrupted after the model read a handover but before any
confirming hook ran gets that update again in its next turn. For
example, the user presses Escape during the agent's first non-`leaf`
tool call. The agent may then see the update twice. Leaf doesn't run a
hook before every tool, because each one costs a process start.

### Checks

- `leaf-dev journey claude-code` passed every step on this branch,
including three new ones. `dropped`: Escape during a wake's prompt
hooks, with a second prompt hook sleeping 6 s, and the comment is
delivered again and answered. `withdrawn`: the same for a resolve, which
reaches a hook's context. `boundary`: Escape during a PostToolBatch in a
woken turn, and the server's nudge brings the comment back, which is
answered. On the base, `withdrawn` and `boundary` fail as described
above. The `--hooks-module` arm named in the decision no longer exists,
since #3540 removed the module's watch, so the plugin's module loaded in
this one run.
- Hook cost from the journeys' debug logs: PreToolUse before a `leaf`
command went from a median of 145 ms (base, n=15) to 169 ms (n=18) under
a loaded host. PostToolBatch had a median of 253 ms on the base and 222
ms here.
- New `test_a_handover_its_turn_never_confirmed_is_offered_again` covers
an owed comment and a resolve. They are handed over, the turn is read as
interrupted, both are deliverable again, the row publisher nudges, a
renewed prompt hands them over again, and PreToolUse confirms. Tests
that read the cursor right after a handover now read the pickup and
confirm with a later hook. Model, process, runtime and snapshot tests
covering hooks, waits, receipts, activity and the CLI pass.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[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