Skip to content

Load the Claude Code module again, and learn a fork's cache rewrite from the main thread's usage - #5947

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

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

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Claude Code refuses to load a hooks module whose $.env.get takes anything but a literal name, and #5907 read the route variables in a loop. Since #5907 landed, Leaf's Claude Code module hasn't loaded in any session: no band, no turn-end check, no thread-reply fork. claude plugin validate refuses main's module at 2.1.322, 2.1.323 and 2.1.325. readRoute now spells each name out. The claude-code journey passes with this branch, where it failed at setup on main (hooks module did not load). #5952 adds that validation to CI and should merge after this.

The PR also tightens the effort learning from #5892/#5907, which keeps turn-end checks from rewriting the prompt cache on Vertex:

  • Rewrite test. A check at a changed effort now counts as a rewrite when it reads less from the cache than the main thread's last request left there (read + creation from the turn.step result, recorded as request.cached in each fork's diagnostics). Before, the test was "wrote more than it read", which misses a rewrite of a conversation shorter than the system prompt and tools the fork still reads (28k tokens on Vertex in A fork's change of effort rewrites the prompt cache on backends without per-message effort, such as Vertex #5904's repro). In 103 real checks where the cache held, plus 12 in the journey, every fork read at least cached. Only answered checks count: a refused fork reports zero reads.
  • Lapse. A stored answer was asked again only in a conversation of at most 20 messages. In practice that never happened: of 902 real checks, none came before message 46. So a stored answer never lapsed. Now the first check after the 7-day lapse asks at low whatever the size. Where the backend still lacks per-message effort, that costs one conversation rewrite per backend per week, about $1.50–3 at 300k tokens. That number is a call to weigh.

The module's stale session.append door names, which 2.1.325's claude plugin validate reports, are left to #5816.

Max asked whether the Vertex caching issue could be fixed. Codex reviewed the change; its two findings, the refused fork and a step racing the fork, are fixed here. tests/process/test_interact_claude_code_module.py passes (18); the new cases fail on main.

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

…ewrite from the main thread's own usage

Claude Code 2.1.325 refuses to load a hooks module whose `$.env.get` names its
variable other than by a literal. #5907 read the route's variables in a loop, so
2.1.325 loaded none of the module: no band, no turn-end check and no thread-reply
fork. `readRoute` now spells each name at its call, and `claude plugin validate`
lists them as the module's env reads.

A turn-end check at low effort counted as a rewrite of the prompt cache when it
wrote more than it read. On Vertex such a fork still reads the system prompt and
tools (28k tokens in #5904's repro), so a rewrite of a conversation shorter than
that went unseen. The `turn.step` hook now keeps how much of the main thread's
last request its response left in the cache (`cached`, also in each fork's
diagnostics `request`), and a check that reads less than that is a rewrite. In
103 checks at low from sessions at xhigh on Opus 5.5, where per-message effort
keeps the cache, every fork read at least that much, as did each of the 12 checks
in a claude-code journey on 2.1.325. Only an answered check counts, since a fork
the API refused reports no tokens read, and only while no other main-thread
request has gone out since the one `cached` measures.

A stored rewrite lapsed only into a check in a conversation of at most 20
messages, which never comes: of 902 checks on the maintainer's machine, none came
before a conversation's 46th message, and no session's first before its 194th.
So a backend that gained per-message effort was never found again. The next check
after the seven-day lapse now asks at low whatever the conversation's size, which
costs one rewrite of it per backend per lapse where the backend still lacks
per-message effort.

The test driver's `turn.step` now answers with a response carrying usage, a fork
can come back refused (`forkRefused`), and the tests' main-thread request carries
200 messages, as long as a session's first check comes in. Behaviour changes held
by tests: a small rewrite is caught, a lapsed answer is asked again in a long
conversation, a re-asked rewrite renews, and a refused check stores nothing.
…rrent door names

Claude Code 2.1.322 renamed session.append's doors: the model's reply now arrives
by `response` and a tool's result by `tool-result`, so the module's `model`
matcher caught nothing, and a fork's `row` and `sent` named the turn's first user
row. A turn-end check's or line fork's diagnostics then pointed a replay at the
turn's opening prompt rather than its final reply. The module now follows every
door of a row the model reads, as 16434b2 on send-pickup-latency does; Claude
Code 2.1.325's `claude plugin validate` reported the stale name and now reports
nothing for the module.
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5816 (open) also rewrites this session.append door list, and the two disagree. #5816 drops tool-message because on a machine with managed settings cc-plugin-sec-default sends Skill bodies on that door past person-level handlers, which shows the skipped-hook notice at each session's first Skill call. It also keeps queue and notice. This PR keeps tool-message and drops queue, and doesn't add notice. Main already has tool-message, so this isn't a regression, but whichever lands second needs to settle the list. Its comment's "Claude Code tells the user when one of those sends a row past a handler" is the same notice #5816 is avoiding.

#5816 settles the same list with evidence from a machine with managed settings, where the security plugin sends Skill bodies on `tool-message` past a person's handlers, so this branch keeps main's list.
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
… here, not from 2.1.325

2.1.322, 2.1.323 and 2.1.325 all refuse main's module (claude plugin validate), so #5907's loop broke the module for every session since it landed.
@max-sixty max-sixty changed the title Load the Claude Code module under 2.1.325, and learn a fork's cache rewrite from the main thread's usage Load the Claude Code module again, and learn a fork's cache rewrite from the main thread's usage Nov 14, 2026
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
max-sixty added a commit that referenced this pull request Nov 14, 2026
A new `newest-harnesses` job, on the daily schedule and on dispatch, installs
`@anthropic-ai/claude-code@latest` and `@earendil-works/pi-coding-agent@latest`
and runs `pnpm run check:hooks`. The pins move with Dependabot's weekly npm
group, while a user's Claude Code updates itself as each release ships, so a
release that refuses `hooks/claude-code.ts` or changes the API `hooks/pi.ts`
uses now turns the daily run red for tend within a day.

Rehearsed locally on this branch's tree with #5947's module: Claude Code 2.1.325
and Pi 1.5.2 installed, and the check passed.
# Conflicts:
#	tests/claude_code_driver.mjs
@max-sixty
max-sixty merged commit d5f093f into main Nov 14, 2026
5 checks passed
@max-sixty
max-sixty deleted the vertex-cache-effort branch November 14, 2026 19:35
max-sixty added a commit that referenced this pull request Nov 14, 2026
…nd daily at the newest release (#5952)

CI now fails wherever Claude Code would refuse to load
`hooks/claude-code.ts`. `pnpm run check:hooks` also runs `claude plugin
validate .` from a pinned `@anthropic-ai/claude-code` (2.1.325), on
every run. The daily scheduled `test` job then runs the same check again
after installing the newest Claude Code and Pi. A release that refuses
the module, or changes the API `hooks/pi.ts` uses, then turns the daily
run red for tend within a day, instead of waiting for Dependabot's
weekly bump of the pin while users' Claude Code updates itself. Until
now nothing in CI asked Claude Code: the module's tests run in a Node
stand-in, and `hooks/tsconfig.json` leaves the module out.

That gap let #5907's `$.env.get(name)` loop through. Claude Code refuses
a module whose `$.env.get` takes anything but a string literal (2.1.305
already did), so every session that loaded the module from an install
since #5907 has had no band, no turn-end clerk and no thread forks. The
refusal shows only in Claude Code's debug log, so all Max saw was an
empty band in a session he resumed today.

#5947, now on main, spells each name out, so the check passes on this
branch; before it merged, the check failed in CI with exactly that
refusal.

The nightly harness scan in `running-tend` now reads Pi's releases too,
since `hooks/pi.ts` depends on Pi's API.

The package's postinstall copies its platform binary into place, so
`pnpm-workspace.yaml` allows its build; pnpm hard-links the 347 MB
binary from its store, so a worktree adds no copy.

Max asked why the band was missing, then for the nightly check against
each harness's newest release, and for Pi in the nightly scan. Checks:
`pnpm run check:hooks` failed in CI with only that refusal before #5947
and passes locally after it; the newest-release step's commands,
rehearsed locally with #5947's module, installed Claude Code 2.1.325 and
Pi 1.5.2 and passed; `pnpm run test:browser` and pre-commit pass. The
`test` job's one failure,
`test_receipts.py::test_ack_rearm_reports_when_its_only_page_transfers_after_selection`,
is inherited: a watchdog warning (`InotifyEmitter.queue_events() called
when the thread is inactive`) on a waiter's stderr broke the test's JSON
parse, in code this PR doesn't touch.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 14, 2026
…kend reads the cache (#5960)

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_
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