Read OpenCode Go local token counts - #3995
Yuxin-Qiao wants to merge 1 commit into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. Reviewed September 25, 2026, 12:53 PM ET / 16:53 UTC. ClawSweeper reviewWhat this changesThe branch reads OpenCode Go token counts from local SQLite messages and step-finish records, adds them to daily and per-model spend history, and adds reader and heatmap tests. Merge readiness⛔ Needs changes before merge - 2 items remain This PR addresses a real gap in OpenCode Go token history and includes a redacted run against a local database. One parsing edge still needs repair: an empty token object is reported as a measured zero, which can make incomplete history appear complete. Priority: P2 Review scores
Verification
How this fits togetherCodexBar reads OpenCode Go's local database to build daily usage snapshots. The Spend dashboard combines those snapshots with other providers to display token activity and coverage. flowchart LR
A[OpenCode local database] --> B[Message and step records]
B --> C[Token reader]
C --> D[Daily usage snapshot]
D --> E[Spend dashboard]
E --> F[Token activity heatmap]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Require an explicit numeric total or at least one valid numeric token component before marking a row resolved, and cover empty and malformed token objects with focused reader tests. Do we have a high-confidence way to reproduce the issue? Yes, from source: a cost-bearing row with tokens: {} passes the object check and becomes a zero-token day. The focused test fixture has not been run in this read-only review. Is this the best way to solve the issue? Yes, reading the existing local token fields is a narrow fit for the reported heatmap gap, provided unreadable token objects remain unknown. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against df5a637ac02e. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Thanks @Yuxin-Qiao. Landed on main via #4000 and ships in the next release, with your changelog credit. The reader now keeps recorded token totals and components from the local OpenCode Go database, prefers step-finish parts, honors explicit totals, and sums older records only when all five components exist; missing, malformed, or overflowing totals stay unknown, and recorded costs and quota behavior are unchanged. Your two token-reading regressions fail on the old reader and pass after the change, and sharing the aggregation trimmed 10 production lines. |
Read the token objects OpenCode Go records locally (step-finish parts preferred, explicit totals honored, older records summed only when all five components exist) so local token history appears in Usage & Spend without inventing costs; malformed or overflowing totals stay unknown. Shares the aggregation with the existing reader and drops its duplicate queries. Adopts steipete#3995. Closes steipete#3995 Co-authored-by: Yuxin Qiao <yuxin.qiao@example.invalid>
Summary
The Spend dashboard's Token activity heatmap showed "Unavailable · Coverage 0 / 365" whenever OpenCode Go was an enabled source.
OpenCodeGoLocalUsageReaderonly selectedcostfromopencode.dband emitted every daily entry withtotalTokens: nil, while the snapshot still declared established history coverage. The heatmap intentionally treats a scanned-but-unresolved source day as unknown, so OpenCode Go poisoned every day in its window, including days where other sources (Codex, Cursor, Antigravity) had complete token data.OpenCode already persists per-message and per-
step-finishtoken counts (tokens.input/output/reasoning/cache.read/cache.write/total), so this reads them:tokensobject alongsidecostin both the message-only and message+part queries;step-finishpart tokens replace message tokens exactly like cost doestotalfrom the components for older rows that omit itWith every day resolved,
last30DaysTokensmatches the daily sum, the dashboard treats OpenCode Go history as complete, and days without OpenCode Go usage count as zero instead of unknown.Tests
OpenCodeGoLocalUsageReaderTests: per-day/per-model token totals (including rows withouttotal),step-finishtokens replacing message tokens, and a tokenless row keeping the day unknownSpendActivityHeatmapTestsregression: an OpenCode Go snapshot alongside another source keeps shared activity days coveredswift build --product CodexBarCLIswiftformat --linton changed filesI could not run
swift test/make checklocally (Command Line Tools only, no Xcode foractool/sourcekitd), so opening as draft to let CI run the suite.Proof
Ran the new reader through a scratch executable against a synthetic fixture and, read-only, against a real local
opencode.db(model names omitted):Before this change every entry reported
total=nil. No live provider probes or Keychain reads were run.