Repository navigation
fix(usage): include OpenCode cache writes in input accounting - #24587
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 306b457 and 93390bc408e25c15f7aaa9716da48fd25172e8dd. 📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughOpenCode input-token totals now include cache reads and writes. Cached-input totals include both cache buckets, while cache-write tokens remain separately available in usage data and token-session output. The daily chart displays input tokens minus cached input. Tests cover parsing, aggregation, and persistence across database generations. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue remains in the reviewed cache-token accounting change. Normal checks can proceed. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is limited to usage accounting and saved usage data. The inspected paths retain read-only database access, worktree attribution, and telemetry controls. No introduced security vulnerability was established, but compatibility and recovery coverage remain incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
93390bc to
5694747
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
No prior Pullfrog review existed on this PR, so this run covered the full 5694747 diff of the two head commits.
- Normalized OpenCode input accounting —
parseOpenCodeUsageRownow treatstokens.inputas uncached, folds both cache buckets intocachedInputTokens, and reportsinputTokens = uncached + cached, matching the Codex/Muse convention where cache hits live inside input. - Retained a distinct cache-write bucket for telemetry — the aggregation metric carries
cacheWriteInputTokensthrough session/location/model/daily rollups and merges, andcodexOpenCodeTokenSessionssplitscached_input_tokens(read only) fromcache_write_input_tokens. Codex entries lack the field, so Codex telemetry is unchanged. - Bumped the OpenCode usage schema to 7 — a version mismatch resets the persisted cache (preserving
scanState.enabled) and triggers the intentional one-time rescan, whiletotalTokensnow derives from the already-inclusive input without double-counting cache. - Fixed the shared daily chart's input segment —
Math.max(0, inputTokens - cachedInputTokens)prevents the cached bucket appearing twice in the stacked input segment for Codex, OpenCode, and Muse, all of which define input inclusive of cache hits.
I traced the accounting through row parsing, the metric fold, the two rollup-merge paths, both projection builders, and the telemetry reporter, and verified Codex/Muse input semantics separately. The focused suites (cache-write-accounting, scanner, opencode2-session-usage, cache-read-reproduction, agent-token-usage, usage-daily-chart) pass 47 tests across 6 files.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Updated to |
OpenCode stores uncached input, cache reads and cache writes separately. Include both cache buckets in total input, keep chart segments disjoint, and preserve separate cache-write telemetry through aggregation and cache reload. Invalidate older usage caches with schema 7. Port the remaining parser and chart corrections from #20187 by @griffinmartin onto the current v2 scanner, retaining its session-generation handling. Co-authored-by: griffinmartin <[email protected]>
365e810 to
8b59a52
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior Pullfrog review (5391388025, head 5694747), the branch was retargeted from fix/journal-import-test-sampler to main and now carries a single commit 8b59a52c that re-applies the OpenCode cache-input accounting fix. The ten PR files are byte-identical to the previously reviewed blobs (git diff 56947472ca 8b59a52 over those paths is empty), so the accounting behavior is unchanged from what was already verified.
- Re-applied the reviewed accounting fix on current
main— cache-input normalization, the schema-7 cache invalidation, per-bucket cache-write telemetry, and the disjoint chart input segment all carry over without source change. - No new behavioral surface in the delta — every remaining difference against
maincomes from mainline commits, not from this PR.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

ELI5
OpenCode's cached input now appears inside input totals, so the Stats page no longer shows more cached input than total input.
What Changed
Normalize uncached input plus cache reads and writes into Orca's input counters, count both cache buckets in cached input, and rebuild saved scans through schema version 7. Separate cache-write counters survive aggregation and persistence so telemetry continues to report distinct read and write buckets. Daily chart segments subtract cached input from the input segment so each token appears once. Current session/session_v2 merging and cache-write SQL remain intact.
Why
OpenCode stores uncached input separately. Fixing that conversion at the scanner boundary keeps every summary consistent and avoids rewriting the already-correct v2 queries. This narrowly ports the remaining changes from @griffinmartin's #20187; that author is credited in the commit.
Linked Issue
Continues #20187 (its original linked #20186 is outside this campaign's assigned issue list).
Visual Proof
Hidden CDP screenshots below show a private copy of a real OpenCode database scanned by Orca on macOS. Identifying fields are outside the screenshots. Before: input 34.1M / cache 340.2M. After: input 377.9M / cache 343.8M; total remains 380,503,601.
Testing
OpenCode v2.0.16 source and real installed CLI inspected; read-only database backup scanned through real Orca IPC before/after, then rendered in Settings → Stats & Usage → OpenCode → All local usage / All time. Rebuilt hidden app used the repository's disposable-home isolation helper and isolated ports/profile. No user configuration or shared OpenCode service changed.
66 focused tests pass (9 files), including v1/v2 merged rows, cache-write-only input, projections, and overview calculations.
pnpm tc, changed-code quality, touched-file oxlint, oxfmt, andgit diff --checkpass. Hidden electron-vite build and CLI build pass; full packaging/full suite are left to CI. Linux, Windows, WSL and SSH were considered but not exercised live.Review
A second real-database projection verified telemetry: input 34,096,719, cache reads 340,213,856, cache writes 3,590,638; the UI retains combined cache totals. The one-time scan rebuild is intentional. This changes accounting categories, not recorded cost or authoritative token totals. Read-only database access and execution-host ownership are preserved.
Agent skill upstream boundary
Notes
Current reviewed head
8b59a52c1b2420f8712da93b4a09b03ea5dd3013targets main after the journal-test dependency merged. Its ten usage postblobs and file modes exactly match the reviewed accounting fix; every other entry matches evaluated main84a4e8a9b0a1a0bd938528aa2dc6e49636917a47. This preserves intervening process/WSL/Git changes rather than replaying an old branch wholesale. The original @griffinmartin credit remains in the source commit.Nine fresh private SQLite fixture controls pass through usage queries, aggregation, cache reload, schema5/6 invalidation and separate telemetry. Process/WSL integration checks also pass:40 default text-capture cases and8 path cases; usage worker/discovery/WSL transport sources remain unchanged. These are focused controls; the actual installed OpenCode and hidden-renderer proof above remains the earlier genuine database experiment. Full-head CI runs after this update.
Replacement for #20187 after this PR merges. Recorded costs and authoritative token totals are unchanged; cached input categories become consistent across views.
Checklist