Skip to content

fix: render_live_sessions shows active fields for resumed sessions (#139)#172

Open
microsasa wants to merge 4 commits intomainfrom
fix/139-live-sessions-resumed-data-368b18ae2a881bf6
Open

fix: render_live_sessions shows active fields for resumed sessions (#139)#172
microsasa wants to merge 4 commits intomainfrom
fix/139-live-sessions-resumed-data-368b18ae2a881bf6

Conversation

@microsasa
Copy link
Owner

Fixes #139

Problem

render_live_sessions used s.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_messages or active_output_tokens set (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 values
  • test_pure_active_session_uses_totals — pure-active session (no prior shutdown) still uses user_messages and model_metrics totals

All 409 tests pass, 98% coverage, ruff/pyright clean.

Generated by Issue Implementer ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • astral.sh

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "astral.sh"

See Network Configuration for more information.

@microsasa microsasa added the aw Created by agentic workflow label Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 06:14
@microsasa microsasa enabled auto-merge March 20, 2026 06:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_sessions to choose between active-period stats vs. historical totals based on presence of active_* 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.

@microsasa microsasa added aw-quality-gate-approved Quality gate approved the PR aw-review-response-attempted Responder has attempted to address review comments labels Mar 20, 2026
@github-actions
Copy link
Contributor

Commit pushed: 69f5961

Generated by Review Responder

@microsasa microsasa disabled auto-merge March 20, 2026 07:05
@microsasa microsasa enabled auto-merge March 20, 2026 07:05
Copilot AI review requested due to automatic review settings March 20, 2026 07:06
@microsasa microsasa force-pushed the fix/139-live-sessions-resumed-data-368b18ae2a881bf6 branch from 69f5961 to 29c1520 Compare March 20, 2026 07:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@microsasa microsasa added aw-review-response-1 Review response round 1 aw-review-response-attempted Responder has attempted to address review comments and removed aw-review-response-attempted Responder has attempted to address review comments aw-quality-gate-approved Quality gate approved the PR labels Mar 20, 2026
@github-actions
Copy link
Contributor

Commit pushed: f0246c4

Generated by Review Responder

github-actions bot and others added 3 commits March 20, 2026 07:22
)

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>
Copilot AI review requested due to automatic review settings March 20, 2026 07:22
@microsasa microsasa force-pushed the fix/139-live-sessions-resumed-data-368b18ae2a881bf6 branch from f0246c4 to 5e7e3a7 Compare March 20, 2026 07:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +353 to 354


Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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"
)

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@microsasa microsasa added aw-review-response-2 Review response round 2 aw-quality-gate-approved Quality gate approved the PR and removed aw-review-response-attempted Responder has attempted to address review comments labels Mar 20, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 None to 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.

@microsasa microsasa added aw-review-response-attempted Responder has attempted to address review comments aw-review-response-3 Review response round 3 and removed aw-review-response-attempted Responder has attempted to address review comments labels Mar 20, 2026
@microsasa
Copy link
Owner Author

❌ Pipeline orchestrator: review-response loop reached 3 rounds. Marking as stuck for human review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

Commit pushed: 53b58c3

Generated by Review Responder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR aw-review-response-1 Review response round 1 aw-review-response-2 Review response round 2 aw-review-response-3 Review response round 3 aw-review-response-attempted Responder has attempted to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] render_live_sessions shows stale historical data for resumed sessions

2 participants