Skip to content

fix(ai): default Anthropic cache retention to 5m - #820

Merged
code-yeongyu merged 3 commits into
mainfrom
code-yeongyu/fix-anthropic-default-cache-5m
Aug 11, 2026
Merged

fix(ai): default Anthropic cache retention to 5m#820
code-yeongyu merged 3 commits into
mainfrom
code-yeongyu/fix-anthropic-default-cache-5m

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • use Anthropic's provider-default 5-minute prompt-cache retention when direct Anthropic requests omit a retention setting
  • preserve explicit one-hour retention through cacheRetention: "long", model configuration, or PI_CACHE_RETENTION=long
  • keep the browser-safe TTL resolver, provider docs, fork change records, and AI/coding-agent changelogs aligned

Why

Direct Anthropic requests currently opt into ttl: "1h" by default even though Anthropic's own default is five minutes. One-hour cache writes cost more and should be an explicit choice rather than Senpi's implicit default.

RED -> GREEN

  • RED payload proof: default canonical Anthropic request expected bare { type: "ephemeral" } but received { type: "ephemeral", ttl: "1h" }
  • RED runtime proof: resolvePromptCacheTtlSeconds() expected 300 but received 3600
  • GREEN focused suite: 3 files passed, 58 tests passed, 4 credential-gated tests skipped

Verification

  • TypeScript LSP: 0 errors, 0 warnings on both changed source files and both changed tests
  • npm run build --workspace packages/ai
  • npm run test --workspace packages/ai - 196 files passed, 1,872 tests passed
  • npm run check
  • node scripts/check-pr-changelog.mjs --base origin/main --labels ""
  • Senpi Anthropic mock-loop self-test - 22/22 passed, localhost-only, real auth unchanged
  • real Senpi CLI capture - five cache-control markers, all bare ephemeral objects with no ttl
  • built SDK driver - default: 300 seconds/no ttl; explicit long: 3600 seconds/ttl: "1h"

Evidence

Local QA receipts are retained under:

local-ignore/qa-evidence/20260811-anthropic-default-5m/

The real CLI request capture is under:

local-ignore/qa-evidence/20260812-anthropic-cache-default/

Cleanup

  • no mock-loop/fake-model/driver process remains
  • no mock-loop temporary sandbox remains
  • no QA listener remains

Summary by cubic

Defaulted direct Anthropic prompt caching to 5 minutes to match Anthropic’s default and lower costs; 1-hour retention is now opt-in. coding-agent keepalive now reports a 300s TTL by default.

  • Bug Fixes

    • Direct Anthropic requests omit ttl by default, sending { type: "ephemeral" } instead of ttl: "1h".
    • resolvePromptCacheTtlSeconds() now returns 300s for Anthropic’s default; precedence stays provider-specific.
    • coding-agent keepalive and tests now expect 300s; docs and changelogs in packages/ai and packages/coding-agent updated.
  • Migration

    • To keep 1-hour retention, set PI_CACHE_RETENTION=long, cacheRetention: "long", or configure it on the model.

Written for commit cc10b74. Summary will update on new commits.

Review in cubic

@code-yeongyu
code-yeongyu merged commit b05cb83 into main Aug 11, 2026
16 checks passed
@code-yeongyu
code-yeongyu deleted the code-yeongyu/fix-anthropic-default-cache-5m branch August 11, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant