Repository navigation
Hold a thread message for the line fork by a turn's pickup in the log - #6156
Merged
Merged
Conversation
Research prototype, not for landing. Admission opens an agent turn for the line fork and records its pickup of the thread's waiting messages with the message, where keeping back started before. Each exit is an existing transition: hand_over or a failed line fork closes the turn, which leaves the thread the main thread's; take records the same turn's pickup again with the delivery's references, and the turn goes on as the working fork's; a line fork that never answers leaves the turn to lapse at activity.STARTING_GRACE. Removed: the line holder kind, forks.kept_back_of, HANDED, LANE_START and the lane cutoff, the lane in presence readings and served state, the follower's bound and nudge on letting go, the fence on the line fork's writes (refuse_unheld now refuses them), and the bound in look. Behavior that changes, each an xfail in test_forks.py: - a kept-back message the cursor passed reaches a busy main thread at its next prompt, not its next tool boundary; - the lane going down ends no line turn; - a message admitted while a fork's turn runs goes to the main thread when the run ends, not to the same fork resumed; - a second message while the line fork judges the first follows the first's line turn, with no second line fork.
…ne turn as BOUND_S did STARTING_GRACE bounds a line turn, whose start nothing confirms, so this matches the old 30 s bound with no grace of its own. On this machine's pages to 2026-11-15, 77 fork starts were confirmed within 0.7 s of the take, and 147 line forks answered within 20 s (median 2.4 s).
…bump the page protocol to 45
The prototype merged before this holds a kept-back thread message by a line
turn's pickup in the log, and told a line turn from a working fork's by its
having written nothing on the page. This records the role where the turn is
opened instead: the session's agent-turns record gives each turn a `role`,
`line` as admission opens it (`state.open_agent_turn`), and `fork` once a
take passes it to the working fork (`state.pass_agent_turn`), which also
names a resumed fork's agent there. The same turn goes on, so the message
never changes hands and the mark stays true.
Behaviour that changed with the mark:
- `leaf page state`'s `holder` names a line turn `{"kind": "line", "state"}`
again, and a command acting as the main session beside one hears "a line
fork holds this thread", where the prototype called it a fork Leaf was
starting.
- The fold counts a message a line turn picked up as in hand for that turn,
and a delivery hands the main thread what a line turn picked up and left
owed once it closes or lapses, as it does for a fork's.
- `leaf-dev logs timeline` lists a line turn as one.
Admission reads who holds each thread once and passes that reading to the
line turn's pickup (`delivery.record_pickup`'s new `holding`), where the
prototype read it twice; the take reuses its reading for the pickup and the
receipt too.
Protocol 45: a Leaf at 44 doesn't know that a line turn's pickup at
admission holds a message, so it would hand the message to the main thread
beside the line fork. `agent-turns` moves to 45 for its `role`. Each session
takes its pages to 45 at its next command or hook naming them.
The forks module header records the five rare paths the user accepted on
2026-11-15 with this design. One reads worse than the decision page put it:
a second message while the line fork writes leaves the thread with no line at
all, since the first message's line responds to a message that no longer
carries the thread's answer.
The tests the prototype marked xfail for those paths now assert the accepted
behaviour, two merged into one, and the one whose subject, the lane going
down, no longer holds anything is gone.
…agent journey to line turns - `holding.Holding.forked` reads a thread's waiting messages On it while a running line turn holds them, as before the prototype, which could not tell a line turn from a fork's and so also read a working fork's further messages On it from the take. - A line whose message owes no reply by the time it would go in, as when a second message joined its turn, now hands the thread over with a reason and nudges a session no watch follows, rather than dropping it silently; so does a take whose newest message owes no reply. - The claude-code journey's fork steps compare the set of turns that picked a comment up, since a take picks it up again in the line turn it passes to the fork, and `fork-work` looks for the main thread's pickup after the line turn's.
…icked it up `leaf delivery ack` of a delivery an earlier turn of the session had already picked up adds a note telling the agent not to redo that turn's work. A line turn picks up every message Leaf keeps back, so the main thread acknowledging a handed-over message delivered by pointer was told an earlier turn had picked it up, though no turn had done any work on it. The note now counts only the main thread's earlier turns: an agent's turn that picked a message up and left it owed handed it on, as a working fork that gives its thread back does too. Also brings the forks header's counts and wording, and comments in holding.py, state.py, served_state/reading.py and hooks/claude-code.ts, up to the line turn passing to the working fork.
…ivers nothing A line turn held its message with an ordinary opened pickup, which every reader of delivery takes as the message entering an agent's context. So the message read Delivered while the line fork wrote, the page read Working, and after a hand-over the message stood picked up by an ended turn: the thread showed "Gone quiet" in place of On it until the main thread took it in, it never counted overdue, and a tool boundary skipped it once the cursor had passed it, leaving a busy main thread to find it at its next prompt. A pickup's phase can now be `held` (`delivery.record_pickup`): it holds the thread as an opened pickup does (`holding.reading`), but takes nothing in, so the workflow, the activity fold, the tool boundary's quick check and the receipt's exceptions read the message as sent to the session until the working fork's take or the main thread opens it. Behaviour that changes from the previous commits: - A kept-back message reads as sent, under On it, while its line fork writes and after the hand-over, as before the prototype; the page no longer reads Working for the line fork. - A thread the line fork hands over after the cursor passed its messages reaches a busy main thread at its next tool boundary again, so the forks header lists four accepted paths, not five. - `leaf delivery ack` no longer notes an earlier turn for a message only a line turn held, so the previous commit's exclusion of agent turns there is reverted, and the claude-code journey's pickup checks are back to main's. - A take that finds the thread taken since its line went in now closes the line turn rather than leaving it to lapse. Also corrects stale test docstrings (the bound, the fence, a minute).
Main moved `$events.protocol` to 45 while this branch was open, so this branch's bump moves to 46: the kernel registry, `agent-turns`' `since`, and the baseline, rebuilt from main's at 45 with this branch's changes (the `held` pickup phase, `agent-turns`' role, and the `forks` and `fork-lane-start` records gone).
…step only while its line turn runs The take passed the line turn to the working fork, so one turn id served as the line fork's and then the fork's. A line fork's step repeated with the same thread after the take, as a hooks module reloaded mid-fork sends, then acted on the fork's turn: a second `hand_over` posted a second line, closed the fork's turn and gave the message to the main thread while the fork worked on. A late line after the line turn lapsed still went in too. Behaviour that changes: - A take closes the line turn, opens a turn of the working fork's own (`state.open_agent_turn(session, "fork", agent)`) and records that turn's pickup, in one page transaction, as before the prototype; `state.pass_agent_turn` is gone and a turn's role never changes. - `ask` and `route` act only while their turn is a running line turn (open, role `line`, not lapsed, `forks._line_runs`), so a repeated or late step posts nothing and closes nothing; a late answer is recorded as dropped. - A line turn's `held` pickup holds its thread only while the turn runs (`holding.Hold.picked` counts opened pickups), so the closed line turn keeps nothing and the fork's pickup takes the thread. - A working fork's start is confirmed within 30 s of the take, not of the message's admission; the forks header's accepted list says so. - Opening a turn drops line turns that have closed or lapsed from the session's `agent-turns` record, so it grows with working forks, not with every kept-back message. A thread such a turn held reads as the main thread's either way, which a new test checks before and after the drop. - `thread.Receipt.fence`, whose only caller the prototype removed, is gone. - `docs/forks.html`'s "Where a further message goes" flowchart sends a message to a running line turn as to a running fork's, at the same drawn height. New tests: a line fork's step repeated after its take, a line fork answering after its turn lapsed (replacing the lapse-then-main-pickup case), a take's 30 s counted from the take, and the record's pruning.
`holding.reading` admitted an ended line turn's `held` pickup into each
thread's newest pickup, so the thread's holder kept naming that turn after it
closed or lapsed. `leaf page state` showed it as `{"kind": "line", "state":
"closed"}` until a later turn dropped the entry, and a running working fork
writing in the thread was refused as if another turn had taken it over,
though nothing held it.
A `held` pickup now counts only while its line turn runs, so once the turn
ends the thread is whoever's it would be without it: the main thread's for
a thread no other turn took. `took` still counts a running line turn's
threads, so a second message there joins it. A new test holds both: the
holder reads as the main thread right after the hand-over, and a running
fork of another thread may answer there.
The record's description changed with the fork's own turn at a take, and the baseline still carried the earlier wording; descriptions are annotations, so nothing else moves. Rebuilt from main's baseline at 45 after the merge.
leaf-agent
previously approved these changes
Nov 16, 2026
Main moved `$events.protocol` to 47 (#6216), and #6238 made the build refuse any schema change at one number, so this branch's `held` pickup phase and `agent-turns` role take the protocol to 48: the kernel registry, `agent-turns`' `since`, and the baseline rebuilt from main's at 47. Conflicts: the protocol line, the pickup row of `events.md`'s table, and a test's stand-in for `thread.checked_text`, which now passes main's new options through.
A message that joined a thread while its line fork was still writing about the first stayed with that line turn, whose line then answered a message that no longer carried the thread's answer, so the thread got no line at all and the `take` was dropped; both messages waited for the main session. A quick correction or "and also" right after a message is a natural pattern, and main asked a new line fork about both. Admission now does that again: where a running line turn holds the message's thread, it closes that turn and opens a new line turn whose `held` pickup names every waiting message of the thread, so the follower lists the new turn and the module asks a line fork about them all. The first line fork's late answer drops, since its turn no longer runs (`_line_runs`). The common path keeps its single reading of the page; this path reads the session's turns again with the threads that reading built (`forks.page_holding`'s new `threads`), not the log's fold. The forks header's accepted list drops the case, three paths remain; a user's rewrite during a line fork still joins the turn and goes to the main thread bare. `docs/forks.html`'s further-message flowchart is main's again. The test for the case now checks the new line turn holding both, the old one closed, the first answer dropped, and the new line and take.
….1.326 asks about Claude Code 2.1.326 asks whether to trust a directory passed with `--add-dir` before it reaches the prompt, so the journey's setup waited out its 300 s on that dialog. The journey's Claude home now records the plugin directory as trusted beside the session's cwd.
leaf-agent
previously approved these changes
Nov 17, 2026
The second-message fix replaced a running line turn only for a further message. Any other event that joins the thread's waiting turns while the line fork writes, such as the user's rewrite of their message or a pick on a widget frozen in the thread, still joined the old turn, whose line then responded to a turn that no longer carried the thread's answer: no line, the take dropped, and the thread to the main thread bare. Admission now decides by that fact, whatever the event's kind: the event is one of the thread's waiting turns and a running line turn holds the thread. With the lane down no follower would list a new turn, so the event still joins and the bare hand-over nudges the session. A non-Claude-Code claim returns early, which lets the type checker narrow the claim for the rest. A line whose append is refused because an event replaced its turn as it went in is now recorded as dropped, its line turn no longer running, rather than as the message's own refusal. Found by review. The forks header describes the rewrite and widget cases with the further message, and a test covers the rewrite: the new line fork is asked with the rewritten words and its take goes through.
…note a rewrite that replaces one A pick on a widget frozen in a thread is its own obligation for the main thread, not one of the thread's waiting turns, so it never replaced a line turn; a review's probe confirmed it, and the header and comment no longer say otherwise. A rewrite that replaces a line turn now writes its fork_admission row, so the timeline shows the admission that opened the new turn.
leaf-agent
previously approved these changes
Nov 17, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 17, 2026
…s that made it (#6212) Removes the history the tree had collected in module headers, comments, test docstrings and eval-case comments: dates of decisions, who asked when, the incidents and sessions behind them, replay and pass counts, PR numbers cited as provenance, and accounts of earlier versions. Each decision stays with its reason, whether the user made it, and the alternatives a later change might reach for, now stated as rejected with why they fail. The removed history stays in the commits that added it (`git log -L`). #6210 changes the two rules that produced it. Lines matching a dated-history pattern outside `notes/`, `examples/` and fixtures go from 264 to 17; the rest are page and prompt data, a page revision's "first version", and three `browser/AGENTS.md` clauses #6024 already removes. Provenance PR numbers leave code comments; one open `TODO(#4041)` stays. `src/leaf/clerk.py`'s docstring goes from 250 lines to 190. What to weigh: a figure that a constant, bound or budget is sized from stays (`DEADLINE_S`, `ROLLOUT_MS`, `FEW`), and so does a version that bounds an observation (a Playwright build, a Claude Code version). An observation of a browser or of Claude Code that carried a date now says what the code guards against ("Chromium can leave … hovered"), since dropping the date alone would have asserted a law. `notes/` keeps its dated research. Every hunk is a comment, docstring or string; no assertion changed. `packages/default/styles/sample.css` also loses a paragraph that described the suggestion as boxless, which `base.css` no longer makes it. Conflicts: open PRs that touch these 423 files, such as #6156 in `forks.py`, will resolve comment hunks when they next merge `main`. Asked for by Max on #6160's review. Six agents swept by area; an independent Codex pass per area compared old and new text claim by claim, and a second pass checked the fixes; their findings are fixed. `pre-commit` passes on every changed file, as do the tests that read them. > _This was written by Claude Code on behalf of max-sixty_
…ol 50 Main took page protocol 49 for agent edits of their own message HTML (#6246), so this branch's `held` pickup phase and the agent turn's `role` take the protocol to 50: `$events.protocol`, the agent-turns record's `since`, and the baseline rebuilt from main's at 49 with only the pickup event and the agent-turns record changed, and the `forks` and `fork-lane-start` records removed. Conflicts kept both sides: `events.md` is main's table with the `held` phase in the pickup row; `thread.py` keeps main's `import json` and drops `Callable` with `Receipt.fence`; the `forks.py` header, the `holding.authorize` docstring and `docs/forks.html` keep this branch's line-turn hold in main's wording without dates or eval counts (#6212).
…to commits Main now asks text in the tree to say what holds rather than how it came to be (#6210, #6212). This branch's own text still carried the date the user chose the line-turn hold, the hold it replaced as "kept until then", and the bound it shortened from a minute. The `forks.py` header now states the decision with the alternative it rejects and why that alternative fails (a second answer to which turn holds a thread, kept partly outside the log); the figures that size `STARTING_GRACE` stay in its comment without the date. No behaviour changes.
leaf-agent
approved these changes
Nov 17, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The description's protocol paragraph went stale with the merge: it says "The page protocol goes to 48. Main took 47 for its own schema change" and "A Leaf at 47 would ignore a held pickup", but the merge (4d246cf) takes the protocol to 50, since main took 49 in #6246. The description becomes main's commit message at the squash, so it's worth updating to 50 / 49.
max-sixty
added a commit
that referenced
this pull request
Nov 20, 2026
…line fork fares (#6592) A thread message Leaf keeps back for a line fork goes to the main session when the line turn ends. When the line fork answers within 30 s, the hand-over nudges a session no watch follows; when it answers later or never, the line turn lapses, which writes nothing, and nothing nudged. A session whose turn its Stop hook closed and whose watch had gone (failed, or past its hook's timeout) then kept the message until its next prompt. An interrupted session was already woken at the lapse by the page server's interrupt nudge. The page server's row producer already wakes at each transition the activity fold names, a line turn's lapse included. It now nudges at a transition whether the main turn was interrupted or closed (`presence.nudge_interrupted` becomes `presence.nudge_left`). `nudge_unwatched` still sends nothing to a session a watch follows, and at most one nudge per turn ending. Worth weighing: this reverses a cost #6156 accepted ("A line turn that lapses nudges no one"). A transition that falls between a Stop and its watch taking the lease wakes the session twice, as input admitted in that moment already does. Asked for in Max's session after a Codex review of #6574 found the gap; Codex also reviewed this diff. Tests: a new model test fails on main and passes here; the in-time hand-over still nudges once; focused model and process suites pass. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 20, 2026
…de it (#6616) A Claude Code thread message now reaches the main session at once, delivered and nudged as any input is, as in Codex and Pi. The line fork runs beside the delivery and posts the agent's working line when it answers. Until now Leaf held the message from the session while the line fork wrote, for up to 30 s. Max chose this on 20 Nov 2026. The hold came with #6156, when the line fork also judged whether a working fork should take the message, and the session had to wait for that judgment. #6574 removed the judgment, which left the hold buying only that the line went in before the session's own words. This reverses the decision `forks.py`'s header recorded, and deletes the hold and everything that existed only for it. ## What holds now - **Which messages get a line fork.** The pages follower lists one for each *round*: an open thread whose waiting messages have nothing of the agent's after the oldest of them, read as the round stood when its newest message arrived. A message that joins a round before its line gets a line fork about all of them. One that joins after the agent spoke in the thread gets none. The follower lists only rounds newer than its first look at a page, and the module runs each id once, so a round gets at most one line fork, across a module reload too. - **When the line goes in.** Only while its round still awaits it: the thread's waiting messages are the ones the line fork read, and the agent has said nothing there since, by a message or a rewrite. Leaf checks this under the lock the append takes (`thread.Receipt`'s `fence`), so a line never lands after the session's words, nor speaks for a round a later message joined. A line that fails the check is recorded as `dropped`. - **On it.** Waiting messages read On it once the line stands, until the session answers, as before. Before the line lands they read as their delivery does: Queued, then Delivered. - **The summary fork** still runs beside each listed round, even where the agent spoke first. A delivery leaves the summary hint to it by the same reading. ## Deleted `holding.py`, line turns (`state.AGENT_TURNS` and its helpers), the `held` pickup phase, `activity.STARTING_GRACE` and the lapse, #6592's lapse nudge, admission's keep-back, the hand-over, the follow-up that replaced a line turn, delivery's branch for input a line turn kept past the cursor, `fork-holds-thread`, and `leaf page state`'s `holder`. Production code nets −1,079 lines, tests −874, `leaf-dev` −119. ## To weigh - The page protocol moves to 53, because the pickup's phases lose `held`. - For the second or two before the line lands, a message reads Queued or Delivered rather than On it. - A message the user sends before the pages follower first reads the page gets no line. As before, the session gets it anyway. - Whether a delivery carries the summary hint now turns on whether the follower holds the session's lane when the delivery is built (`forks.lane_up`), rather than on a record in the log. - `leaf-dev eval run 'line-fork*' --base` can't compare across this change, since its scripts call the new `forks.look` under the base arm's Leaf too. How it works' Forks tab describes the new flow, and its "Anatomy of a fork journey" is re-recorded from the journey run on this branch. Also fixes two tests #6573 left failing on main: the third delivery that `evals/beside-work-goes-to-a-fork` pastes moves to `leaf-delivery/52`, and `test_an_agent_reply_can_remove_a_subject_and_detach_its_open_thread` expects the thread's new `rewritten_from`. Tests: model and process suites for the touched modules pass. New tests cover delivery at once, a joining message, the agent speaking first (answer, message, progress, rewrite), the race under the lock, a repeated step, and the summary fork's ownership. Each new guarantee has a test that fails without its fix. `pnpm run check` passes. `leaf-dev journey run claude-code` passed all 14 steps on the final code. The line was in the thread 1.6–2.0 s after each message (the line fork itself took 1.3–2.0 s), and an idle session's prompt took a message 0.2–0.4 s after it was sent. Before this change it waited for the line. Codex reviewed the change and then its fixes. It found three gaps, each fixed with a test that fails without the fix: a rewrite of the agent's own answer didn't stop a late line, the agent's progress could leave a long thread's summary with no owner, and a second rewrite could list a round again. > _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.
With forks on, a thread message to a Claude Code session gets a line fork, which writes the agent's working line and judges
take(a working fork does the work) orhand_over(the main session does). Leaf holds the message from the main session while it judges. Until now that hold was a state of its own, kept partly outside the page log by seven mechanisms. This change holds the message the way a working fork's turn already holds its thread: as a message is admitted, Leaf opens an agent turn for the line fork and logs that turn's pickup of the thread's waiting messages. Every reader already asks the log which turn holds a thread, so the separate hold goes.This design was chosen over keeping the separate hold after a prototype measured both.
How a held message leaves the hold
take: in one page transaction, the line turn closes, the working fork's own turn opens, and that turn's pickup is recorded, as main's take path did.hand_over, or a failed line fork: the line turn closes and the main session gets the message as ordinary input, nudged if nothing watches it.dropped:askandrouteact only while their turn is open, a line turn, and not lapsed (forks._line_runs).What's removed
The
LINEholder kind andHolding.keeping;kept_back_of; theforkshand-over record outside the log (HANDED);_still_kept_back; the lane lock and itsfork-lane-startcutoff record; the lane and hand-over fields copied into presence and served state;BOUND_Swith the follower's_let_gonudge; andReceipt.fence, whose only caller went.What's added
heldpickup phase. A line turn's pickup holds its thread while the turn runs and delivers nothing. Recording it as an ordinaryopenedpickup made every delivery reader treat the message as delivered: Gone quiet after a hand-over, Working while the line fork wrote, never overdue, and a tool boundary skipping a hand-over the cursor had passed.lineorfork, recorded when the turn opens and never changed.leaf page statenames a running line turn as the holder.delivery.record_pickuptakes the caller's holding reading, so admission reads who holds each thread once.open_agent_turndrops line turns that have closed or lapsed when it rewrites the session's record, so the record doesn't grow with every held message.The page protocol goes to 50. Main took 49 for its own schema change, and the build refuses a second schema change at one number. A Leaf at 49 would ignore a
heldpickup and hand the message to the main thread beside the line fork. Each session takes its pages to 50 by itself.Behaviour changes accepted with the design
These are recorded in the
src/leaf/forks.pyheader:Cost
On the bench's 1,600-thread page, with a Claude Code claim and the lane up, the hold decision at admission takes 11.0–11.5 ms against 9.8–10.8 ms on main (the prototype took 16.4–17.6 ms). Before the merge, accepting a message plus reading state took 90.5 ms against 96.3 ms on main in a quiet run. Only the second-message path reads the session's agent turns a second time, reusing the threads admission already built.
leaf-dev benchhas no claimed page with a fork lane, so its daily chart doesn't see this path.Testing
tests/model/test_forks.py, activity, delivery, workflows, model folds, hooks, stop guard, session lifecycle, to-dos, wait, Codex adapter,tests/process/test_interact_claude_code_module.py, the served-state schema test, and the dev timeline and journey tests.--forksand with--fork-work. Claude Code 2.1.326 asks before trusting a directory passed with--add-dir, and both journeys sat on that dialog until setup timed out, so the journey's Claude home now marks the plugin directory as trusted (dev/leaf_dev/journey_claude_code.py).takegoes through. A review's probes for the races between the old fork's steps and the new turn (a take or hand-over mid-flight, the line's own append, a third message) pass.