Skip to content

fix(usage): show opencode tokens and models on usage page - #1

Open
Mina-Sayed wants to merge 12 commits into
mainfrom
fix/usage-opencode-support
Open

fix(usage): show opencode tokens and models on usage page#1
Mina-Sayed wants to merge 12 commits into
mainfrom
fix/usage-opencode-support

Conversation

@Mina-Sayed

Copy link
Copy Markdown
Owner

The Usage page only scanned claude/codex/grok transcripts, so opencode sessions showed zero tokens and no model breakdown even though the SDK exposes tokens/cost on every assistant message. The live adapter also never emitted thread.token-usage.updated, so the context window bar stayed empty.

How I fixed it:

  • Add opencode to UsageProviderKind and bump USAGE_CONTRACT_VERSION to 6 (compatible since 4)
  • Add OpenCode presentation for web and mobile (PROVIDER_PRESENTATION, PROVIDER_ORDER, colors)
  • Emit live token usage from OpenCode adapter (message.updated, step-finish parts, session.updated, generic step events) and include usage in turn.completed
  • Scan opencode's SQLite DB (~/.local/share/opencode/opencode.db) for historical buckets with (size,mtime) caching and dedup via message id
  • Update docs, scan cache guard, and chart tests

Verification:

  • Read real opencode.db (4085 messages) and aggregated 7 daily buckets for last 7 days
  • vp test run for usage, OpenCodeAdapter, and chart suites: 107 passed
  • tsgo --noEmit clean
  • Manual check via npx vp run dev on Usage page now shows OpenCode

Model: muse-spark-1.2-contributor-free
Harness: opencode

Usage page only scanned claude/codex/grok transcripts, so opencode sessions showed zero tokens and no model breakdown even though the SDK exposes tokens/cost on every assistant message. The live adapter also never emitted thread.token-usage.updated, so the context window bar stayed empty.

- Add opencode to UsageProviderKind and bump USAGE_CONTRACT_VERSION to 6 (compatible since 4)
- Add OpenCode presentation for web and mobile
- Emit live token usage from OpenCode adapter (message.updated, step-finish parts, session.updated, generic step events) and include usage in turn.completed
- Scan opencode's SQLite DB (~/.local/share/opencode/opencode.db) for historical buckets with caching and dedup
- Update docs, scan cache guard, and chart tests

Verified with real opencode.db (4085 messages) and vp test run for usage, OpenCodeAdapter, and chart suites.

Model: muse-spark-1.2-contributor-free
Harness: opencode
@devloai

devloai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: ce36b0c0-27dd-4e56-bc6e-0b8d125908af


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.

Mina-Sayed and others added 11 commits August 31, 2026 20:43
- Fix cache double subtraction: opencode input is exclusive of cache, so uncached should be input directly (not input - cache)
- Fix session.updated overwriting: session tokens are cumulative, do not emit as thread.token-usage or store for turn.completed
- Fix WAL cache staleness: stat now includes opencode.db-wal size/mtime, busting cache on WAL writes
- Add V2 session_message table scan alongside legacy message table
- Fix null vs empty: preserve readOpenCodeDbRecords null failure, reporting source as failed instead of ok
- Thread HostProcessEnvironment into resolveOpenCodeDbPath instead of module-global process.env
- Use Path service (path.join/dirname) instead of node:path import, removing suppression comment
- Fix as never cast on turn.completed payload, spreading only defined keys with proper typing
- Fix V2 session_message parsing: handle role in type column, nested model.id/providerID, and column times
- Fix blocking DB read: use iterate() with setImmediate yields every 100 rows instead of all()
- Fix diagnostic suppression comment to include rationale
- Add focused tests for parseOpenCodeMessage covering all easy-to-regress behaviors

Addresses Macroscope high blocking and Cursor V2 findings
…support

# Conflicts:
#	apps/server/src/provider/Layers/OpenCodeAdapter.ts
…#9292)

Co-authored-by: Julius Marminge <julius@mac.lan>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants