Fix Agent switch stuck on Connecting after transport retirement - #883
Merged
Merged
Conversation
Preserve the in-flight preflight state when transport retirement and reconnect-ready notifications arrive for the same agent rebind. Add regression coverage for Copilot to OpenCode switching without changing cancellation retirement barriers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: df937457-6f9d-4a02-a8bf-fca6697e63a5
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The core state-machine fix is small, targeted, and backed by a regression test; only a minor test maintainability nit was identified.
Pull request overview
This PR fixes an agent-switching regression in WTA where duplicate transport-retirement notifications (AgentTransportRetired followed by AgentReconnectReady) could inadvertently cancel an in-flight reconnect preflight, leaving the UI stuck on “Connecting”. The change ensures non-Disconnecting reconnect states survive duplicate completion notifications so the valid preflight result is still accepted.
Changes:
- Preserve
AgentReconnectStatewhenbegin_pending_agent_reconnect_preflightis called while alreadyPreflighting(or otherwise notDisconnecting). - Add a unit test that reproduces the duplicate-notification sequence and asserts the target preflight still triggers ACP startup.
File summaries
| File | Description |
|---|---|
| tools/wta/src/app.rs | Adjusts reconnect-preflight initiation to restore non-Disconnecting reconnect states instead of accidentally resetting to Idle. |
| tools/wta/src/app_tests.rs | Adds regression coverage for duplicate retirement notifications to ensure preflight completion is still honored. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
haonanttt
approved these changes
Sep 7, 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
Fix Agent switching getting stuck on Connecting when the old helper ACP transport emits both
AgentTransportRetiredandAgentReconnectReady.The first event starts target preflight. The second previously consumed
Preflightingviastd::mem::take()and left the stateIdle, causing the valid preflight result to be discarded as stale. Restore non-Disconnectingstates unchanged so duplicate completion notifications cannot cancel an in-flight preflight.This addresses the regression introduced by #832 while preserving its transport retirement and cancellation cleanup barriers.
Regression coverage
AgentTransportRetired->AgentReconnectReady->AgentReconnectPreflightComplete.Validation
cargo fmt --manifest-path tools\wta\Cargo.toml -- --checkx86_64-pc-windows-msvctarget, copied into the dev package, and opened for manual testing. Manual switch results have not yet been reported.