Skip to content

feat(adaptive): add logical response cache keys - #818

Draft
zhongxuanwang-nv wants to merge 7 commits into
NVIDIA:mainfrom
zhongxuanwang-nv:feat/response-cache-logical-keys
Draft

feat(adaptive): add logical response cache keys#818
zhongxuanwang-nv wants to merge 7 commits into
NVIDIA:mainfrom
zhongxuanwang-nv:feat/response-cache-logical-keys

Conversation

@zhongxuanwang-nv

@zhongxuanwang-nv zhongxuanwang-nv commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds a logical key strategy for LLM response caching so description-only edits and tool-definition reordering do not invalidate otherwise compatible cache entries.

  • 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

  • Adds key_strategy = "logical", which recursively removes string-valued tool-description fields and canonically sorts the request's tool definitions before keying. Tool names, parameter schemas, constraints, settings, and every non-tool request field remain key-significant.
  • Keeps logical and exact_request entries in separate keyspaces.
  • Exposes typed response-cache key strategy values in Rust, Python, Node.js, and Go, while preserving the existing string wire format and field-specific diagnostics for unknown values.
  • Adds unit and end-to-end coverage for description changes, tool ordering, interface changes, built-in tools, parameter enums, and strategy partitioning.
  • Documentation is tracked separately in docs(adaptive): document logical response cache keys #819.
  • Breaking changes: the typed Rust, Python, and Go ResponseCacheConfig.key_strategy helpers now use a strategy type instead of a plain string; the JSON/TOML wire values remain unchanged. The Node.js TypeScript surface narrows the field from string to the supported strategy union.
  • Validation:
    • cargo fmt --all -- --check
    • cargo test -p nemo-relay-adaptive
    • just test-rust
    • cargo clippy --workspace --all-targets -- -D warnings
    • just test-python (686 passed)
    • just test-node (391 passed)
    • just test-go
    • uv run pre-commit run --all-files
    • uv run pre-commit run --files <changed code files>

Where should the reviewer start?

Start with build_cache_key and structural_tool_schema in crates/adaptive/src/response_cache/key.rs, then review the logical-key cases in crates/adaptive/tests/unit/response_cache/key_tests.rs.

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

A higher-hit-rate `key_strategy`: tools are keyed by a structural,
description- and order-insensitive schema hash, so rewording or
reordering tool definitions no longer busts the cache — only a changed
tool interface does. Every other field keys exactly as `exact_request`;
the two strategies never share keys.

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 307ef1c3-dd66-48e8-9a54-e8a9bd6637f7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@github-actions github-actions Bot added size:L PR is large Feature a new feature lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code labels Aug 20, 2026
@github-actions

Copy link
Copy Markdown

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@zhongxuanwang-nv
zhongxuanwang-nv force-pushed the feat/response-cache-logical-keys branch from f98b3a5 to 46238bc Compare August 20, 2026 16:18
@github-actions github-actions Bot added size:M PR is medium and removed size:L PR is large labels Aug 20, 2026
Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code 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