Repository navigation
agentHost: harden Claude cancellation and lifecycle recovery - #345929
Merged
Merged
Conversation
Preserve the Claude cancellation/replacement runtime behavior and strengthen its test baseline: stateful component cases for stale old-runtime results, late-startup cleanup and truncation anchors, a test-only SDK streaming helper, stronger model-history assertions, one live-recorded truncation capture, and related E2E docs. Co-authored-by: Copilot <[email protected]>
Reject a rebuilt runtime as soon as cancellation begins without closing the previous transport before interruption completes. Cover both startup and interrupt completion orders with deterministic regression tests. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Recovery has unresolved race conditions that can submit a cancelled replacement prompt or fail a replacement because of an old interrupt error despite successful teardown.
2 open issues
What changed in this PR
This PR hardens Claude Agent Host cancellation and recovery by interrupting turns before closing transport, waiting for shutdown, and ignoring stale query results. It also restores Claude truncation coverage without changing production truncation behavior.
Changes:
- Coordinate cancellation, rebuild recovery, and cleanup when interruption fails.
- Add lifecycle regression tests and stronger paused-turn assertions.
- Enable Claude cancellation and truncation E2E scenarios, refresh captures, and document validation limits.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/e2e/suites/fileOperationsSuite.ts |
Verify pending approval, cancellation, and replacement completion. |
src/vs/platform/agentHost/test/node/e2e/suites/coreSuite.ts |
Strengthen input-cancellation and continuation-history assertions. |
src/vs/platform/agentHost/test/node/e2e/README.md |
Document restored coverage and remaining validation requirements. |
src/vs/platform/agentHost/test/node/e2e/providers/claudeAgentHostE2E.integrationTest.ts |
Enable Claude cancellation and truncation scenarios. |
src/vs/platform/agentHost/test/node/e2e/KNOWN_ISSUES.md |
Remove entries for the re-enabled scenarios. |
src/vs/platform/agentHost/test/node/e2e/captures/copilotcli-cancelling-a-turn-paused-for-file-tool-approval-allows-a-replacement-turn.yaml |
Align the capture with the approval-requiring filename. |
src/vs/platform/agentHost/test/node/e2e/captures/claude-truncating-a-materialized-chat-removes-later-context-and-allows-continuation.yaml |
Add a truncated-history continuation capture. |
src/vs/platform/agentHost/test/node/e2e/captures/claude-cancelling-a-turn-paused-for-input-allows-a-replacement-turn.yaml |
Refresh interrupted-input and replacement history. |
src/vs/platform/agentHost/test/node/e2e/captures/claude-cancelling-a-turn-paused-for-file-tool-approval-allows-a-replacement-turn.yaml |
Refresh interrupted file-approval history. |
src/vs/platform/agentHost/test/node/claudeSdkPipeline.test.ts |
Cover shutdown ordering, rebuild cancellation, and stale-result isolation. |
src/vs/platform/agentHost/test/node/claudeMapSessionEventsTestUtils.ts |
Add a reusable SDK text-response helper. |
src/vs/platform/agentHost/test/node/claudeAgent.test.ts |
Cover startup cancellation, retries, rebuilds, and teardown failures. |
src/vs/platform/agentHost/node/claude/claudeSdkPipeline.ts |
Coordinate interruption, shutdown, recovery, and result filtering. |
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts |
Await cancellation before releasing pending requests. |
src/vs/platform/agentHost/node/claude/claudeAgent.ts |
Await session cancellation and preserve cleanup on failure. |
Review effort: Balanced
Keep pending recovery cancellation distinct from the previous SDK shutdown. Report interrupt failures to abort callers without blocking recovery after successful teardown, and retain shutdown failures. Cover both review cases with gated SDK-boundary tests. Co-authored-by: Copilot <[email protected]>
TylerLeonhardt
marked this pull request as ready for review
November 4, 2026 23:05
TylerLeonhardt
enabled auto-merge (squash)
November 4, 2026 23:05
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 4, 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.


Summary
This is a bounded reliability chunk for human review, not the planned launch/runtime architecture refactor. The SDK remains at
0.3.304.Validation
Current head:
5ca3fdfa09e92aa6c60d0b9a1a2437ca45081043.pnpm run build-fast --client-only.\scripts\test.bat --run src\vs\platform\agentHost\test\node\claudeSdkPipeline.test.ts --run src\vs\platform\agentHost\test\node\claudeAgent.test.ts --run src\vs\platform\agentHost\test\node\claudeMapSessionEvents.test.ts --run src\vs\platform\agentHost\test\node\claudeSdkMessageRouter.test.ts --reporter dot.\scripts\test-integration.bat --run src\vs\platform\agentHost\test\node\e2e\providers\claudeAgentHostE2E.integrationTest.ts --grep 'cancelling a turn paused|truncating a materialized chat' --reporter specpnpm run eslint src\vs\platform\agentHost\node\claude\claudeSdkPipeline.ts src\vs\platform\agentHost\test\node\claudeSdkPipeline.test.tsnode .\build\hygiene.ts src\vs\platform\agentHost\node\claude\claudeSdkPipeline.ts src\vs\platform\agentHost\test\node\claudeSdkPipeline.test.ts src\vs\platform\agentHost\test\node\e2e\README.mdgit diff --checkFor both replay executions,
AGENT_HOST_TEST_PROFILE=full;AGENT_HOST_REPLAY_RECORD,AGENT_HOST_UPDATE_SNAPSHOTS,AGENT_HOST_UPDATE_AHP_SNAPSHOTS, andAGENT_HOST_RUN_KNOWN_ISSUESwere explicitly set to0. No captures were changed for the final correction.The permanent regression selector
.\scripts\test.bat --run src\vs\platform\agentHost\test\node\claudeSdkPipeline.test.ts --grep 'cancellation discards a late runtime' --reporter specproduced 1 failure / 1 pass before the fix. Both cases pass in the final 403-test run. An earlier isolated probe also passed against pre-change29aacc7fand failed againstb52e4b40.The follow-up selector
.\scripts\test.bat --run src\vs\platform\agentHost\test\node\claudeSdkPipeline.test.ts --grep 'replacement waiting for previous shutdown' --reporter specproduced 2 failures / 1 pass before the feedback fixes. All three now pass in the 403-test run: cancelling a waiting replacement, successful recovery despite an interrupt failure, and preserving shutdown failure. The interrupt-order test also checks that the old prompt stream remains open until interruption is acknowledged.The original GitHub Actions run 41725486505 failed on nine browser/terminal tool-registration cases in Linux extension-host API tests, not Claude E2E. Attempt 2 passed on the unchanged
34e87ac1head, without modifying those unrelated tests. This establishes that the failure was transient; its precise cause was not proven. That retry is prior-head evidence, not CI validation of5ca3fdfa. The subsequent current-head run 41731865422 has now succeeded at5ca3fdfa, including the previously failing Linux extension-host job and PR Gate. Required Azure validation and the disclosed local/platform gaps remain separate.Scoped TypeScript check — passed for both edited files
This uses the repository TypeScript project, checks diagnostics for the two files changed by the correction, and emits nothing. It is not a new full-client type-check.
Live UI verification
On
5ca3fdfa, the Windows Code OSS Agents window was exercised using the actual Claude Agent provider and Claude Haiku 5.5 with live model traffic, not replay.pnpm run build-fastconfirmed the complete client and extension outputs were current. Three scenarios passed:isResume=truefor the original SDK conversation.This was one Windows live session, not exhaustive platform/model testing or a replacement for deterministic race tests. No policy or source changes were made, and the isolated app/profile/workspace were cleaned up. The earlier full-suite/environment issues and outstanding platform-validation limits below are unchanged.
Review and validation limits
b52e4b40, covering Windows x64, Linux x64, and macOS ARM64, not x64. Those runs show repeatability at that revision; they do not validate the final correction. No new Azure runs were queued for this head.EPERMfailures around FNM junctions, and Copilot discovery affected by three machine-policy hooks. Passing focused retries and CI did not erase or explain those failures. They remain separate investigations; no skips, timeouts, policy controls, or expected-failure assertions were weakened to obtain green output.main@29aacc7f; it has not been rebased onto current main. Any update to the base requires validation of the changed inputs. No tracking issue was supplied.Ready for human review of this bounded cancellation/reliability change. Human approval and required checks remain necessary; the validation limits above are not waived. Broader architecture simplification remains a separate PR.