Skip to content

Fork at the session's effort and ask for a quick answer, so every backend reads the cache - #5960

Merged
max-sixty merged 3 commits into
mainfrom
vertex-cache-effort
Nov 14, 2026
Merged

max-sixty merged 3 commits into
mainfrom
vertex-cache-effort

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Leaf's two conversation forks (the turn-end check and the thread-reply line) no longer ask $.model.fork for low effort. 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's ModelForkRequest.effort docs 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 the effort plumbing through clerk.py, forks.py and their diagnostics. A TODO in runFork marks the switch back to low once 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):

  • Turn-end check: 15/15 passed, as low did. It wrote 1.62× low's output (95% 1.26–2.09) and took 1.23× its time (1.10–1.38). The check runs off the turn's path.
  • Reply line: 7/7 passed, against low's 6/7. It wrote 1.49× the output (0.91–2.44) and took 1.09× the time (0.94–1.25), about 4 s a line.

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.py and tests/model/test_forks.py pass.

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

…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
@max-sixty
max-sixty merged commit a1cb106 into main Nov 14, 2026
5 checks passed
@max-sixty
max-sixty deleted the vertex-cache-effort branch November 14, 2026 20:59
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.
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