Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): Compact chip follows Claude's real prompt cache TTL #17945

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/17945/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

The 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_creation on each main-agent response and reports the TTL it wrote (1h or 5m) as an optional promptCacheTtlMs on 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

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Approved at 5f98d60

      Macroscope'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).
    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 5f7294d · PR result: 5f98d60 · Source CI: success

      Scenario 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.

    5. Review in Change Stack →

      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.ts
      • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
      • apps/web/src/components/ChatView.tsx
      • apps/web/src/components/chat/ContextWindowMeter.logic.test.ts
      • apps/web/src/components/chat/ContextWindowMeter.logic.ts
      • apps/web/src/lib/contextWindow.test.ts
      • apps/web/src/lib/contextWindow.ts
      • docs/user/providers-claude.md
      • packages/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.ts
      The 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.md
      The web client selects provider-turn usage by newest updatedAt and 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 fallback

      Suggested reviewers: juliusmarminge


      Merge Risk: ⚪ Minimal · up to 5f98d

      No merge-blocking issue was identified; the Compact chip measures the reported cache lifetime from the matching usage timestamp.

      Pre-merge checks | Passed 3 | Failed 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Description checkWarningThe 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 nameStatusExplanation
      Title checkPassedThe title is concise, specific, and accurately describes the main change: making the Compact chip follow Claude's prompt-cache TTL.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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.

Sign in to join this conversation.