agentHost: preserve Claude tool state across steering results - #336752
Aleksandr Logunov (Longarithm) wants to merge 3 commits into
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
|
There was a problem hiding this comment.
🟡 Changes recommended
Result handling has a queue-state race and lacks cleanup when an intermediate result is followed by abort or failure.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Preserves Claude tool and subagent state across intermediate steering results while filtering internal diagnostics.
Changes:
- Propagates intermediate-result state through the queue, pipeline, and router.
- Defers pending tool/subagent cleanup until the final result.
- Adds regression coverage for steering and diagnostic filtering.
File summaries
| File | Description |
|---|---|
claudePromptQueue.ts |
Detects prompts remaining after the current head. |
claudeSdkPipeline.ts |
Classifies intermediate results. |
claudeSdkMessageRouter.ts |
Forwards result classification. |
claudeMapSessionEvents.ts |
Preserves state and filters diagnostics. |
claudePromptQueue.test.ts |
Tests queue classification. |
claudeMapSessionEvents.test.ts |
Tests filtering and final cleanup. |
claudeAgent.test.ts |
Tests steering with foreground subagents. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@microsoft-github-policy-service agree |
…tate Keep result classification, queue settlement, mapped signals and completion in one synchronous operation. Clear foreground mapper state on abort, failure and disposal. Cover microtask steering and recovery after interrupted results. Make multi-turn SDK tests wait for prompt consumption rather than incidental microtask ordering.
There was a problem hiding this comment.
🟢 Approval recommended
The prior cleanup and race issues are addressed with focused regression coverage, and no unresolved correctness issues were found.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Balanced
|

Problem
A steering prompt can cause an intermediate Claude SDK
resultwhile the protocol turn is still running. The pipeline delaysChatTurnCompleteuntil the prompt queue drains, but the mapper clears pending tool calls and foreground subagent spawns on every result. Later tool results then lose their pending state. The SDK's[ede_diagnostic]entry can also appear as a user-facing error.Change
Related work
Related to #330785, which also filters the diagnostic and proposes separate protocol turns for steering. This PR retains same-turn steering behavior and fixes pending-state cleanup independently.
Validation
Regression tests failed before the corresponding fixes and now pass:
363 tests pass across
claudeAgent,claudePromptQueue,claudeMapSessionEvents,claudeSdkMessageRouter, andclaudeSdkPipeline. Three existing multi-turn tests now wait for the fake SDK to consume the next prompt before returning its result, rather than depending on microtask timing.Targeted TypeScript checking of changed files and their imports, and repository hygiene/formatting/ESLint on all changed files, pass. Validation reused existing dependencies and Electron. No full application build or live SDK/UI reproduction was run for this upstream branch.