fix: set _ps_resumed for ASSISTANT_TURN_START after shutdown (#1165)#1166
Open
fix: set _ps_resumed for ASSISTANT_TURN_START after shutdown (#1165)#1166
_ps_resumed for ASSISTANT_TURN_START after shutdown (#1165)#1166Conversation
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>
There was a problem hiding this comment.
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 = TruewhenASSISTANT_TURN_STARToccurs 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1165
Problem
In
_first_pass, theASSISTANT_TURN_STARTbranch incremented_ps_turn_startswhen 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 anASSISTANT_MESSAGE) to be incorrectly reported asis_active=Falsewithactive_model_calls=0, silently discarding the accumulated post-shutdown turn starts.Fix
Add
_ps_resumed = Trueto theASSISTANT_TURN_STARTbranch when_shutdownsis non-empty, making it consistent with theUSER_MESSAGEandASSISTANT_MESSAGEbranches.Tests Added
Three regression tests in
TestBuildSessionSummaryResumed:test_turn_start_alone_marks_resumed— Shutdown followed by a singleASSISTANT_TURN_START(noASSISTANT_MESSAGE) →is_active=True,active_model_calls=1test_turn_start_then_assistant_message_marks_resumed— Shutdown followed byASSISTANT_TURN_START+ASSISTANT_MESSAGE→is_active=True,active_model_calls=1,active_output_tokens=200test_pure_active_session_unaffected_by_turn_start_fix— Session with no shutdown →is_active=Truewith correct total counters (no regression)Warning
The following domains were blocked by the firewall during workflow execution:
astral.shpypi.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.