Repository navigation
fix(copilot): avoid duplicate residual for cumulative shutdown totals - #1973
Open
2389400626lh-ops wants to merge 1 commit into
Open
2389400626lh-ops wants to merge 1 commit into
2389400626lh-ops wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1968
During Copilot reconciliation in
src/parser.ts, legs containing asession.compaction_completeevent currently assumesession.shutdowncounters always reset atcompactedAtMs, so pre-compaction store rows are excluded fromcovered. When a Copilot host (such as the VS Code agent host) writes cumulativesession.shutdowntotals 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-compactioncoveredtotals. When a leg has a compaction boundary (leg.compactedAtMs > prevLegTs) and all five token fields (input,output,cacheRead,cacheWrite,reasoning) ofcoveredAllmatch 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
tests/parser.test.tsreproducing 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).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)