Skip to content

agent-coding-session: per-group token_usage is last-call-wins — token sums undercount and depend on sync granularity #236

Description

@bdelanghe

Evidence from a live session (path-claude-code-25095aad, claude-code 2.1.241):

  • The doc covers the FULL conversation — 347 steps, last ingested step is line 4088 of the 4090-line transcript. Coverage is fine.
  • But only 72 steps carry structural.token_usage, summing to 102,354 output tokens, while the transcript's per-API-call usage (529 unique assistant message ids) sums to 784,105.
  • Same binary base earlier read 729,846 for the same session — because incremental sync (a path query every ~25s from a statusline) ingested fine-grained turn groups, each capturing a usage snapshot. A from-scratch rebuild of the same transcript makes coarse groups and keeps only the last call's usage per group.

So token sums from path query are a function of sync cadence, not of the session — two syncs of identical data disagree by 7×. For spend accounting the kind should either sum token_usage across the API calls inside a group at ingest, or store the per-call usage array so consumers can sum. (Found while reconciling toolpath against transcript + OTEL + proxy witnesses, which now agree with each other and not with path.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions