Skip to content

Extract _effective_stats to deduplicate active-vs-totals branching (#242)#255

Merged
microsasa merged 1 commit intomainfrom
aw/extract-effective-stats-242-357b97411ddcbe6e
Mar 22, 2026
Merged

Extract _effective_stats to deduplicate active-vs-totals branching (#242)#255
microsasa merged 1 commit intomainfrom
aw/extract-effective-stats-242-357b97411ddcbe6e

Conversation

@microsasa
Copy link
Owner

Closes #242

Changes

Adds a frozen _EffectiveStats dataclass and _effective_stats() helper that returns active-period stats when available, otherwise falls back to session totals. This replaces three copy-pasted if _has_active_period_stats(s) branches in:

  • render_live_sessions
  • _render_active_section
  • render_cost_view

Each call site now uses stats = _effective_stats(s) and accesses stats.model_calls, stats.user_messages, stats.output_tokens.

Tests

Added TestEffectiveStats with three tests:

  • test_returns_active_stats_when_active_period — resumed session returns active_* values
  • test_returns_session_totals_when_no_active_period — pure-active session falls back to totals
  • test_frozen_dataclass — verifies immutability

All 509 tests pass. Coverage: 98.76%.

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.

…anching (#242)

Add frozen _EffectiveStats dataclass and _effective_stats() helper that
returns active-period stats when available, otherwise session totals.

Replace three duplicated if/else branches in render_live_sessions,
_render_active_section, and render_cost_view with calls to
_effective_stats().

Add unit tests covering both branches (active period and session totals)
plus frozen-dataclass immutability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Mar 22, 2026
@microsasa microsasa enabled auto-merge March 22, 2026 18:05
Copilot AI review requested due to automatic review settings March 22, 2026 18:05
@microsasa microsasa merged commit a5b2b07 into main Mar 22, 2026
5 checks passed
@microsasa microsasa deleted the aw/extract-effective-stats-242-357b97411ddcbe6e branch March 22, 2026 18: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

This PR refactors copilot_usage.report to centralize the “active-period vs session-total” stat selection logic in a single helper, reducing duplication and keeping the live/active/cost views consistent.

Changes:

  • Added frozen _EffectiveStats dataclass and _effective_stats() helper to encapsulate active-vs-total fallback logic.
  • Replaced repeated _has_active_period_stats() branches in render_live_sessions, _render_active_section, and render_cost_view with _effective_stats().
  • Added unit tests covering both branches of _effective_stats() plus immutability.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/copilot_usage/report.py Introduces _EffectiveStats / _effective_stats() and updates renderers to use it instead of duplicated branching.
tests/copilot_usage/test_report.py Adds TestEffectiveStats to validate both selection branches and frozen dataclass behavior.

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

microsasa pushed a commit that referenced this pull request Mar 22, 2026
Copilot CLI broke branch protection rules during a safe admin merge
by setting the wrong required status check name ("CI" instead of
"check"), causing a 9-hour infinite loop of quality gate runs on
PR #246 (100+ pointless approvals). When Copilot CLI then fixed the
check name, it failed to also fix the review requirement settings
(dismiss_stale_reviews and required_approvals), leaving protections
down. It then repeatedly tested hold/release scripts against live
settings while the orchestrator was still running, allowing this PR
and others to auto-merge without any quality gate review.

Copilot CLI is a liar and cannot be trusted with repository settings.
It reports success while silently breaking things, hides mistakes
behind summaries instead of showing raw data, and has repeatedly
broken branch protection across multiple incidents. It has been
stripped of permission to modify branch protection directly. This
revert is part of repo recovery forced by Copilot CLI's repeated
carelessness.

This reverts commit a5b2b07.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract _effective_stats to deduplicate active-vs-totals branching

2 participants