Skip to content

Fix Agent switch stuck on Connecting after transport retirement - #883

Merged
Kai Tao (vanzue) merged 1 commit into
mainfrom
dev/vanzue/fix-agent-switch-rebind-race
Sep 7, 2026
Merged

Fix Agent switch stuck on Connecting after transport retirement#883
Kai Tao (vanzue) merged 1 commit into
mainfrom
dev/vanzue/fix-agent-switch-rebind-race

Conversation

@vanzue

Copy link
Copy Markdown
Contributor

Summary

Fix Agent switching getting stuck on Connecting when the old helper ACP transport emits both AgentTransportRetired and AgentReconnectReady.

The first event starts target preflight. The second previously consumed Preflighting via std::mem::take() and left the state Idle, causing the valid preflight result to be discarded as stale. Restore non-Disconnecting states 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

  • Reproduce Copilot to OpenCode switching with AgentTransportRetired -> AgentReconnectReady -> AgentReconnectPreflightComplete.
  • Assert the pending target survives the second notification and successful preflight queues ACP startup.

Validation

  • Agent rebind test group: 7 passed.
  • Full Windows-target WTA suite: 2053 passed, 0 failed, 1 ignored.
  • cargo fmt --manifest-path tools\wta\Cargo.toml -- --check
  • Debug WTA built with the explicit x86_64-pc-windows-msvc target, copied into the dev package, and opened for manual testing. Manual switch results have not yet been reported.

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
Copilot AI lite review requested due to automatic review settings September 7, 2026 09:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 AgentReconnectState when begin_pending_agent_reconnect_preflight is called while already Preflighting (or otherwise not Disconnecting).
  • 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.

Comment thread tools/wta/src/app_tests.rs
@vanzue
Kai Tao (vanzue) merged commit de2dba8 into main Sep 7, 2026
11 checks passed
@vanzue
Kai Tao (vanzue) deleted the dev/vanzue/fix-agent-switch-rebind-race branch September 7, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants