Skip to content

fix: 1h TTL cache write pricing and dynamic savings/overhead wording#445

Merged
BYK merged 1 commit into
mainfrom
fix-1h-ttl-pricing
May 21, 2026
Merged

fix: 1h TTL cache write pricing and dynamic savings/overhead wording#445
BYK merged 1 commit into
mainfrom
fix-1h-ttl-pricing

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 21, 2026

Problem

Anthropic charges 2x base input price for 1h TTL cache writes ($10/MTok for Opus vs $6.25 for 5m TTL). Three code paths in the cost tracker used the 5m rate regardless of TTL, causing:

  1. computeCallCost() — conversation turn costs underreported by ~6% for 1h sessions
  2. estimateCompactionCost() — avoided compaction savings undercounted (e.g. $10.29 → $13.44 for 28 compactions)
  3. setCachePricing() — gradient's bust-vs-continue gate used wrong write cost

Additionally, several UI locations displayed "savings" language even when the net value was negative, which was confusing.

Fix

1h TTL Pricing (cost-tracker.ts, pipeline.ts, sentry.ts)

  • Added ttl?: "5m" | "1h" param to computeCallCost(), recordConversationCost(), updateShadowContext(), estimateCompactionCost(), and emitCostMetric()
  • When ttl === "1h", applies 2x multiplier to cache_write rate
  • Pipeline call sites pass sessionState.resolvedConversationTTL
  • setCachePricing() now uses the 1h-adjusted rate for bust-vs-continue decisions

Dynamic Wording (ui.ts)

5 locations now switch between "savings" and "overhead" based on sign:

Location Before (negative) After (negative)
Table column header Savings Net (neutral)
Dashboard stat card (hidden) Net Overhead (red)
Live bar right side N% saved N% overhead
Live breakdown Net savings: -$X Net overhead: $X
Historical row Net estimated savings Net estimated overhead

- computeCallCost(), estimateCompactionCost(), updateShadowContext() now
  accept TTL param; 1h sessions apply 2x cache_write multiplier
- setCachePricing() in gradient uses 1h-adjusted rate for bust-vs-continue
- Sentry cost metric accounts for 1h TTL
- Dashboard wording switches between 'savings' and 'overhead' based on sign
  (table header, stat card, live bar, breakdown, historical row)
@BYK BYK merged commit 2c31e71 into main May 21, 2026
9 of 10 checks passed
@BYK BYK deleted the fix-1h-ttl-pricing branch May 21, 2026 10:15
@craft-deployer craft-deployer Bot mentioned this pull request May 21, 2026
6 tasks
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