Skip to content

feat(acp): Add agent switcher to ACP CLI#84

Merged
CSRessel merged 2 commits into
devfrom
claude/add-acp-model-switcher-01EgmWtzHtKFKwF2voyAYhJA
Dec 9, 2025
Merged

feat(acp): Add agent switcher to ACP CLI#84
CSRessel merged 2 commits into
devfrom
claude/add-acp-model-switcher-01EgmWtzHtKFKwF2voyAYhJA

Conversation

@CSRessel
Copy link
Copy Markdown
Collaborator

@CSRessel CSRessel commented Dec 9, 2025

Implements agent/model switching for ACP mode:

  • Add /agent slash command to open agent picker popup
  • Add agent_picker component in nori/ with SelectionViewParams
  • Track pending agent selection - switch happens on next prompt submission
  • Modify /model to show disabled options in ACP mode with redirect to /agent
  • Add list_available_agents() and AcpAgentInfo to ACP registry
  • Add AppEvent variants for SetPendingAgent, ClearPendingAgent, SubmitWithAgentSwitch
  • Add ACP file tracing initialization to TUI
  • Add E2E tests for agent switching behavior

claude and others added 2 commits December 9, 2025 01:32
…lection

Implements agent/model switching for ACP mode:
- Add /agent slash command to open agent picker popup
- Add agent_picker component in nori/ with SelectionViewParams
- Track pending agent selection - switch happens on next prompt submission
- Modify /model to show disabled options in ACP mode with redirect to /agent
- Add list_available_agents() and AcpAgentInfo to ACP registry
- Add AppEvent variants for SetPendingAgent, ClearPendingAgent, SubmitWithAgentSwitch
- Add ACP file tracing initialization to TUI
- Add E2E tests for agent switching behavior
When switching agents, events from the OLD agent could leak into the NEW
widget before SessionConfigured was received, causing the UI to show
responses from the wrong agent.

Fix:
- Add expected_model field to ChatWidgetInit to specify expected model
- Add session_configured_received flag to ChatWidget
- Filter events in handle_codex_event() until SessionConfigured arrives
  with matching model name

Also:
- Add E2E tests for agent switch message flow
- Remove unused ClearPendingAgent event and has_pending_agent method
- Fix clippy warnings for dead code
🤖 Generated with [Nori](https://nori.ai)

Co-Authored-By: Nori <contact@tilework.tech>
@CSRessel
Copy link
Copy Markdown
Collaborator Author

CSRessel commented Dec 9, 2025

Bugfix: Race Condition During Agent Switching

This commit fixes the race condition bug where switching from mock agent to real agent (claude/gemini) caused no model response until ESC was pressed.

Root Cause

When switching agents, both the OLD and NEW agents share the same app_event_tx channel. The OLD agent may still be processing/shutting down when the NEW agent starts up, causing events from the OLD agent to leak into the NEW widget before SessionConfigured was received.

Fix

Added event filtering mechanism to ChatWidget:

  • expected_model: Option<String> in ChatWidgetInit specifies which model the widget expects
  • session_configured_received: bool tracks whether SessionConfigured has arrived
  • handle_codex_event() filters events when expected_model is set:
    • All events ignored until SessionConfigured arrives
    • SessionConfigured only accepted if model name matches (case-insensitive)
    • Once matching event arrives, normal event processing resumes

Changes

  • tui/src/chatwidget.rs - Core event filtering logic
  • tui/src/app.rs - Pass expected_model during agent switch
  • tui/src/app_backtrack.rs - Set expected_model: None for backtrack
  • tui-pty-e2e/tests/agent_switching.rs - New E2E tests for event isolation
  • Cleanup: Removed unused ClearPendingAgent event and has_pending_agent method
  • Fixed clippy warnings for dead code

Testing

  • Added test_agent_switch_message_flow_mock_to_mock_alt E2E test
  • Added test_agent_switch_logs_correct_sequence E2E test
  • All 14 agent_switching tests pass
  • Full workspace clippy check passes

@CSRessel CSRessel merged commit 7c67079 into dev Dec 9, 2025
1 of 3 checks passed
@CSRessel CSRessel deleted the claude/add-acp-model-switcher-01EgmWtzHtKFKwF2voyAYhJA branch December 9, 2025 19:49
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.

2 participants