fix: render_live_sessions shows active fields for resumed sessions (#139)#172
fix: render_live_sessions shows active fields for resumed sessions (#139)#172
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes render_live_sessions so that resumed active sessions display post-resume activity (active_user_messages, active_output_tokens) instead of stale historical totals, aligning it with the existing _render_active_section behavior.
Changes:
- Update
render_live_sessionsto choose between active-period stats vs. historical totals based on presence ofactive_*fields. - Add unit tests covering resumed-session behavior and ensuring pure-active sessions keep using totals.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/copilot_usage/report.py |
Switch live-session Messages/Output Tokens to active_* fields for resumed sessions, otherwise keep existing totals logic. |
tests/copilot_usage/test_report.py |
Add coverage for resumed sessions vs. pure-active sessions in render_live_sessions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Commit pushed:
|
69f5961 to
29c1520
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Commit pushed:
|
) For resumed sessions (with active_user_messages or active_output_tokens), render_live_sessions now uses the post-resume active_* fields instead of the historical totals from model_metrics/user_messages. This matches the pattern already used by _render_active_section. Pure-active sessions (never shut down) remain unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Harden test_resumed_session_shows_active_fields assertions: - Use a session_id without digits that could match test values - Use more distinctive numeric values (91, 263) for messages - Use word-boundary regex for integer assertions to prevent false positives from substring matches in other columns Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use last_resume_time to detect resumed sessions instead of truthiness check on active_user_messages/active_output_tokens, fixing the edge case where a resumed session with zero post-resume activity would incorrectly show historical totals. - Fix test_pure_active_session_uses_totals: use a clean session_id and word-boundary regex to prevent false positives from substring matches. - Add test_resumed_session_zero_activity_shows_zeros for the zero- activity resumed session edge case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f0246c4 to
5e7e3a7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
There was a problem hiding this comment.
test_resumed_session_zero_activity_shows_zeros currently only asserts that historical totals are absent, but it doesn’t assert that the active-period zeros are actually rendered. If the renderer regresses to showing a dash/blank for zeros, this test would still pass. Consider asserting for whole-word 0 in the output (and ideally in both Messages and Output Tokens columns) to match the test’s docstring/intent.
| # And should explicitly render zeros for the active period | |
| session_line = next( | |
| (line for line in output.splitlines() if "Just Resumed" in line), | |
| "", | |
| ) | |
| # Expect at least two whole-word zeros on the session row (Messages and Output Tokens) | |
| zeros_on_row = re.findall(r"\b0\b", session_line) | |
| assert len(zeros_on_row) >= 2, ( | |
| "resumed session row should show 0 for both messages and output tokens" | |
| ) |
There was a problem hiding this comment.
Good catch — added the suggested assertions. The test now finds the "Just Resumed" row and verifies at least two whole-word 0 values appear (Messages and Output Tokens), so a regression to dash/blank would be caught.
Generated by Review Responder
There was a problem hiding this comment.
Quality Gate: APPROVED ✅
Code Quality: Good — clean conditional using last_resume_time is not None to distinguish resumed vs. pure-active sessions, consistent with the existing pattern in _render_active_section.
Impact: LOW — display-only bug fix in render_live_sessions table rendering (+32/−3 lines across report.py and test_report.py). No changes to data models, APIs, or dependencies.
Tests: Three meaningful test cases covering the resumed session case, the pure-active fallback, and the zero-activity edge case.
Auto-approving for merge.
There was a problem hiding this comment.
Quality Gate: APPROVED ✅
Low-impact bug fix with good test coverage. Auto-approving for merge.
Evaluated:
- Code quality: Clean, focused fix. Uses
last_resume_time is not Noneto detect resumed sessions — correctly handles the zero-activity edge case. Follows existing patterns (_render_active_section). - Tests: 3 new tests covering resumed session (active values shown), pure-active regression (totals preserved), and zero-activity edge case.
- Impact: LOW — display-only change in
render_live_sessions(), no data mutation or API changes. 2 files, ~12 lines of source.
|
❌ Pipeline orchestrator: review-response loop reached 3 rounds. Marking as stuck for human review. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
Fixes #139
Problem
render_live_sessionsuseds.user_messages(all-time total) and_estimated_output_tokens(s)(model_metrics sum from shutdown data only) for all active sessions. For resumed sessions, this showed stale historical data instead of the current post-resume activity.Fix
When a session has
active_user_messagesoractive_output_tokensset (indicating it was resumed), use those fields instead. Pure-active sessions (never shut down, where both are 0) continue using the existing totals. This matches the pattern already used by_render_active_section.Tests added
test_resumed_session_shows_active_fields— resumed session with historical model_metrics and non-zero active fields shows only the active-period valuestest_pure_active_session_uses_totals— pure-active session (no prior shutdown) still uses user_messages and model_metrics totalsAll 409 tests pass, 98% coverage, ruff/pyright clean.
Warning
The following domain was blocked by the firewall during workflow execution:
astral.shTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.