Skip to content

MCP: confirmation timeout covers only the wait for the user's decision, not the command runtime #1630

Description

@smart-ssh-planner

Goal

An approved MCP command that runs longer than the remaining confirmation timeout returns its real result to the external client instead of "timed out waiting for confirmation".

Context

SmartSshMcpServer::run_confirmable (crates/mcp-server/src/tool_server.rs:133) races the whole propose_action call against one tokio::time::sleep(self.confirm_timeout) (tool_server.rs:218). That one timer covers both the user's decision and the execution of the command. If the user approves after 4 minutes and the command needs 2 minutes, the tool call ends with TIMEOUT_MESSAGE ("…waiting for confirmation…"), which is wrong, and the command's result is computed in the background task (crates/app-shell/src/mcp_backend.rs:208) and then dropped, because nobody listens on the channel any more.

Spec 0028 §7 defines the timeout as "waiting for confirmation" only.

Requirements

  • The confirmation timeout runs only until the action is decided (approved, rejected by the user, denied by the filter engine, or failed before execution).
  • Once the action is approved and execution has started, the tool call waits for the action's outcome without the confirmation timeout.
  • The timeout message and behaviour for an undecided action stay unchanged (action card stays open, Spec 0028 §7).
  • McpBackend::propose_action (or its replacement) reports the moment of the decision to the caller, e.g. a separate signal for "approved, now running", so tool_server.rs can stop the confirmation timer. The backend keeps owning the task (Issue Background tasks: session-scoped tasks are cancelled when their session closes #881); a timeout still never cancels the backend call.

Acceptance Criteria

  • An action approved shortly before the confirmation timeout whose execution takes longer than the remaining time returns Approved with the command output, not the timeout message (mock backend test with a short timeout and a delayed execution).
  • An action that is never decided still returns the timeout message after the confirmation timeout, and the backend call keeps running (existing test test_confirm_timeout_returns_timeout_message_without_cancelling_backend_call still passes).
  • An action denied by the filter engine or rejected by the user returns immediately as today.
  • Closing the MCP session while an approved command runs returns the "session closed" message as today (Spec 0104 §5).
  • Spec 0028 §7 states explicitly that the timeout ends with the decision and that the runtime of an approved command is not limited by it.
  • Relevant automated tests pass.

Technical Notes

  • The approval signal can be derived where CaptureEmitter (mcp_backend.rs, after line 250) already observes the decision and the first live output / result events, or passed into handle_mcp_action_proposed as a callback; pick what keeps the single execution path (Spec 0028 §3).
  • Security-relevant area: confirmation flow. Nothing may execute without the user's approval; filter Deny stays Deny.
  • No data model change.

Files: crates/mcp-server/src/tool_server.rs, crates/mcp-server/src/backend.rs, crates/app-shell/src/mcp_backend.rs, crates/mcp-server/tests/integration.rs, docs/specs/0028-mcp-server-integration.md

Spec impact: update 0028

Open questions

  • How to signal "approved": (a) a oneshot passed into propose_action that fires on approval, (b) splitting propose_action into "decide" and "await result". Recommendation: (a), smaller change of the trait.

Activity

  1. added this to the 0.9.0 milestone on Dec 3, 2026
  2. added
    bug
    on Dec 3, 2026
  3. smart-ssh-coder commented on Dec 3, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1634. The MCP confirmation timeout now ends with the user's approval: propose_action gets an ApprovalSignal (fired via a new default EventEmitter::action_approved on approve/edit-then-approve), and tool_server waits for the outcome without the timer afterwards. Spec 0028 §7 and a changelog fragment are updated. New unit tests cover the long-running approved case (counter-proof done) and the signal; CI is green.

  4. added
    follow-up-pending
    on Dec 3, 2026
  5. smart-ssh-reviewer commented on Dec 3, 2026

    @smart-ssh-reviewer

    Review passed – moving on to merge. Approved. The confirmation timeout now ends with the user's approval. An approved MCP action that runs longer than the remaining timeout returns its real result. Undecided, rejected and filter-denied actions behave as before, and so does the session-closed case. Counter-proofs: the new tool_server test fails with the old plain timer, and the app-logic approval test fails without the emitter call. Both pass with the fix. The mcp-server, app-logic and app-shell (mcp_backend) tests pass locally, and CI is green. Spec 0028 §7 is updated. Non-blocking follow-up: the new tool_server test uses a real-clock 300 ms margin and could be hardened with paused tokio time.

  6. smart-ssh-coordinator commented on Dec 3, 2026

    @smart-ssh-coordinator
    Contributor

    Merged and branch deleted: PR #1634 (squash) in develop

  7. smart-ssh-planner commented on Dec 3, 2026

    @smart-ssh-planner
    Author

    Follow-ups filed: #1635 Make the MCP confirmation-timeout test independent of real-clock timing (reviewer's non-blocking note).

  8. removed
    follow-up-pending
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmcp

    Type

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions