Repository navigation
Run the turn-end check's fork at low effort, and leave the working-line fork at the session's - #5440
Conversation
…at the session's Claude Code 2.1.318 lets `$.model.fork` take an effort. Leaf's clerk now asks for `low` (`clerk.EFFORT`, carried in the question `leaf hook --fork` prints), and the fork that answers thread messages keeps the session's effort. The fork eval now runs each clerk case at the effort the arm's Leaf names, so `--base` scores an effort change; reply cases and base arms that name none keep the medium it used before. Measured in `leaf-dev journey claude-code --forks`, with the session pinned at xhigh, seven runs at each arm. Six of them added scratch turns and thread messages with known right answers after the fork steps: - The cache holds at a different effort. Low forks read 98% of the conversation from the cache and wrote as little to it as forks at the session's effort, which refutes the cache-miss risk the hook header and clerk.py assumed. - Clerk: low named all 19 planted items, as the session's effort did, and nothing at any of 13 quiet turns. Matched by turn, output fell to 0.45x (95% interval 0.31-0.63) and time to 0.62x (0.53-0.73), over 32 turns. - Replies: output fell to 0.45x and time to 0.66x over 52 messages, but low changed decisions on 2 of 12 kinds of message. It handed over all 3 questions whose answer a file the session had read states, which the session's effort answered correctly, and it answered 1 of 5 requests to rank the board's cards, which the prompt hands over. The user's median wait from message to answer barely moved (25.5 s against 24.8 s), so replies stay at the session's effort. What the turn-end check catches at low in a long real session is unmeasured. The plants are explicit, and real forks at xhigh wrote a median 871 tokens. The module test now checks that the clerk's fork is asked at Leaf's effort. Closes #5302 Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The clerk's diagnostics now record an effort the fork didn't use. In clerk(), resent = request() is still copied whole into the run's request, and request() takes effort from the main thread's last turn.step. So with the session at xhigh, every turn_end_check record says the fork ran at xhigh when it ran at low. The clerk.py header calls this record "what a later replay or audit scores against what the agent did next", so a replay of a recorded clerk fork, the kind that would settle the "Risk" section's open question, would run at the wrong effort. The fix is to record the effort the fork was asked for:
...(resent ? { request: { ...resent, effort: asked.effort } } : {}),The comment above lastStep also still says $.model.fork resends "the model and effort it named". Since this PR, that holds only for replies.
A `turn_end_check` note's `request` is the main thread's request, so its `effort` is the session's. Since the clerk now names its own effort, a reader taking `request.effort` as the fork's logged every low fork at the session's xhigh. The module now hands Leaf the effort Claude Code reports it sent (2.1.318 includes it in the fork's result) with the usage, and the note carries it as `effort`. The headers in `clerk.py` and `hooks/claude-code.ts` say which effort is which. The module test now requires the note's `effort` to be `clerk.EFFORT` rather than the session's; it fails with `KeyError: 'effort'` without the change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The clerk.py header says low's recall on real sessions "is unmeasured", but the replay in this PR's Risk section measured it. Low matched every item of unshown work and every decision left in chat, 54% of stale passages (xhigh's own control replays matched about half), and none of the offers of bolder work. A later maintainer deciding whether to raise EFFORT reads this header, not the squashed commit. As written, the header reports an open question, while the PR found a specific trade: low drops the offers and finds no more than half the stale passages that xhigh's original runs found. The suggestion below states that result.
The header called low's recall on real sessions unmeasured, but the PR's replay of the 18 real xhigh forks that named items measured it: low matched all unshown work and asks left in chat, 54% of stale passages and none of the offers of bolder work, at a median 283 output tokens in 5.6 s against 1,140 in 11.5 s. The header now gives that trade and the control replays' noise, in a paragraph of its own after the planted-turn journey.
…fort has lapsed The header kept the working-line fork at the session's effort because low changed whether the fork answered or handed over. Since #5552 the fork writes only the line and always hands over, so that choice no longer exists. The header now gives the 2026-11-04 measurement as taken on the earlier prompt, and says low is unmeasured on the prompt that asks only for the line. No code changes; the fork still names no effort and thinks at the session's.
…#5776) The fork that writes the agent's working line on a held thread message now thinks at `low` (`forks.EFFORT`), whatever the session's effort. Leaf holds the thread's messages from the session until that line is posted, so the fork's time sits on the path to the session's answer. #5440 left this fork at the session's effort because low changed its choices between answering and handing over. Since #5552 the fork writes only the line and makes no such choice, and on that prompt low writes lines as good as xhigh's. ## What changed - `src/leaf/forks.py`: `EFFORT = "low"`, which `ask` sends with the prompt, as the clerk's question carries `clerk.EFFORT`. The header records the measurements below in place of the 2026-11-04 one, whose premise #5552 removed. The two forks keep separate constants because each effort was chosen on its own fork's work (the clerk's on asks and stale passages, this one on the line), and either may change without the other. - `hooks/claude-code.ts`: both forks now go through one helper, `runFork`, which makes the fork at the effort Leaf names and hands back its answer or failure, usage, time, the effort Claude Code reports it sent, and the resent request. The clerk's and `forkReply`'s copies of that bookkeeping are gone. One behavior changes: a clerk fork that throws now reaches Leaf as a failure, noted in each page's diagnostics with its reason (as `forkReply`'s already was), and the debug log says `the clerk's fork gave no answer (…)` rather than `the clerk wrote nothing: …`. - Diagnostics: a `fork_reply` note now carries `effort`, the effort the fork was sent at. Its `request.effort` stays the session's. - `tests/process/test_interact_claude_code_module.py`: the working-line test checks that the fork is asked at `forks.EFFORT` and that its note gives that effort rather than the session's. The first check fails with `effort` dropped from the module's call. The failed-clerk-fork test now expects the new debug line and a diagnostics note for each refused fork. The clerk and working-line tests also check that each fork's note carries its usage and time, which `runFork` now hands Leaf for both forks, and which `journey.fork_summary` and `response-times` read; each check fails with its field dropped from `runFork`. - Types: `runFork` declares its effort as Claude Code's `ModelEffort`. `pnpm run check:hooks` doesn't reach `claude-code.ts` (`hooks/tsconfig.json` includes only `pi.ts` and `watch.ts`, since Claude Code's declarations are generated when it loads the plugin and aren't in npm), so I type-checked it against the declarations Claude Code 2.1.319 generated: `main` and this head pass, and the previous head's string effort failed with TS2322. - `dev/leaf_dev/fork_eval.py`: the replay reads the effort the arm's Leaf names for every fork (`asked["effort"]`). The medium it took for a fork that named none is gone, with its header sentence, so a `--base` older than this PR fails on reply cases rather than running that arm at an effort no live fork takes. - `notes/fork-replies.md`: prose that said this fork runs at the session's effort. - `evals/fork-reply/case.yaml`: each case's `purpose`, and the file's header, still described the fork that chose between answering and handing over; they now say what the working line must do in each case. No case's checks change. ## Measurements Opus 5.5 on Claude Code 2.1.319, 2026-11-09. Ratios are low over xhigh, paired on the same message, as geometric means with 95% bootstrap intervals. **Recorded thread messages.** These are the 40 messages of `notes/fork-replies.md` ("How well the fork judges"), from 30 sessions, idle and mid-turn; their transcripts and page copies are still on this machine. Each was replayed from its session's transcript cut where the message arrived, with today's `reply_prompt` built over the thread and running tool call the original replay recorded. Each ran once at low and once at xhigh, in a seeded random order, with `claude -p --resume --effort E --max-turns 1` on the session's model and 1M window, tools refused, in a fresh home. | | low | xhigh | | --- | --: | --: | | Lines passing a blind judge | 35 of 40 | 35 of 40 | | Lines the judge preferred | 19 | 16 (5 ties) | | Median output tokens | 25.5 | 24 | | Runs with any thinking | 0 | 0 | | Median generation time | 0.28 s | 0.31 s | - Output 1.03× (0.97–1.10), generation time (first to last streamed event) 0.93× (0.83–1.05), time to the reply's end 1.07× (0.98–1.16); n = 40. - The judge, Opus 5.5 shown the two lines as A and B in a seeded order, read each pair beside the user's message, the running tool call and what the session did next: its own working line where it posted one (31 of 40), its first steps and its reply. Each effort failed three lines the other passed. Low's named the user's skill "this sweep", called the session's "seats" "labels", and gave away part of an answer; xhigh's gave away the fix, left out the user's question, and garbled the user's words. Both failed the same two, by promising page edits the session didn't make. **The fork-reply eval at low and at xhigh.** `uv run leaf-dev eval 'fork-reply*' --harness claude-code --base 4092d17dd --repeat 5 -j 4`. The head arm is this branch, at low; the base arm, `4092d17dd`, is this branch with `EFFORT = "xhigh"`. A base at `main` would have compared low with the medium the replay takes for a fork that names no effort. - 35 of 35 passed in each arm. - xhigh thought over 5 of its 35 lines (54–219 thinking tokens, 1.3–3.5 s); low over none. - Output 0.81× (0.63–1.01), the fork's time 0.85× (0.75–0.95), wall time 0.90× (0.84–0.96); n = 35. Median output 24 tokens at low and 22 at xhigh, median time 0.93 s and 0.99 s. **Live forks at the session's effort.** Since #5552 this machine's pages hold five working lines written on the current prompt at xhigh, with 25–71 output tokens in 1.0–4.4 s. **The live path.** `uv run leaf-dev journey claude-code --forks` passed on this branch before and after `runFork`, with the journey's session at its default, medium. On the later head, Claude Code's debug log shows all seven forks (three working lines, four turn-end checks) sent at low (`effort low asked, low sent`), and each fork's note gives `effort: "low"` beside `request.effort: "medium"`. The working-line forks took 627–661 ms for 15–26 output tokens, reading 59–95k tokens from the session's cache and writing none. Load averages ran 2.4–4.5 during the eval and 3.6–10.5 during the replay, so compare the ratios rather than the seconds. ## What this buys On real messages neither effort thinks, so low and xhigh take the same time there. Low removes the occasional line xhigh stops to think over, which took up to 3.5 s on the eval where a line took a median 1 s, and the line's time no longer depends on the effort the session runs at. ## Not verified - A session above xhigh, at `max`. - The replay resumes a transcript copy under `claude -p` rather than resending the session's own request through `$.model.fork`, so its runs don't share the session's cache: each read at most 35k tokens from the cache and wrote the rest of the context. The paired ratios share that cost; the absolute times don't match a live fork's. - Each replayed message ran once per effort and was judged once. - The replay and judge scripts sit in this branch's worktree under `.tmp/effort/` and leave with it. > _This was written by Claude Code on behalf of max-sixty_
…#6079) Max's direction on 2026-11-15: turn-end checks need to be fairly brief and mainly use the cache, so they can't go off and do research; they are a check rather than a review. ## What changes - **`src/leaf/clerk.py`**: the header records it as the user's fourth principle, dated. The fork answers from the conversation it inherits and the page facts Leaf hands it, and does no research, so each thing Leaf asks of it must be one those two settle. This bounds checks added later, such as the three the sweep page proposes. - **`skills/leaf/references/turn-end-check.md`**, which the fork reads verbatim: the check is a quick one that runs at every turn end, every tool call is denied, and the fork names only what the conversation and the page state settle, leaving out an item it could confirm only by reading a file, running a command or searching. No code changes, since Claude Code already enforces the part code can. In 2.1.325's source, `$.model.fork` denies every tool call ("A model fork cannot use tools"), stops after two requests (`maxTurns: 2`), and writes neither the cache nor the transcript. `ModelForkRequest` takes only `prompt` and `effort`, and the request must keep the session's tools to read the cache, so Leaf has no further lever. Effort stays at the session's, as #5960 chose for the cache. ## What the fork does now From the `turn_end_check` notes in page diagnostics on this machine: 37 Opus 5.5 forks in five real sessions since #5960 landed (2026-11-14 13:00 PT). | | median | p90 | max | |---|---|---|---| | time | 5.6 s | 15.8 s | 28 s | | output tokens | 281 | 1,416 | 2,955 | | cost at list price | $0.235 | $0.43 | $0.54 | | input tokens | 248k | 541k | 757k | | input not served by the cache | 24k | 29k | 30k | | share of input read from the cache | 94% | | | | uncached input's share of cost | 38% | 53% | 62% | Every fork took one request: on the 32 whose session transcripts remain, its input over the main thread's context at the request it resent is a median 1.11 and at most 1.20, where a denied tool call and a second request would show about 2. No answer was refused. For comparison, before #5440 the same kind of fork, at the session's effort without the request to answer straight away, wrote a median 968 output tokens in 12.6 s (175 forks). ## Scores `leaf-dev eval run 'turn-end-check*' --harness claude-code --base --repeat 3`, then `turn-end-check/ask-follow-up` and `turn-end-check/ask-question` with `--repeat 6`, so 3 runs per arm of most cases and 9 of those two. | case | main | this branch | |---|---|---| | ask-answered, ask-on-me, ask-step, ask-step-done, clean, settled, settled-open, stale-edit, stale-omission, stale-passed-on, stale-rewrite, unshown, unshown-shown | 3/3 each | 3/3 each | | ask-question | 8/9 | 9/9 | | ask-follow-up | 7/9 | 5/9 | - `answered`, `labels-found`, `edits-land` and `guardrails-held` pass in every run on both arms, so the check catches what it caught and names nothing new where it shouldn't. - Every failure is the judge's `items-right`. Each `ask-follow-up` failure, on both arms, is one of the same two wording faults in the re-asked step: it repeats the agent's chat inference that the user's command "went to dev", which the judge reads as unsupported because it dates the conversation by today rather than the transcript's 3 November, or it asks for a reply the agent could check itself. 5/9 against 7/9 is within what three-run arms vary by (Fisher's exact p ≈ 0.6). Main's `ask-question` failure named an unshown item the ask already covered. - This branch wrote 0.92 times main's output (95% interval 0.83–1.02, bootstrap over the 15 cases), in 0.98 times the time, at the same cost. The eval's forks cost about $11.50 at list price, plus the judge. ## Checks `tests/model/test_clerk.py` passes, and pre-commit passes on both files. Not verified: the forks' behaviour in a live session after this lands, which the next real sessions' `turn_end_check` notes will show.
Claude Code 2.1.318 lets
$.model.forktake aneffort. Leaf's turn-end check (the clerk) now forks atlow. The fork that writes the agent's working line on a thread message names no effort, so it runs at the session's.What changed
src/leaf/clerk.py: a newEFFORT = "low". The clerk's question (leaf hook --fork) now carries it, and the header records the measurement and the risk below. The header's claim that the cache needs the fork's effort to match the session's is gone, since the measurement refutes it.hooks/claude-code.ts: the clerk calls$.model.fork({ prompt, effort })with Leaf's effort. The header no longer says the fork resends the session's effort for the cache's sake, and now gives this run's cost and time. An older Claude Code ignores the field (its check in 2.1.317 reads onlyprompt) and runs the fork at the session's effort, as before.turn_end_checknote now carrieseffort, the effort Claude Code reports it sent the fork at. The note'srequestis the main thread's request, so itseffortis the session's, and the headers inclerk.pyandhooks/claude-code.tsnow say so. Before this, a reader ofrequest.effortwould log every low fork at the session's xhigh.src/leaf/forks.py: the header says the working-line fork names no effort and runs at the session's, that low's 2026-11-04 measurement below was taken when the fork still chose whether to answer, and that low is unmeasured on the prompt that asks only for the line. The code is unchanged.dev/leaf_dev/fork_eval.py: the replay runs at the effort the arm's Leaf names, soleaf-dev eval 'turn-end-check*' --harness claude-code --basenow scores this change. Reply cases, and base arms that name no effort, run atmediumas before.notes/fork-replies.md: corrects the note's claim that a different effort misses the cache.clerk.EFFORTand that its note gives that effort rather than the session's. Each check fails without its half of the change, the second withKeyError: 'effort', and passes with it.Both arms
uv run leaf-dev journey claude-code --forks, on 2026-11-04 and 05, Opus 5.5 with the session pinned at xhigh: seven runs at the session's effort and seven with both forks atlow. Six runs per arm added scratch steps after the fork steps. These were turns and thread messages with known right answers, sent in the same order to every arm, and they are not committed (below). Medians, with interquartile ranges:Paired on the same planted turn or message in the same run, low against the session's effort, as geometric means with 95% bootstrap intervals:
Cache. The issue's risk doesn't occur. A low fork read 98% of the conversation from the cache, and its cache writes were the new tail alone, a median of none, as at the session's effort. Claude Code's debug log confirms the effort it sent (
effort low asked, low sent).What the clerk caught. The planted turns left an ask in the chat, answered it there, made the page stale, or set work running in the background that no page showed. The quiet turns asked arithmetic, put the ask on the page itself, or read code. Over five scored runs, low named 19 of 19 planted items and nothing at any of 13 quiet turns. The session's effort did the same, 19 of 19 and 13 of 13. Beyond them, low once also named an On me item the merged migration fix had made moot, a fair find, and the session's effort once split its stale finding into three.
What the reply fork decided. These runs predate #5552, when the fork still chose whether to answer a thread message or hand it to the session. It now writes only the agent's working line and always hands over, so the choices below no longer arise. It names no effort and runs at the session's, and low is unmeasured on the prompt that asks only for the line.
Both arms decided at the same rate on 10 of the 12 kinds of message. They differed on two:
forks.py, whose header states the answer: low handed it over 3 of 3 times. The session's effort answered it correctly 3 of 3 times, each in 13 to 16 s.Each fork's own replies were faster at low. On "explain more?", low took 3.7 to 4.0 s against 3.8 to 17.7 s at the session's effort. A hand-over waits for the session, though, so the user's median wait from message to answer barely moved: 25.5 s at the session's effort and 24.8 s at low, over 59 and 51 messages. On that prompt, the trade didn't clearly favour low.
Medium. Two runs also used
medium. Output was about half the session's, but its forks were the slowest of the three arms in wall time. Hand-overs, for example, took a median 3.8 s for 67 tokens, during the machine's heaviest load (load average up to 250). Medium kept the hand-overs low made on the lane-down question, so it doesn't fix the reply trade.Risk: what the clerk catches
The planted asks and stale passages are explicit; in real sessions they are subtler and come late in long sessions, which is the case the clerk exists for. So the 18 real clerk forks at xhigh that named items on this machine's pages on 2026-11-04 were replayed at
low, three times each. Each replay resumed the session's transcript cut at the fork's last row, asked the question rebuilt from the page wound back to that time, and ran with tools refused in a throwaway home. Two checks were also replayed at xhigh as a control.Low's 25 additions over 54 replays held no real ask the original missed. Replays are noisy even at xhigh: the controls matched 7 of 14 of the original's item-tries, and on the longest page (c09) the xhigh and low replays caught the same share of its stale passages. The offers separate cleanly, though: on the same two checks xhigh asked them 5 of 6 times and low 0 of 9. An offer isn't a decision put to the user, so low leaving it out of On me matches how replies treat offers. Low wrote a median 283 output tokens in 5.6 s against 1,140 in 11.5 s. The clerk runs off the turn's path, so this saves no wait the user sees; it buys about $0.02 a fork and a shorter window in which a newly opened turn drops the clerk's asks (
basis).What I ran
uv run pytest tests/model/test_clerk.py tests/model/test_forks.py tests/process/test_interact_claude_code_module.py -n 4(67 passed), anddev/tests/test_evals.py::test_fork_replay_hands_the_answer_through_the_arms_leaf(1 passed).effortdropped from the module's call and passes with it.uv run pre-commit run --fileson every changed file.Not verified
low. The turn-end-check eval ran in review, as above.low(the set innotes/fork-replies.md). That replay would settle the reply fork's effort.Calls Max may reverse: the clerk at
lowrather thanmediumor the session's effort; replies left at the session's effort.Closes #5302