Skip to content

fix(#1115): opencode driver reports modelUsage from step_finish tokens - #1204

Merged
admarble merged 4 commits into
mainfrom
fix/1115-opencode-token-usage
Sep 28, 2026
Merged

admarble merged 4 commits into
mainfrom
fix/1115-opencode-token-usage

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Part of #1115. opencode runs now report token usage: the driver sums each step_finish event's part.tokens into modelUsage, so sequant stats and 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)

Acceptance criteria

  • AC-1: OpencodeDriver.executePhase returns modelUsage with non-zero input/output tokens for a completed run. Verified with npx vitest run src/lib/workflow/drivers/opencode.test.ts (49 passed, 7 new cases; the exact totals come from the real fixture).
  • AC-2: aider usage. Not done: needs a real capture. aider.ts captures 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 a PROVENANCE.md line.
  • AC-3: typed opencode quota errors. Not done: needs a real capture. The mapping goes in evaluateOpencodeRun's parsed.errors branch, following codex's USAGE_LIMIT_RE/THROTTLE_RE. Needed: real opencode run --format json stdout and stderr from one usage-limit run and one throttled run.
  • AC-4 (partial): the opencode item-5 gap: #1115 skip 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 with npx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts (34 passed).
  • AC-5: npm run build && npm test: see this PR's CI test job. Locally, npx vitest run src/lib/workflow/drivers passed (282 passed, 3 skipped) and npm run build exited 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 merging main
  • CI test + canary

🤖 Generated with Claude Code

@admarble
admarble merged commit a15d4b4 into main Sep 28, 2026
18 checks passed
@admarble
admarble deleted the fix/1115-opencode-token-usage branch September 28, 2026 13:40
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