Skip to content

fix(opencode): add session-level token fallback for OpenCode 1.16.0+ - #88

Merged
PanAchy merged 2 commits into
developfrom
fix/opencode-session-level-tokens
Jun 7, 2026
Merged

fix(opencode): add session-level token fallback for OpenCode 1.16.0+#88
PanAchy merged 2 commits into
developfrom
fix/opencode-session-level-tokens

Conversation

@PanAchy

@PanAchy PanAchy commented Jun 6, 2026

Copy link
Copy Markdown
Owner

What changed

  • Query the session table as a fallback when per-message tokens sum to zero
  • Filter sessions by json_extract(model, '$.providerID') = 'github-copilot'
  • Replace zero-token message records with a single session-level aggregate record per session
  • Add 7 tests covering session fallback: zero-token messages, non-zero messages preferred, session-only records, non-copilot sessions skipped, zero-token sessions skipped, sinceMs filtering, compaction detection
  • Update test fixtures to include the session table and time_created column on message

Context

OpenCode 1.16.0 introduced session-level token tracking for GitHub Copilot (token-based billing). For some Copilot sessions, token data may only exist on the session table (tokens_input, tokens_output, etc.) rather than in per-message data JSON. The tool previously only queried FROM message, returning zero usage for these sessions.

Resolves #87

Test plan

  • npx vitest run — all 144 tests pass
  • npx tsc --noEmit — clean

OpenCode 1.16.0 introduced session-level token tracking (tokens_input, tokens_output, etc. on the session table) for GitHub Copilot token-based billing. The tool previously only read per-message data JSON, missing sessions where token data lives only at the session level.

- Query the session table as a fallback when per-message tokens sum to zero
- Filter sessions by model.providerID matching github-copilot
- Replace zero-token message records with a single session-level aggregate record
- Add 7 tests covering the fallback behavior
- Update test fixtures to include the session table
@PanAchy
PanAchy force-pushed the fix/opencode-session-level-tokens branch from bc5633e to 46582cd Compare June 6, 2026 15:53
@PanAchy
PanAchy merged commit 267334d into develop Jun 7, 2026
3 checks passed
@PanAchy
PanAchy deleted the fix/opencode-session-level-tokens branch June 7, 2026 20:05
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.

showing zero cost with latest opencode

1 participant