fix(opencodego): include recorded local token counts - #4000
Conversation
Preserve recorded tokens in local daily and model history, prefer step-finish parts, and leave incomplete or invalid totals unknown. Reuse shared daily aggregation and remove duplicate local query and quota wrappers without changing recorded costs. Closes #3995 Co-authored-by: Yuxin Qiao <104957188+Yuxin-Qiao@users.noreply.github.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 maintainer review before merge. Reviewed September 25, 2026, 1:59 PM ET / 17:59 UTC. ClawSweeper reviewWhat this changesThe branch reads recorded OpenCode Go message and step-finish token counts into daily and per-model spend history, with focused tests and documentation. Merge readiness✅ Ready for maintainer review Keep open. Current main and the latest release still omit local OpenCode Go token totals, and this owner-authored PR addresses that gap. The read-only review found no confirmed defect introduced by this branch. Priority: P2 Review scores
Verification
How this fits togetherCodexBar reads OpenCode Go's local SQLite database to build usage history. The Spend dashboard combines that history with other providers to display token activity and coverage. flowchart LR
A[OpenCode local database] --> B[Assistant messages and step records]
B --> C[Local usage reader]
C --> D[Daily token and cost history]
D --> E[Spend dashboard]
E --> F[Token activity heatmap]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Use one local-reader implementation that preserves incomplete counts as unknown, keeps recorded costs separate from tokens, and resolves the overlapping contribution at #3995. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main emits nil token totals for cost-bearing OpenCode Go rows, and the PR reports failing-before, passing-after SQLite fixtures. This read-only review did not run those fixtures. Is this the best way to solve the issue? Yes. Extending the existing local reader and using the shared daily merger is a narrow fit for the missing history, while preserving recorded costs and unknown totals. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d8c2af958176. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Local OpenCode Go history retained costs and requests but dropped the token counts already recorded in
opencode.db. Adapt @Yuxin-Qiao's #3995 to include daily and per-model token history, preferring step-finish parts over their parent message. Explicit totals remain authoritative; older rows sum complete components. Missing, malformed, negative, and overflowing totals stay unknown, and token counts never produce dollar costs or change quota calculations.Reuse the shared daily report merger and remove duplicate SQLite query and quota aggregation wrappers: production changes are 93 insertions / 103 deletions (net -10). Documentation and the 0.67.0 Unreleased changelog describe the behavior and credit @Yuxin-Qiao.
Validation:
Fixtures cover both message-only and message/part schemas, part precedence, component and explicit totals, missing/malformed data, zero values, and sticky overflow. Token semantics were checked against OpenCode's stored schema and usage normalization. Independent autoreview found no actionable P0–P2 issues. A read-only installed signed CLI probe returned an OpenCode Go provider error, so live reproduction was inconclusive; synthetic SQLite fixtures establish the red-to-green proof.
Closes #3995