Skip to content

Address Claude Code forks by agent id, and score the line fork on a lookup in a file the session just changed - #6018

Merged
max-sixty merged 4 commits into
mainfrom
send-pickup-latency
Nov 15, 2026
Merged

max-sixty merged 4 commits into
mainfrom
send-pickup-latency

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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 the fork-holds-thread advice 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.spawn accepts the reused name, and the newest fork takes it.
  • If the main session had already sent to the earlier fork, a send to the name is refused ("now resolves to a different agent … Nothing was sent").
  • If it hadn't, a send meant to stop the older, still-running fork reaches the newer one.
  • After claude --resume, a send to the name reaches nothing.
  • A send by raw agent id always reaches its agent: it resumes an ended one, queues for a running one, and works across generations.

So the module now spawns forks unnamed, and fork_name is 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 from forks._take to forks.started; a resumed fork's id is known at the take. state.agent_turn_stamps and the served agent_turns carry the agent. The probe's findings are recorded in notes/fork-replies.md, and docs/forks.html gives 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, started still 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" take 17 times and hand_over 3 times. Each time, the session had just recorded a release in the page's source. The line-fork cases never had such an edit, so they didn't measure this. There are two new variants:

  • source-edited (label take): the session has finished its edit and ended its turn. It scored 13/15.
  • source-editing (label hand_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

  • Focused model suites: forks, hooks, clerk, activity, delivery, todos, interact and workflows; the Claude Code module process test; the timeline dev test; and the served-state schema test.
  • Each changed test fails on the old addressing.
  • pnpm run check passes.
  • 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-work passes every step: fork-idle, fork-follow-up, fork-resume (the follow-up reached the same fork by its agent id), fork-todo and fork-work. The journey now reads a fork's agent from its start record, since a new fork's take no longer carries it.

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

… 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
leaf-agent previously approved these changes Nov 15, 2026

@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.

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.
@max-sixty
max-sixty merged commit 0a66fbe into main Nov 15, 2026
4 of 5 checks passed
@max-sixty
max-sixty deleted the send-pickup-latency branch November 15, 2026 19:15
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