Skip to content

bug(agent): one MCP call with an unknown result retires the connection and fails every later request #7112

Open

Description

What happened

After one MCP tool call ends with an unknown result, the connection to that server is retired and never reopened in the same Host process. From then on every model request that includes a tool of that server is refused before it is sent, so the current turn, every later turn, and every new conversation using that server fail. The workaround is to restart the Host or change the MCP configuration (a new configuration digest opens a new connection).

A call ends this way when the server process exits during the call, the call exceeds the timeout (120 s by default), the user presses Stop during the call, or the request cannot be sent.

1. The connection is never reopened. uncertain() in plugins/agent/mcp/src/lib.rs sets invalid and closes the connection; available() is false from then on. Connections are opened in three places (Agent activation, a configuration digest that misses the cache in native/src/mcp/projects.rs, and sessionMcp), and none of them checks whether a cached connection is still alive. In the test the server process is started exactly once.

2. The turn fails with a misleading reason. #7043 records the call as unknown, but the next model request is refused by the authorization check in native/src/owner/access/model.rs ("selected tool X MCP connection is unavailable"). That error is a LocalAuthorization, which is deliberately not recorded as a failure, so the attempt has no recovery evidence and the turn ends with:

Recovery is unavailable for adapter supplied no safe interrupted-attempt recovery evidence (version 1).

The real reason is only in the model_interrupted fact: model input preparation failed: source authority changed: selected tool mcp__fixture__crash MCP connection is unavailable. The model never sees the unknown result that #7043 hands back.

3. The next turn and a new conversation fail the same way, before any model request is sent.

4. A remote server also holds the conversation. For a remote connection uncertain() returns CleanupUnconfirmed even when close() succeeded. Custody is not released and the engine writes a ToolCleanupUnconfirmed blocker. In the test the turn is still running after 25 s, shows waiting_for_user with no pending interaction, the next message in that conversation does not start, and Host shutdown reports accepted Root work cleanup is unconfirmed.

By reading only, not tested: in Code Mode (the default) the tool contracts count every catalogue tool as selected, so a conversation would fail even if it never used that server; tools/list_changed also sets invalid.

How to reproduce

Two tests on rust-preview 871e747, both passing today because they assert the behaviour above (direct tool mode, discovery off, servers from the deployment configuration):

  • mcp_server_exit_mid_call_fails_every_later_model_request: a local stdio server; one call succeeds, the next makes the process exit. The same turn, the next turn and a new conversation each send no model request and fail with the text above.
  • mcp_remote_call_timeout_holds_the_session_and_fails_new_sessions: an HTTP server with callTimeoutMs: 500 and a call that never returns.

I can push the branch if useful.

Direction

  1. Reopen a retired connection the next time it is needed (a new protocol session, never a replay of the call).
  2. Do not fail the whole request at the authorization check when a selected MCP tool is unavailable: drop the tool from the request, or keep it and let the call return the existing ToolRejection::Unavailable.
  3. For a remote server whose close() succeeded, return OutcomeUnknown so it follows the fix(agent): hand a tool call with an unknown result back to the model #7043 path and releases the conversation.
  4. Let a LocalAuthorization failure end the turn with its real reason.

@M4n5ter this touches connection ownership and the authorization contract, which are yours. I plan to try 3 and 4 first since they are local; tell me if you would rather take 1 and 2 yourself or want them done differently.

Investigation and text by Claude Code (Claude Fable 5.2, with a Claude Opus 5.5 subagent writing the reproduction).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions