Skip to content

Renew a Claude Code session's pages follower when its Leaf changes, record why each message was forked, and add leaf-dev timeline - #5796

Merged
max-sixty merged 10 commits into
mainfrom
fork-observability
Nov 10, 2026
Merged

max-sixty merged 10 commits into
mainfrom
fork-observability

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Forks went silent on long-lived Claude Code sessions after a protocol bump, and nothing recorded why. This adds the diagnostics and the tool that found it, and the fix.

The bug. On 8 Nov the leaf-issue-triage session's pages follower had run since 4 Nov at protocol 41. Its checkout moved past two bumps (#5445, #5716), and the session's hooks ran the newer Leaf, which reads a fork lane written at an older protocol as down. So the old follower held messages and asked for forks, the fork step said "not held" and made none, and each message waited out the 30 s hold with no working line. One waited 64 s while the session sat in a 70 s foreground poll, the case forks exist for.

The fix. The pages follower (hooks.cmd_pages) now exits with EX_TEMPFAIL (75) once the session's hooks would run another Leaf than its own: another installed copy, another selected checkout, its own checkout moved past a protocol bump, or its own install removed. The hooks module (hooks/claude-code.ts) starts it again on exit 75, under that Leaf. Verified live: changing the protocol on disk and back replaced a running session's follower each time, and the next comment got its line at 3.1 s.

Diagnostics. Each page's observations now record fork_hold at admission (held or not, and whether the session's fork lane was up) and fork_asked when Leaf gives the module the fork's question, beside the existing fork_reply outcomes. When the module's own fork step fails, it now tells Leaf, which hands the message over at once and records the error instead of a silent 30 s wait.

leaf-dev timeline PAGE [--message ID] merges a page's log and diagnostics, each Claude Code session's transcript (turns, the context Leaf's hooks carried in, leaf commands, subagents) and Claude Code's debug log into one time-ordered story, with a summary line per message: held or not and why, the fork's outcome and time, first words, pickup and what the session was doing, answer. The Claude Code journey now keeps the session's transcript in its evidence, so the tool reads a journey run as it reads a live page.

TODO.md also gains a challenge Max asked for: streaming the agent's reply into its thread through one general interface.

Tests: tests/model/test_forks.py (the diagnostics; the follower ending for each kind of Leaf change), tests/process/test_interact_claude_code_module.py (a follower that exits 75 starts again), dev/tests/model/test_response_times.py. Live: leaf-dev journey claude-code --forks --case working, and real pages from 6 to 9 Nov.

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

…asn't forked

`leaf-dev timeline PAGE` puts a page's log and diagnostics beside the transcript,
subagents and debug log of each Claude Code session that held it, in one
time-ordered list, with a line per message saying when its fork ran, when the agent's
first words, the session's pickup, start and answer came, and what the pickup waited
on (`response_times.page_timings`). `--message ID` keeps one message's story.

Asking it why two messages on a real page (leaf-issue-triage, 8 Nov) had no working
line found the record too thin to say: the lane's hold ran out at 30 s ("no answer
within 30 s") while the session sat in a 70 s foreground poll, but nothing said
whether a fork was ever asked, and the module's failures go only to a debug log real
sessions don't write. So:

- admission notes whether it held each thread message for a fork and, where it
  didn't, whether the session's lane was up (`fork_hold`, `forks.held_at_admission`);
- `forks.ask` notes each fork Leaf asks for (`fork_asked`), so one that never
  answers shows;
- the module tells Leaf when its own step fails, which hands the thread over at once
  and notes why, rather than leaving the hold to run out unexplained;
- the claude-code journey keeps the session's transcript and its subagents' in the
  run's evidence (`claude/`), where the timeline reads them.
… protocol

A pages follower runs as long as its Claude Code session, and holds the session's
forks lane with a lease naming the page protocol it speaks. A worktree's checkout can
move past a protocol bump meanwhile, and the session's hooks then run the newer Leaf,
which reads that lease as no one's (`leases.lease_speaks_here`). On the
leaf-issue-triage page a follower started on 4 November at protocol 41 was still
running on 9 November, with the checkout at 43: twice on 8 November it held a message
and listed it for a fork, and the fork's step, under the newer Leaf, found it not held
and asked no fork, so the message waited out its 30 s hold with no working line, once
while the session sat in a 70 s foreground poll. `leaf-dev timeline` showed the hold
running out with no fork asked, and the lane file read 41.

The follower now ends, without a last list, once the kernel registry on disk names
another protocol than the one it loaded (`registry.kernel.installed_protocol`, read
each presence interval at about 0.3 ms), and the module starts it again when one ends
cleanly while it listed pages. In a live Claude Code session, bumping the registry's
protocol on disk replaced the follower within 2 s, and a comment sent after it got the
fork's line at 2.4 s.
A follower checks the kernel registry on disk each presence interval to see whether
its Leaf moved to another protocol. Where Claude Code removed the plugin version it
was loaded from, or a checkout is mid-write, that read fails: before, the follower
would exit with an error the conversation shows, though a follower started again
from that install couldn't start. It now reads that as no move and keeps running.
…cord what the live runs found

The timeline now lists each line Leaf's clerk queued after a delivery, such as the
line telling the agent what Leaf put On me as its own, and counts a subagent's tool
calls without the call a plugin spawned it with. notes/fork-replies.md records the
real pages of 6-9 November and the follower that outlived two protocol bumps;
/developing-leaf points at the timeline for finding out what happened to one message.
…eaf, by an explicit exit

A review found two gaps in starting the follower again across a protocol bump.
The module inferred a renewal from a clean exit while it last listed pages, so a
follower renewed after the session's last page went could start again and again
(the launcher's no-claim gate exits 0 with no list), and one holding only pages
whose servers were down was never renewed. And the follower compared only its own
install's protocol, while Claude Code installs an update into a new directory and
the session can select another checkout: the session's hooks then hand themselves
to that Leaf (`session_runtime.delivering_launcher`), which reads the old
follower's lane as no one's, though the follower's own install never changed.

The follower now ends with EX_TEMPFAIL once the session's delivering launcher is
not its own or its install moved to another protocol, the same test `hooks.main`
makes before it hands a hook over, and the module starts it again on that exit
code alone.
…-dev timeline

The timeline found transcripts and decided each message's fork with copies of what
reply_phases and response_times already do. reply_phases now names the transcript's
path (claude_code_transcript_path), and response_times' fork reading carries Leaf's
reason where it handed a thread over without a line, which the timeline prints. A
journey's debug log goes only to the session the journey ran, and a subagent whose
metadata doesn't say it finished reads as last writing, not ended.
A second review found one more way a follower outlives the Leaf its session runs:
a checkout the session selected is removed while the session still holds a page.
The session's hooks then fall back to the installed copy, while the follower,
running the removed checkout, finds no other selection from where it stands, so it
kept its lane under the old runtime. It now ends for renewal once its own launcher is
gone too; the module starts it again from its own launcher, which hands it to the
Leaf delivering now. This reverses the guard that kept such a follower running: it
assumed a renewal would start from the removed install, but it starts from the
module's. A registry read mid-write still reads as no change.
# Conflicts:
#	src/leaf/forks.py
@max-sixty
max-sixty merged commit c27dc7e into main Nov 10, 2026
5 checks passed
@max-sixty
max-sixty deleted the fork-observability branch November 10, 2026 18:28
max-sixty added a commit that referenced this pull request Nov 26, 2026
…e Code renews Leaf's hooks module

A hook whose skill differs from the previous hook's now tells the agent to
read the skill again whatever copy ships it, a checkout the session's hooks
run included. Before, a checkout at the same root was exempt, on the guess
that a session running a checkout is the one editing its skill, so a merge
or branch switch that changed the skill under a `--plugin-dir` session went
unnoticed (the gap #6782 named). An edit the session makes to that skill
now draws the notice too.

Three texts said Claude Code keeps the hooks module until `/reload-plugins`.
Measured at 2.1.332 with a probe mod loaded by `--plugin-dir` in an
interactive session: a save to the module file renewed the instance within
seconds (register and session.start ran again, and the child the old
instance spawned was killed); a save to any other file, a SKILL.md or a data
file, renewed nothing, and neither did `/reload-plugins` or
`/reload-plugins --force` after it. A module can't import JSON ("not named
like code and was not loaded"), so Claude Code can't learn that Leaf's
Python or kernel registry moved. The follower's restart on a protocol move
(`_moved_on`, #5796) therefore stays: it is the one part of running a
checkout in place that Claude Code can't do for Leaf.

The skill-notice test now expects the notice for an edited checkout skill.
max-sixty added a commit that referenced this pull request Nov 26, 2026
…nd say when Claude Code renews Leaf's hooks module (#7221)

Leaf no longer tells the agent to read the leaf skill again when the
skill its session's hooks ship changes; the skill text the agent read is
the harness's to keep or renew, as Claude Code's `/reload-skills` does.
The notice fired on nearly every update a session picked up (444 of
main's 2,093 commits in the last 30 days touched `skills/leaf`), and it
needed a change for each way a copy of Leaf changes: Codex's and Pi's
in-place updates, then a checkout loaded with `--plugin-dir`. Each hook
now records only the root of the Leaf it runs (`leases.mark_root`,
`sessions/<digest>.root`), which `state.hooks_root` still reads, and no
longer hashes the skill's files on every call. The notice after a
compaction stays.

It also corrects three texts (the `carrier.py` header, How it works'
carrier paragraph, `cmd_pages`) that said Claude Code keeps the hooks
module until `/reload-plugins`. A probe plugin loaded with
`--plugin-dir` in an interactive 2.1.332 session showed that a save to
the module file renews the instance within seconds and kills the
children it spawned, while a save to any other file renews nothing, even
through `/reload-plugins --force`. A module can't import JSON, so Claude
Code can't see Leaf's Python or kernel registry move, which is why the
follower's restart on a protocol move (`_moved_on`, from #5796) stays.

Worth weighing: the record's file is renamed from `.skill` to `.root`,
so across the one update that ships this, a page server from the older
copy won't follow to the newer one; both speak the same protocol.

The maintainer asked whether Leaf supports `--plugin-dir` well, then
proposed dropping the skill notice. The hooks, forks, server-lifetime,
session-lifecycle and hook-registration model tests pass.

> _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