GeezerVison is showing github.com — Track auxiliary V2 LLM usage in session lifetime totals · Issue #35781 · anomalyco/opencode
Track auxiliary V2 LLM usage in session lifetime totals #35781
Labels
2.0bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff) Description
Summary
V2 session lifetime usage currently counts coding-agent steps, but omits LLM calls made for session title generation and compaction. Both paths consume an LLM stream directly and discard settled usage, so their tokens and cost never reach Session.Info or session.usage.updated.
Current behavior
packages/core/src/session/title.ts consumes title-generation stream events but retains only text and provider failure state.
packages/core/src/session/compaction.ts consumes compaction stream events but retains only text and provider failure state.
packages/core/src/session/projector.ts increments lifetime usage only from usage-bearing session.step.ended and session.step.failed events.
- Forked sessions correctly start their own lifetime totals at zero; copied transcript tokens remain available separately for context-window display.
Expected behavior
- Capture normalized token usage for title-generation and compaction calls.
- Calculate cost through the same typed pricing/billing path used by normal model steps.
- Attribute those calls once to the owning session lifetime totals, including settled failed calls when the provider reports usage.
- Persist an irreducible durable usage fact so replay and retries cannot lose or double-count spend; do not rely on an untracked direct
SessionTable mutation.
- Continue publishing absolute
session.usage.updated snapshots after the aggregate is projected.
- Do not represent auxiliary calls as assistant steps or include them in context-window usage.
Implementation notes
A dedicated durable usage event may be cleaner than adding unrelated billing fields to session.renamed and compaction completion events. The event should carry a stable source identity or otherwise preserve exactly-once accounting under retries.
Compaction currently receives a route-level model without catalog pricing, so its input may need the resolved model cost information or a shared billing service.
Tests
- Successful title generation increments lifetime tokens and cost once.
- Successful automatic and manual compaction increment lifetime tokens and cost once.
- Usage-bearing failures are counted once.
- Retry/replay does not duplicate usage.
- Auxiliary usage does not change context-window percentage.
Related
Activity
added
bugSomething isn't working coreAnything pertaining to core functionality of the application (opencode server stuff) on Jul 7, 2026opencode-agent commented on Jul 8, 2026
Audit update (2026-07-08): this is now the focused remaining auxiliary title-generation/compaction usage slice after #35468 landed coding-step/session usage totals. Currently unassigned.
rvaccone commented on Jul 17, 2026
Looks like this was resolved by #37441, which added the durable session.usage.recorded event covering both title generation and compaction usage. Probably safe to close.
Metadata
Metadata
2.0bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff) Development
No branches or pull requestsIssue actions