Skip to content

feat: add safe cache support for Anthropic on-demand compaction - #1164

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mnajafian-nv:feat/anthropic-on-demand-response-cache
Sep 29, 2026
Merged

rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mnajafian-nv:feat/anthropic-on-demand-response-cache

Conversation

@mnajafian-nv

@mnajafian-nv mnajafian-nv commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Anthropic on-demand compaction lets an application request a signed server-side summary to replace prior conversation history. Relay previously bypassed response caching for these requests because a cache hit must preserve the provider’s signed compaction block exactly.

This PR adds safe cache reuse for on-demand compaction requests using the compact-2026-09-04 beta, including signed continuations and re-compaction. It builds on #1163’s paused-threshold foundation while keeping incomplete, ambiguous, or unsupported traffic live.

  • 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

  • Validate signed on-demand continuations and re-compaction requests before caching.
  • Replay the validated signed compaction block in its native block-start event without synthesizing a compaction_delta.
  • Keep cache entries isolated by Anthropic protocol and operation.
  • Add unit and integration coverage for cache hits, continuations, re-compaction, and malformed or unsigned traffic.
  • Document the supported opt-in contract and live-only fallback behavior.

Where should the reviewer start?

Start with crates/adaptive/src/response_cache/anthropic.rs, which defines the on-demand protocol and response validation. Then review crates/adaptive/tests/integration/response_cache_tests.rs for end-to-end cache and replay coverage.

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

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv mnajafian-nv added this to the 0.10 milestone Sep 29, 2026
@mnajafian-nv mnajafian-nv self-assigned this Sep 29, 2026
@mnajafian-nv
mnajafian-nv requested review from a team as code owners September 29, 2026 01:40
@github-actions github-actions Bot added size:M PR is medium Feature a new feature lang:rust PR changes/introduces Rust code labels Sep 29, 2026
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: f2aa9f00-070a-4ee7-99ef-04d22900b9a5

📥 Commits

Reviewing files that changed from the base of the PR and between db4c6c5 and 8733225.

📒 Files selected for processing (6)
  • crates/adaptive/src/response_cache/anthropic.rs
  • crates/adaptive/tests/integration/response_cache_tests.rs
  • crates/adaptive/tests/unit/response_cache/anthropic_tests.rs
  • crates/adaptive/tests/unit/response_cache/key_tests.rs
  • crates/adaptive/tests/unit/response_cache/mark_tests.rs
  • docs/configure-plugins/adaptive/response-cache.mdx

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Preview docs
  • GitHub Check: Changes / Detect
🧰 Additional context used
📓 Path-based instructions (8)
Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.

⚙️ CodeRabbit configuration file

Files:

  • docs/configure-plugins/adaptive/response-cache.mdx
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

⚙️ CodeRabbit configuration file

Files:

  • crates/adaptive/tests/unit/response_cache/mark_tests.rs
  • crates/adaptive/tests/unit/response_cache/key_tests.rs
  • crates/adaptive/tests/integration/response_cache_tests.rs
  • crates/adaptive/tests/unit/response_cache/anthropic_tests.rs
Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.

⚙️ CodeRabbit configuration file

Files:

  • crates/adaptive/tests/unit/response_cache/mark_tests.rs
  • crates/adaptive/tests/unit/response_cache/key_tests.rs
  • crates/adaptive/tests/integration/response_cache_tests.rs
  • crates/adaptive/tests/unit/response_cache/anthropic_tests.rs
  • crates/adaptive/src/response_cache/anthropic.rs
Source excerpt: 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/configure-plugins/adaptive/response-cache.mdx
Source excerpt: Verify MDX files use JSX delimiters for top-of-file SPDX comments.

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

Files:

  • docs/configure-plugins/adaptive/response-cache.mdx
Source excerpt: Search documentation source for references to the old version and update current-version install commands, package examples, and configuration examples to `` where appropriate: Review matches before changing th...

📄 CodeRabbit inference engine (.agents/skills/prepare-code-freeze/SKILL.md)

Files:

  • docs/configure-plugins/adaptive/response-cache.mdx
Source excerpt: `crates/adaptive`

📄 CodeRabbit inference engine (.agents/skills/maintain-optimizer/SKILL.md)

Files:

  • crates/adaptive/tests/unit/response_cache/mark_tests.rs
  • crates/adaptive/tests/unit/response_cache/key_tests.rs
  • crates/adaptive/tests/integration/response_cache_tests.rs
  • crates/adaptive/tests/unit/response_cache/anthropic_tests.rs
  • crates/adaptive/src/response_cache/anthropic.rs
Source excerpt: Preserve MDX front matter and the JSX SPDX comment.

📄 CodeRabbit inference engine (.agents/skills/draft-release-notes/SKILL.md)

Files:

  • docs/configure-plugins/adaptive/response-cache.mdx
🔇 Additional comments (6)
crates/adaptive/src/response_cache/anthropic.rs (1)

15-15: LGTM!

Also applies to: 23-23, 31-33, 40-40, 105-105, 116-123, 135-141, 245-253, 270-288, 310-320, 394-399, 410-410, 421-426, 452-459, 553-558, 630-636

crates/adaptive/tests/unit/response_cache/anthropic_tests.rs (1)

35-37: LGTM!

Also applies to: 69-88, 94-98, 142-176, 191-250, 259-261

crates/adaptive/tests/unit/response_cache/key_tests.rs (1)

656-661: LGTM!

Also applies to: 675-678

crates/adaptive/tests/integration/response_cache_tests.rs (1)

1398-1408: LGTM!

Also applies to: 1434-1455, 2172-2211, 2213-2251, 2314-2344, 2503-2558, 2560-2604

crates/adaptive/tests/unit/response_cache/mark_tests.rs (1)

131-131: LGTM!

Also applies to: 193-193

docs/configure-plugins/adaptive/response-cache.mdx (1)

317-321: LGTM!


Walkthrough

The Anthropic response cache now supports on-demand compaction using the compact-2026-09-04 beta. It validates request and response shapes, caches signed compaction blocks, and replays them for buffered and streaming calls.

Changes

Anthropic compaction caching

Layer / File(s) Summary
Protocol and response validation
crates/adaptive/src/response_cache/anthropic.rs, crates/adaptive/tests/unit/response_cache/anthropic_tests.rs, crates/adaptive/tests/unit/response_cache/key_tests.rs
The cache recognizes on-demand summarize, continuation, and recompaction operations. It validates signed continuation and response blocks, checks protocol-specific streaming shapes, and tests response classification and unsupported protocol cases.
Cache storage and replay
crates/adaptive/tests/integration/response_cache_tests.rs, crates/adaptive/tests/unit/response_cache/mark_tests.rs, docs/configure-plugins/adaptive/response-cache.mdx
Integration tests cover signed-block caching and replay across buffered and streaming calls, continuation responses, recompaction, and malformed responses. Fixtures use signatures, and the documentation describes the supported cached path.

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant AnthropicClient
  participant ResponseCache
  participant AnthropicProvider
  participant CacheStore
  AnthropicClient->>ResponseCache: Send on-demand compaction request
  ResponseCache->>CacheStore: Look up request
  CacheStore-->>ResponseCache: Cache miss
  ResponseCache->>AnthropicProvider: Forward request
  AnthropicProvider-->>ResponseCache: Return signed compaction block
  ResponseCache->>CacheStore: Store validated response
  AnthropicClient->>ResponseCache: Repeat request
  ResponseCache->>CacheStore: Look up request
  CacheStore-->>ResponseCache: Return cached signed block
  ResponseCache-->>AnthropicClient: Replay response
Loading

Merge Risk: ⚪ Minimal · up to 87332

This change adds cache support for Anthropic on-demand compaction. Malformed or unsigned traffic still goes to the provider, and the PR adds tests for the cached and fallback paths. No merge-blocking risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title follows Conventional Commits format with the allowed lowercase type feat, uses an imperative summary, is 63 characters long, and clearly describes the main change.
Description check ✅ Passed The description includes all required template sections, completed overview confirmations, implementation details, reviewer guidance, and a valid Relates to #1034 issue reference.
Full details: Docstring Coverage

Explanation

Docstring coverage is 42.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 5 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ 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

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit a922697 into NVIDIA:main Sep 29, 2026
100 of 101 checks passed

This branch was successfully deployed

1 active deployment
fern — 8733225e Deployed Sep 29, 2026 by rapids-bot[bot] via Clean up docs preview #5153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature 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