Avoid false `WarnOnCacheBusts` warnings after native tool calls

Merged
AW
2mo ago
+230-8

This pull request was posted by Codex Desktop using gpt-6-luna on behalf of David.

  • Closes #9745
  • Related: #6534. After this fix merges, #6534 must carry this guard and its regression coverage into the replacement shared detector.

Why

A provider can sum cache reads across multiple internal calls in one response. WarnOnCacheBusts treated that sum as one prefix, so the healthy request that followed could warn as a collapse. This addresses #9745.

New public surface

None.

User-visible behavior

Before: an established 8,000-token prefix followed by a response reporting 20,000 cached tokens across a main-model call and compaction raised the mark to 20,000; the next healthy 8,000-token read warned.

After: the aggregated response leaves the 8,000-token mark unchanged, so the next healthy read does not warn. A low aggregate can still prove a collapse, but cannot clear the collapse latch. When the provider reports one call to the main model and no compaction, normal cache accounting is preserved. Gemini responses with separate tool-use prompt accounting also use normal accounting; a healthy read confirms recovery. Advisor usage remains excluded from cache totals.

Verification

The warning regression tests, including Anthropic compaction and harness documentation snippet checks passed locally. CI and coverage passed on this head, and the current-head fork review approved it.

Existing users

No public API or usage-accounting fields change; aggregated native-tool usage no longer inflates the cached-prefix mark or falsely signals recovery.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.