Repository navigation
Closed
Labels
2.0bugSomething isn't workingSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)Anything 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.tsconsumes title-generation stream events but retains only text and provider failure state.packages/core/src/session/compaction.tsconsumes compaction stream events but retains only text and provider failure state.packages/core/src/session/projector.tsincrements lifetime usage only from usage-bearingsession.step.endedandsession.step.failedevents.- 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
SessionTablemutation. - Continue publishing absolute
session.usage.updatedsnapshots 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
- Add typed Copilot billing usage to the V2 runtime #35765 tracks the typed provider-reported billing contract, including Copilot billing.
- v2 SessionRunner publishes Step.Ended.cost: 0; Copilot refresh drops Anthropic cache-write pricing in token fallback #30706 tracks broader V2 cost-accounting history and Copilot fallback pricing.
Metadata
Metadata
Assignees
Labels
2.0bugSomething isn't workingSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Activity
opencode-agent commentedon 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 commentedon Jul 17, 2026
Looks like this was resolved by #37441, which added the durable
session.usage.recordedevent covering both title generation and compaction usage. Probably safe to close.