Skip to content

fix: add active_model_calls to has_active_stats/has_active predicates (#196)#200

Merged
microsasa merged 3 commits intomainfrom
fix/196-active-model-calls-predicate-2ade8f9efa9a6696
Mar 21, 2026
Merged

fix: add active_model_calls to has_active_stats/has_active predicates (#196)#200
microsasa merged 3 commits intomainfrom
fix/196-active-model-calls-predicate-2ade8f9efa9a6696

Conversation

@microsasa
Copy link
Owner

Closes #196

Problem

The has_active_stats predicate in render_live_sessions (both live view and full summary) and the has_active predicate in render_cost_view checked active_user_messages > 0 and active_output_tokens > 0 but did not check active_model_calls > 0.

A resumed session can have post-shutdown assistant.turn_start events (so active_model_calls > 0) while active_user_messages and active_output_tokens remain 0. In that case the code incorrectly fell back to historical totals instead of showing the active-period values.

Fix

Added s.active_model_calls > 0 to all three predicate locations in report.py:

  1. has_active_stats in render_live_sessions (live view)
  2. has_active_stats in the full summary active sessions section
  3. has_active in render_cost_view

Tests

Added edge-case tests for last_resume_time=None, active_model_calls > 0, active_user_messages=0, active_output_tokens=0 to:

  • TestRenderLiveSessions
  • TestRenderFullSummary
  • TestRenderCostView

All 438 tests pass, coverage at 98%.

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 21, 2026
Copilot AI review requested due to automatic review settings March 21, 2026 05:12
@microsasa microsasa enabled auto-merge March 21, 2026 05:12
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 an edge case in report rendering where sessions with active_model_calls > 0 (but active_user_messages == 0 and active_output_tokens == 0) were incorrectly treated as having no active-period stats, causing the UI to fall back to historical totals.

Changes:

  • Update active-period predicates to include active_model_calls > 0 in live sessions, full summary active section, and cost view.
  • Add regression tests covering the “model calls only” active-period scenario across all three views.

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 Includes active_model_calls > 0 in the active-period detection predicates so resumed/active sessions take the correct rendering path.
tests/copilot_usage/test_report.py Adds edge-case tests ensuring the renderers use active-period fields when only active_model_calls is non-zero.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Mar 21, 2026
github-actions[bot]
github-actions bot previously approved these changes Mar 21, 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

Changes reviewed:

  • src/copilot_usage/report.py: 3 one-line additions of or s.active_model_calls > 0 to has_active_stats/has_active predicates in render_live_sessions, _render_active_section, and render_cost_view
  • tests/copilot_usage/test_report.py: 3 new edge-case tests covering active_model_calls > 0 with active_user_messages=0, active_output_tokens=0, last_resume_time=None

Assessment:

  • Code quality: Good — follows existing predicate pattern exactly, logically correct fix for issue #196
  • Impact: LOW — display-only predicate fix in rendering layer, no API/data model/security changes
  • Tests: Meaningful coverage of the exact edge case across all 3 rendering paths (103 lines of tests for 3 lines of production code)

Low-impact bug fix with thorough test coverage. Auto-approving for merge.

@microsasa microsasa added aw-review-response-attempted Responder has attempted to address review comments aw-review-response-1 Review response round 1 and removed aw-review-response-attempted Responder has attempted to address review comments labels Mar 21, 2026
@github-actions
Copy link
Contributor

Commit pushed: 2dd15af

Generated by Review Responder

@microsasa microsasa disabled auto-merge March 21, 2026 05:38
@microsasa microsasa enabled auto-merge March 21, 2026 05:38
@microsasa microsasa force-pushed the fix/196-active-model-calls-predicate-2ade8f9efa9a6696 branch from 2dd15af to a49e937 Compare March 21, 2026 05:43
Copilot AI review requested due to automatic review settings March 21, 2026 05:43
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-2 Review response round 2 aw-review-response-attempted Responder has attempted to address review comments and removed aw-review-response-attempted Responder has attempted to address review comments labels Mar 21, 2026
@github-actions
Copy link
Contributor

Commit pushed: e847169

Generated by Review Responder

@microsasa microsasa disabled auto-merge March 21, 2026 06:39
@microsasa microsasa enabled auto-merge March 21, 2026 06:39
Copilot AI review requested due to automatic review settings March 21, 2026 06:41
@microsasa microsasa force-pushed the fix/196-active-model-calls-predicate-2ade8f9efa9a6696 branch from e847169 to 0de95c3 Compare March 21, 2026 06:41
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 no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsasa microsasa disabled auto-merge March 21, 2026 14:43
@microsasa microsasa enabled auto-merge March 21, 2026 14:43
@microsasa microsasa removed the aw-quality-gate-approved Quality gate approved the PR label Mar 21, 2026
github-actions bot and others added 3 commits March 21, 2026 14:49
…#196)

Add s.active_model_calls > 0 to the has_active_stats predicate in
render_live_sessions (live view and full summary) and the has_active
predicate in render_cost_view. Without this, a resumed session with
post-shutdown assistant.turn_start events but no user messages or
output tokens would incorrectly fall back to historical totals.

Add tests for the edge case: last_resume_time=None,
active_model_calls > 0, active_user_messages=0, active_output_tokens=0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract duplicated has_active_stats/has_active predicate into a
_has_active_period_stats() helper and reuse it across all three
renderers (render_live_sessions, render_full_summary, render_cost_view)
to prevent future drift when active_* fields change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add Output Tokens assertion to full summary edge-case test
- Make Model Calls assertion exact (== instead of 'in') in cost view test
- Add Output Tokens assertion to cost view edge-case test (cols[6])

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/196-active-model-calls-predicate-2ade8f9efa9a6696 branch from 0de95c3 to 86fcc23 Compare March 21, 2026 14:49
@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Mar 21, 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

What was evaluated:

  • Bug fix adding missing active_model_calls > 0 condition to the has_active_stats/has_active predicates in report.py (3 call sites)
  • Refactored duplicated inline predicates into shared _has_active_period_stats() helper (DRY improvement)
  • 3 new edge-case tests covering the exact bug scenario (active_model_calls > 0, user_messages=0, output_tokens=0, last_resume_time=None) across TestRenderLiveSessions, TestRenderFullSummary, and TestRenderCostView

Impact: LOW — Display/rendering logic only. No API contracts, data models, or security-sensitive code affected. 2 files changed (source + tests), net +111 lines.

Auto-approving for merge.

@microsasa microsasa merged commit c630dca into main Mar 21, 2026
4 checks passed
@microsasa microsasa deleted the fix/196-active-model-calls-predicate-2ade8f9efa9a6696 branch March 21, 2026 14:53
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-attempted Responder has attempted to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw] active_model_calls missing from has_active_stats/has_active predicates

2 participants