Skip to content

fix(session): warn on cache busts - #40796

Open
zcxGGmu wants to merge 1 commit into
anomalyco:devfrom
zcxGGmu:cache-bust-warning
Open

fix(session): warn on cache busts#40796
zcxGGmu wants to merge 1 commit into
anomalyco:devfrom
zcxGGmu:cache-bust-warning

Conversation

@zcxGGmu

@zcxGGmuzcxGGmu commented Aug 6, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#40790

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a small diagnostic for likely Anthropic prompt-cache busts. When a completed step reports a large cache write with zero cache reads for an Anthropic/Claude model, the session processor now emits a warning with the session, model, finish reason, cache-write tokens, cache-read tokens, and cost.

This does not revive the previously rejected object-identity caching approach from #36852. It only makes the high-cost pattern reported in #40790 visible in logs so users and maintainers can confirm when it happens.

How did you verify your code works?

  • RED: bun test test/session/compaction.test.ts --test-name-pattern "flags likely Anthropic cache busts|does not flag ordinary cache hits" --timeout 30000 failed because SessionNs.cacheBustWarning did not exist.
  • GREEN: bun test test/session/compaction.test.ts --test-name-pattern "SessionNs.getUsage" --timeout 45000 — 17 pass.
  • bun run typecheck
  • bun run lint packages/opencode/src/session/session.ts packages/opencode/src/session/processor.ts packages/opencode/test/session/compaction.test.ts
  • git diff --check

Notes: two broader session tests fail the same way on a clean dev baseline in this Windows checkout:

  • stops quickly when aborted during retry backoff
  • retry OpenAI-compatible midstream server errors

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Sign up for freeto 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.

Production evidence: Anthropic cache bust bug causes $14.82 waste across 3 sessions (22.5% bust rate)

2 participants

@zcxGGmu@MaskerFather