Skip to content

Read who holds each thread once, and have a command acting as the main session on a fork's thread say so - #6005

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

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

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Follow-up to #5961, which let a fork of a Claude Code conversation answer a thread in a turn of its own. This PR lands three decisions from that work.

One reading of who holds each thread

Before this change, who held a waiting message was worked out in several places. holding_turns and last_taken read pickups and answers. forks.kept_back was a second reading of the messages kept back for the line fork. Callers then built their own sets from those: kept_from_main, agent_held, left_by_agent_turns, the fold's owes() and thread_holders, and forks.forked, and each walked the log again. They disagreed in page state. A thread kept back for the line fork printed main as its holder, both on the thread and on its owed answer, for up to 30 s.

The rule's unit is the thread: a turn that picks up any of a thread's waiting messages takes the whole thread. So holding.reading() now builds one Holding per page operation, with a Hold(turn, picked, holder) for each thread. The holder is the line fork while the thread is kept back, else the turn whose pickup of a waiting message is newest, else the thread's last taker. Every rule asks that reading:

  • delivery and admission;
  • the fold, and through it the Stop hook (activity.agent_holds) and page state, which prints the reading on each thread and, through owed_by, on each owed answer;
  • the fork rules: pickable, to_carry, refuse_unheld, taken_by_agent_turns and forks.ended.

It replaces holding_turns, last_taken, newest_pickups, picked_in, turn_threads, running_threads, forks.forked, forks.kept_from_main, holding.agent_held, holding.left_by_agent_turns and the fold's own composition. deliverable reuses the fold's reading, so the Stop hook reads holders once. In the served state, kept_back replaces forked as the one presence field, and On it is Holding.forked().

The only intended behavior change is that a kept-back thread's holder reads {"kind": "line"}. An independent reviewer ran the merge base's code beside this branch's at every call in the fork, hook, clerk, delivery and stop-guard suites. The results matched in every call (deliverable 372/372, turn_obligations 257/257, pickable 225/225, refusals 309/309, among others), and holders differed only for the 127 kept-back threads.

A command acting as the main thread on a fork's thread says so

A leaf command that no agent id marks acts as the main session: the main session itself, a fork's own script, a worker subagent, or a terminal. The question was what such a command should do with a thread a running fork holds. The decision: let it go through, keeping the main session's authority, and warn that the thread has a holder. holding.authorize now returns an advice finding, fork-holds-thread, which names the fork. On an answer, which takes the thread, it also says the fork's later writes there are refused and how to stop the fork; on a working message or a start, it says the command acted beside the fork. It covers a writer outside the session and a start on a to-do in the fork's thread. leaf task end takes nothing a fork holds, so it isn't warned.

Worker subagents no longer told to leave the page alone

The decision: shipped instructions should say only what we have a strong view on. So conversation-loop.md no longer tells worker briefs to keep off the page. The Claude Code contract keeps one line with a mechanism behind it: a subagent's leaf wait takes the main thread's input. On parent-keeps-leaf-responsive (Claude Code, 3 runs each), head and base both passed 2/3, and both misses were the parent doing a setup check itself. A TODO in holding.holder says what to build if workers come to act on pages.

Testing

  • Focused model suites: forks, activity, hooks, delivery, todos, threads, session lifecycle, interact, workflows, stop guard, clerk, claims, Codex adapter, folds and obligations.
  • New tests, each checked to fail without its behavior:
    • a kept-back thread reads line on the thread and on its answer;
    • a message beside a fork's answer leaves the fork holding the thread;
    • a command from outside the session is warned;
    • a start on a to-do in a fork's thread is warned;
    • Leaf's own line post prints no warning.
  • pnpm run check passes.
  • leaf-dev journey claude-code --fork-work passed all 8 steps on Claude Code 2.1.325. Working messages came at 2.6–5.1 s, a running fork answered a follow-up 13.2 s after it was sent, and a resumed fork answered at 13.9 s.
  • Reviews: Codex and three Fable passes.

Size

Production files (src, dev) are +691/−529. Docstrings and comments account for about +65 of the net, code for about +92, and the warning for about 45 of those code lines. The change removes no lines overall. What it removes is eleven helpers, each of which composed its own answer to who holds a thread.

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.
@max-sixty
max-sixty merged commit 5fa519c into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the send-pickup-latency branch November 15, 2026 02:07
max-sixty added a commit that referenced this pull request Nov 15, 2026
main's one reading of who holds each thread (#6005) replaces the fold's own
composition. The standing fold takes it as `holding`: the running agent turns
and each owed answer's holder come from it, and a waiting update a fork has
taken on reads `running` from `Holding.forked`, which presence no longer
carries. A start on a to-do reads the to-do's thread from the obligation record
it now is.
max-sixty added a commit that referenced this pull request Nov 15, 2026
…ookup in a file the session just changed (#6018)

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-<thread>",
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_
max-sixty added a commit that referenced this pull request Nov 16, 2026
…ent (#6097)

Every message head and progress face in a thread now shows when it was
said: its clock time, with its day unless that is today ("17:52",
"Yesterday 15:35", "15 Aug 09:12"). Before, a thread showed a relative
age only where it changed from the message above, so a day-old thread
read one "1d ago" over replies hours apart, such as "I'm building it
now" at 15:35 and "Built in #6005" at 17:52. Each reply says what was
true when it was sent, so the reader needs each one's moment. The agent
now gets the same: `leaf page state <page> <message>` and a delivery's
thread digest carry each message's `ts`, where before only the batch's
own events did.

To weigh: this reverses the 26 October choice in #4323 to say an age
only where it changes, which answered "72d ago" repeated down a thread;
clock times differ where ages repeat, but a day-old thread now repeats
its day ("Yesterday" on each message). Each time names its own day so a
head read alone (a card's sticky head, or below a first message scrolled
away) never reads as today's. Where a head beside a card's controls
can't hold both, the clock is dropped whole and the day stays
(`surfaces.css`), where an ellipsis cut it to "15 Au…". The digest's
`ts` is optional in the delivery record, so the protocol stays put.

Asked for by the user on a Leaf page; a fresh reviewer read the
before/after captures and Codex reviewed the diff. Tests: `saidAt` unit
cases; the browser tests that read a head's time; the page-state paging
test checks each message's `ts`, and a delivery snapshot gains it.

> _This was written by Claude Code on behalf of max-sixty_
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