Repository navigation
Move a session's hooks to a checkout only for a page the session holds - #5229
Merged
Merged
Conversation
A checkout's `page init` made that checkout its session's delivering Leaf
(`session_runtime.select_checkout`) whatever page it initialized. A plain
`leaf-dev preview`, or a scratch page a Claude Code subagent initialized in its
own worktree, then moved the session's hooks, watch and post-compaction skill
reread to that checkout, though the session never reads that page.
A checkout now selects itself as a command claims a page for the session
(`server start`, `server run`, `page claim`), or as it initializes or renews a
page the session holds. `layer-registry.md` already stated that rule ("the
checkout that last initialized one of its pages"); the code ignored whose page
it was. Serving a page from a checkout still hands the session's hooks to it,
now at the claim rather than the init before it.
Claude Code runs a subagent's shell commands with its parent's session
variables and nothing naming the subagent (2.1.317), so a subagent's
`server start` on a scratch page still claims it for the parent and moves the
parent's Leaf. `ClaudeCodeHarness` records that fact.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Codex task's adapter starts from the selected Leaf, and an adapter running from another Leaf exits once a different one is selected (`codex_adapter.run_adapter`). The previous commit selected after the claim commands prepared delivery, so preparation joined the adapter about to leave and nothing replaced it. `server start`, `server run` and `page claim` now prepare the claim, select, then prepare delivery, the order a user preview already follows. A checkout's init or renewal of a page the session holds now readies delivery after it selects; on main that left a Codex task with no adapter. `test_a_claim_makes_its_checkout_the_sessions_leaf_before_preparing_delivery` checks, for all three claim commands, that the selection is in place when delivery preparation starts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Leaf A checkout's init or renewal of a page its session holds started the session's delivery again every time, even where the selection stayed: from an installed copy, which selects nothing, or from the checkout already selected. A Codex watcher task, which delivers through its own `leaf wait`, would then get an adapter that takes the wait lease. `select_launcher` and `select_checkout` now say whether they changed the selection, and the init starts delivery again only then, which is when a Codex adapter running from the former Leaf leaves. The held-page rule moves from `select_checkout`'s docstring to `vendoring._deliver_from_here`, which applies it; the claim commands need no such check, since the page they claim becomes the session's. `test_a_checkout_that_takes_over_a_held_page_starts_its_sessions_delivery_again` checks, for `page init` and a renewal, that delivery starts once, after the checkout is selected, and not again when nothing changed; the unheld-page test checks that delivery never starts. Each fails with the restart removed or made unconditional. Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty
marked this pull request as ready for review
November 3, 2026 20:49
leaf-agent
approved these changes
Nov 3, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 10, 2026
…5558) Adds one sentence to "Preview a page" in `/developing-leaf`: serve a scratch or repro page only with `leaf-dev probe`, `stills` or a plain `leaf-dev preview --source`, never `bin/leaf server start` or `page claim`. Those commands bind the page to the session running them, which for a subagent is its parent. Seven asks from a subagent's repro deck landed on a parent's turn-end checks and On me list this week. Since #5229 the dev tools neither claim a page nor move the session's Leaf, so they are the isolated test path; binding to a live session stays explicit. This changes agent instructions, so Max lands it. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.
A checkout's
page initmade that checkout its session's delivering Leaf (session_runtime.select_checkout) whatever page it initialized. A plainleaf-dev preview, or a scratch page a Claude Code subagent initialized in its own worktree, then moved the session's hooks, watch and post-compaction skill reread to that checkout, though the session never reads that page. The claim commands (server start,server run,page claim) selected nothing, so a fresh session's firstpage initandserver startfrom a checkout left its hooks on the installed copy, which can't read the page if the checkout is at a newer page protocol (#4557's case).Now a checkout becomes the session's Leaf when a command takes a page for the session (
server start,server run,page claim), or when it initializes or renews a page the session already holds.layer-registry.mdalready stated that rule ("the checkout that last initialized one of its pages"); the code ignored whose page it was.A claim selects before it prepares delivery. A Codex task's adapter starts from the selected Leaf, and an adapter running from another Leaf exits once a different one is selected (
codex_adapter.run_adapter), so a selection made after preparing would retire the adapter that preparing had just joined, leaving the task with none. Likewise, a checkout's init or renewal of a held page now starts delivery again when it changes the session's Leaf; on main that left a Codex task with no adapter. Where the selection doesn't change, as from an installed copy or the checkout already selected, it leaves delivery alone, so a Codex watcher task delivering through its ownleaf waitdoesn't get an adapter that takes its wait lease (inferred fromsession.py, not run).What this leaves
Claude Code runs a subagent's shell commands with its parent's session variables and nothing that names the subagent. In a subagent's Bash at 2.1.317,
CLAUDE_CODE_SESSION_ID,CLAUDE_PID,CLAUDE_JOB_DIR,CLAUDE_CODE_CHILD_SESSION,AI_AGENTand the shell snapshot all match the parent's; only hook payloads carryagent_id. So a subagent'sserver starton a scratch page still claims it for the parent: the parent holds it, Leaf's turn-end clerk offers it to its fork beside the user's page, and the claim makes the subagent's checkout the parent's Leaf.ClaudeCodeHarness's docstring now records that fact.A hook could pass the id on only by rewriting the command (PreToolUse
updatedInput, or the hooks module'stool.call). When Claude Code matches a command against permission rules it strips only a fixed list of variable prefixes (NODE_ENV,LANGand the like), so a command rewritten to set a Leaf variable would likely stop matching a rule that allowsbin/leaf. That is read from 2.1.317's bundled source, not tried. This PR doesn't rewrite commands.Deriving the delivering Leaf from the runtime each held page's service record names, instead of storing a selection that commands set, would remove
select_checkoutand its ordering. It isn't in this PR, because it needs an answer every process computes the same way (the hooks, a Codex adapter and the command preparing its successor), and a session holding pages served by two runtimes, such as its own page and a subagent's scratch page, has no record that says which one the user reads. It also has to keep a user preview's explicit choice, give a held page that was never served a fallback, and have a Codex adapter hand over to its successor rather than exit.Evidence
.tmp/repro.sh(not committed) runs in a throwawayXDG_STATE_HOMEwithCLAUDE_CODE_SESSION_IDandCLAUDE_PIDset by hand, as every Bash call of a Claude Code session and its subagents carries them. The parent serves its page and selects another Leaf; then, in the same environment, a "subagent" runs this checkout's commands.page initof a scratch pageleaf-dev preview triage-boardleaf-dev probe review-a-planarms.pyscrubs identity)server starton that scratch pageA fresh session's first
page initthenserver startfrom a checkout selects nothing on main and selects the checkout here.Tests:
test_a_checkout_leaves_its_session_alone_for_a_page_the_session_doesnt_holdfails on main and passes here; it also checks that delivery never starts.test_a_checkout_that_takes_over_a_held_page_starts_its_sessions_delivery_again, forpage initand a renewal, checks that delivery starts once, after the checkout is selected, and not again when nothing changed. It fails with the restart removed or made unconditional.test_a_claim_makes_its_checkout_the_sessions_leaf_before_preparing_delivery, forpage claim,server startandserver run, checks the selection is in place when delivery preparation starts.page claim,page initorserver start, then expects an adapter to queue the next input; not committed) passes all three here. By the reviewer's runs,claimandstartlose the adapter on this PR's first commit, andinitloses it on main.Tests run
uv run pytest tests/model/test_hooks.py tests/model/test_hook_registration.py tests/model/test_claims.py tests/model/test_server_lifetime.py tests/model/test_session_lifecycle.py tests/model/interact_contract/test_revendoring.py tests/model/test_codex_adapter.py dev/tests/model/test_interact_preview.py tests/process/test_interact_server.py tests/journeys/test_claims.py tests/journeys/test_server_lifetime.py tests/journeys/interact_contract/test_revendoring.py "tests/journeys/test_codex_adapter.py::test_selecting_a_checkout_replaces_the_sessions_delivery_runtime" -n 4: 454 passed, 1 skipped, 1 failed. The failure,dev/tests/model/test_interact_preview.py::test_preview_file_subscription_follows_atomic_replacements, fails the same way on main.-n 3: 3 passed.uv run pytest tests/model/test_hooks.py tests/model/test_codex_adapter.py tests/model/test_claims.py tests/model/test_hook_registration.py tests/model/test_server_lifetime.py tests/model/interact_contract/test_revendoring.py tests/process/test_interact_server.py tests/journeys/interact_contract/test_revendoring.py "tests/journeys/test_codex_adapter.py::test_selecting_a_checkout_replaces_the_sessions_delivery_runtime" -n 4, with the reviewer's Codex test added: 365 passed, 1 skipped.uv run pre-commit run --fileson the changed files.Not run: the claude-code and codex journeys (
leaf-dev journey), which/developing-leafasks for after a change toClaudeCodeHarnessor Codex delivery; theClaudeCodeHarnesschange is a docstring, and the Codex ordering is covered by the reviewer's test above.