Skip to content

Count OpenCode v2 usage - #16

Merged
btsouth merged 2 commits into
mainfrom
fix/opencode-v2-usage
Oct 6, 2026
Merged

btsouth merged 2 commits into
mainfrom
fix/opencode-v2-usage

Conversation

@btsouth

@btsouth btsouth commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

OpenCode 2.x writes messages to session_message and session_v2 instead of message and session, so Agent Pulse stopped counting OpenCode and OpenCode Go usage after the upgrade.

The OpenCode scan now reads whichever tables exist. v2 rows go through the same opencode_record path, so routing and pricing match v1. OpenCode v2 copied v1 messages into the new table with their original ids, so a message in both tables still counts once.

Releases 1.10.5.

Checks:

  • python3 -m unittest discover -s tests: 237 tests OK, including four new OpenCode v2 cases (v2-only database, an id present in both tables, the Go route, and an in-place update under WAL)
  • Read-only check against a real OpenCode database: all 9,262 messages present in both tables have the same route and token counts, and 50 messages exist only in v2

Summary by CodeRabbit

  • Bug Fixes

    • OpenCode usage tracking now includes assistant-message tokens from both v1 and v2 history.
    • Messages carried over between versions are counted once, preventing duplicate usage totals.
    • Usage updates are reflected during scans, including when OpenCode data changes while the app is running.
  • Release

    • Updated the release version to 1.10.5.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d07c0cc4-0df5-425b-b27e-28f9ec11d326
📥 Commits

Reviewing files that changed from the base of the PR and between b538b2d and fc8e89f.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • README.md
  • VERSION
  • collector.py
  • docs/installation.md
  • plugin/manifest.json
  • tests/test_collector.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The collector now reads OpenCode v1 and v2 message tables. Tests cover v2 token counting and duplicate message IDs. Release references change from version 1.10.4 to 1.10.5.

Changes

OpenCode usage collection

Layer / File(s) Summary
Read and count v1 and v2 messages
collector.py, tests/test_collector.py, VERSION, plugin/manifest.json, README.md, docs/installation.md, CHANGELOG.md
The collector reads available v1 and v2 message tables and sends converted records through the existing ledger upsert. Tests cover v2 token counts, shared message IDs, provider routing, and WAL updates. Release references change to version 1.10.5.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant OpenCodeDB
  participant Collector
  participant Ledger
  OpenCodeDB->>Collector: Return rows from available v1 and v2 message tables
  Collector->>Ledger: Upsert converted records by message ID
Loading

Suggested reviewers: hilather

Merge Risk: ⚪ Minimal · up to fc8e8

No identified issue remains that needs correction before merge; normal checks still apply.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (5 skipped: 5 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: counting OpenCode v2 usage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (5 skipped: 5 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@btsouth
btsouth merged commit 75acdd6 into main Oct 6, 2026
5 checks passed
@btsouth
btsouth deleted the fix/opencode-v2-usage branch October 6, 2026 16:23
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