Repository navigation
Fork at the session's effort and ask for a quick answer, so every backend reads the cache - #5960
Merged
Merged
Conversation
…kend reads the cache The turn-end check and the thread-reply fork asked `$.model.fork` for `low` effort. Where Claude Code's per-message effort doesn't reach the model, as on Vertex, that rewrote the whole conversation to the prompt cache (#5891, #5904), and the hooks module learned it per backend from each check's usage (#5892, #5907, #5947): route variables, a stored answer in `$.store`, a weekly lapse and a cache-warmth window. Both forks now name no effort, so they think at the session's and read its cache on every backend, and their prompts ask them to answer straight away without thinking it over, as Claude Code's `ModelForkRequest.effort` documentation suggests. A TODO in `runFork` marks the switch back to `low` once a change of effort rides per message on every backend without an environment variable. Measured with `leaf-dev eval 'turn-end-check*' 'fork-reply*' --base`, one sample per case, xhigh with the request against the low fork: - turn-end check: 15/15 passed, as low did; 1.62 times low's output (95% interval 1.26-2.09) in 1.23 times its time (1.10-1.38). - reply fork: 7/7 passed, against low's 6/7; 1.49 times the output (0.91-2.44) in 1.09 times the time (0.94-1.25). `clerk.EFFORT`, `forks.EFFORT` and the forks' `effort` diagnostic go. The fork eval replays a fork that names no effort at the session's (`SESSION_EFFORT`, xhigh), so `--base` against an arm that still names `low` compares the two. The module tests that held the learning go with it; the driver loses `$.store`, `forkUsage`, `forkRefused` and the steps' usage, which only they used. The two fork tests now check that the fork names no effort.
…used, and put the reply fork's low-effort finding in the past
leaf-agent
approved these changes
Nov 14, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 16, 2026
…#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.
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.
Leaf's two conversation forks (the turn-end check and the thread-reply line) no longer ask
$.model.forkforloweffort. They think at the session's effort, which reads the prompt cache on every backend, and their prompts ask them to answer straight away without thinking it over, as Claude Code'sModelForkRequest.effortdocs suggest. That removes the per-backend learning from #5892/#5907/#5947 (route variables, a stored answer in$.store, a weekly lapse, a cache-warmth window) and theeffortplumbing throughclerk.py,forks.pyand their diagnostics. A TODO inrunForkmarks the switch back tolowonce Claude Code carries a change of effort per message on every backend without an env var.What it costs, from
leaf-dev eval 'turn-end-check*' 'fork-reply*' --base(one sample per case, xhigh with the quick-answer request against the low fork):To weigh: the turn-end check is roughly a quarter slower than at
low. In exchange, Vertex and proxy sessions stop paying a conversation rewrite to learn their backend.Max asked for the effort change to go in favour of the prompt. The claude-code journey passes, and Codex reviewed it; its two findings, an unused driver clock and a stale comment, are fixed.
tests/process/test_interact_claude_code_module.py,tests/model/test_clerk.pyandtests/model/test_forks.pypass.