fix(agents): honor cacheRetention for custom anthropic providers#59049
fix(agents): honor cacheRetention for custom anthropic providers#59049vincentkoc merged 5 commits intomainfrom
Conversation
|
Supersedes #58756. Refreshed onto current main, revalidated locally, and kept the fix scoped to explicit cache retention for custom anthropic-messages providers. |
Greptile SummaryThis PR fixes a targeted bug where custom providers using the Key changes:
Confidence Score: 5/5Safe to merge; the logic change is minimal and well-scoped, with no behavior change for direct Anthropic or Bedrock users. All findings are P2 style/test-coverage suggestions. The core fix in anthropic-cache-retention.ts is correct: the new guard requires both anthropic-messages API and explicit config, preserving existing defaults for all other providers. The optional chaining in extra-params.ts ensures backward compatibility. No P0 or P1 issues found. No files require special attention; the only suggestions are about adding tighter direct unit tests in extra-params.cache-retention-default.test.ts. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-runner/extra-params.cache-retention-default.test.ts
Line: 154-173
Comment:
**Integration tests only verify `streamFn` is defined, not that `cacheRetention` was applied**
`applyAndExpectWrapped` asserts `expect(agent.streamFn).toBeDefined()`, but `createAnthropicToolPayloadCompatibilityWrapper` is unconditionally applied inside `applyPrePluginStreamWrappers`, meaning `streamFn` will always be defined regardless of whether the `cacheRetention` path was exercised. The new tests at lines 154–173 and 179–198 would both pass even if `resolveCacheRetention` returned `undefined` for the custom provider path.
The one direct unit test (`resolveCacheRetention(undefined, "litellm", "anthropic-messages")` at line 175–177) correctly validates the no-default path. Consider adding similar direct-unit-test coverage for the positive cases (`"long"` / `"short"`) to lock in the actual regression scenario without relying on indirect `streamFn` presence:
```ts
it("passes cacheRetention 'long' through for custom anthropic-messages provider", () => {
expect(
resolveCacheRetention({ cacheRetention: "long" }, "litellm", "anthropic-messages"),
).toBe("long");
});
it("passes cacheRetention 'short' through for custom anthropic-messages provider", () => {
expect(
resolveCacheRetention({ cacheRetention: "short" }, "litellm", "anthropic-messages"),
).toBe("short");
});
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/extra-params.cache-retention-default.test.ts
Line: 175-177
Comment:
**`cacheRetention: "none"` for custom provider not covered**
The new tests cover `"long"` and `"short"` for custom `anthropic-messages` providers, but there is no test that a custom provider with `cacheRetention: "none"` actually passes `"none"` through (rather than being dropped). Given that `"none"` is the explicit opt-out value, a missed regression here could silently re-enable caching for providers that opted out. A direct unit test is straightforward:
```ts
it("passes cacheRetention 'none' through for custom anthropic-messages provider", () => {
expect(
resolveCacheRetention({ cacheRetention: "none" }, "litellm", "anthropic-messages"),
).toBe("none");
});
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Merge branch 'main' into vk/pr-58756-cac..." | Re-trigger Greptile |
|
@vincentkoc Thanks for picking this up! I fixed tests and addressed greptile comments in #59216 Anything I can help with to get this merged? |
|
#59216 tests passed. I rebased onto main, tests are running again now. |
|
Addressed Greptile test coverage feedback in 46c05e8. Added direct unit assertions for custom
This avoids relying on Local verification:
|
…nclaw#59049) * fix(agents): honor cacheRetention for custom anthropic providers * docs(changelog): add cache retention entry * Update CHANGELOG.md * test(agents): add direct cache retention assertions
…nclaw#59049) * fix(agents): honor cacheRetention for custom anthropic providers * docs(changelog): add cache retention entry * Update CHANGELOG.md * test(agents): add direct cache retention assertions
…nclaw#59049) * fix(agents): honor cacheRetention for custom anthropic providers * docs(changelog): add cache retention entry * Update CHANGELOG.md * test(agents): add direct cache retention assertions
…nclaw#59049) * fix(agents): honor cacheRetention for custom anthropic providers * docs(changelog): add cache retention entry * Update CHANGELOG.md * test(agents): add direct cache retention assertions
…nclaw#59049) * fix(agents): honor cacheRetention for custom anthropic providers * docs(changelog): add cache retention entry * Update CHANGELOG.md * test(agents): add direct cache retention assertions
Summary
anthropic-messagesAPI never honored explicitcacheRetentionsettings because retention was gated on provider id instead of model API.model.apiinto cache-retention resolution and allow explicit retention for customanthropic-messagesproviders; add targeted regression tests.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
resolveCacheRetentionkeyed behavior off provider id and treated only direct Anthropic or Anthropic Bedrock as cache-capable paths.model.api === "anthropic-messages"plus explicit retention config.git blame, prior PR, issue, or refactor if known): user reports in [Feature]: Support prompt caching for custom providers using anthropic-messages API #37325 and [Feature]: Prompt caching does not work for custom providers using anthropic-messages API #37733 plus prior attempt in fix: respect cacheRetention for custom providers using anthropic-messages API #58756.Regression Test Plan (if applicable)
src/agents/pi-embedded-runner/extra-params.cache-retention-default.test.tscacheRetentionis passed through for custom providers usinganthropic-messages, while the no-config default remains disabled.User-visible / Behavior Changes
Custom providers using
anthropic-messagesnow honor explicitcacheRetentionvalues. No behavior change for direct Anthropic or Bedrock users.Diagram (if applicable)
Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation: N/ARepro + Verification
Environment
anthropic-messagescacheRetentionSteps
api: "anthropic-messages".cacheRetentionin effective extra params.Expected
Actual
Evidence
Attach at least one:
Human Verification (required)
anthropic-messagesprovider with explicitshortandlongretention; custom provider without explicit config stays unset.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes)No)No)Risks and Mitigations
anthropic-messagesbut reject Anthropic cache fields.