Skip to content

fix: bypass response cache for Anthropic compaction - #1127

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:release/0.9from
mnajafian-nv:fix/anthropic-compaction-cache-bypass
Sep 19, 2026
Merged

rapids-bot[bot] merged 2 commits into
NVIDIA:release/0.9from
mnajafian-nv:fix/anthropic-compaction-cache-bypass

Conversation

@mnajafian-nv

@mnajafian-nv mnajafian-nv commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Overview

Anthropic compaction changes both the response stream and how later requests continue a conversation. Relay's optional response cache cannot yet reproduce those semantics faithfully, so this PR keeps compaction-related requests on the live provider path while leaving ordinary Anthropic Messages requests cacheable.

It covers requests that enable compaction and follow-up requests that carry a previous compaction block.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Recognize compaction configured through context_management, the top-level compaction field, or an anthropic-beta compaction token.
  • Recognize conversations that continue from an existing compaction content block.
  • Treat malformed or incomplete context_management declarations as unsafe for caching.
  • Keep ordinary Anthropic Messages requests and known non-compaction context-management edits cacheable.
  • Report anthropic_compaction as the response-cache bypass reason.
  • Add unit coverage for compaction, continuation, malformed, and non-compaction request shapes.
  • Add an integration test showing that repeated compaction requests both reach the provider and forward the native compaction_delta stream.
  • Document the cache limitation and bypass behavior.

This complements #1035, which preserves compaction deltas when Relay assembles a live Anthropic stream. That collector fix does not make cached replay of the stream safe.

Validation completed:

  • just test-rust
  • just test-python
  • just test-node
  • just test-go
  • just docs
  • just docs-linkcheck
  • uv run pre-commit run --all-files

Where should the reviewer start?

Start with anthropic_compaction_requested in crates/adaptive/src/response_cache/key.rs. It contains the cache-eligibility decision. The integration test anthropic_compaction_streams_bypass_lookup_and_storage then shows the resulting behavior across two identical requests.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Bug Fixes

    • Anthropic Messages requests using server-side compaction or compaction-related beta features now bypass response caching, preserving the native compaction lifecycle.
    • Compaction events are forwarded unchanged during streaming responses.
    • Cache-bypass telemetry now reports the anthropic_compaction reason.
  • Documentation

    • Updated response-cache documentation to describe compaction-related bypass behavior and observability.
    • Documented the known limitation for requests continuing from compaction blocks.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv
mnajafian-nv requested review from a team as code owners September 18, 2026 23:13
@mnajafian-nv mnajafian-nv self-assigned this Sep 18, 2026
@github-actions github-actions Bot added size:M PR is medium Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Sep 18, 2026
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: NVIDIA/NeMo-Relay/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 43458bea-dad8-4629-afc2-caa6973c334b

📥 Commits

Reviewing files that changed from the base of the PR and between bd95502 and a30d0f9.

📒 Files selected for processing (1)
  • docs/about-nemo-relay/release-notes/index.mdx

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (44)
  • GitHub Check: Rust / Package (windows-arm64)
  • GitHub Check: Rust / Package (windows-amd64)
  • GitHub Check: Node.js / Package (windows-arm64)
  • GitHub Check: Python / Package (windows-arm64)
  • GitHub Check: Python / Test (linux-amd64)
  • GitHub Check: Node.js / Package (windows-amd64)
  • GitHub Check: Python / Package (linux-musl-arm64)
  • GitHub Check: Python / Package (linux-arm64)
  • GitHub Check: Node.js / Package (linux-musl-arm64)
  • GitHub Check: Python / Package (macos-arm64)
  • GitHub Check: Python / Package (linux-musl-amd64)
  • GitHub Check: Node.js / Test (linux-arm64)
  • GitHub Check: Node.js / Package (linux-musl-amd64)
  • GitHub Check: Rust / Package (linux-amd64)
  • GitHub Check: Rust / Package (macos-arm64)
  • GitHub Check: Python / Package (linux-amd64)
  • GitHub Check: Python / Package (windows-amd64)
  • GitHub Check: Node.js / Test (macos-arm64)
  • GitHub Check: Node.js / Package (linux-amd64)
  • GitHub Check: Node.js / Package (linux-arm64)
  • GitHub Check: Python / Test (windows-arm64)
  • GitHub Check: Python / Test (macos-arm64)
  • GitHub Check: Rust / Package (linux-arm64)
  • GitHub Check: Python / Test (windows-amd64)
  • GitHub Check: Rust / Test (linux-arm64)
  • GitHub Check: Node.js / Package (macos-arm64)
  • GitHub Check: Rust / Package (linux-musl-arm64)
  • GitHub Check: Rust / Test (windows-arm64)
  • GitHub Check: Node.js / Test (linux-amd64)
  • GitHub Check: Python / Test (linux-arm64)
  • GitHub Check: Rust / Package (linux-musl-amd64)
  • GitHub Check: Node.js / Test (windows-amd64)
  • GitHub Check: Node.js / Test (windows-arm64)
  • GitHub Check: Rust / Test (linux-amd64)
  • GitHub Check: Rust / Test (macos-arm64)
  • GitHub Check: Go / Test (macos-arm64)
  • GitHub Check: Go / Test (windows-amd64)
  • GitHub Check: Go / Test (windows-arm64)
  • GitHub Check: Rust / Test (windows-amd64)
  • GitHub Check: Go / Test (linux-arm64)
  • GitHub Check: Node.js / Package OpenClaw plugin
  • GitHub Check: Go / Test (linux-amd64)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (4)
Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.

⚙️ CodeRabbit configuration file

Files:

  • docs/about-nemo-relay/release-notes/index.mdx
In MDX files, top-of-file comments must use JSX comment delimiters: `{/*` to open and `*/}` to close.

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Files:

  • docs/about-nemo-relay/release-notes/index.mdx
Run `just docs` when the docs site changed; `./scripts/build-docs.sh html` remains the compatibility wrapper

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Files:

  • docs/about-nemo-relay/release-notes/index.mdx
Verify MDX files use JSX delimiters for top-of-file SPDX comments.

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

Files:

  • docs/about-nemo-relay/release-notes/index.mdx
🔇 Additional comments (1)
docs/about-nemo-relay/release-notes/index.mdx (1)

299-301: LGTM!


Walkthrough

Anthropic compaction requests now bypass response caching. The change covers compaction fields, blocks, beta headers, and malformed context-management data. It adds telemetry, integration coverage, unit coverage, and documentation.

Changes

Anthropic compaction cache handling

Layer / File(s) Summary
Compaction detection and bypass reason
crates/adaptive/src/response_cache/key.rs, crates/adaptive/src/response_cache/mark.rs
The cache detects Anthropic compaction requests and returns CacheReason::AnthropicCompaction. The reason serializes as anthropic_compaction.
Cache behavior validation and documentation
crates/adaptive/tests/unit/response_cache/*, crates/adaptive/tests/integration/response_cache_tests.rs, docs/configure-plugins/adaptive/response-cache.mdx, docs/about-nemo-relay/release-notes/index.mdx
Tests cover recognized and unrelated request forms. Integration coverage verifies live execution, bypass marks, and preserved compaction_delta events. Documentation lists the new bypass behavior and reason, and the release notes record the known issue.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant AnthropicMessagesRequest
  participant ResponseCache
  participant Provider
  AnthropicMessagesRequest->>ResponseCache: submit compaction-enabled request
  ResponseCache->>ResponseCache: detect compaction and mark bypass
  ResponseCache->>Provider: execute request without cache lookup or storage
  Provider-->>ResponseCache: return native compaction_delta events
Loading

Merge Risk: ⚪ Minimal · up to a30d0

Compaction requests avoid cached responses while preserving native provider events, with ordinary requests retaining cacheability; no concrete current-head production risk is established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with the allowed lowercase type fix, uses a concise imperative summary, stays under 72 characters, and has no trailing period. It accurately describes t…
Description check ✅ Passed The description includes all required sections, completed contribution and duplicate-work confirmations, clear change details, reviewer guidance, a valid related-issue action keyword, and validation r…
Docstring Coverage ✅ Passed Docstring coverage is 81.25% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

@willkill07 willkill07 added this to the 0.9 milestone Sep 18, 2026
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@willkill07

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit 1304734 into NVIDIA:release/0.9 Sep 19, 2026
98 checks passed
@mnajafian-nv
mnajafian-nv deleted the fix/anthropic-compaction-cache-bypass branch September 19, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants