Repository navigation
Fork the conversation at each turn's end to put the agent's missed asks On me (experimental) - #4801
Merged
Merged
Conversation
The Workflow tab described Leaf's skill, package instructions, delivery handling and Stop hook notices in four separate places, and left out the compaction reload, x-instructions, data-contract instructions, package audiences beyond the author, and command refusals. A new section, Agent instructions and notices, lists each source with what it tells the agent and when the agent reads it; the package-instructions details block moves into it.
The section claimed every instruction sits where it applies, though the bookkeeping rules live only in the skill; said page instructions joins x-instructions without --use; and left out PostToolBatch, unpicked input and how a delivery reaches the agent.
… states Late in long sessions agents leave decisions waiting on the user only in their chat replies, so On me reads empty, and rewording the skill changed 0 of 6 replays. Leaf's clerk now forks the conversation as each main-loop turn ends in a Claude Code session holding a live page, asks it what the page's bookkeeping misses, and writes the answer itself: - each ask (🟡) or reversible call (🔵) left to the user that On me lacks becomes a to-do on the user, marked `by: "leaf"`, which the On me card shows as added by Leaf from the agent's reply; - the status line becomes the `text` of a `waiting` declaration, shown while no start holds an item, so a page waiting on the user says for what; - each record written, and each missed step the fork names, reaches the agent as one line at its next prompt or tool boundary (`clerk.queued`). `src/leaf/clerk.py` is the one home every harness shares: the prompt with each page's state (On me, On you, undelivered input, asks waiting on nobody, Leaf's items the user has settled), the answer schema, and applying the answer. `hooks/claude-code.ts` forks with `$.model.fork` off the turn's path and hands the answer back through `leaf hook --fork`. An answer that arrives after another turn opened is dropped. The `todo` record gains optional `by` and `status` gains optional `text`; the build's protocol comparison accepts both at protocol 36, so no bump. Replayed on the 21 recorded turn ends, three runs each on Opus 5.5 with the shipped prompt: 59/63 🟡 asks found, 33/36 🔵 calls found, 63/63 answers valid, $0.11 per warm fork (median).
The conversation loop's On lists now say that in Claude Code Leaf checks each reply as the turn ends and adds decisions left only in chat to On me, that this doesn't register questions for the agent, and how to drop one that isn't the user's to decide. How it works lists the fork among the sources of agent notices. The clerk takes the page lock a command's write takes, and its notice names `leaf task end`'s outcome as the positional argument it is.
Claude Code's debug log redacts every `*_tokens` field, so the clerk's usage line read [REDACTED]; Claude Code already logs each fork's tokens as `Forked agent [plugin_model_fork] finished`. The header records what the claude-code journey measured: twelve warm forks at $0.02-0.04 and 3-11 s.
The fork now asks one thing, in Leaf's own words: each decision, answer,
permission or step the agent left to the user, in its replies or anywhere in the
conversation, that no On me item holds and the user hasn't answered since. Its
answer is `{"asks": [{page, title, quote}]}`. The 🟡/🔵 markers come from the
user's personal skills, and Leaf shouldn't depend on them; the user chose to start
the fork from this one class of finding.
Removed with the status and missed parts: the fork-written status line (the
optional `text` on `status`, its served-state field, the listening line in
activity-words.js, `leafRow` and the Claude Code band) and the missed-step lines.
What those steps found that the page state alone settles is code's to report, not
a model's. Kept: the On me to-dos marked `by: "leaf"`, a context line for each at
the agent's next step, and dropping an answer once another turn has opened.
Replayed on the same 21 turn ends, three runs each on Opus 5.5: 59 of 63 labelled asks found, 62 of 64 findings labelled asks and 2 borderline, none false, $0.08 per warm fork. In the claude-code journey twelve forks cost $0.015-0.026 each and took 1-6 s.
# Conflicts: # browser/runtime/floating-panel.js # dist/kernel/kernel.json # dist/kernel/leaf.js
…fork The fork is a second look at the agent's own bookkeeping, not a second actor, so the user never meets it and the agent keeps the say over every record. A to-do it adds is now the agent's, authored by the agent's session with no `by: "leaf"` field, and On me no longer shows "added by Leaf from Claude's reply". The agent hears each one at its next step as its own and keeps or ends it; the fork is shown every ended to-do on the user, whoever ended it, so it never adds one back. clerk.py's header states the three principles. Behavior change: the todo event and the served obligation lose the optional `by` field, and the On me card loses its "added by Leaf" line.
# Conflicts: # docs/how-it-works.html
How it works, the conversation-loop reference and clerk.py's header now say the fork is an experiment that runs only in Claude Code.
# Conflicts: # docs/how-it-works.html
An independent review found that the fork could undo or slip past the agent's own say over its records. Each change below makes Leaf, not the fork's wording, hold the guarantee the clerk header states: - An ask whose title matches a to-do on the user that the agent or the user ended is skipped, as one matching an open to-do already was; before, a dropped ask came back under a new id when the fork named it again. - The check that no turn has opened since the fork read the conversation runs under each page's locks and then the session's, the lifecycle's lock order, so a prompt can no longer open a turn between the check and the writes. - Each page's lines for the agent are queued as that page is written, so a later page's failure no longer leaves earlier to-dos unreported. - The hooks module logs every failure of the fork to the debug log, never the conversation, and a turn that ended while a failed fork was out still forks. - The module forks after every answered turn and lets Leaf say whether the session holds a page, since the band can lag a claim the turn's last command made. A prompt that Escape drops still loses the lines its hook carried; the header says so, and what would close it. The How it works row is renamed "Turn-end check (experimental)" and, with its intro sentence, rewritten to say the to-dos are ordinary ones the agent is told of, after a fresh read found the old wording hard to follow.
leaf-agent
approved these changes
Oct 31, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 31, 2026
…ecks for (#4850) How it works described the experimental turn-end fork (#4801) only in two sentences appended to the paragraph on where agent guidance lives, and didn't say what the fork looks for. It now has its own block under "Harness connections and receipt", beside "Claude Code integration". The block covers: - what the fork is asked to name: a decision, an answer, a permission, or a step the agent left to the user that On me doesn't hold; - what it leaves out, and that Leaf skips an ask with the same title as a to-do on the user; - what Leaf writes (the agent's own to-do, with nothing marking the fork) and when the agent hears it; - why it costs the turn nothing: it starts after the turn ends, reads the prompt cache, and writes nothing more once another turn opens. The guidance table's row now points at the block instead of restating it. `leaf page check` passes on the docs page, as does `tests/model/test_product_page.py`. A fresh reviewer read the rendered block and checked each sentence against `src/leaf/clerk.py` and `hooks/claude-code.ts`, and found no contradiction. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Late in long sessions, agents leave decisions waiting on the user only in their chat replies, so On me reads empty: on 2026-10-25 five sessions holding live pages did this, and rewording the skill changed 0 of 6 replays of such a session. This adds an experimental check, in Claude Code only: as each main-loop turn ends while the session holds a live page, Leaf forks the conversation and asks the fork what the agent left to the user that On me doesn't hold. Leaf adds each ask to On me as the agent's own to-do, and tells the agent at its next step.
Principles
src/leaf/clerk.py's header states the three that bound it:How it runs
hooks/claude-code.ts, onturn.completefor a turn the model answered, runsleaf hook --if-claimed --forkfor the question, forks with$.model.fork(which resends the main thread's own last request, so the cache serves the conversation), and hands the reply back throughleaf hook --fork. A turn that ends while a fork is out starts one more after it, whether or not the first failed.src/leaf/clerk.pyis the fork's one home, shared by every harness: the prompt with each page's On me, the answer schema ({"asks": [{page, title, quote}]}, checked by Leaf since$.model.forktakes no schema), and applying it. Codex and Pi would add only the fork call.src/leaf/hook_transport.pycarries the queued lines at the next prompt or PostToolBatch hook and clears them.leaf hookgains--fork;agent_state._page_statebecomes publicpage_state.conversation-loop.md("The On lists") tells agents the to-dos it adds are theirs to keep or end.Measured
Replaying 21 recorded turn ends three times each on Opus 5.5 (transcript copies cut at the turn end, all tools denied), the shipped question found 59 of 63 labelled asks; 62 of its 64 findings were real and 2 borderline, none false, and 2 of 39 runs at clean turn ends named anything. Labels were written before the runs and are one agent's judgment. A warm fork cost $0.08 (median); in the
claude-codejourney, twelve forks cost $0.015–0.026 each and took 1–6 s.Checks
tests/model/test_clerk.pyand the Claude Code module tests (with a fake$.model.forkin the driver, answering or refusing) pass, as do the hooks, todos and obligations tests,pnpm run checkandpnpm run test:runtime. Theclaude-codejourney passed all 12 steps on an earlier revision of this branch, before the fork's to-dos stopped carrying a mark of their own. An independent review found seven defects, and this revision fixes six of them.Left out
leaf page statelists them, but the agent isn't told. Confirming the lines from the transcript, asdelivery.confirm_entereddoes for input, would close that gap.conversation-loop.mdsentence has no eval score.