Keep cache breakpoints ahead of a downgraded request-scoped `CapabilityPart`
Part of #11029. Stacked on #11935 (base capability-part-core). Release blocker for the release containing #11935.
A capability lowered with with_authority('none') that enqueues a scope='request' part on every step got no message-cache hits and rewrote the whole history on each request. #11935 leaves the answered frame out of later requests, which stays, but cache_control sat after that frame, so no breakpoint recurred in the next request. Now the breakpoint goes ahead of the frame, as it does for an operator part.
Measured
Live, about 21k tokens of history, 4 steps, cache read / cache write per step, rows from a capability that enqueues on every step unless the row says otherwise. Before is #11935's head c9ccf45632.
| Provider, model, capability | Step 1 | Step 2 | Step 3 | Step 4 |
|---|---|---|---|---|
Anthropic claude-opus-5-5, anthropic_cache_messages, downgraded, before | 0 / 21,138 | 0 / 21,173 | 0 / 21,265 | 0 / 21,324 |
| Same, after | 0 / 20,989 | 20,989 / 33 | 21,022 / 51 | 21,073 / 58 |
| Same, operator part, for comparison | 0 / 20,989 | 20,989 / 33 | 21,022 / 31 | 21,053 / 31 |
| Same, downgraded, sent once in step 1, before | 0 / 21,137 | 0 / 21,021 | 21,021 / 31 | 21,052 / 31 |
| Same, after | 0 / 20,988 | 20,988 / 33 | 21,021 / 31 | 21,052 / 31 |
| Same, downgraded, sent once in step 2, before | 0 / 20,989 | 20,989 / 184 | 20,989 / 116 | 21,105 / 31 |
| Same, after | 0 / 20,986 | 20,986 / 33 | 21,019 / 52 | 21,071 / 31 |
Same, anthropic_cache instead, downgraded, after | 0 / 21,145 | 20,990 / 190 | 21,023 / 208 | 21,074 / 204 |
Anthropic claude-haiku-5-5, downgraded, before | 0 / 21,073 | 0 / 21,224 | 0 / 21,317 | 0 / 21,405 |
| Same, after | 0 / 20,990 | 20,990 / 207 | 21,197 / 90 | 21,287 / 111 |
| Same, operator part, for comparison | 0 / 20,991 | 20,991 / 143 | 21,134 / 100 | 21,234 / 95 |
OpenRouter anthropic/claude-opus-5.5, downgraded, before | 0 / 21,145 | 0 / 21,180 | 0 / 21,211 | 0 / 21,279 |
| Same, after | 0 / 20,986 | 20,986 / 33 | 21,019 / 60 | 21,079 / 58 |
Bedrock Converse global.anthropic.claude-opus-5-5, downgraded, before | 0 / 21,059 | 0 / 21,214 | 0 / 21,245 | 0 / 21,319 |
| Same, after | 0 / 20,986 | 20,986 / 159 | 21,145 / 31 | 21,176 / 70 |
Request bodies on claude-opus-5-5, after (* is cache_control):
user[*tool_result call_1, <requests_left>3 requests left.</requests_left>] | system[note, announcement]
user[tool_result call_1] | assistant[...] | user[*tool_result call_2, <requests_left>2 requests left.</requests_left>] | system[note, announcement]
Only the three explicit-breakpoint paths have this defect. Anthropic and OpenRouter needed adapter changes; Bedrock reproduced it and is fixed by the shared pass. The other adapters place no message breakpoints, so I didn't change or measure them.
How
- The frame goes in the request-scoped tail on every profile.
_move_request_scoped_prompts_to_tailalready moved these prompts last on a model that can't clear them, and recorded them for_request_scoped_tail_texts. It now also takes a downgraded part's frame, on a model that can clear operator ones too, since nothing clears user-channel text.Model._goes_in_request_scoped_taildecides. - Notes. On adapters that send a request's system entries after its user turn, the capability note and lookalike notes stay where #11813's placement left them: they're already past the frame, and the application's own change still ends the entry. Elsewhere they move with the frame.
- One text. A downgraded request-scoped body renders as one string rather than three
TextContents, which is what the tail matching and OpenRouter's single-stringtext_ofrecognize. The model sees the same text. These parts are never replayed, so no stored conversation's bytes change. - Looking past system messages. A lasting system message sits behind the frame on these adapters, and the next request sends it without the frame ahead of it, so a breakpoint on it can't recur.
lasting_blocks_at_end(Anthropic) andis_after_tailon_request_scoped_suffix_start(OpenRouter) skip system messages while a text is left to match.
Review notes
- Frame after the application's change on sealed models. On
needs_sealed_system_blocksprofiles,_system_prompts_after_user_wordsputs a genuine change after the last user prompt, and the body used to count as one. The frame now goes after that change. It's still after the user's words, and it's text with no authority behind a note, but a request holding both a genuine change and a downgraded request-scoped frame has a different order from #11935's, which I did not measure for steering. anthropic_cachealso puts its top-level breakpoint on the frame, on top of the explicit one, so each step writes about 200 tokens rather than about 50. Reads aren't affected.
Tests
test_message_cache_breakpoint_stays_ahead_of_a_downgraded_request_scoped_frame(Anthropic, 8 cases) and the OpenRouter and Bedrock counterparts check the bytes of two consecutive requests: the breakpoint is before the frame, and everything up to it comes back identically.test_rendering_is_append_onlyis unchanged.- Mutation-checked: reverting the tail move, the one-text body, the Anthropic or OpenRouter skip, the note flags and the note placement each fail a test.
docs/capabilities/custom.mdno longer states the cost.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code
Summary by cubic
Fixes message-cache misses for a capability lowered with with_authority('none') that enqueues a scope='request' part: every step rewrote the whole history, because the frame was left out of later requests and the cache breakpoint landed after it. The frame now goes in the request-scoped tail, ahead of the breakpoint, so the prefix before it stays cached on Anthropic, OpenRouter, and Bedrock Converse.
- The frame renders as one text, which the adapters match on the wire, and notes stay with the frame.
- Anthropic and OpenRouter now skip a lasting system message sitting behind the frame when placing the breakpoint, since the next request sends it without the frame.
- The docs no longer state the cache cost, and mixed-requests tests cover the old and new request bytes.