#22303: fix: extend cacheRetention auto-injection and runtime pass-through for amazon-bedrock
agents
size: XS
Cluster:
Bedrock and Caching Improvements
## Summary
Two changes to make `cacheRetention` work end-to-end for Anthropic Claude models on the `amazon-bedrock` provider.
## Changes
### 1. `src/config/defaults.ts` — config auto-injection
The config auto-injection in `applyContextPruningDefaults` only sets `cacheRetention: "short"` for `provider === "anthropic"`, skipping Bedrock Claude models. Extended the provider gate to also match `amazon-bedrock` models whose ID contains `anthropic.claude`.
### 2. `src/agents/pi-embedded-runner/extra-params.ts` — runtime pass-through
`resolveCacheRetention` hard-gates on `provider !== "anthropic"` and returns `undefined` for all other providers. This means `cacheRetention` configured in model params is never consumed at runtime for Bedrock models. Extended the gate to also accept `amazon-bedrock` when `cacheRetention` is explicitly set in `extraParams`. No default is applied for Bedrock since pi-ai's own provider already defaults to `"short"` internally.
## Related
- Fixes the config + runtime parts of #21986
- Complements PR #20866 (disables caching for non-Anthropic Bedrock models)
- The TTL validation gap (`cacheRetention: "long"` → `ttl: "1h"` on unsupported models) is a separate upstream pi-ai concern, tracked in #21986 and [pi-mono discussion #1571](https://github.com/badlogic/pi-mono/discussions/1571)
## Testing
- [x] AI-assisted (Kiro CLI)
- [x] Lightly tested against local openclaw instance with `amazon-bedrock/us.anthropic.claude-opus-4-6-v1`
- [x] Confirmed `cacheRetention` is auto-injected and consumed at runtime for Bedrock Claude models
- [x] Confirmed non-Anthropic Bedrock models are correctly skipped
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Extends `cacheRetention` support to Anthropic Claude models running on Amazon Bedrock by adding two complementary changes:
- Config auto-injection in `applyContextPruningDefaults` now recognizes Bedrock Claude models (matching `amazon-bedrock` provider with model IDs containing `anthropic.claude`) and applies the default `cacheRetention: "short"` setting
- Runtime pass-through in `resolveCacheRetention` now accepts Bedrock when `cacheRetention` is explicitly configured, allowing the auto-injected or user-specified values to flow through to the streaming API
The changes correctly preserve the existing behavior for direct Anthropic models while extending support to Bedrock's Anthropic Claude variants. The string matching logic handles both region-prefixed (`us.anthropic.claude-*`) and non-prefixed (`anthropic.claude-*`) model ID formats.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-scoped, logically sound, and follow the existing patterns in the codebase. The two-part approach (config auto-injection + runtime pass-through) correctly implements the feature. The string matching logic using `.toLowerCase().includes("anthropic.claude")` appropriately handles all documented Bedrock Claude model ID formats, and the guard condition `extraParams?.cacheRetention !== undefined` ensures Bedrock only gets cacheRetention when explicitly configured (via auto-injection or user config). The changes preserve backward compatibility with direct Anthropic models and existing cacheRetention behavior.
- No files require special attention
<sub>Last reviewed commit: fb85a4d</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#20866: fix: disable prompt caching for non-Anthropic Bedrock models
by pierreeurope · 2026-02-19
87.9%
#8963: fix(bedrock): fix amazon bedrock model problem of dealing with profile
by 67ailab · 2026-02-04
80.7%
#17560: fix: Anthropic Prompt Caching Not Working - Missing cache_control H...
by MisterGuy420 · 2026-02-15
79.5%
#17462: fix(cache): enable cache retention for Google Vertex AI (#15525)
by rrenamed · 2026-02-15
79.1%
#14744: fix(context): key MODEL_CACHE by provider/modelId to prevent collis...
by lailoo · 2026-02-12
77.0%
#17015: fix: correct Claude 4.5 context limits in model registry
by Limitless2023 · 2026-02-15
76.8%
#5500: Fix #5290 Bedrock Auto Discovery fails to retrieve or support Inferen…
by heqiqi · 2026-01-31
76.3%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
76.2%
#13119: fix: add forward-compat for google-antigravity claude-opus-4-6 models
by sdb001 · 2026-02-10
76.0%
#2806: [AI-Assisted] Fix: Repair tool_use/tool_result pairing for Claude o...
by Arthur742Ramos · 2026-01-27
75.9%