fix(web): Compact chip follows Claude's real prompt cache TTL #17945
main fromrefs/pull/17945/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubThe Compact chip used a fixed 70 minute idle timer. That is right for 1h cache writes on a Claude subscription. But Claude Code writes 5 minute cache entries with an API key, Bedrock, or Vertex, and after a subscription goes over its limits. For those users the cache is cold long before the chip shows. A user also reported that the chip showed after only about 10 minutes, which was confusing.
Changes:
- The Claude adapter now reads
usage.cache_creationon each main-agent response and reports the TTL it wrote (1h or 5m) as an optionalpromptCacheTtlMson the turn's token usage. - The chip shows when that TTL has passed. When no TTL is known (old turns, or a response with no cache writes), it uses the old 70 minute rule.
- The web now picks the newest token usage by its timestamp. Before, it took the last turn in the array, and snapshots sort turns by provider thread id. So a thread with more than one provider thread (for example after a Codex to Claude handoff) could read an old turn's usage after a reload. That gave an old timestamp and a wrong token count to both the chip and the context meter. This is a likely cause of the early chip report, but I did not reproduce it.
- The Claude user doc now says the chip follows the cache, not "more than an hour".
Data check: in my local Claude transcripts, 99.8% of cache-write tokens are 1h, so subscription users see the chip at 60 minutes, not 70.
🤖 Generated with Claude Code using Claude Opus 5.5
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
5f98d60Macroscope's review found this PR approvable — This is a focused correction that reports Claude's actual cache lifetime and uses it to time the existing Compact chip, with a backward-compatible optional field and targeted tests. The fallback behavior remains intact, and the change introduces no new workflow, infrastructure, or sensitive-data surface.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
5f7294d· PR result:5f98d60· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
c06d917d-f32c-48bf-9a90-e9a68560a83e
📥 Commits
-
Reviewing files that changed from the base of the PR and between 5f7294d452a5c6d6e0b7bd2c992478f830fbe212 and 5f98d60c188ca3f6e4794570f83ce2d7b46fd91c.
📒 Files selected for processing (9)
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsapps/web/src/components/ChatView.tsxapps/web/src/components/chat/ContextWindowMeter.logic.test.tsapps/web/src/components/chat/ContextWindowMeter.logic.tsapps/web/src/lib/contextWindow.test.tsapps/web/src/lib/contextWindow.tsdocs/user/providers-claude.mdpackages/contracts/src/orchestrationV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
Walkthrough#
Claude token usage now reports prompt-cache lifetime. The web client selects the newest provider-turn usage report and uses its lifetime to determine when to offer resume compaction. Claude provider documentation describes cache lifetimes by authentication source.
Changes#
Prompt-cache lifetime and compaction
Layer / File(s) Summary Report Claude prompt-cache lifetime
packages/contracts/src/orchestrationV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsThe token-usage contract adds an optional prompt-cache lifetime. The Claude adapter reports 60 minutes when one-hour cache tokens are present, or 5 minutes when only five-minute cache tokens are present. Tests cover both values and the unset case. Apply cache lifetime to compaction
apps/web/src/lib/contextWindow.ts,apps/web/src/lib/contextWindow.test.ts,apps/web/src/components/ChatView.tsx,apps/web/src/components/chat/ContextWindowMeter.logic.ts,apps/web/src/components/chat/ContextWindowMeter.logic.test.ts,docs/user/providers-claude.mdThe web client selects provider-turn usage by newest updatedAtand supplies its prompt-cache lifetime to compaction timing. The timing uses the reported lifetime or a 70-minute fallback. Tests cover selection and the five-minute threshold. Documentation describes cache lifetimes by authentication source.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant ClaudeAdapterV2 participant ProviderTurn participant ChatView participant shouldOfferResumeCompaction ClaudeAdapterV2->>ProviderTurn: Adds promptCacheTtlMs to token usage ChatView->>ChatView: Selects usage with the newest updatedAt ChatView->>shouldOfferResumeCompaction: Supplies promptCacheTtlMs shouldOfferResumeCompaction->>shouldOfferResumeCompaction: Compares elapsed time with reported TTL or fallbackSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
5f98dNo merge-blocking issue was identified; the Compact chip measures the reported cache lifetime from the matching usage timestamp.
Pre-merge checks |
3 | 1-
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Description check The description clearly explains the problem and implementation, but it does not provide the required scope and approval information or focused verification results. It also omits the required before/… Add the triaged issue or explicit maintainer approval, or explain why this focused bug fix qualifies without one. Document the focused tests or manual checks with observed results, including anything not checked. Add before/after screenshot… ✅ Passed checks (3 passed)
-
Check name Status Explanation Title check The title is concise, specific, and accurately describes the main change: making the Compact chip follow Claude's prompt-cache TTL. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Description check
-
Explanation
The description clearly explains the problem and implementation, but it does not provide the required scope and approval information or focused verification results. It also omits the required before/after UI evidence for this UI change.
Resolution
Add the triaged issue or explicit maintainer approval, or explain why this focused bug fix qualifies without one. Document the focused tests or manual checks with observed results, including anything not checked. Add before/after screenshots and a short recording if timing or interaction behavior requires it.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.-
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes