-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Root Cause
render_cost_view in src/copilot_usage/report.py incorrectly inflates the Grand Total Model Calls column for any session that is active/resumed.
In build_session_summary (parser.py), two fields are built from separate loops:
model_calls=total_turn_starts, # ALL ASSISTANT_TURN_START events in the session
active_model_calls=post_shutdown_turn_starts, # subset: only events AFTER the last shutdownactive_model_calls is already a subset of model_calls (the implementation doc at src/copilot_usage/docs/implementation.md:187 confirms: "model_calls … are the total counts across the entire session").
In render_cost_view (lines 958–969) both are added to grand_model_calls:
grand_model_calls += s.model_calls # line 958 – correct: all turns
if s.is_active:
...
grand_model_calls += s.active_model_calls # line 969 – bug: post-shutdown already in model_callsFor a resumed session with model_calls=10 (total) and active_model_calls=3 (post-shutdown), the Grand Total accumulates 13 instead of the correct 10.
The README copilot-usage cost example (lines 108–114) was written with this bug in place — it shows Session Gamma model_calls=2, active=1 and a Grand Total of 9 (= 3+3+3), whereas the correct total is 8 (= 3+3+2).
Note: the grand_output accumulation is correct — active_output_tokens are not present in model_metrics, so adding them separately is intentional.
Fix
Remove the duplicate increment in render_cost_view:
# src/copilot_usage/report.py ~line 969
# DELETE this line:
grand_model_calls += s.active_model_callsUpdate the README example Grand Total (Model Calls column) to reflect the corrected value.
Testing Requirement
Add a regression test in tests/copilot_usage/test_report.py inside TestRenderCostView that:
- Creates a resumed session with known
model_callsandactive_model_callsvalues (e.g.,model_calls=10, active_model_calls=3). - Captures the
render_cost_viewoutput and asserts the Grand Total row shows10for Model Calls — not13.
This ensures the double-count does not regress.
Generated by Code Health Analysis · ◷