Skip to content

Stopping an Agent Mode run can silently discard queued ACP steering #867

Description

@baron

Impact

Stopping an active ACP Agent Mode run can silently discard steering text that the UI already accepted but that is still queued behind active MCP tools. Claude steering is restored to the composer on ordinary user stop; ACP steering is cleared without restoration.

Affected snapshot

Confirmed statically on origin/main at a094dd9a83d03820201769ebc079c49fbd2e86fc.

Reachable scenario

  1. Run an ACP-backed Agent Mode session.
  2. Submit steering while an MCP tool is active, so the ACP flush task waits for MCP idle with the steering still in pendingACPSteeringInstructions.
  3. Stop the run before delivery.
  4. Cancellation clears the ACP queue and token queue; the draft is neither delivered nor restored to the composer.

Because the cancellation and flush paths are MainActor-isolated, the cancelled flush cannot requeue the draft before cancelRun clears it.

A focused test can block awaitNoActiveMCPTools, enqueue ACP steering, invoke .userStop, and assert that the exact undelivered text is restored once.

Evidence

  • ACP steering waits for MCP idle at Sources/RepoPrompt/Features/AgentMode/Runtime/AgentModeRunService.swift:340-354.
  • cancelRun cancels both flush tasks at AgentModeRunService.swift:930-936.
  • For .userStop, only restoreAllQueuedClaudeSteeringDrafts is called at AgentModeRunService.swift:938-948.
  • The method then unconditionally clears pendingACPSteeringInstructions and pending input tokens at AgentModeRunService.swift:950-960.
  • The execution-location-change path already has a combined restoration helper, demonstrating the intended lossless behavior for undelivered drafts.

Expected behavior

Accepted but undelivered user text must be either delivered or restored exactly once. Stopping a run must not silently erase it.

Suggested direction

Restore queued ACP drafts alongside Claude drafts for .userStop, using the existing coalescing/order rules and reconciling pending token-queue entries. Preserve the distinction between undelivered steering and the already-delivered active prompt.

Acceptance criteria

  • User stop restores all undelivered ACP steering exactly once and in order.
  • Already-delivered steering is not replayed.
  • Pending token accounting is reconciled with restored/coalesced drafts.
  • Tests cover cancellation while waiting for MCP idle, after dequeue but before send completion, and ordinary successful delivery.

Validation status

Static source review only; no provider run was started.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agent-modeAgent Mode runtime and interfacebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions