Repository navigation
Drop checkout selection, and keep sessions and claims readable across record shapes - #7061
Conversation
A checkout's `bin/leaf` no longer makes itself the session's Leaf when it claims, serves or initializes a page the session holds, and `leaf-dev preview --user` no longer selects the launching checkout. The session's hooks, pages follower, bare `leaf` and Codex adapter run the copy the harness loaded; a checkout runs only the command it was given and any page server that command starts. The maintainer asked for this on the page comparing ways for a Leaf-dev session to run Leaf, since sessions should start normally on the installed plugin rather than with --plugin-dir. Removed: `session_runtime.py` and every hand-off to it (`hooks.main`'s exec, the follower's selection check, `cli`'s `hand_off_command`, `vendoring._deliver_from_here`, the selection calls before a claim in `service` and `hosting`, the Codex adapter's exit on selection and the claim's wait for it, preview's `launching_checkout`), and the `launcher` field of the session lifecycle and Codex adapter records. `renew_layer` loses its `command` flag. `bin/leaf` already ran only its own tree since #6758, so it needs no change beyond its comment. Kept as the one guard: a Leaf at a later page protocol than the Leaf a live session's hooks run refuses to take a page that session holds to its own protocol, by renewal or `page init` (`vendoring._refuse_unheard`, finding `unheard-protocol`); a re-init that moves no protocol passes. It reads the hooks' Leaf from the root each hook already records (`state.hooks_root`) and its protocol from that tree's kernel registry, so hooks write nothing new. Such a move can't be undone, since no Leaf takes a page back down. A claim gets no check: since #6954 the hooks refuse a page at another protocol and say so, and the agent can hear such a page with the checkout's `leaf wait`. The `newer-layer` refusal now names the page's protocol, so that report tells a checkout ahead of the plugin from a plugin update. A Codex task's new adapter starts through the launcher of the copy the task's hooks run (`state.hooks_launcher`), whichever Leaf claims, so a checkout's claim no longer puts the task's delivery on the checkout. Protocol: the session lifecycle and Codex adapter records change shape, so each moves `since` from 13 to 56, the current protocol; per `layer-registry.md`, "Page protocol", that needs no bump, since neither `since` named 56 already and a reader treats a record at another format as absent rather than misreading it. No logged event changes. A bump would not help the one cost this leaves: a checkout and the session's own Leaf now write the session's records side by side, so until both keep them at the same `since`, each reads the other's lifecycle as absent and replaces it. `session-lifetime.md` now says so. Behaviour changes in tests: the selection tests go (bare command and hook hand-off, the bridge before hand-off, selection on claim, init and renewal, the Codex adapter's replacement on selection); the follower's "selected" case goes; new tests cover the rewrite refusal and the adapter starting from the hooks' copy.
leaf-agent
left a comment
There was a problem hiding this comment.
The one point is in the inline comment: the new unheard-protocol refusal on renewal and page init guards a state this PR deliberately allows for claims, and its docstring gives a reason the rest of the PR contradicts. Either keep it and say what makes renewal different from a claim, or drop it. Apart from that, the removal is complete. session_runtime, the launcher fields, select_checkout and LEAF_PREVIEW_LAUNCHER_ROOT have no remaining references. The focused tests touching the follower, adapter start and renewal refusal pass locally.
A Leaf whose page protocol differs from that of the Leaf the session's hooks run now refuses a claim for the session (`service.refuse_unheard`, which every claim prepares through, `leaf-dev preview --user` included), in both directions, as well as a renewal or `page init` that takes a held page from an older protocol to its own. A re-init that moves no protocol passes; the check before refused any re-init of a held page while the hooks ran an older Leaf, whose advice then named a Leaf that couldn't read the page. Why: a worktree is usually behind the plugin's protocol, and from there a claim let the session's hooks renew the page up to their protocol and restart its server under the plugin, so the user reviewed the plugin's runtime in place of the change. A probe of the prompt, tool-batch and Stop hooks renewing such a page printed nothing at all. Ahead, the hooks refuse the page, but only at the next prompt. The refusal now arrives at the command and names the route: merge main when behind; serve the page unclaimed and hear it with that checkout's `bin/leaf wait PAGE` when ahead, or `/reload-plugins` once the installed copy has caught up. A preview --user from such a checkout gets the same refusal rather than a fallback that serves it unclaimed, which would need code of its own. `state.protocol_at` takes over `registry.kernel.installed_protocol`, so `service`, below `registry` in the import order, can read a tree's protocol. Tests: the claim refusal in both directions, and a re-init that moves no protocol.
leaf-agent
left a comment
There was a problem hiding this comment.
The new commit settles the earlier thread consistently: refuse_unheard now covers claims too, and its docstring names what makes each direction harmful. But the PR description, which becomes main's commit message on the squash, still says the opposite. Its Invariant paragraph reads "A Leaf at a later protocol than the session's hooks won't take a page the session holds… Unlike the prototype, claims aren't refused; the hooks' newer-layer refusal (#6954) reports them". After b6ea42b, a claim is refused at either protocol mismatch, earlier or later, and leaf-dev preview --user is refused with it. Please update that paragraph, and the What developers lose line if you want it to mention the "merge main first" case, before this lands.
…g-leaf /developing-leaf told agents to run every `leaf` command through the checkout's launcher, conversation pages included. With checkout selection gone, a page the session holds stands at the protocol of the copy its hooks run, so a worktree behind that copy, the usual case, is refused on the session's own page. "Run `leaf`" now splits the two cases: a page the session holds goes to the session's own `leaf`, the copy its hooks run; this checkout's runtime (previews, fixtures, pages the session doesn't hold, the tests and `leaf-dev`) goes to `<root>/bin/leaf` and `uv run`. "Author or revise a page" reads the leaf skill of the Leaf that runs the page. No other guidance sent every command to the checkout. The ahead refusal now says what running the session's launcher is for.
The user decided that developing Leaf works exactly as developing any
other project does, so a checkout's `bin/leaf` run inside a session should
matter to the session no more than a project's dev server, and its
version, page protocol included, should never reach the session.
`harness.session_harness`, the one place a command learns which session it
acts for, now finds no harness where the session's hooks last ran another
Leaf (`state.runs_session`, from the root each hook already records). Such
a Leaf acts as a command from a bare shell does: it claims nothing, writes
none of the session's records, and serves a page unclaimed, which its own
`leaf wait` hears. A `leaf-dev preview --user` from a checkout therefore
serves its durable page unclaimed in a session started normally, and
claims only where the session's hooks run that checkout, as in
`leaf-dev journey session`.
Removed with it: the claim refusal at another protocol
(`service.refuse_unheard`, its two refusal texts and its tests),
`state.protocol_at` (`registry.kernel.installed_protocol` takes a root
again), `state.hooks_launcher`, and starting a Codex task's adapter through
the hooks' launcher, since only the Leaf the hooks run now claims.
Kept, as the one guard, for any Leaf: a page a live session holds isn't
taken to a later protocol than the one that session's hooks run
(`vendoring._refuse_unheard`). A bare-shell Leaf's `page init` on a held
page whose server runs is refused already by the restart
(`hosting.restarting_server`), and its renewal by `renew_layer`'s
ownership rule; the guard covers the case where the held page's server is
down, which would otherwise move the page irreversibly onto a protocol its
holder can't read. A checkout's `page claim` now says only the Leaf an
agent session's hooks run can claim for it.
Prose: `session-lifetime.md`, `how-it-works.html`, `/developing-leaf`
("Run `leaf`": a page the checkout serves, `--user` previews included, is
heard with `<root>/bin/leaf wait`), `previews.md` (a checkout's preview
connects to no chat), and the preview's header and `--user` help.
Tests: the two refusal tests become one that a Leaf other than the
hooks' acts for no session at any protocol, and one that no Leaf takes a
held page past its hooks' protocol; the adapter-launcher test goes.
leaf-agent
left a comment
There was a problem hiding this comment.
The Codex journey's --preview mode now fails every time, but it stays in the tree. The description says so ("the codex --preview journey now fails by design"). leaf-dev journey run codex-app-server --preview installs an extracted copy of the plugin into the throwaway Codex home (install_codex_plugin), so the task's hooks mark that copy. Its setup then runs leaf-dev preview --user from the checkout, so runs_session is false and session_harness() returns None. The preview serves unclaimed, no adapter starts, and the mode's checks fail before any step runs: Codex.between's "the preview lost its acquisition", the claim naming the task's turn, and the reconnect step. A journey mode that can never pass protects no behavior and misleads the next person who runs it (AGENTS.md, "Stage": change or delete a test whose behavior changed). Removing it is the cheap fix: the --preview option in journey/run.py, Codex.preview and its branches in dev/leaf_dev/commands/journey/_codex.py, the reconnect step and the module docstring's --preview paragraph. With it gone, the leaf-dev preview header's "In Codex it also starts or joins the task's delivery adapter" applies only in a journey session, so that sentence could be scoped the same way. I can push that removal if you'd like.
…views A page a live session holds is now served and re-initialized only by the Leaf that session's hooks run, whatever the protocols and with its server up or down (`service.refuse_held`): `page init`, a first serve that takes no claim, and a restart for another session all refuse with one message. Another session takes the page over first by claiming it. Since only the hooks' Leaf acts for a session, no other Leaf can move a held page to a protocol those hooks can't read, so the protocol comparison that guarded that move (`vendoring._refuse_unheard`, finding `unheard-protocol`) goes, and `registry.kernel.installed_protocol` takes no root again. The `newer-layer` text returns to main's, since it no longer reports a checkout's claim. Behaviour change: another session's or a terminal's `page init` of a page a live session holds is refused with its server stopped too, where it used to rewrite the layer. A probe of a checkout behind, at and ahead of the session's protocol, with the page's server up and down, found every `server start` and `page init` refused and nothing changed; the two `server start` cells with a running server at another protocol answer with the existing protocol refusal, which `start_page` reaches first. With a worktree's preview unable to reach a Codex chat, as the user decided, the paths that served one go: the codex journeys' `--preview` mode and its guidance in `agent-journey.md`, and the preview's desktop detach (`start_desktop_preview`, the worker's `--prepared-claim` and `--handshake`, and `--base`'s wait for detached arms), with their journey tests. Nothing else reached them; `claim_and_start`'s prepared claim stays for the prompt hook's reconnect.
…kout act only once the hooks run it An independent review found two defects, both confirmed in temporary state homes. Held pages. `refuse_held` read a session record another Leaf wrote at another `since` as absent, so it took a page the session's own Leaf served for unheld: the review's probe had this Leaf stop the live server, move the page to its protocol and leave it disabled. `renewable()` already counted such a page held. Both now ask one predicate, `service.held_elsewhere`: a live claim another session holds, or a claim or lifecycle record this Leaf can't read. The claim carries no lifetime of its own (`claim_reading` takes it from that record), so nothing this Leaf reads proves such an owner ended; a session takes the page over by claiming it, which reads no earlier claim, or the Leaf that wrote the records retires them. `_restarts_for_session` asks it first, so an unreadable record no longer reads as an ended session whose service the restart stops. Which Leaf acts for a session. `runs_session` let any Leaf act for a session no hook had marked yet, so a checkout's `leaf-dev preview --user`, which no PreToolUse rule matches, claimed the page in a fresh session; and a stale mark from an earlier copy left the session's own installed copy acting for no session. It now decides from facts a process has at start: an installed copy acts for the session, and a checkout only once the session's hooks run it (`state.hooks_run_here`, which `renew_held` uses too). `harness.unserved_session` names the session a Leaf doesn't act for, and `server start` and a `--user` preview from such a Leaf say they serve for no session and that its own `leaf wait` hears the page (`serves-for-no-session`). The held-page refusal's remedy now reads for a person in a shell as for an agent. Tests: the suite runs this tree, a checkout, as the Leaf of every session it sets up, so each session now records that its hooks run this tree, as a real first hook would (`conftest.hooks_run_this_tree`): the conftest's own sessions and Codex's `codex-thread`, the sessions `start_server_command` and `under_codex` start, the Claude Code and Pi module helpers, and each `monkeypatch.setenv` of a session id. New tests cover a checkout acting only once the hooks run it (with an installed copy acting whatever the mark), and a page whose lifecycle record another Leaf wrote staying held until another session claims it.
…n's hold whichever Leaf recorded it A restart for anyone but the holding session now refuses a held page before it stops anything, whatever the service's lifetime (`hosting.restarting_server`). Before, a persistent service skipped the check, so the stop ran first and the new server refused, leaving the page down: the review's probe12 had NEW's `restarting_server(page, None)`, the step `follow_copy` takes, stop OLD's server and then refuse. A restart with nothing to stop, as a fresh `page init` at a path whose earlier page a session held, refuses nothing. Whether another session holds a page is read from that session's lifecycle record whichever Leaf wrote it, through the keys every shape of the record keeps (`state.session_lifecycle`: generation, ended, lifetime, transcript_path, which mean the same at since 13 and 56). A page whose session ended under another Leaf is free to a terminal; one whose session another Leaf runs stays held. Before, a record in another shape counted as held for good, so the review's probe10 (B) refused NEW's bare-shell `page init` and `server start` on a page whose session ended under OLD. `claim_is_active` still reads only this Leaf's shape. The session's own hooks begin a new generation where they can't read their record, and their prompt serves the page again only because the old claim reads as ended; reading the lifecycle across shapes there kept the prompt from serving the page, which then stayed down until the next prompt (probed). A page server's orphan check stays on `claim_is_active` too. Read across shapes, it kept a server serving through a later bump under Claude Code (probed, with a copy at since 57), but after an in-place update the server declines the follow once, never asks again, and would keep running the replaced copy's modules (from reading). `leaf server run` gives the `serves-for-no-session` notice `server start` gives. A wait acting for no session on a page a session holds says so (`held-for-a-session`) instead of "this session no longer owns it". `leaf-dev site demo` records that its session's hooks run this checkout, so the recorder acts for its session under the rule that a checkout acts only for a session whose hooks run it. Tests: a new generation's first hook marks the tree again (test_private_startup_keeps_previous_owner_until_acceptance, the CI failure). Sessions the codemod missed are marked: new-owner, harness-owner, s2, and the managed_server fixture's. A `--user` preview's tests record that the session's hooks run the preview's runtime (`conftest.hooks_run_leaf`), and its wait is that runtime's. A persistent server on a held page is started by the holding session. The old plugin in the init-restart journey sits at an installed-copy path. The journey model test drops the `preview` argument the `--preview` removal left. New tests cover a held page whose session lives or ended under another Leaf, and a restart for another session refused before it stops.
…eps its generation and input One fact, whether a live session holds a claim, had two readings: `held_elsewhere` read the session's lifecycle across shapes for refusals, and `claim_is_active` read only this Leaf's shape for receipt, the server's orphan check, follow, presence and restarts. The third review's probe13 (3) showed the cost: a live OLD session held a page, N2's `held_elsewhere` said held, but `claim_is_active` said no, so `may_receive(None)` let a terminal's `leaf wait PAGE` print the user's comment and `delivery ack` record a pickup and a receipt. OLD still read its claim as live, so its hooks never handed the comment over: the user's comment was received and never reached the agent. It would recur at every session-record bump, for any checkout's or terminal's wait on a page an older installed copy holds. `state.session_record` is now the one reading. It reads a record of another shape through the keys every shape keeps (`generation`, `ended`, `lifetime`, `transcript_path`, the same at since 13 and 56), with no turn yet, so every reader gets the cross-shape answer, and the session's own hooks carry the generation and lifetime on and rewrite the record in their own shape at their next write instead of starting a new generation. `session_lifecycle` goes; `held_elsewhere` is a live claim of another session, or a claim this Leaf can't read. `layer-registry.md` says a record at another format reads as absent except through those keys. With it, a later session-record bump keeps a live session's server serving (probe16: before, N2's server stopped within 5 s of the record changing shape; after, it keeps serving), the server follows the session to the newer copy (a copy at since 57 took the page over within 8 s), and a copy's follow no longer gives up on a persistent server for a live session in another shape. This PR's own landing still drops OLD's servers once, since OLD's code reads the new record as absent: probe10 (A) keeps the page down until the second prompt, as before. A prompt hook already serves a held page whose server is down whatever the claim's liveness (`reconnect.to_serve`); it skipped in that probe because OLD's server was still running when the hook looked, and retired after. `serves-for-no-session` now prints only where this Leaf has just bound a server for no session: a start that reuses a server says nothing (probe14, probe15), and a refused one prints only the refusal. The detached child reports whether it bound one (`PageStart.fresh`). Tests: a wait for no session leaves the input of a session another Leaf recorded alone; a session goes on in its generation when its record changes shape; a checkout's `--user` preview in a session whose hooks run another Leaf serves unclaimed, says so, and the checkout's own wait hears the user.
…ough one method, and refuse in the build a shape that drops one A `Record` read any other shape as absent, so each record other Leaves must read grew its own hand-written cross-shape reader (`named_pages` over raw JSON, `registry.storage.layer_packages`, the carry in `session_record`), each resting on a prose rule nothing checked, and the claim and Codex adapter records had none. The fourth review's probe18 moved a claim file to `leaf-claim/999`, as a claim-record bump would: the session's own server retired within 5 s, its own `page init` was refused as "held by a session another Leaf recorded", and its next prompt hook found no page to serve. At an adapter-record bump, `running_adapter` saw no adapter (probed: a live lease with a record at `leaf-codex-adapter/999` read as None), so a second adapter would start and be refused. And a future session shape that dropped `lifetime` made `session_record` raise `KeyError` in `page init`, the hooks and the claim scans. Each `Record` now declares `kept`: the keys, or paths such as `batches/*/page`, every shape of the kind keeps. `Record.read_any` returns a record whole at this Leaf's shape and its kept keys at any other, and is the one cross-shape reading. The build (`build/browser/protocol.mjs`) refuses a kept key that is dropped, changes its schema, stops being required, or isn't in the schema, whatever the `since`; the baseline records each kind's kept keys. Kinds that declare them: session (generation, ended, lifetime, transcript_path), claim (every key), codex-adapter (app_server), layer (packages), delivery and codex-delivery (batches/*/page), file-bindings (bindings). The prose rules for every record's `page` and the layer record's `packages` give way to the build rule in `layer-registry.md`, "Page protocol". The readers move onto it: `session_record` fills a record of another shape from its kept keys, `page_claim` and the claim scans read claims through `CLAIM.read_any` (the claim record moves beside those scans in `state.py`, since `state` can't import `service`), `retire_if_gone` takes the record's kind, `layer_packages` and `running_adapter` read through `read_any`, and the file grants keep those another Leaf recorded. `held_elsewhere` still counts a claim naming a harness this Leaf doesn't know as held, as a later Leaf's may; that case is a value, not a shape. probe18 after: the claim at another shape stays readable and active, the server keeps serving, the session's `page init` succeeds, and the session record missing `lifetime` raises nothing. The drafts record is left: its kept keys would be the whole drafts map, which would freeze the draft entries' schema for good. `ClaudeCodeHarness.lifetime` refuses, naming CLAUDE_PID, where CLAUDE_CODE_SESSION_ID names a session but CLAUDE_PID is unset, instead of a `KeyError` traceback (probe17; on main too). The agent journey's check between steps (`between`) waits as `settle` does: what holds between steps must hold through a quiet spell, so a watch's wake that opens a turn just after the session goes idle no longer fails it. Tests: a claim in another shape reads as the same claim; the build refuses a dropped, changed, loosened or missing kept key; a grant another shape recorded survives the next grant; a Claude Code session without CLAUDE_PID is refused by name. The older-claim test now expects the claim to read as that claim rather than be dropped.
…pes, and read a record lacking a kept key as absent
A claim holds its page only while its session lives, by the session's record
alone: `held_elsewhere` reads the claim whichever Leaf wrote it and returns it
where it names another live session, and its branch counting any claim file it
couldn't take as a claim as held goes. That branch kept a page held for good
once its claim named a harness this Leaf doesn't know, even after the session
ended, and it held every page whose claim an earlier Leaf wrote without a
format: the fifth review's probe21 had a terminal's `page init` refused for
both, and the maintainer's state home holds 319 such format-less claims, all on
pages that still stand. Liveness never needed the harness: `claim_is_active`
now takes the lifetime from the session's record with the claim's id, so it
reads a raw claim as a claim reading. A format-less claim file reads as no claim,
as `CLAIM.read_any` reads any file no claim shape describes. A new session's own
claim of such a page was never refused, and still isn't (probed).
The session record's `lifetime` schema names each shape `lifetime_is_live`
reads (none yet, `pid`, `job`, `app`, `chat`), each closed to other keys, so a
lifetime respelled or given a new key changes the kept key's schema and the
build refuses it; with `{"type": "object"}`, a newer Leaf could have respelled
it and every older Leaf would have read its sessions as dead. The other kept
keys are plain values whose schema already carries their meaning, apart from
the claim's `harness`, which stays an open string: a later Leaf may add a
harness, which an older one reads as a claim it can't dispatch on.
A record of another shape that lacks a kept key its kind requires reads as
absent (`Record.read_any`): the build holds every shape to its kept keys, so
such a record predates them. Before, a claim lacking `harness` raised KeyError
in `claim_reading`, and a session record lacking `ended` read as alive.
The protocol baseline is rebuilt from main's, since the session record's shape
moves to since 56 in this change as a whole.
Tests: a format-less claim and an unknown harness's claim with its session
ended leave the page free to a terminal; a session record lacking `ended` or
`lifetime` reads as absent; a claim lacking `harness` reads as absent.
leaf-agent
left a comment
There was a problem hiding this comment.
Closing lifetime's schema and keeping the key means no Leaf can add a new kind of lifetime. protocol.mjs refuses any change to a kept key's schema at every protocol, with no exemption for a bump (kept ${path} changed its schema), and since its check is equality, adding a fifth branch to this anyOf counts as a change. So a new harness or desktop host whose lifetime is not a pid, job, app or chat would be refused by the build, and the only way through is editing protocol-baseline.json by hand. That contradicts lifetime_is_live's docstring: "a harness that states its lifetime a new way joins here alone".
The closed schema does buy something: a later Leaf can no longer write a lifetime form that this Leaf's lifetime_is_live falls through to "pid" in lifetime and reads as dead, which would leave a held page looking unheld. But the cost lands on every future harness. Two ways to settle it: let a protocol bump change a kept key's schema, or keep lifetime open ({"type": "object"}) and accept that an unknown form reads as dead. If closing it for good is the intent, the docstring and Record.kept's header should say how a new lifetime form gets added.
…nds every process's registration "Each process of a session that lives as its own pid keeps its own registration" read as if one process's end left the others' registrations standing. It doesn't: the first process to end the session (`state.end_harness_instance`) ends it for all of them, which removes every registration along with their claims, as ending the session already made every process's claims inactive. The header now says so. The surviving process registers again at its next `leaf` command's hook; the path takes two live processes on one session id, so it stays as it is (the ninth review's probe27, case b).
leaf-agent
left a comment
There was a problem hiding this comment.
The new sentence in the bridge's header says ending the session "removes every registration along with their claims", and the code does neither of those things whenever a claim is held. end_harness_instance → _end_session writes ended and calls _retire. While held_claims finds a claim naming the session on a page that still stands, _retire removes only the hooks file and returns, so the .bridge registrations stay. The claims also stay: end_session's docstring says they "become inactive by this one atomic write". What stops the bridge counting the other processes is session_lives reading the ended record, which the header's earlier sentence already cites ("until its record says it ended"). The suggestion below states that mechanism.
… counting before then The header said a session's end removes its registrations, and that the first process to end a session removes every registration along with the claims. Neither holds while a claim names the session: `state._retire` then removes only the hooks file, and the registrations and claims stay. A registration goes with its session's files once no claim keeps the session's records (`state._retire`); until then the session's ended record stops it counting, and the bridge's sweep forgets it (`live_sessions`, `service.session_lives`). Each process of a pid-lifetime session keeps its own registration until the first to end the session ends it for all of them (`state.end_harness_instance`). The header now says that (Leaf's CI reviewer on 8d99c0b).
…ckward imports (#7118) This moves two functions into the modules that own their facts and reorders one module. That ends three of the backward imports `.config/importlinter.ini` allows in `src/leaf`, taking them from 77 to 74. Behavior is unchanged. - **`unlined` moves from `forks` to `events`.** It is a pure fold over a built thread that reads only `events.unanswered_turns` and `events.spoken_turns`, which it used to import inside its body. It now sits beside `owed_turns`. `thread_context.batch_threads` then imports it downward, instead of reaching past `forks`'s imports of service, leases and state. - **`activity` moves above `obligations` in the order.** `activity` decides where the agent's work stands from the records `obligations` produces. Its only path back ran through the import above, so only the ini changes. - **`package_layer_inputs` moves from `packages` to `layer`.** It resolves the layer a one-package selection composes, beside `layer_inputs` and `checked_layer_inputs`. `render_gate.widget_quality` was the only part of `render_gate` that imported `packages`. With the function moved, `packages`, which holds the `package` commands, stands above `render_gate`, as `validation` does. These are the cuts that read better from one group of the 77, the page readings and checks. The rest of that group stays as it is: - `authored_checks.source → sample_content` is a real recursion that `admission.py` comments. - `passages → obligations` and `passages → data_contracts` come from `SourceReading` caching readings that higher modules own. Ending them would mean redesigning those caches, not moving code. - `render_gate.handover_pass → validation.command` waits on #7114, which edits `handover_pass.py`. max-sixty asked for refactoring to continue while each change improves the code. No file that #7061 or #7114 changes is touched, and the branch merges cleanly with both. Tests: - `lint-imports` and pre-commit pass. - `tests/model/test_forks.py`, `test_thread_reading.py` and `test_render_gate.py` pass. - The line-fork and summary-fork process tests, and the `package`, summary and batch interaction tests, pass. > _This was written by Claude Code on behalf of max-sixty_
…es, so todos, plans and forks import only downward (#7121) `todos.py` and `plans.py` each held two levels: readings that admission, `activity` and the served state build on, and the `leaf task` commands, which write through admission. Each command imported `event_contracts`, `thread`, `service`, `revisioning` and `leases` inside its body, and wrapped its work in a nested `def write` only because `contract_writer` couldn't be imported at load. The commands now live in a new `tasks.py`, which mirrors the `leaf task` CLI group and sits beside `thread`, the other write-command module. Its imports are module-level, and each command carries `@contract_writer` as `thread`'s commands do. `todos` and `plans` become readings, so `activity` imports `todos` once at load instead of in three functions. `lane_path`, `take_lane` and `lane_up` are a session lease, so they move from `forks` into `leases`, beside the adapter and watch leases of the same shape. `delivery` had imported the whole line-fork module for that one question, which held `forks` and `summary_fork` below `thread`, although both post through `thread`'s writes. Now `clerk`, `forks`, `summary_fork` and `thread_titles` stand above `thread` in `.config/importlinter.ini`. No module imports `forks` at load any more, so `summary_fork`'s page readings import at module level, and only its imports from `forks`, which imports it, wait until called. This branch merges #7118, still in CI. On top of it, `src/leaf`'s allowed backward imports go from 74 to 64. Behavior is unchanged: the moved bodies differ from the originals only in imports, decorators and docstring pointers. Two further cuts in this group wait on open PRs. Once #7061 lands, the reply reservations can move from `thread` into `delivery`, whose header already describes them. Once #7114 lands, the fork helpers split between `clerk` and `forks` can move into one module below both. max-sixty asked for refactoring to continue while each change improves the code. The branch merges cleanly with #7061; its only conflicts with #7114 are ones #7114 already has with `main`. Tests: `lint-imports` and pre-commit pass. The model tests for forks, hook registration, responses, clerk, activity, to-dos, thread readings and the suite's source checks pass (1847), as do the fork, pages and follower tests in `test_hooks`, `dev/tests/test_evals.py` and the browser test that ends a to-do. > _This was written by Claude Code on behalf of max-sixty_
…h and stamp them (#7122) `served_state/reading.py` declared which writes count as a page's inputs (`page_input`, `page_roots`, `outside_inputs`) and took the stamps over them (`page_reading`, `source_readings`, `record_reading`, `join_reading`). Its callers are the file watchers, activation, publishing, the row publisher and the hooks, none of which projects state, and it imported nothing from the projection. It becomes the top-level module `page_inputs`, below its callers, and `served_state` holds only the served state: the page read, its projection, and the patch sent to a tab holding an earlier reading. `version_written`, which names when the files a version is built from last changed, moves to `revision_artifact` beside `CAPTURED_TREES`, ending its deferred import. `session`, `hosting`, `server_rows`, `http` and `agent_state` now stand just above `served_state` in `.config/importlinter.ini`, since each reads the served state and `served_state` imports none of them. Only the order changes for those, in a commit of its own. `src/leaf`'s allowed backward imports go from 64 to 51. Behavior is unchanged. `.config/importlinter.ini` will conflict with #7061 and #7114 on one hunk: this branch deletes the `leaf.session -> leaf.served_state.*` allowances, and both PRs delete the adjacent `leaf.session_runtime -> leaf.harness`. Deleting all three lines resolves it, and `lint-imports` checks the result. Every other file merges cleanly with both. From their files, this touches import lines in `hooks.py`, `session.py`, `render_gate/handover_pass.py` and `worker/leaf_website/storage.py`, and one docstring line in `presence.py`. max-sixty asked for refactoring to continue while each change improves the code. Tests: `lint-imports` and pre-commit pass, as do the model tests for file bindings, native watches, the handover pass, seen, hook registration, model folds, the render gate and render export, the website's saved records and the revendoring contract (163). > _This was written by Claude Code on behalf of max-sixty_
# Conflicts: # .config/importlinter.ini
…for a Codex record at its own shape CI on 18af799 ran two tests this branch edited without running: - A data source's publication file a hand edit leaves as `{}` made `Record.read` raise, so `/api/state` answered 500, where main reads it as no publication and the widget recovers. `Record.read` again reads an object at its file without this shape's `format` as none. - The Codex journey waited for a history record named with the delivery envelope's `since` rather than the Codex record's. Four other journey failures in that run (the server row tests in test_interact_server and test_render_controls) also fail on main at 118f31f: they serve a page a live session holds for no session, which #7061's refusal turns away. > _This was written by Claude Code on behalf of max-sixty_
…t arbitrates (#7157) Each `state.Record` shape now lives in a file named with its `since` (`drafts.json` is kept at `[email protected]`), and a Leaf reads and replaces only its own shapes' files. This takes out #7061's `Record.kept`, `read_any` and the build's kept-key checks: root `AGENTS.md` "Stage" forbids fallback reads, and in the last five weeks the records #7114 would carry across changed shape only during the drafts store's first two days. A record that arbitrates between Leaves (a page's claim with its session's lifecycle, a page's service, a grant, the Codex adapter's) holds while a file of any shape of it stands, without being read, and a session's end, `leaf server stop`, a grant's withdrawal and a takeover of the page end it at every shape. Who holds a page is one reading, `service.page_holder`, which every reader deciding whether it may act on a page asks, and a rolled-back takeover puts back what it removed. The cost: after a `SESSION` shape change, which comes with a protocol bump, a page whose session ended under the older Leaf stays held for the newer one until an agent takes it over with `leaf server start`, which every refusal of a held page names; the takeover leaves one owner. `layer.json` stays one file, and renewal keeps its `packages`. `page check` names a drafts store of another shape, the user's unsent words, and says to point the user at it rather than read it. Max chose this over #7114 on his Leaf page; it supersedes #7114. At a shape change, against main: drafts, connection grants, the sign-in key and the server address are gone from the page as on main, their files kept; file grants, which main carries across, are gone too; a claim-shape change leaves the page held until the agent runs `leaf server start`. Session records, delivery envelopes and the layer behave as on main. Net lines: production code +83, comments and docstrings +57, tests +96, prose +22, baseline data −7. Tests: `tests/model/test_record_shapes.py` (a page held at another shape, a session-less wait stopping there, a takeover leaving one owner and its rollback restoring the other holder, a withdrawal at every shape, the `page check` note) and a stop beside another shape's server in `test_server_lifetime.py`; the model and process files that touch records pass on Python 3.14 and 3.12. CI also runs the journey and browser tests this branch edits; the four server-row journeys in `test_interact_server` and `test_render_controls` fail on main at 118f31f too, since #7061 refuses to serve a held page for no session. Edited but not run locally: `tests/journeys` (test_activity, test_claims, test_codex_adapter, test_hook_registration, test_interact_document, test_interact_layer, test_interact_server, test_native_watch, test_render_controls, test_session_lifecycle, test_site), `tests/browser` (drafts/test_shared_drafts, startup/test_projected_data, projection/test_code_review) and `dev/tests/journeys` (test_render_export, test_interact_preview). > _This was written by Claude Code on behalf of max-sixty_
) Four journeys fail on `main` since #7061, which refuses a server start that takes no claim on a page another live session holds (`service.refuse_held`). Each recorded a live claim on a neighbour page and then started its server for no session, so it raised `StartRefused` at setup. #7061's CI missed it because `--changed-since` adds a later-tier test only when the test's own function changes, and #7061 changed none of these four; #7157 edits lines inside them, so its run selected them and they failed. Each test now starts, revives or restarts the server with the harness the claim names (`harness.claim_harness`), as the holding session's own Leaf does in use and as the `live_leaf` fixture already does. No assertion changed, and the refusal stays as it is. A scan of `tests/journeys`, `tests/smoke`, `tests/browser` and `dev/tests` for other tests that write a live claim and then start, restart or re-init the page for another session found no others; browser tests serve through `TemporaryPageServer`, which the refusal doesn't reach. Tests: the four failed locally on `main` with the refusal and pass with this change. > _This was written by Claude Code on behalf of max-sixty_
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; Claude Code 2.1.332 has `/reload-skills`
("Pick up skills added or changed on disk during this session").
The maintainer asked how much the notice costs to maintain and proposed
dropping it. It landed on 2026-11-22 (#6757) and has needed a change in
each of #6782 (Codex's and Pi's in-place updates), #7061 and the previous
commit on this branch (a checkout's own skill). Over the last 30 days 444
of main's 2,093 commits touched skills/leaf, so nearly every update a
session picked up made it reread SKILL.md and its references. A command
whose interface changed still reports that through its own error or
`--help`, which is the agent's path for any command it misremembers.
Each hook now records only the root of the Leaf it runs (`leases.mark_root`,
`sessions/<digest>.root`), which `state.hooks_root` reads for a checkout's
right to act for the session and for a server's follow to another copy. The
hook no longer hashes the skill's 33 files on every call. The record's file
is renamed from `.skill` to `.root`. An older Leaf at this protocol reads only
`.skill`, so across the one update that ships this commit a page server from
the older copy doesn't see the newer copy's root and stays where it is, which
two versions of Leaf at one protocol may. The clerk queue's schema description drops the
notice, an annotation the protocol baseline carries without a bump.
The notice after a compaction (`hooks.reload_skill`) stays: it covers the
text a compaction dropped, not a skill that changed.
…ow to hear the page (#7251) In a session started normally, a checkout's `leaf-dev preview --user` serves its page for no session, so only the checkout's `bin/leaf wait PAGE` hears the user's replies. The preview's `serves-for-no-session` advice said so, but as the first line of the log, above the URL that agents read with `tail` or `grep http://`. Two of the four sessions that handed such a preview over since #7061 missed the advice, and the user's replies sat unheard until they asked in chat. In one of them a reply waited 30 minutes. The preview now holds what its start notes and prints it in the `--user` service reading, the same record `leaf server start` prints with its `url`, in one write with the bare URL line above it. The `--user` help and the module header lead with the unclaimed case. The bare URL line keeps its own line, so `grep -o 'http://[^ ]*' | head -1` and the tests' `startswith("http://")` still find a clean URL. Max asked for this diagnosis. Codex reviewed the change, and its findings are folded in: one write for URL and reading, and `tests/journeys/test_codex_adapter.py`'s use of the renamed `PreviewService.note`. It also suggested routing through `started_server`, which was left out: that would add a `loopback-only` finding to every preview, advising a `--host` flag that `leaf-dev preview` doesn't have. Tests: `dev/tests/model/test_interact_preview.py` (29 passed), and a live `--user` preview before and after. > _This was written by Claude Code on behalf of max-sixty_
…7423) Since #7061 a checkout's `bin/leaf`, run from a session's shell, serves a page for no session. So the page a session developing Leaf talks to the user on, usually a `leaf-dev preview --user`, was missing from Leaf's line above Claude Code's prompt, which listed only claimed pages. Of 34 Leaf sessions that served a page after #7061, 10 handed the user only such previews and 4 more used both. A server for no session now names the session whose shell started it in its row (`started_in`, passed to the detached server as `--started-in`, since it starts with no harness identity). The pages follower lists those pages beside the held ones and does nothing else with them (no line forks, notes or watches), since such a page may be at another protocol. The hook gate lets the follower through only where a readable row names the session, so a session with no page still starts no uv. To weigh: the 90 s step limit follows the band, so it now also holds in a session whose page is a checkout preview, whose input likewise arrives only between steps. The row's shape moves to 62 (`state.ROW_SINCE`), so a checkout behind this commit stays out of the band and All pages until it merges main. Max asked for the fix. Tests: follower, module-through-launcher, `--user` preview, `server run` and gate cases; the module and preview tests fail without the change. `leaf-dev journey run claude-code` passed every step but `boundary` across two runs (`fork-busy` failed once on the agent not delegating); `boundary`'s 300 s wake timeout also fails on other branches this week. > _This was written by Claude Code on behalf of max-sixty_
Max decided Leaf development works as any project's does. Checkout selection goes (
session_runtime.py, the records'launcherfield); the session's hooks, follower, bareleafand Codex adapter run the loaded copy.The rules. Only an installed copy, or a checkout the session's hooks run, acts for a session (
state.runs_session). Any other checkout acts as a bare shell does: it claims nothing and serves pages unclaimed, heard with its ownleaf wait. Only the holding session's Leaf serves, restarts or re-initializes a held page, refusing before anything stops.Records across shapes. Each record kind declares the keys every shape keeps (
state.Record.kept), every Leaf reads them throughRecord.read_any, and the build refuses a shape that drops or changes one. A value a Leaf doesn't know there reads as the session live, so a session keeps its pages and input across a record bump.What developers lose. A checkout can't serve or re-initialize the session's pages. A worktree's preview reaches no Codex chat, so the codex
--previewjourney goes.Protocol. Two records move
sinceto 56; no bump.Tests: model, process and later-tier tests; four agent journeys.