Repository navigation
fix(#1115): opencode driver reports modelUsage from step_finish tokens - #1204
Merged
Merged
Conversation
…s; conformance item 5 asserts it
Entire-Checkpoint: 55b1140a5949
5 tasks
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
Part of #1115. opencode runs now report token usage: the driver sums each
step_finishevent'spart.tokensintomodelUsage, sosequant statsand the #986 token metrics stop counting opencode runs as 0.AC-2 (aider usage) and AC-3 (typed opencode quota errors) are not in this PR. Both need output captured from a real run, and neither exists yet. The issue stays open after this PR merges.
Mapping (grounded in the real fixtures)
input→inputTokens,cache.read→cacheReadInputTokens,cache.write→cacheCreationInputTokens. Cache is separate from input on both sides: the claude-code recordsdk-result-modelusage-986.jsonhasinputTokens: 326besidecacheReadInputTokens: 2000172.outputTokens = output + reasoning. On all 29 steps ofopencode-run-qa.ndjson,total == input + output + reasoning + cache.read + cache.write, so opencode'soutputleaves reasoning out. The SDK counts thinking as output.costUSD= the summed per-stepcost. The key is the pinnedsettings.model, oropencode-defaultwhen no model is pinned (codex usescodex-defaultthe same way).modelUsageis also set on failed runs, as claude-code does since fix(metrics): tokensUsed is 0 on every recorded run — capture-tokens.sh reads .usage (transcripts carry .message.usage) and run reads the wrong dir; wire SDK modelUsage tokens+costUSD per phase × model into metrics and stats #986.Acceptance criteria
OpencodeDriver.executePhasereturnsmodelUsagewith non-zero input/output tokens for a completed run. Verified withnpx vitest run src/lib/workflow/drivers/opencode.test.ts(49 passed, 7 new cases; the exact totals come from the real fixture).aider.tscaptures stdout, but the repo holds no real aider output, and aider is not installed here. Needed: verbatim stdout and stderr from a real run with the driver's exact args (--yes --no-auto-commits --no-pretty --message …), added as a fixture with aPROVENANCE.mdline.evaluateOpencodeRun'sparsed.errorsbranch, following codex'sUSAGE_LIMIT_RE/THROTTLE_RE. Needed: realopencode run --format jsonstdout and stderr from one usage-limit run and one throttled run.gap: #1115skip in the conformance suite is gone and the item now asserts against the real fixture. The item-3 opencode skips and all aider skips stay, because they depend on AC-2 and AC-3. Verified withnpx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts(34 passed).npm run build && npm test: see this PR's CItestjob. Locally,npx vitest run src/lib/workflow/driverspassed (282 passed, 3 skipped) andnpm run buildexited 0.Mutation records
Mutation-verified: AC-1 — outputTokens set to t.output (reasoning dropped) in toOpencodeModelUsage; src/lib/workflow/drivers/opencode.test.ts > 1115 AC-1 — modelUsage from step_finish tokens > 1115 AC-1 maps onto the SDK modelUsage shape, reasoning folded into output failed; restored.
I re-ran this mutation independently of the implementing agent: exactly one test failed, and the rest of the file (48 tests) passed.
Mutation-verified: AC-4 — step_finish tokens accumulation commented out in OpencodeStreamParser; src/lib/workflow/drivers/tests/driver-conformance.test.ts > driver conformance > opencode > outcome: a completed turn returns the structured shape with a non-zero token total failed; restored.
Test plan
npx vitest run src/lib/workflow/drivers/opencode.test.ts src/lib/workflow/drivers/__tests__/driver-conformance.test.ts: 83 passed, run after mergingmaintest+canary🤖 Generated with Claude Code