agents: fix spinner stuck after session completes#314608
Merged
roblourens merged 2 commits intomainfrom May 6, 2026
Merged
Conversation
Race condition: _summaryNotifyScheduler debounces SessionSummaryChanged
notifications by 100ms. When _maybeEvictIdleSession calls removeSession
within that window after a turn completes, the session is removed from
_dirtySummaries before the scheduler fires. Clients never receive the
status=Idle notification and the spinner stays stuck.
Fix: in removeSession, flush any dirty summary synchronously before
clearing the session maps. This guarantees clients see the final status
even when the session is evicted within the debounce window.
For deleteSession (permanent removal), the forthcoming SessionRemoved
notification supersedes any summary diff, so dirty summaries are
dropped before removeSession is called to preserve the existing
"no spurious SessionSummaryChanged on delete" invariant.
scheduler fired (status=InProgress
assert SessionSummaryChanged{status=Idle} emitted synchronously.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Screenshot ChangesBase: Changed (6) |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a race in the agent-host sessions process where a session can be evicted during the debounced summary-notification window, causing clients to miss the final status = Idle update and leaving the Sessions list spinner stuck “in progress”.
Changes:
- Flushes any pending
SessionSummaryChangednotification synchronously duringremoveSessionteardown, ensuring the final status reaches clients even if eviction happens before the debounce fires. - Ensures
deleteSessionsuppresses any pending summary diff so clients don’t see a last-momentSessionSummaryChangedright beforeSessionRemoved. - Adds a regression test covering eviction within the debounce window after a turn completes.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/agentHostStateManager.ts | Flush pending summary notifications on eviction; refactors flush logic into a helper; suppresses pending diffs on delete. |
| src/vs/platform/agentHost/test/node/agentHostStateManager.test.ts | Adds a regression test verifying removeSession synchronously emits the final status = Idle summary change. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/platform/agentHost/node/agentHostStateManager.ts:417
- For consistency with the rest of
AgentHostStateManager(which uses the protocolURItype alias for session identifiers), consider changing_flushSummaryNotificationFor(session: string)to_flushSummaryNotificationFor(session: URI). This avoids mixing rawstringwith the semantic URI type in this API surface.
/**
* Emits a {@link NotificationType.SessionSummaryChanged} notification for
* `session` if its current summary differs from the last one sent to
* clients, then advances `_lastNotifiedSummaries` to the current summary.
*
* Does NOT remove `session` from `_dirtySummaries` — callers are
* responsible for that bookkeeping.
*/
private _flushSummaryNotificationFor(session: string): void {
const state = this._sessionStates.get(session);
- Files reviewed: 2/2 changed files
- Comments generated: 2
Per Copilot review on #314608: - JSDoc now clarifies removeSession won't emit SessionRemoved but may emit SessionSummaryChanged (synchronous flush side-effect) - Remove 'as unknown as string' cast on _dirtySummaries. thedelete other delete calls on the same maps use session directly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
osortega
approved these changes
May 6, 2026
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.
Problem
Completed agent host sessions show a perpetual spinner in the Sessions list. The session finishes successfully but the UI never transitions away from the "in progress" state.
Root cause
There is a race between
AgentHostStateManager's_summaryNotifyScheduler(100 ms debounce) and the call toremoveSessiontriggered by_maybeEvictIdleSession.SessionTurnCompleteis processed →endTurnproduces a new summary withstatus = Idle→ session is added to_dirtySummaries→_summaryNotifyScheduler.schedule()(fires in 100 ms).unsubscribe,_maybeEvictIdleSessionseesactiveTurn === undefinedand no remaining subscribers → callsremoveSession.removeSessionclears_sessionStates,_lastNotifiedSummaries, and_dirtySummaries.SessionSummaryChangednotification is ever emitted._handleSessionSummaryChangednever receivesstatus = Idle→ spinner stays.Evidence from live IPC/agent-host logs:
SessionTurnCompleteenvelopes arrive for all three sessions, followed ~250 ms later by"Action for unknown session"warnings — confirming the session was evicted before the flush.Fix
removeSession: before clearing state maps, synchronously flush any pending summary notification. This guarantees clients see the final status even when a session is evicted within the debounce window.deleteSession(permanent removal): drop the session from_dirtySummariesbefore callingremoveSession. The forthcomingSessionRemovednotification supersedes any pending summary diff, so we preserve the existing invariant that permanently-deleted sessions don't emit spuriousSessionSummaryChangedevents.Testing
Added a regression test to
agentHostStateManager.test.ts:_lastNotifiedSummariesrecordsstatus = InProgressremoveSessionbefore the 100 ms debounce firesSessionSummaryChanged { status: Idle }was emitted synchronously insideremoveSessionAll 31 existing tests continue to pass.
(Written by Copilot)