Repository navigation
Answer a held thread message from a fork of the Claude Code conversation - #4892
Merged
Merged
Conversation
…read messages from one notes/fork-replies.md records what Leaf's hooks module can fork, measured on Claude Code 2.1.316 with Opus 5.5 by a probe module run under `claude -p`: `$.model.fork` answered mid-command in 1.9 s at 44k tokens and 4.5–6.0 s at 225–274k when the main thread's cache entry lived, and in 13.9 s when it didn't; a forked subagent answered in 3.7–8.6 s. Mid-turn the fork misses the tool call now running; at a turn's end it sees the final reply. It proposes, unbuilt, a fork for each thread's waiting messages that answers or hands them to the session, with Leaf holding them from delivery while a live fork lane decides, the reply posted as the session's, and the session reading the exchange at its next step through the delivery that exists. notes/leaf-run-sessions.md drops its `--fork-session` side-lane measurement, which the module's primitives supersede, and points its side-lane option and table cell at the new note.
In Claude Code, a user message in a thread the session hasn't picked up is now held from delivery while a fork of the session's conversation decides: the fork answers from the conversation, posted as the agent's reply, or hands the thread to the session, which receives it as any input. `src/leaf/forks.py` owns the state machine: a thread with waiting messages is held, answered or with the session, computed by `forks.held` from the log, the session's hand-over record (`sessions/<session>.forks`, protocol 36) and its forks lane, with nothing stored. The lane is the session's pages follower (`hooks.cmd_pages`), which lists held threads for the module to fork, and hands a thread over itself once 30 s have passed since its newest message. A lane holds only messages admitted after it took its lease, so a restarted follower never re-holds what an earlier one let go. Every way out of the hold but a killed follower is a write the session's waiters read: the reply in the log, a hand-over in the record the watch's reading stamps, which also nudges a session no watch follows. The reply is fenced to the hold under the lock its append takes (`thread.Receipt.fence`), so it writes nothing once the session has the message. A follower that stops with a thread held nudges what it leaves, as a watch does. The session hears of a fork's reply at its next prompt or tool boundary, with the reply in the thread's digest and a queued line asking it to correct the reply where its context shows it wrong. `LEAF_FORK_REPLIES=off` in Claude Code's environment turns forks off; a module or Leaf without the lane holds nothing and delivers as before. The fork's prompt hands over whenever it would have to work an answer out, and whenever the user answers or decides something the session asked. Replayed on 15 fresh real thread messages it answered 8, one wrongly, and handed over 7 correctly; `notes/fork-replies.md` has the replays, timings and limits. Behavior changes: admission no longer nudges for a held message (its hand-over nudges instead), and `delivery.deliverable` leaves held messages out.
`leaf-dev journey claude-code --forks` runs the session with forked replies on and, in place of the delivery steps, asks a question while the session is idle, one during a 25 s command, and a request for work during one, checking that a fork answered each question, the session answered each request, and every comment still has one reply. Each comment a fork decided on carries the fork's outcome, time and tokens in the sample. Without `--forks` the journey runs with `LEAF_FORK_REPLIES=off`, so its delivery steps keep testing the session's own answers.
# Conflicts: # build/browser/protocol-baseline.json # src/leaf/clerk.py # src/leaf/hook_transport.py
leaf-dev journey-chart named a forks run's samples as it named the rest, so their release replies pooled with the session's own; the row now says "with forks". The developing-leaf skill says to add --forks to the claude-code journey after a change to forks.py or the module's forkReply.
leaf-agent
approved these changes
Nov 1, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 7, 2026
Comments, docstrings and one note that point at names the code no longer has. Each now names the rule or function it means. Nothing that runs changes. - **Renamed `browser/AGENTS.md` sections.** `floating-panel.js` cited "News never moves what the reader is reading", and `composing/text-field.js` cited "Editing in place" and "Stability". None of these is a heading or rule any more. They now name "News moves what the reader reads only in the thread they are in", "Editing something keeps it where it stood and as it read" and "The page holds still under the user's aim". - **`keyboard/layer-stack.js`, `nativeModes`.** The comment counted hint popovers among the modes, but since #5614 `pushNativeLayer` returns `null` for `popover="hint"`, so no hint popover ever joins the stack. The module header already says so. - **Functions that were removed or never existed:** - `floating-panel.css` cited `rowNotice`, which #5613 deleted. It now cites `rowNoticeTemplate`. - `thread/messages.js` cited `preview.js`'s `fitList`, which has never existed. The fitter is `fit`. - **`packages/diff/widget-shadow.css`.** Two z-index comments gave the full-name path box as their reason, and #5614 removed that box. The values stay. The comments now give the stacking they keep: the line numbers sit at 2, the pinned name at 3 and the file's actions at 4. - **`notes/fork-replies.md`.** It said a `forked-replies` branch builds the design, and that the fork posts "the reply". `forks.py` has been on main since #4892, and since #5552 the fork posts only the working line. The rest of the note, the research and the unbuilt "fork that takes the work", stays. - **Smaller fixes:** - The `plans.py` docstrings now name the `items` parameter. - The `structure.py` allocation comment now points at `AUTHORED_ALLOCATIONS`, which also holds `data-height` and the page-wide allocations. - A runtime test now names `tokens.css`, where the card widths live. - A test comment now names `test_admission.py`, where #3089 moved the named-dependency test. - **`packages/default/styles/sample.css`.** A trailing comment governing no rule repeated the exhibit rule that `options.css` states and applies, so it is deleted. Verification: pre-commit (ruff, prettier, eslint, ty, knip, typos) passes on the changed files, and `tests/runtime/comment-placement.test.mjs` passes. No test is added, since nothing that runs changes. Co-authored-by: leaf-agent <[email protected]>
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.
In Claude Code, a user message in a thread the session hasn't picked up is now held from delivery while a fork of the session's conversation decides: the fork answers from the conversation, and its reply is posted as the agent's, or it hands the thread to the session, which receives it as any input. A question the conversation already answers gets its answer in a median 12 s on real thread messages, against 48 s for an idle session and 100 s for a busy one today; everything else reaches the session about 6 s later than today.
LEAF_FORK_REPLIES=offin Claude Code's environment turns forks off.How it works
src/leaf/forks.pyowns the state machine, and its header states it. A thread with waiting messages is held, answered or with the session, computed byforks.heldfrom the log, the session's hand-over record (sessions/<session>.forks, a newstate.Recordat protocol 37) and its forks lane; nothing stores the state. The lane is the session's pages follower (hooks.cmd_pages): it lists held threads for the module to fork (forks.look), and hands a thread over itself once 30 s have passed since its newest message. A lane holds only messages admitted after it took its lease, so a restarted follower never holds again what an earlier one let go.Every way out of the hold but a killed follower is a write the session's waiters already read: the reply in the log, or a hand-over in the record the watch's reading stamps (
served_state.reading), which also nudges a session no watch follows, as admission would have. The reply is fenced to the hold under the lock its append takes (thread.Receipt.fence), so it writes nothing once the session has the message. A follower that stops with a thread held nudges what it leaves, as a watch does.hooks/claude-code.ts(forkReply) forks with$.model.fork, names the tool calls the session is running (which the fork's copy of the last request predates), and hands the answer back throughleaf hook --fork. Python writes the prompt (forks.reply_prompt) and reads the answer. The session hears of a fork's reply at its next prompt or tool boundary: the settled message arrives with the reply in the thread's digest, and the clerk's queue adds a line asking the session to correct the reply where what it knows shows it wrong.Behavior changes elsewhere:
delivery.deliverableleaves held messages out, and admission doesn't nudge for a held message, since its hand-over nudges instead.Evidence
tests/model/test_forks.pywalks each transition, and each of eight races Codex found over three review rounds has a test that fails without its fix.tests/process/test_interact_claude_code_module.pydrives the hooks module with a scripted fork.leaf-dev journey claude-codepassed against a real Claude Code session both ways. With forks off it ran all 13 delivery steps. With--forks(new here, and charted in its own row byleaf-dev journey-chart), forks answered a question while the session was idle in 3.4 s and one during a 25 s command in 2.4 s, and handed both work requests to the session in about 2 s. About 2 s of each forked reply is Leaf's own: the follower's poll, twoleaf hook --forkprocesses and the post.notes/fork-replies.md, "How well the fork judges"). On 15 fresh messages the shipped prompt answered 8, one of them wrongly, and handed 7 over correctly; the 95% interval on its wrong-answer rate runs from under 1% to about 50%.Known limits
A follower killed outright while it holds a message, after the user pressed Escape, leaves that message waiting for the page's next change. Admission's nudge can still race a starting Stop watch into waking a session twice; that race predates this change, and the follower now adds a nudge only when it held a thread.