Skip to content

fix(sse): RTK must preserve cache_control-marked tool_result blocks (prompt-cache regression) - #4560

Merged
diegosouzapw merged 1 commit into
release/v3.8.33from
fix/escalated-rtk-cache-control-preserve
Jun 21, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.33from
fix/escalated-rtk-cache-control-preserve

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Problem

Since v3.8.32 (PR #4468 added Anthropic tool_result support to RTK), enabling compression broke upstream prompt cache on caching providers — reported from the channels as "provider cache again broken in combo section" and "cache rate seems very low" right after upgrading.

A tool_result content block (or text sub-block) carrying cache_control is an explicit prompt-cache breakpoint: the provider caches the prefix up to and including that block. processToolResultBlocks rewrote the marked block's inner text, so the cached prefix no longer matched byte-for-byte → guaranteed cache miss on every turn.

This re-broke the invariant #3936 established for #3890 (memory + system-prompt cache safety), which never covered tool_results.

Fix

processToolResultBlocks now skips any block / text sub-block carrying cache_control, preserving it byte-for-byte. Blocks without cache_control still compress normally (no over-protection). Mirrors #3936's principle: under caching, only ever preserve more of the prefix — never rewrite a client-declared breakpoint.

+21 production lines, single file (open-sse/services/compression/engines/rtk/index.ts).

Validation (TDD — Hard Rule #18)

  • New tests/unit/compression/rtk-cache-control-preserve.test.ts — red→green, 3 cases:
    1. cache_control-marked tool_result (string content) preserved byte-for-byte
    2. cache_control-marked inner text sub-block (array content) preserved
    3. control: unmarked tool_result still compresses (hint lines dropped)
  • Full compression suite: 777/777
  • RTK Anthropic tool_result suite (fix(compression): RTK compresses Anthropic-shape tool_result blocks #4468): 3/3 (zero regression)
  • typecheck:core clean · lint 0 errors/0 warnings · check:file-size OK · check:any-budget:t11 OK

Research

A tool_result block (or text sub-block) carrying cache_control is an explicit
upstream prompt-cache breakpoint — the provider caches the prefix up to and
including it. Since v3.8.32 RTK started compressing Anthropic tool_result blocks
(processToolResultBlocks), rewriting the marked block's content and invalidating
the cached prefix every turn → guaranteed cache miss (provider cache 'again broken').

Skip any cache_control-marked block/sub-block in processToolResultBlocks, preserving
it byte-for-byte. Unmarked blocks still compress (no over-protection). Mirrors #3936:
under caching, only ever preserve more of the prefix — never rewrite a declared breakpoint.

TDD: rtk-cache-control-preserve.test.ts (red->green, 3 cases). Compression suite 777/777.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw
diegosouzapw merged commit 3ff08e2 into release/v3.8.33 Jun 21, 2026
3 checks passed
@diegosouzapw
diegosouzapw deleted the fix/escalated-rtk-cache-control-preserve branch June 23, 2026 13:13
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
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.

1 participant