Skip to content

Fix the forks review's six bugs, and read who holds each thread once per served state - #6032

Merged
max-sixty merged 25 commits into
mainfrom
fork-review-fixes
Nov 15, 2026
Merged

max-sixty merged 25 commits into
mainfrom
fork-review-fixes

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

A full review of the forks feature (behind LEAF_FORK_WORK=on) found six bugs and several descriptions that no longer held. This fixes them, along with what three further review rounds of the fixes found.

Bugs fixed

Each fix has a test that fails without it.

  • Two rules for where a thread's round ends. holding.rounds ended a round at any agent message, while the fold settles by the message an answer names. So the main thread answering an older choice took the thread from a fork that held newer words, and the fork's answer was refused. rounds now builds threads with the fold's own events.build_threads, with the page's containment, and skips threads that stand closed, so resolution is read in that one place too.
  • One delivery cursor served several readers. A receipt stopped at the first message the line fork kept back or a fork held, so later input waited behind it. A receipt now passes every waiting message the main thread doesn't owe, and the tool boundary gives the main thread any message the cursor passed that no pickup names and that it now owes.
  • A fork turn whose start report was lost read as running for 15 minutes, holding back deliveries to the main thread meanwhile. A turn whose start the hooks module hasn't confirmed now lapses after a minute, for spawned and resumed forks alike. The module keeps a fork's $.state entry until Leaf has heard its end, and tells Leaf again of a missed end at the pages follower's next listing.
  • A fork could start a to-do in a thread another turn had taken. refuse_unheld now checks the thread's holder.
  • A thread the user resolved was handed back to the main thread as owed. A fork ending on it now records outcome: resolved and hands nothing back.
  • Served state listed every agent turn of the session, so it grew with the session's length. A page now reads its open turns and the turns its log names.

The reviews of these fixes added four more:

  • A reply names its parent's thread to authorize, so the main thread answering a frozen choice in a fork's thread is told the fork still holds it.
  • A running fork's tool boundary carries the user's messages as logged, rather than as the thread reads them.
  • A kept-back message the cursor passed reaches the main thread at its next tool boundary once the fork lane is gone.
  • A Codex abandonment's failed pickup names every input its receipt passes, so the cursor passes input only where a pickup names it, and a quiet Codex tool hook after an abandonment still reads the log alone.

Descriptions

Claude Code runs no hook for a call that hands leaf to another program, such as bash -c 'leaf …', timeout 30 leaf … or a script (measured on 2.1.325). The Forks guide, hooks.py and the test of denied forms no longer claim Leaf denies those; such a command acts as the main thread's and is told which fork holds the thread. A rule that matched leaf anywhere in a call would reach them, but it would also run the hook, and open the sandbox's path out (bridge.py), for every call through a directory named leaf.

Also corrected: when a resumed fork's take line is queued, the guide's fork outcomes (now with resolved), and the effort rationale, which now lives only in runFork's comment.

Simplifications

Every reading of who holds a thread goes through holding.reading_of, and a served state builds it once: presence reads the kept-back threads from it rather than building a second reading. activity.present_holding, forks.claim_holding, kept_back_threads and _left_by_agent_turns are gone. The served field kept_back is renamed handed; nothing in the browser read it.

Cost

A quiet tool boundary builds no holding reading, except on a page where a kept-back message settled (resolved, taken back or answered) before any pickup named it: every later tool boundary there builds one, about 50 ms on the largest bench page and a few ms on a typical one. Telling a settled message from an owed one without that reading would take a third copy of the fold's closing rules. On a 41,000-event bench page, the tool-boundary hook's median is 193 ms against 206 ms at the base, and the prompt hook's 1,545 ms against 1,652 ms (18 alternating runs per arm, load average 3 to 9).

Testing

  • Focused model suites (forks, activity, workflows, delivery, todos, hooks, clerk, codex_adapter, session_lifecycle, model_folds, thread_reading, responses, obligations), the guide's page tests and the hooks module's process tests pass.
  • pnpm run check passes.
  • The endFork change, which removes a fork's entry only if it is still the same run, has no test: staging a resume during a fork step needs a driver option that doesn't exist.
  • leaf-dev journey run claude-code --fork-work passes every step on this branch: fork-idle, fork-follow-up, fork-resume, fork-todo and fork-work.

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

The user's call on the fork roadmap: shipped instructions should say only what
we have a strong view on, and see how workers use the page without the rule.
conversation-loop.md no longer tells a worker brief to leave the page alone, and
the Claude Code contract keeps only the part with a mechanism behind it: a
subagent's `leaf wait` takes the main thread's input, so `leaf wait` stays
with the main thread. SKILL.md's "Stay responsive" still has the parent own the
conversation.

On parent-keeps-leaf-responsive (Claude Code, 3 runs each) the head and the
merge base both passed responsive-coordination 2/3 and delegated-work-visible
3/3. Both misses kept the setup check in the parent, and head's briefs still
kept the page with the parent.

A worker's `leaf` command acts as the main thread; the TODO in
`holding.holder` says what to build if workers come to act on pages.
…'s message as its own

Who answers each of the user's waiting thread messages was composed separately by each reader: delivery joined forks.kept_from_main (kept_back plus holding.agent_held) with holding.left_by_agent_turns, admission asked kept_back and agent_held again, and the activity fold named holders from holding_turns alone. So a message Leaf keeps back while a line fork judges it read as the main thread's in leaf page state for up to 30 s.

holding.message_holders is now the one reading: each waiting message's holder, a fork by name with its turn's state, or the line fork for one the presence reading lists as kept back (its new kept_back field, forks.kept_back_threads), with the main thread holding the rest. holding.owed_by says who owes the answer now: that holder while it is the line fork or a running fork, and otherwise the main thread. Delivery (through forks.page_holders), admission and the fold filter that reading, so page state's obligation holder reads {"kind": "line"} for a kept-back message, and agent_holds counts it as not the main thread's. forks.kept_from_main, holding.agent_held and holding.left_by_agent_turns are gone.

The fork_admission note's held_by now names the fork (leaf-<thread>) rather than its turn id, and leaf-dev timeline prints that name.
…y which fork it acted beside

A leaf command no agent id marks acts as the main thread, whoever ran it: the main thread itself, a fork's script, a worker or the terminal. The user chose on 2026-11-14 that such a command keeps going through on a thread a running fork holds, rather than being refused, and warns that the thread has a holder.

holding.authorize now returns a fork-holds-thread advice finding for a write of the main thread's on a thread whose holder, as leaf page state gives it, is a running fork. thread.post_reply and todos.take_in_hand note it beside their result: an answer says it took the thread from the fork, whose own writes there are refused from then on, and a working line or a start says it acted beside the fork. state.acting_turn's TODO to mark every caller is replaced by that decision, and take_in_hand's docstring no longer says workers leave starts to the session driving the page, since the shipped instructions stopped keeping workers off it.
…hat reading

The holding rule's unit is the thread: every waiting message of a thread has one holder. Yet the reading was per message (holding.message_holders, over holding_turns), page state's thread holder came from a second reading (last_taken), and authorize's warning from a third, so a kept-back thread printed `line` on its obligations and `main` on itself, and each caller re-walked the log and re-read the agent-turn stamps.

holding.reading now reads each thread's Hold once: its turn (the newest pickup of a waiting message, else the turn that last took it), whether that turn holds the waiting messages by a pickup, and its holder for a reader. Holding.keeping gives the threads Leaf keeps back to the line fork, and forks.page_reading reads both for a page, computing rounds and the stamps once. Every caller asks it: page state prints each thread's holder and, through owed_by, each obligation's; delivery and admission filter it; the fold reads it once and the Stop hook's deliverable reuses the fold's (WorkState.holding); pickable, to_carry, taken_by_agent_turns, refuse_unheld, forks.ended, forks._left_by_agent_turns and kept_back_threads read turn ids and pickups from it, and fork_admission's held_by is the holding turn's id again. holding_turns, last_taken, newest_pickups, picked_in, turn_threads, running_threads, message_holders, the fold's thread_holders and forks.forked are gone.

The presence reading keeps one public field, kept_back; On it is Holding.forked, from it and the working lines, and the served `forked` field is gone (browser/types/contract.d.ts regenerated).

authorize now decides its warning from the thread's holder whoever writes, a terminal outside the session included, for a fork or the line fork, and a start on a to-do resolves the to-do's thread. Only a reply that responds to a message says it took the thread. The finding says the fork holds the thread, how to stop it with SendMessage, and that a fork's leaf command acts as the fork only as a Bash call of its own that begins with leaf, in the readers' word, the main session.
…ding, and carry the reading beside the fold

Leaf warned itself on every line fork's working message: forks.route posts it in the claimant's name while the line fork holds the thread, and post_reply printed authorize's note. The note now goes out only for a command's own write, where post_reply has no claimed_session; Leaf's own writes on a session's behalf, the line fork's working message and a harness's failure receipt, say nothing.

The fold read an ended session's agent turns into its Holding, so leaf page state names the forks that held its threads, while forks' reading read none without an active claim; deliverable on the fold's reading then handed on a message an ended session's fork had picked up, where the base handed nothing. Both now build from the page's claim whatever its state, as page state has it, with Holding.live saying whether the session holds the page by an active claim: an ended session's turns name what they held but run nothing, and deliverable's hand-on of what a fork left, pickable and taken_by_agent_turns act only for a live session, as their base readings did. Page state for an ended session's threads is unchanged.

The reading is built once beside the fold (activity.present_holding) and passed into canonical_activity, and WorkState carries it as a field, so the served activity no longer holds it behind a deny-list. forks' readers are renamed page_holding and claim_holding, apart from projection's and served_state's page_reading and service's claim_reading. Holding.newest, which nothing read, is gone; _resumable and look ask the reading their caller has, and look keeps _kept_back_for's one guard. The line fork's took-the-thread words are gone, since no command answers a message it holds. The warning and the Forks guide say working message, the glossary's word.

Tests pin each: Leaf's line post prints nothing where a command's write in the same state hears of the line fork; an ended session still names its fork in page state and deliverable hands nothing on; and a waiting message's pickup holds its thread over an older message's newer pickup.
… changed

The line-fork eval had no case where the session had just edited the
page's source, which is where the claude-code journey's `fork-lookup`
question ("How many cards does this page's source hold? Count them in
the file.") lands. In 20 `--fork-work` journey runs from 10 to 14
November the line fork took that question in 17 and handed it over in
3, each time just after the session had recorded a release on the
board and ended its turn.

Two variants now measure where the take criterion puts that lookup:

- `source-edited` (label `take`): the session served a release board,
  recorded a passed release in its source, replied, and ended its turn.
  The criterion excludes what the session "is changing or about to
  change", and nothing in the conversation is under way or announced,
  so a fork can read the file. The parenthetical that lists the page's
  source with the session's files is read as examples of what the
  session may be changing, as the `meaning` and `why-ci` labels already
  read it for the session's files.
- `source-editing` (label `hand_over`): the same question while the
  session is part way through splitting a card into three, so the count
  in the file changes under a fork that reads it.

On a2773d8 `source-edited` passed 13 of 15 runs; both misses
answered `hand_over` with the line "counting the cards in this page's
source file". `source-editing` passed 14 of 14. A control with the
edit removed took 8 of 8, too few runs to tell whether the edit is what
draws the misses.
Leaf spawned every working fork of a thread as `leaf-<thread>`, and told the
main session to reach it by that name. On Claude Code 2.1.325 a name moves to
the newest agent spawned under it, so a second fork for the thread (after the
main thread answered there last, or in a later generation) took it. The main
session's SendMessage to a name it had already used was then refused, one it
hadn't used reached the newer fork, and after `claude --resume` the name
reached nothing. A send by agent id reaches its agent in every run and
generation.

- The hooks module spawns working forks without a name, so ListAgents offers
  no second address that could move.
- The line telling the main session which fork took a thread names the agent
  id. For a new fork it moves from the take to `forks.started`, where Leaf
  first learns the id; a resumed fork's still goes at the take.
- `leaf page state`'s fork holder is `{"kind": "fork", "agent", "state"}`,
  `agent` null until the fork has started, read from the served `agent_turns`,
  which now carry each turn's agent id.
- The advice beside a main-session command on a fork's thread, the lines at a
  fork's end and the diagnostics name the agent id. `holding.fork_name` and
  the work prompt's name for the fork are gone.
- `fork_outcome` start records carry the id as `agent` (was `agentId`), which
  `leaf-dev logs timeline` and the Claude Code journey now read.

Tests: a new fork's take queues no line until the fork starts; the holder,
the advice and the end lines assert the agent id; the module test asserts the
spawn carries no name.

`leaf-dev eval run recovery-leaves-a-forks-answer --harness claude-code
--repeat 3`, with the holder in the new shape: the agent left the fork's
answer 3/3.
# Conflicts:
#	browser/types/contract.d.ts
#	docs/forks.html
#	src/leaf/findings.py
#	src/leaf/forks.py
#	src/leaf/holding.py
#	src/leaf/session-lifetime.md
#	tests/model/test_forks.py
holding.rounds ended a thread's round at any message of the agent's that was no progress, while the fold settles by the message an answer names (events.settlements). So the main thread answering the user's older widget choice, in a thread where a fork held the user's newer message, read as the main thread taking the thread: the fork's answer was refused, its end said taken_over, and the fold still owed the message.

rounds now places each thread's history of turns by the thread its message names, as build_threads keeps it, and reads it with the fold's unanswered_turns and settlements, so the two can't disagree. A user's rewrite of a waiting message is a waiting turn of its own, held as the thread's other messages are, as the coordinator decided. An answered message's answer is read for its one thread only when an agent's turn acts on it (Rounds.answer_to), round_of is gone, and an agent's message or to-do start in a thread is held to the thread's holder (refuse_unheld's thread). The fold's history keeps the events themselves rather than a projection of each (events.in_history), which also makes build_threads cheaper.

On the reviewer's synthetic logs, best of 15: rounds 0.15/1.6/9.1 ms before and 0.29/3.0/16.3 ms after for 870/8,700/41,000 events; the whole Holding reading 0.24/2.6/13.3 ms before and 0.39/4.1/20.3 ms after; build_threads 7.1 ms before and 6.5 ms after at 8,700 events.
… or fork-held message no longer holds back its later input

The page keeps one cursor, and a receipt stopped at the first input nobody had taken. A message Leaf kept back for a line fork, or one a running fork held without a pickup, therefore kept every later input the main thread took in from its receipt, so a message the main thread took in and answered was handed over again after its turn ended, and the watch woke the session again for one it had started on.

A receipt now passes, beside what the main thread took in, each input an agent's turn picked up and each waiting message whose answer another holder owes, a running fork or the line fork (holding.not_awaited, which replaces taken_by_agent_turns). The cursor passing such a message hands it to nobody: kept_back reads the pickups and hand-overs rather than the cursor, and the hand-over record keeps what no turn has taken in. Once the main thread owes a message it never took in, deliverable gives it as input on the tool-boundary path too, read only for a session with forks so a quiet page of any other still reads its log alone; the fold's debt with no reference already gave it at a prompt or a Stop.

The reviewer's expectation that an input the main thread started on woke the session after each turn held: the watch no longer does, since the started update isn't input again (reproduced before and after).
…rk until Leaf has heard its end

A take whose result was lost, through the module's 60 s step timeout or a reload, left the turn Leaf opened for it open and unnamed: page state named a running fork for 15 minutes, nothing reached the main thread, and every subagent's leaf command was denied with "run the same command again". A turn no agent runs yet now counts for STARTING_GRACE, a minute (activity.agent_turn_end), which every reader of agent turns, the hooks' denial among them, believes.

The module also forgot a fork before telling Leaf its run ended, so a failed ended step left the turn running unseen until it lapsed. It now marks the fork in $.state with how its run ended, forgets it only once the step succeeds (endFork), and tells Leaf again of each such fork as the next main-loop turn ends; a second end of the same fork while the first is in flight runs nothing.
…d owes, and serve only the agent turns a page needs

A fork could start on a to-do in a thread another turn had taken from it, since only message ids named a thread; the thread check that refuse_unheld now makes covers it, and a test pins it.

A fork ending on a thread the user had resolved said hand_back: the clerk told the main thread it owed the answer and its next prompt carried the message with an answer reference, though the fold owed nothing. forks.ended and deliverable's hand-on of what a fork left now count only threads the fold still owes an answer (holding.owed_threads), so such a message counts for nothing, as one the user took back does.

Every state answer carried every agent turn of the session's generation, so it grew with how long the session ran. agent_turn_stamps now reads, from the page's log, only the turns still open and those the log names, whose holders page state names; and opening a turn drops the turns of the session's earlier generations from its record, whose agents ended with them.
- No hook runs for bash -c 'leaf …', sh -c, timeout 30 leaf …, bash reading a here-document, grep leaf or python -c naming it under hooks.json's if rules, while one runs for cd x && leaf, if …; then, $(…), backticks, pipes, an assignment, a quoted or relative leaf and a here-document's substitution (probed with claude -p on 2.1.325 with a stand-in word). The agent_command and leaf_words docstrings, the Forks guide and test_a_forks_leaf_command_must_lead_its_bash_call now claim the denial only for those forms; such a command acts as the main thread's and hears of the fork holding its thread. A rule matching leaf anywhere would reach them, but would run the hook, and open the sandbox's road out, for every call through a directory called leaf, so the rules stay.
- A resumed fork's turn is named with its agent id as Leaf opens it, not at forks.started: the guide's take paragraph, session-lifetime.md and notes/fork-replies.md now say so, and the guide and the contract say an unnamed turn lapses within a minute.
- The guide says no shipped instruction asks a recovering main thread to leave a running fork's answer alone: the holder field does it, 3/3 with it and 0/3 without on recovery-leaves-a-forks-answer.
- forks.py's header cites holding.Holding.forked for On it.
- Why a fork at another effort can rewrite the conversation to the cache is said once, in runFork's comment; forks.py and clerk.py keep their own measurements and point to it.
…ce through it

Every reading of who holds a page's threads now goes through
`holding.reading_of`, from the log and the facts a presence reading carries
of the claim. The fold calls it with the page's presence and
`forks.claim_holding` with its claim's, so the served state and the fork lane
can no longer read the session's turns by two rules. `activity.present_holding`
is gone.

`forks._still_kept_back`, the fence `_take` checks before giving a thread to a
working fork, reads whether the line fork holds the thread with the same
waiting messages from that reading, rather than rebuilding the kept-back list.
`_kept_back_for` is folded into `look`.

Behavior changed: when the lane hands a kept-back thread to the session at its
bound, the `fork_outcome` note always says "no answer within 30 s". It no
longer says "its fork's turn ended before carrying it"; that case had no
reader beyond the diagnostic and cost a second walk over agent turn stamps
(`_left_by_agent_turns`, removed).

A new test holds the receipt fix for a message a running fork holds without
having picked it up: input the main thread took in past it is received once,
not handed over again when the main thread's turn ends, while the fork's tool
boundary still carries the message. It fails with the receipt rule reverted to
passing only running turns' pickups.
… keep the main thread off what it doesn't owe

The review of the receipt fix found that passing kept-back and fork-held
messages with the cursor made two consumers of the cursor misread them. This
fixes both and moves the facts they lacked into the one reading every rule
asks (`holding.reading_of`).

Behavior changed:

- A prompt that reaches the session while Leaf keeps a message back no longer
  records the main thread's pickup of it. `holding.pickable` now leaves out of
  any main-thread pickup the waiting messages the main thread doesn't owe
  (`owed_by`): a running fork's, as before, and now also the line fork's. The
  line fork keeps the thread, posts its line, and the next tool boundary hands
  the message over, as before the receipt fix.
- The tool-boundary reading (`deliverable(received=False)`) adds a cursor-passed
  message only for a session with agent turns or a fork lane, and only for a
  thread no pickup of any phase took any waiting message from. A Codex
  comment the adapter queued is no longer offered again beside newer input. A
  kept-back thread of two messages is no longer input at every boundary after
  the main thread took in its newest.
- `holding.rounds` reads resolution: a thread the user resolved, or a choice's
  answer closed, has nothing waiting, for every reader. A running fork's tool
  boundary no longer carries a resolved thread's message, and a resolved
  kept-back message no longer holds the tool-boundary gate open.
  `holding.owed_threads`, the patch that read the fold for this at
  `forks.ended` and `deliverable`, is gone, and `forks.ended` no longer folds
  the page.
- A fork whose run ends on a thread the user resolved now records its end
  (`outcome: resolved`, with the inputs it took), so the timeline shows the
  start's end.

Structure:

- `rounds` builds its threads with `events.build_threads`, the fold's own
  thread history, in place of a second walk. The served reading passes the
  fold's threads, so it no longer builds any; a hook builds them without the
  page's layer, which only narrows which of a widget's dependencies a
  version's retraction reaches.
- `reading_of` derives the kept-back threads from the reading itself, the
  lane's start and the hand-overs (`forks.kept_back_of`), so presence no longer
  builds a second reading. The served reading carries the hand-overs
  (`handed`) in place of the kept-back ids nobody in the browser read.
  `Holding.taken` holds every input any pickup names, which kept-back and the
  tool-boundary reading both read. `forks.claim_holding` and
  `kept_back_threads` are folded into `page_holding` and `kept_back_of`.

Cost at 41,000 events on a loaded machine: a served reading's holding is
14.9 ms, where the light walk and presence's second reading together took
about 57 ms; a hook's reading is 45.9 ms, where it was 28.6 ms, since it now
builds the fold's threads. A served reading walks the threads once (was
twice) and a take seven times (was nine).
… answer took it

`holding.authorize` found a write's thread only by the messages it names, so
the main thread answering a widget frozen in a thread a fork holds, which
names no message of the thread's, heard nothing beside its result. A reply
now names its own thread, its parent's, so the advice reaches it, and a
fork's answer to such a widget is fenced to the thread it writes in as its
other writes are.

The advice's "took the thread from it" no longer rests on the write being an
answer: the reply reads, once it is in, whether the thread is now the main
thread's. An answer to an older message, or to a frozen widget, leaves a
message the fork picked up waiting and the thread with the fork, and the
advice now says the fork holds the thread. `authorize` lost its `answers`
argument.
…sumes too, and tell an idle Leaf of a fork's end

The short grace keyed on a turn no agent was named for, so a resumed take,
which Leaf names as it opens, read running for the whole working grace when
the module never started it. It now keys on a start nothing has confirmed: a
turn never renewed since it opened counts for `STARTING_GRACE` from its
opening, spawned or resumed. The module confirms a resume once its message
is delivered, as it confirms a spawn (`forks.started`), which renews the turn;
an agent's first tool boundary renews it too, so a resumed fork whose
confirmation went missing keeps its turn while it runs.

Behavior changed:

- The main session hears which fork has a resumed thread once the module
  confirms the resume, not at the take, so a resume that fails tells it only
  that the thread came back.
- The served reading's next transition for such a turn is when it lapses, a
  minute after it opened, not 15 minutes after its last renewal
  (`agent_turn_end`), and the served agent turns carry `opened`.
- A turn that lapsed with its agent lost, which nothing closes, is no longer
  served on the session's pages whose logs never named it
  (`state.agent_turn_stamps`).
- The module tells Leaf again of a fork's end it hasn't heard of each time
  the pages follower lists the session's pages, which it does while the
  session idles, not only as a main-loop turn ends (`endForks`). A run's end
  is told once at a time, and forgetting it leaves a run the fork was resumed
  for since under the same agent id.
The cursor's writers include the receipt that passes what the main thread
doesn't await, and a delivery comment and the fork docs still described the
cursor stopping at a kept-back message and one kept-back function. No
behavior changed.
… hook does

Since `holding.rounds` builds the fold's threads (`events.build_threads`), a
hook's reading of who holds each thread costs about 50 ms on a page of
41,000 events, and a quiet tool boundary of a session with forks built it
twice: once as it confirmed what its harness took in, and once for the
tool-boundary check. Neither could change anything there:

- `confirm_entered` reads it only where input lies past the cursor, since a
  receipt moves only past such input.
- The tool-boundary check (`deliverable(received=False)`) reads it only
  where input is pending, or the cursor passed input that no pickup names,
  which is the only input its re-add can find.

So a quiet tool boundary reads the log alone, and a hook builds the reading
only after its own appends have changed what the reading would say. A
per-process memo of the reading keyed on the log's position was tried and
dropped: in the flows measured, every second reading followed an append, so it
never hit, and holding the last reading alive made later work in the process
slower.

Measured in process on a page of 41,000 events (1,000 threads of 13 rounds,
each picked up and answered), a session s1 with its fork lane up and a fork's
turn open, interleaved with the pre-fix base 81a3f7e, 18 runs each, median:
tool-boundary hook 193 ms here against 206 ms at the base, prompt hook
1,545 ms against 1,652 ms. Before this change, in one run of 7, they were
358 and 1,676 ms against the base's 217 and 1,590 ms.

No behavior changed.
…nment, and hand on a passed kept-back message once the lane is gone

Behavior changed:

- A running fork's tool boundary hands it the user's further messages as
  logged, as every other delivery does. `holding.rounds` took its waiting
  turns from the thread's reading, so a message and its rewrite reached the
  fork as the message in the rewrite's words with an `edited` key beside the
  rewrite. Each waiting turn is now the logged event, by id.
- The hooks build the page's threads with its containment
  (`revision_artifact.active_enclosing`), as the fold does, in place of none,
  so a thread a later version reopened by retracting a widget's answer
  through an element containing the widget reads open to both. That costs a
  1 ms read once the hook's modules are loaded. `rounds` and `reading_of` now
  take the threads from every caller.
- A kept-back message the cursor passed is the main thread's input at its
  next tool boundary once the lane goes down for good, with no fork turn or
  lane left in the session. The tool boundary now opens its re-add on input
  the cursor passed that no pickup names, which it reads from the log, for
  any session, and builds the page's reading for pending input only in a
  session with forks.

Structure: `forks.kept_back` reads the threads the line fork holds in the
page's reading, which derived them once (`kept_back_of`, now returning the
thread ids), instead of deriving them again.

Prose: the fork guide's outcome flowchart and table gain `resolved`, and the
module header, the guide and `session-lifetime.md` say the take's line and
the start's confirmation follow `forks.started` for a resumed fork too. The
module's `endForks` comment says why no clock retries a missed end: the
follower lists each change the user makes on a page, and an untold fork's
turn lapses within the working grace.
The adapter's abandonment receipted its batch and named in its failed pickup
only what the failure answers left owed, so a settled input stood past the
cursor with no pickup naming it, and every later tool hook on the page read
who holds each thread, which a quiet Codex hook had skipped. The failed
pickup now names everything the receipt passes, as every receipt's pickup
does. On a settled input a failed pickup changes nothing, since only an
action still owed reads one (workflows).

Behavior changed: an abandoned delivery's settled inputs now carry a failed
pickup, and a quiet Codex tool hook after an abandonment reads the log alone.
The delivery and harness docstrings now describe what the tool hook hands
over.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading "input the cursor passed that no pickup names" as "a holder kept this from the main thread" isn't enough to know the input is still owed. A kept-back message can stop waiting without ever being picked up: the user resolves its thread, the user takes it back, or the main thread answers it with a leaf reply, which records no pickup. After that, passed in deliverable stays non-empty for the rest of the page's life. Every tool boundary then builds page_holding, with build_threads and active_enclosing, even when nothing has changed. That applies to any later session that claims the page, whether or not it runs forks.

I checked this by extending test_a_kept_back_message_in_a_thread_the_user_resolved_is_no_input. After the resolution, two more PostToolBatch calls, then a third with holding_model.rounds counted: the quiet boundary still calls rounds once. So the description's "A quiet tool boundary builds no holding reading" holds only until the first such resolution. On the 41,000-event bench page, that puts the ~50 ms reading back on every tool call.

_hand_over_kept_back uses the same test. It now prunes HANDED by "named by a pickup" rather than by the cursor, so an id handed over and then resolved or withdrawn before any pickup stays in the session's record for good.

Both would go away if this path asked whether the passed input is still waiting, which the fold already knows. One option: record a pickup, or prune the id, when a held message stops being owed. Another: narrow passed to messages whose thread hasn't settled them. Then "no pickup" would stop standing in for "still owed".

Comment thread src/leaf/delivery.py Resolved
…ndary reads who holds each thread

The record of what the line forks handed to the main thread kept an id until a
pickup named it, so one whose thread the user resolved, or that they took
back, before the main thread took it in stayed for good. It now keeps, at each
hand-over, only the ids that still wait with no pickup naming them, by the
page's reading.

The tool boundary reads who holds each thread on a page holding input the
cursor passed that no pickup names. A held message that settles before any
pickup stays such input, so from then on that page's tool boundaries build the
reading, about 50 ms on a page of 41,000 events. Telling it from one that
still waits takes the fold's closing rules, which only the reading applies,
and the fold's own reader of what is owed (`current_responses`) cost 360 ms
against the reading's 217 ms there under the same load. The comments now say
so rather than that such input is held only while it waits.

Behavior changed: a settled id leaves the hand-over record at the next
hand-over.
leaf-agent added a commit that referenced this pull request Nov 15, 2026
…amps from files.py (#6039)

This is the weekly duplicate sweep of `src/leaf/` and `hooks/` (ISO week
46). It moves four capabilities that were implemented more than once to
one home each, and moves every caller. Behavior does not change. Every
replaced copy computed the same result as the home it now calls.

- **Applying non-overlapping `(start, end, text)` edits to a source.**
The new home is `structure.splice`, which is
`revision_delivery._spliced` moved and generalised to str or bytes. It
replaces five copies:
  - `revision_delivery._spliced`, from #3313, removed.
- The reverse-slice loop in `revision_artifact.bind_imports`, from
#1280.
  - The loop in `structure.rewrite_attribute_references`, from #1658.
  - The loop in `leaf_dev.docs.compose`, from #2660.
  - The loop in `leaf_dev.arrangement_eval`, from #4629.

The four reverse-slice loops copied the whole source once per edit. Each
of them applies edits that don't overlap and don't start at the same
offset, so splicing them in one pass gives the same output.
- **The file name of a stamped version.** `live_shell` wrote
`f"v{version}.html"` inline, from #666. It now calls
`files.version_name`.
- **Whether a note stamps a revision.** `validation/source_history.py`
scanned for the note inline, from fe4e8ea. It now calls
`files.stamped_version`, which was added in the same commit.
- **The `sha256:` digest of a revision's HTML.**
`revision_artifact._capture_artifact` hashed `document.data` again, from
#666. It now reads `SourceDocument.digest`, from #606, which holds the
same value.

I left `compose_document`'s two-insertion loop in `revision_delivery.py`
alone. `splice` orders edits at the same offset by their text, but that
loop relies on list order when `<html>` and `<head>` are both implicit.

**Verification.** `ruff` and `ty` pass on the touched files. These model
tests pass: `test_module_url_delivery`, `test_revision_delivery`,
`test_live_shell_artifact`, `test_product_page`,
`test_interact_document`, `test_interact_anchors` and
`test_interact_layer`, 626 tests in all. In
`dev/tests/model/test_product_page.py`, the second case of
`test_a_composed_part_refuses_an_authored_copy` fails at `assert slot in
authored`, before `compose` runs. Its fixture string expects `<img`
followed by `alt="Sandbox` at 16 spaces of indentation, and
`docs/index.html` on `main` now indents that line by 18. The failure is
in the test's fixture, not in this change.

<details><summary>Sets found but not consolidated here</summary>

Another open pull request already changes each of these:

- **Claude Code and Codex config homes, and the inline-delivery opening,
repeated in `leaf_dev`.** #6014 moves them onto
`harness.claude_code_config`, `harness.codex_home` and
`hook_transport.INLINE_OPENING`.
- **`hooks._awaits_agent` repeats `holding.running_turns`.** #6032
rewrites `running_turns`.
- **The "N user updates with no answer" sentence**, written in both
`activity.unanswered` and the `page-open-owes` finding. `activity.py`,
`findings.py` and `session.py` are all being changed in #5979, #6018 and
#6032.
- **Raster magic bytes**, read in both `media._UPLOAD_TYPES` and
`revision_delivery.media_size`. `media.py` is being changed in #6014.

These are not worth a shared helper, because they are one-line stdlib
idioms or the copies differ in meaning:

- `json.dumps(..., sort_keys=True)` used as a cache key.
- Compact `json.dumps` with `separators=(",", ":")`.
- The `script_kind(...) in {"module", "classic"}` membership test.
- `lock_is_held(page_dir / SERVER_LOCK)`.
- Inline closed-object JSON schemas.

**Not consolidated, needs a separate look.**
`sample_content._non_json_number` repeats `http.reject_json_constant`.
The real question is where Leaf refuses non-finite numbers. The HTTP
path refuses NaN and numbers past a double's range. Sample fixtures
refuse only NaN and infinity. No other reader of event JSON in
`src/leaf/` passes `parse_constant`. Sharing the helper would change the
`sample-json` message without settling that question, so it is left out
of this PR.

</details>

Co-authored-by: leaf-agent <[email protected]>
Base automatically changed from send-pickup-latency to main November 15, 2026 19:15
# Conflicts:
#	browser/types/contract.d.ts
#	dev/leaf_dev/journey_claude_code.py
#	docs/forks.html
#	src/leaf/forks.py
#	src/leaf/holding.py
#	src/leaf/served_state/state.schema.json
#	src/leaf/session-lifetime.md
#	src/leaf/state.py
#	tests/model/test_forks.py
@max-sixty
max-sixty merged commit 60e2b3e into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the fork-review-fixes branch November 15, 2026 23:32
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