fix(caching): prompt_caching.enabled toggle for strict Anthropic proxies (salvage #35862, closes #13477) - #184
Merged
Merged
Conversation
|
Review Complete Risk: 🟢 Low (15/100) — no findings · 199 LOC across 8 files This PR adds a prompt_caching kill-switch config key and cleans up moa trace config entries from DEFAULT_CONFIG. No defects found — all 4 flagged candidates were correctly rejected by the verifier as false positives (redundant type guards that are actually load-bearing, pre-existing doc-code drift, and .get() fallback patterns). Files Reviewed (8 files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
prompt_caching.enabledconfig toggle so a user on a strict Anthropic-compatible proxy (LiteLLM-style, e.g.llm.echo.tech) that injects its owncache_controlmarkers can turn off client-side markers entirely — fixing the HTTP 400"A maximum of 4 blocks with cache_control may be provided. Found 5"reported in NousResearch#13477 without regressing caching for every well-behaved third-party gateway.Salvages @janrenz's PR NousResearch#35862 (the config toggle), then closes the gap it left: the disable must survive
/modelswitches and fallback re-derivation.Why the toggle, not a third-party strip
The original report (NousResearch#13477) proposed stripping ALL markers whenever
base_urlisn'tanthropic.com. That matches every non-Anthropic endpoint, so it would kill caching for MiniMax, Zhipu GLM, Bedrock, Foundry, Kimi, DeepSeek — all of whichanthropic_prompt_cache_policydeliberately caches on and none of which double-inject. Wrong lever. The real problem is one misbehaving proxy adding a 5th marker on top of our 4; the correct fix is a per-setup opt-out.Changes
hermes_cli/config.py: addprompt_caching.enabled: truedefault + escape-hatch comment.agent/agent_runtime_helpers.py: gateanthropic_prompt_cache_policyonenabled=false→ returns(False, False)before any branch, so init,/modelswitch, and fallback all honor it.agent/agent_init.py: keep @janrenz'sisinstancehardening on thecache_ttlread; drop the now-redundant init-only override (the policy gate covers it).tests/: policy-level kill-switch tests (native / OpenRouter / third-party / model-switch survival / enabled-true-keeps-caching) + @janrenz's init test.website/docs/: document theenabledtoggle.scripts/release.py: AUTHOR_MAP entry for @janrenz.Root cause
Client never exceeds 4 markers on native Anthropic (traced E2E:
apply_anthropic_cache_controlmarks system + last-3, tool-merge collapses them 1:1). The proxy adds a 5th server-side. The only client-side lever that helps is not sending markers to that proxy — a config toggle.Validation
/modelswitchE2E confirmed the disable survives all three re-derivation paths and re-enabling restores caching.
test_anthropic_prompt_cache_policy.py29/29 green;test_run_agent.pycaching subset 9/9 green.Closes NousResearch#13477 (via the toggle, not the proposed strip). Salvages NousResearch#35862 with authorship preserved.
Infographic
Mirror-of: NousResearch#56105
NousResearch#56105