fix(agents): honor explicit long Anthropic cache TTL on custom hosts#67800
Conversation
Greptile SummaryThis PR fixes a bug where explicit Confidence Score: 5/5Safe to merge — minimal, targeted fix with correct logic and comprehensive regression tests. The logic change is provably correct across all four input cases (explicit long, env-driven long, explicit short, none). Tests cover the new behavioral paths. No P0/P1 findings. No files require special attention. Reviews (1): Last reviewed commit: "Merge branch 'main' into codex/anthropic..." | Re-trigger Greptile |
suboss87
left a comment
There was a problem hiding this comment.
Nice fix. The distinction between explicit user opt-in vs env-driven defaults is the right call for custom proxy hosts.
One thing to watch: retention is derived from cacheRetention (possibly after env defaults), so the condition retention === "long" && (cacheRetention === "long" || isLongTtlEligibleEndpoint(baseUrl)) works correctly but the relationship between the two variables is implicit. If someone later changes how retention is resolved without updating this site, the behavior could drift. Might be worth a comment noting that cacheRetention === "long" is the "was this explicitly set by the user" check vs the env/hostname path.
The env save/restore in the test is clean. Tests look solid.
|
@hxy91819 PTAL |
5a61244 to
ad9f567
Compare
|
The security bot's concern seems overstated for this use case. When a user explicitly sets The Option 3 from the original issue is the right call — honor explicit user intent. The allowlist can remain as the default guard when |
Cherry-pick of openclaw#67800 (ad9f567) - Explicit cacheRetention: 'long' now emits ttl: '1h' for any host - Implicit/env-driven long retention still requires allowlisted host - Tests added for explicit long, implicit long, explicit short
Review: Honor explicit long Anthropic cache TTL on custom hostsAPPROVED — this is completing an already-open capability path, not introducing new behavior. Custom Why the gap exists — historical investigationThe allowlist and custom-provider support evolved independently:
The gap was not an intentional security boundary — it was an alignment miss between two layers implemented at different times. No blocking issues. Optional nice-to-have: warn-level log when Note: Do not merge until after the next release. |
bca4213 to
3852331
Compare
|
Merged via squash.
Thanks @MonkeyLeeT! |
* 'main' of https://github.com/openclaw/openclaw: (653 commits) docs(changelog): deduplicate openclaw#67800 entries in Unreleased (openclaw#69670) fix(agents): honor explicit long Anthropic cache TTL on custom hosts (openclaw#67800) fix: fix Telegram media file delivery (openclaw#69641) fix(media): preserve outbound attachment filenames fix(media): parse lowercase media directives fix(bluebubbles): add opt-in coalesceSameSenderDms for split-send DMs (openclaw#69258) fix: centralize provider thinking profiles docs: prepare 2026.4.20 changelog fix: stage ACP and Codex runtime deps fix(gateway): drop stale service env on reinstall test: add bundled channel dependency Docker smoke test: relax detached task recovery timing assertion fix: ignore placeholder shells in runtime detection (openclaw#69308) shell: fall back to sh when SHELL is /usr/bin/false or nologin fix(browser): clarify DevToolsActivePort attach failures fix: sanitize mcp transport warning fields fix: launch Windows startup gateway directly fix(openai-codex): normalize legacy copilot transport fix: narrow MCP stdio env safety filter (openclaw#69540) fix(mcp): block dangerous stdio env overrides ...
…penclaw#67800) Merged via squash. Prepared head SHA: 0ffde15 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com> Reviewed-by: @hxy91819
…enclaw#69670) * fix(changelog): remove duplicate entry for PR openclaw#67800 * docs(changelog): move openclaw#67800 note from Unreleased into 2026.4.20
…penclaw#67800) Merged via squash. Prepared head SHA: 0ffde15 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com> Reviewed-by: @hxy91819
…enclaw#69670) * fix(changelog): remove duplicate entry for PR openclaw#67800 * docs(changelog): move openclaw#67800 note from Unreleased into 2026.4.20
…penclaw#67800) Merged via squash. Prepared head SHA: 0ffde15 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com> Reviewed-by: @hxy91819
…enclaw#69670) * fix(changelog): remove duplicate entry for PR openclaw#67800 * docs(changelog): move openclaw#67800 note from Unreleased into 2026.4.20
…penclaw#67800) Merged via squash. Prepared head SHA: 0ffde15 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com> Reviewed-by: @hxy91819
…enclaw#69670) * fix(changelog): remove duplicate entry for PR openclaw#67800 * docs(changelog): move openclaw#67800 note from Unreleased into 2026.4.20
…penclaw#67800) Merged via squash. Prepared head SHA: 0ffde15 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com> Reviewed-by: @hxy91819
…enclaw#69670) * fix(changelog): remove duplicate entry for PR openclaw#67800 * docs(changelog): move openclaw#67800 note from Unreleased into 2026.4.20
Summary
cacheRetention: "long"for customanthropic-messagesproviders when building Anthropic cache-control payloadsWhy
Custom Anthropic-compatible proxies can support 1-hour prompt-cache TTLs even when they do not use Anthropic or Vertex hostnames. OpenClaw was silently downgrading explicit
cacheRetention: "long"to the default 5-minute ephemeral cache for those providers.Closes #67164.
Root Cause
src/agents/anthropic-payload-policy.tsonly emittedttl: "1h"whencacheRetentionwaslongand thebaseUrlhostname matched a hardcoded Anthropic/Vertex allowlist. That made explicit long-retention opt-ins ineffective for customanthropic-messagesendpoints.Behavior Change
cacheRetention: "long"now emitscache_control: { type: "ephemeral", ttl: "1h" }even for custom hostsshortandnonebehavior are unchangedValidation
pnpm test src/agents/anthropic-payload-policy.test.ts