Repository navigation
agentHost: finish foreground turns independently of background work - #336083
Draft
Justin Chen (justschen) wants to merge 1 commit into
Draft
Justin Chen (justschen) wants to merge 1 commit into
Justin Chen (justschen) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Turn-replacement and session-lifecycle races can strand turns, restarts, or late child edit metadata.
Get a fresh assessment by requesting another Copilot review.
Review tier: Balanced (auto)
Findings: 1
Note
Copilot is running an experiment and ran this review at Balanced.
Open findings (3)
What changed in this PR
Separates foreground turn completion from session-wide background work while protecting active tasks from release and restart.
Changes:
- Uses request-scoped foreground completion and root assistant-idle events.
- Preserves background subagent streams and defers lifecycle cleanup.
- Adds lifecycle, race, and shell regression coverage.
| File | Description |
|---|---|
providerIntegration/README.md |
Documents shell lifecycle coverage. |
copilotMockLlm.integrationTest.ts |
Tests attached and detached shells. |
copilotAgentSession.test.ts |
Covers foreground completion and background work. |
copilotAgent.test.ts |
Tests deferred restart races. |
copilotSessionWrapper.ts |
Exposes assistant-idle events. |
copilotAgentSession.ts |
Implements foreground/background lifecycle separation. |
copilotAgent.ts |
Protects background work from release and restart. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1891
to
+1897
| private async _completeForegroundRequest(request: symbol, abortToken: CancellationToken): Promise<void> { | ||
| const turn = this._currentTurn.value; | ||
| if (turn?.foregroundRequest === request) { | ||
| turn.markProviderCallResolved(); | ||
| await this._completeTurnAfterTools(turn, abortToken); | ||
| } | ||
| } |
Comment on lines
+1208
to
+1211
| const sessions = this._allLiveSessions(); | ||
| if (sessions.length > 0) { | ||
| const backgroundWork = await Promise.all(sessions.map(session => session.hasRunningBackgroundWork())); | ||
| if (backgroundWork.some(Boolean)) { |
| this._agentMergeTurn = false; | ||
| this._streamingToolCalls.clear(); | ||
| this._streamingToolDisplaySchedulers.clearAndDisposeAll(); | ||
| this._clearStreamingToolCalls(); |
This branch has not been deployed
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.


Summary
Fix the Copilot parent turn remaining Working after its foreground response has finished while an intentional background shell or agent is still running. The SDK defines
session.idleas whole-session quiescence, including background agents and attached shell commands; it is not the foreground request completion boundary.This is independent of the subagent-rendering work in #335899 and is based directly on main, not on that PR.
Changes
assistant.idlefor SDK-initiated turns without a host request promise.Reproduction and validation
Checked against freshly fetched main
3e8601c5f63f5b2358e0fbbfb825fbbfd72cbe2b: a real attached asynchronous shell waits for a test-controlled release file. After the final foreground Markdown arrives, main retains the active parent andInProgressstate. Releasing the shell unblocks parent completion. The identical probe passes with this change while the shell remains running.Local macOS validation:
npm run build-fastpassed.One replay attempt timed out at test-server startup before either scenario began; both passed on a standalone rerun without code or timeout changes. Tests use isolated temporary state and local synthetic/captured model responses, with no real model requests. Cross-platform CI is still to be validated.
The original symptom was observed in Autopilot, but the reproduced host completion-boundary issue is not Autopilot-only. The historical export cannot identify every native-runtime condition in that particular run.