Skip to content

fix(opencodego): include recorded local token counts - #4000

Merged
steipete merged 1 commit into
mainfrom
triage/20260921-new-prs-l
Sep 25, 2026
Merged

steipete merged 1 commit into
mainfrom
triage/20260921-new-prs-l

Conversation

@steipete

Copy link
Copy Markdown
Owner

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:

# Before production changes: 48 tests, 2 failing token-reading tests, 12 failed assertions.
CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --jobs 4 --filter 'OpenCodeGoLocalUsageReaderTests|SpendActivityHeatmapTests'

# Final: 269 + 53 + 3 tests passed; 325 total, no failures.
CODEXBAR_TEST_CODEX_FILE_ISOLATION=1 CODEXBAR_TEST_SESSION_FILE_ISOLATION=1 CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --jobs 4 --filter 'OpenCodeGo|SpendActivityHeatmapTests|SparkleUpdaterControllerTests|InstallOriginTests|ProviderPluginRuntimeTests|ProviderPluginParityTests|ProviderArchitectureGatekeeperTests|CostUsageDailyReportMergeTests'

# Final: 21 tests passed, including corrected local-day fixtures.
TZ=Pacific/Fiji CODEXBAR_TEST_CODEX_FILE_ISOLATION=1 CODEXBAR_TEST_SESSION_FILE_ISOLATION=1 CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --skip-build --filter OpenCodeGoLocalUsageReaderTests

# Passed; zero lint violations across 2659 files.
make check

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

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>
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 1:59 PM ET / 17:59 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 0bbed3b23c7a34b3ed383956ad3ae254d447a83c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, reduces production code, and covers the important token-validity boundaries; owner-authored proof is exempt.
Proof confidence 🌊 off-meta tidepool Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its changed local reader is exercised by reported synthetic SQLite before-and-after tests through the fetch entrypoint, but the signed CLI probe returned a provider error, so this head has no demonstrated real-database or live-app result. The diff changes queries and existing report fields, not a stored-data contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its changed local reader is exercised by reported synthetic SQLite before-and-after tests through the fetch entrypoint, but the signed CLI probe returned a provider error, so this head has no demonstrated real-database or live-app result. The diff changes queries and existing report fields, not a stored-data contract.
Evidence reviewed 8 items Current main behavior: The base reader selects cost history and emits daily entries with totalTokens set to nil; current main does not solve the reported heatmap gap.
Introduced reader behavior: The PR's read-only SQL selects token objects from assistant messages and step-finish parts, with cost-bearing parts taking precedence over their parent message.
Unknown-count handling: Explicit totals take precedence; absent totals require all five components, while negative, malformed, or overflowing values leave the row's token total unknown.
Findings None None.
Security None None.

How this fits together

CodexBar 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]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +93/−103, tests +249/−7 The focused regression coverage accompanies a net reduction in production lines.

Technical review

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

Labels

Label changes:

  • add P2: This repairs inaccurate token-history coverage for one provider without changing account quota or stored data.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its changed local reader is exercised by reported synthetic SQLite before-and-after tests through the fetch entrypoint, but the signed CLI probe returned a provider error, so this head has no demonstrated real-database or live-app result. The diff changes queries and existing report fields, not a stored-data contract.

Label justifications:

  • P2: This repairs inaccurate token-history coverage for one provider without changing account quota or stored data.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The owner-authored PR is exempt from the contributor proof gate. Its changed local reader is exercised by reported synthetic SQLite before-and-after tests through the fetch entrypoint, but the signed CLI probe returned a provider error, so this head has no demonstrated real-database or live-app result. The diff changes queries and existing report fields, not a stored-data contract.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • kentoku24: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Sopen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit a2cf7fa into main Sep 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant