Skip to content

fix(copilot): avoid duplicate residual for cumulative shutdown totals - #1973

Open
2389400626lh-ops wants to merge 1 commit into
getagentseal:mainfrom
2389400626lh-ops:fix/copilot-cumulative-shutdown-reconciliation
Open

2389400626lh-ops wants to merge 1 commit into
getagentseal:mainfrom
2389400626lh-ops:fix/copilot-cumulative-shutdown-reconciliation

Conversation

@2389400626lh-ops

Copy link
Copy Markdown

Summary

Fixes #1968

During Copilot reconciliation in src/parser.ts, legs containing a session.compaction_complete event currently assume session.shutdown counters always reset at compactedAtMs, so pre-compaction store rows are excluded from covered. When a Copilot host (such as the VS Code agent host) writes cumulative session.shutdown totals covering the entire leg (prevLegTs, leg.ts], the pre-compaction tokens are not subtracted and get emitted as a duplicate residual dated at shutdown (which can fall on a later day with zero calls).

This change tracks the full-leg store row totals (coveredAll) over (prevLegTs, leg.ts] alongside the existing post-compaction covered totals. When a leg has a compaction boundary (leg.compactedAtMs > prevLegTs) and all five token fields (input, output, cacheRead, cacheWrite, reasoning) of coveredAll match the shutdown leg exactly, the leg is already completely accounted for by its per-call rows and emits no residual. Legs whose counters genuinely reset at compaction (or have missing store rows) retain the exact existing fallback behavior.

Testing

  • Added an end-to-end regression test in tests/parser.test.ts reproducing the two-day cumulative shutdown scenario from Copilot: cumulative shutdown totals double-count earlier usage on the wrong day #1968 (Day 1 counts both calls once; Day 2 shutdown-only reports 0 input/output tokens).
  • Verified locally:
    • npx vitest run tests/parser.test.ts tests/copilot-agent-host.test.ts (87/87 passed, including existing labelled/unlabelled compaction reset tests)
    • npx tsc --noEmit (passed)
    • npm run build:cli (passed)

This branch has not been deployed

No deployments
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.

Copilot: cumulative shutdown totals double-count earlier usage on the wrong day

1 participant