Skip to content

fix: set _ps_resumed for ASSISTANT_TURN_START after shutdown (#1165)#1166

Open
microsasa wants to merge 1 commit intomainfrom
fix/first-pass-turn-start-resumed-1165-26073d849ebbb724
Open

fix: set _ps_resumed for ASSISTANT_TURN_START after shutdown (#1165)#1166
microsasa wants to merge 1 commit intomainfrom
fix/first-pass-turn-start-resumed-1165-26073d849ebbb724

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #1165

Problem

In _first_pass, the ASSISTANT_TURN_START branch incremented _ps_turn_starts when occurring after a shutdown but never set _ps_resumed = True. This caused in-flight sessions (with an active model turn that hasn't yet produced an ASSISTANT_MESSAGE) to be incorrectly reported as is_active=False with active_model_calls=0, silently discarding the accumulated post-shutdown turn starts.

Fix

Add _ps_resumed = True to the ASSISTANT_TURN_START branch when _shutdowns is non-empty, making it consistent with the USER_MESSAGE and ASSISTANT_MESSAGE branches.

Tests Added

Three regression tests in TestBuildSessionSummaryResumed:

  1. test_turn_start_alone_marks_resumed — Shutdown followed by a single ASSISTANT_TURN_START (no ASSISTANT_MESSAGE) → is_active=True, active_model_calls=1
  2. test_turn_start_then_assistant_message_marks_resumed — Shutdown followed by ASSISTANT_TURN_START + ASSISTANT_MESSAGEis_active=True, active_model_calls=1, active_output_tokens=200
  3. test_pure_active_session_unaffected_by_turn_start_fix — Session with no shutdown → is_active=True with correct total counters (no regression)

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • astral.sh
  • pypi.org

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

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

See Network Configuration for more information.

Generated by Issue Implementer · ● 12.6M ·

The _first_pass function incremented _ps_turn_starts for
ASSISTANT_TURN_START events occurring after a shutdown but did not set
_ps_resumed = True. This caused in-flight sessions (with an active model
turn but no ASSISTANT_MESSAGE yet) to be incorrectly reported as
is_active=False with active_model_calls=0.

Add the missing _ps_resumed = True assignment, consistent with the
USER_MESSAGE and ASSISTANT_MESSAGE branches.

Add three regression tests:
- Shutdown followed by lone ASSISTANT_TURN_START → is_active=True
- Shutdown followed by ASSISTANT_TURN_START + ASSISTANT_MESSAGE → active
- Pure-active session (no shutdown) unaffected by the fix

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label May 2, 2026
Copilot AI review requested due to automatic review settings May 2, 2026 21:47
@microsasa microsasa enabled auto-merge May 2, 2026 21:47
@microsasa microsasa added the aw Created by agentic workflow label May 2, 2026
Copy link
Copy Markdown

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 resumed-session detection in copilot_usage parsing so that an assistant.turn_start occurring after a shutdown correctly marks the session as resumed/active (preventing post-shutdown in-flight model calls from being dropped in summaries).

Changes:

  • Mark _ps_resumed = True when ASSISTANT_TURN_START occurs after a shutdown in _first_pass.
  • Add regression tests covering turn-start-only and turn-start+assistant-message post-shutdown behavior, plus a no-shutdown regression test.

Reviewed changes

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

File Description
src/copilot_usage/parser.py Ensures post-shutdown assistant.turn_start sets the resumed flag so is_active/active_model_calls are computed correctly.
tests/copilot_usage/test_parser.py Adds regression tests to prevent this resumed-detection bug from returning and to ensure no-shutdown behavior is unchanged.

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

2 participants