Fix OpenCode router calls with missing usage#342
Open
ozymandiashh wants to merge 1 commit into
Open
Conversation
This was referenced May 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #341 for OpenCode users whose router/provider writes assistant activity but does not persist token or cost usage metadata.
The reporter uses OpenCode through EdenAI as a router. In that kind of setup, OpenCode can still store the assistant response and tool activity in the
parttable while the assistant message usage fields remain all zero. CodeBurn treated those rows as empty placeholders and skipped them, which could make OpenCode look like it had no usage at all.Root Cause
The OpenCode parser reads two tables:
message: assistant/user metadata, includingrole,modelID,tokens, andcostpart: message content and tool callsBefore this PR, CodeBurn skipped every assistant message where all token fields and cost were zero:
That is safe for truly empty assistant placeholders, but too aggressive for router-backed sessions. A router can produce a real assistant turn like this:
while still having real activity in
part:or:
Previously both examples were dropped because usage was zero. That is why the provider could report no OpenCode usage even though OpenCode had real assistant turns.
What Changed
The skip condition now distinguishes empty placeholders from zero-usage real activity:
partcontains non-empty text.partcontains a valid tool call.The kept calls intentionally remain zero-token and zero-cost. This avoids inventing token totals or spend that OpenCode did not record, while still allowing CodeBurn to show the session/call/tool activity.
Before / After
Before:
message.data.tokensandmessage.data.costare all zero.After:
message.data.tokensandmessage.data.costare all zero.partrow contains tools.Tests Added
Added focused OpenCode SQLite fixtures for:
Validation
npx vitest run tests/providers/opencode.test.ts tests/provider-registry.test.ts- 49/49 tests passed.npx tsc --noEmit --pretty false- passed.npm run build- passed.git diff --check- passed.check,assess,semgrep- passed.Safety / Scope
This PR does not change OpenCode database discovery paths and does not add a new schema parser. It only relaxes the existing skip logic when the already-read
partrows prove the assistant turn had real activity.I did not validate against the reporter's local OpenCode database. The coverage uses synthetic SQLite fixtures matching the reported failure mode, so no local project names, prompts, paths, session IDs, usage values, or private product details are included.