Conversation
…ted_summary (#992) Apply the same 'if resume.session_resumed else 0' guard to active_user_messages and active_output_tokens that already protects active_model_calls, making the contract explicit rather than relying on an implicit invariant in _first_pass. Add test that constructs a _ResumeInfo with session_resumed=False but non-zero post-shutdown counters and verifies the built summary zeros them out. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR makes _build_completed_summary explicitly zero out all active-period counters (active_model_calls, active_user_messages, active_output_tokens) when resume.session_resumed is False, preventing future regressions from implicit invariants in _first_pass.
Changes:
- Add explicit
resume.session_resumedguards foractive_user_messagesandactive_output_tokensin_build_completed_summary. - Add a direct regression test that constructs a synthetic
_ResumeInfowithsession_resumed=Falsebut non-zero post-shutdown counters and verifies the summary zeros them out.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/copilot_usage/parser.py | Ensures active-period counters are consistently gated on session_resumed for completed sessions. |
| tests/copilot_usage/test_parser.py | Adds a regression test to enforce the contract that active counters must be zero when session_resumed=False. |
There was a problem hiding this comment.
Low-impact defensive consistency fix with a targeted regression test. The production change adds if resume.session_resumed else 0 guards to active_user_messages and active_output_tokens — matching the existing guard on active_model_calls. No behavior change for current code paths. Test correctly exercises the invariant-violation scenario. All CI green. Auto-approving for merge.
Closes #992
Problem
In
_build_completed_summary,active_model_callshas an explicitif resume.session_resumed else 0guard, butactive_user_messagesandactive_output_tokensrely on an implicit invariant — that_first_passnever increments these counters without also settingsession_resumed=True. A future refactor could break this invariant, causing double-counted tokens, spurious "↳ Since last shutdown" rows, and incorrecthas_active_period_stats()results.Fix
Apply the same guard consistently to all three active-period counters:
This is a no-op for current code paths but makes the contract explicit and self-documenting.
Testing
Added
test_completed_session_zeroes_active_counters_despite_post_shutdown_valuestoTestResumeDetectionDirect— constructs a synthetic_ResumeInfowithsession_resumed=Falsebut non-zero post-shutdown counters and verifies the built summary zeros them out. Without the fix, this test fails.