Skip to content

fix(compression): RTK compresses Anthropic-shape tool_result blocks - #4468

Merged
diegosouzapw merged 1 commit into
release/v3.8.32from
fix/escalated-rtk-anthropic-tool-result
Jun 21, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.32from
fix/escalated-rtk-anthropic-tool-result

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Problem

A user reported: "I set compression mode to only RTK, but it's not working — I ran git status via my agent and the RTK stats stayed the same." (community-escalated cmqmf7d29).

Root cause

applyRtkCompression only compressed OpenAI-shape tool results (role:"tool"). Anthropic-shape tool results — which arrive as tool_result content blocks inside a (typically role:"user") message — were skipped entirely. So coding agents speaking the Anthropic Messages format (/v1/messages, "Claude format — auto convert via handleChat") got zero RTK savings, even though RTK's command-aware filters (e.g. git-status) would have compressed the output.

caveman/aggressive already handle this shape (B-AGG-ANTHROPIC-TR via compressAnthropicToolResultBlock in toolResultCompressor.ts); RTK was the only engine that didn't.

Fix (open-sse/services/compression/engines/rtk/index.ts)

  • shouldCompressMessage: a message whose content array contains a tool_result block is now eligible (gated by applyToToolResults), same as an OpenAI tool message.
  • toolCallLookup: now also captures Anthropic assistant tool_use blocks (id → name / input.command), so the shell command resolves exactly like the OpenAI tool_call_id path. (Removed the early continue that skipped the content scan.)
  • New processToolResultBlocks: compresses the inner text of each tool_result block (string or nested text-block array), preserving block type + tool_use_id exactly; resolves command/skipFilters per block.
  • Extracted SHELL_TOOL_NAME_RE + resolveToolMeta, shared by the OpenAI and Anthropic paths (reuses the existing isAnthropicToolResultBlock detector — DRY).

Legacy/OpenAI behavior is unchanged: non-tool_result content and role:"tool" messages take the exact same path as before.

Tests (TDD)

New tests/unit/compression/rtk-anthropic-tool-result.test.ts — red→green:

  • string-content tool_result inside a user message → compressed, tool_use_id/structure preserved, (use ...) noise dropped, branch/changed-file lines kept
  • array-content tool_result (nested text blocks) → inner text compressed
  • non-tool_result user content → untouched (control)

Validation: full compression suite 774/774 · typecheck:core clean · lint 0 new warnings · check:file-size OK · check:any-budget:t11 PASS.

RTK only compressed OpenAI-shape tool results (role:"tool"); Anthropic-shape
tool_result content blocks inside (typically role:"user") messages were skipped
entirely, so coding agents speaking the Anthropic Messages format saw zero RTK
savings — e.g. a `git status` tool result was never filtered. caveman/aggressive
already handle this shape (B-AGG-ANTHROPIC-TR via compressAnthropicToolResultBlock);
RTK was the only engine that didn't.

- shouldCompressMessage: messages whose content has a tool_result block are eligible
  (gated by applyToToolResults), same as OpenAI tool messages
- toolCallLookup also captures Anthropic assistant tool_use blocks (id -> name/command)
- new processToolResultBlocks compresses the inner text of each tool_result block
  (string or nested text-block array), preserving block type + tool_use_id exactly;
  resolves command/skipFilters per block via tool_use_id
- extract SHELL_TOOL_NAME_RE + resolveToolMeta, shared by the OpenAI and Anthropic paths

TDD: tests/unit/compression/rtk-anthropic-tool-result.test.ts (red -> green).
Full compression suite 774/774.
@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 92afce6 into release/v3.8.32 Jun 21, 2026
4 checks passed
@diegosouzapw diegosouzapw mentioned this pull request Jun 21, 2026
@diegosouzapw
diegosouzapw deleted the fix/escalated-rtk-anthropic-tool-result branch June 21, 2026 12:33
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