Repository navigation
Address Claude Code forks by agent id, and score the line fork on a lookup in a file the session just changed - #6018
Merged
Merged
Conversation
… 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.
leaf-agent
previously approved these changes
Nov 15, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The description's Testing list says the leaf-dev journey run claude-code --fork-work result on this head is "see below", but nothing follows it. Since the description becomes main's commit message, either add that result or drop the line.
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]>
The journey named the fork in its fork-idle, fork-follow-up and fork-todo details from the take record, which no longer carries the agent for a new fork: Leaf learns the agent only as the fork starts. It now reads the start record of the take's turn, as fork-resume already did, through one agent_of shared by the fork steps.
leaf-agent
approved these changes
Nov 15, 2026
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.
Two follow-ups from the forks work (#5961, #6005): Leaf now addresses each Claude Code fork by its agent id rather than a per-thread name, and the line-fork eval gains a case for a lookup in a file the session just changed.
Forks are addressed by agent id
Leaf used to spawn each working fork under the name
leaf-<thread>. The main session was told "to steer or stop it, SendMessage leaf-", and page state and thefork-holds-threadadvice named the fork that way. Leaf spawns a second fork under the same name when the main session answered a thread last and a later message there goes to a fresh fork, and across a session's generations. A probe on Claude Code 2.1.325 found what then happens:$.agent.spawnaccepts the reused name, and the newest fork takes it.claude --resume, a send to the name reaches nothing.So the module now spawns forks unnamed, and
fork_nameis gone. Everything that tells the main session how to reach a fork names the agent id: the clerk's take line, the line at a fork's end, the advice beside a main-session command on a fork's thread, and page state's holder, which is now{"kind": "fork", "agent": <id> | null, "state"}. A new fork's id exists only once its spawn returns, so its take line moved fromforks._taketoforks.started; a resumed fork's id is known at the take.state.agent_turn_stampsand the servedagent_turnscarry the agent. The probe's findings are recorded innotes/fork-replies.md, anddocs/forks.htmlgives the reason in "#telling-address".One window is left: if the main session takes a thread over in the second before a new fork starts,
startedstill queues "leave that thread to it". The fork's own writes are refused all the same.Line-fork eval: a lookup in the page's source
In 20 live journey runs, the line fork judged "How many cards does this page's source hold? Count them in the file"
take17 times andhand_over3 times. Each time, the session had just recorded a release in the page's source. Theline-forkcases never had such an edit, so they didn't measure this. There are two new variants:source-edited(labeltake): the session has finished its edit and ended its turn. It scored 13/15.source-editing(labelhand_over): the session is part way through editing that file. It scored 14/14.Read as written, the take criterion agrees with these labels, so the prompt is unchanged.
Testing
pnpm run checkpasses.recovery-leaves-a-forks-answer, which reads the holder's new shape, still leaves the fork's answer alone 3/3.leaf-dev journey run claude-code --fork-workpasses every step:fork-idle,fork-follow-up,fork-resume(the follow-up reached the same fork by its agent id),fork-todoandfork-work. The journey now reads a fork's agent from its start record, since a new fork's take no longer carries it.