Skip to content

Skip the permission prompt for an fx mcp call whose client left - #2303

Open
fazxes wants to merge 3 commits into
mainfrom
fazxes/skip-prompt-for-gone-mcp-call
Open

fazxes wants to merge 3 commits into
mainfrom
fazxes/skip-prompt-for-gone-mcp-call

Conversation

@fazxes

@fazxes fazxes commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A fx mcp call whose command exits or is killed while it waits for the permission prompt lock no longer opens a prompt.
  • A prompt that is already open when its command leaves still stays until it is answered, and its answer still runs nothing. That rule does not change.

Why

The bridge runs one permission prompt at a time (bridge.prompt). A second call waits for that lock behind the first call's open prompt. When the second call's command left during that wait, the core withdrew the request, but after the lock the bridge still called authorize. So the person saw a prompt for a command that no longer existed. Nothing ran after the answer, because the core frees the slot of a withdrawn request, so this was a confusing prompt, not a safety problem.

Fix

  • mcp_call.awaitingPermission(state, id), a read-only query on the core: true only while the request is in its authorizing stage.
  • In serve, after the prompt lock, the bridge checks it under bridge.mutex and skips authorize for a withdrawn request. The core then frees the slot with no reply, since no client is left to read one.
  • The withdraw trace now says that nothing runs and that only a prompt that is already open stays, since a queued request no longer opens one.
  • Two test counters on the bridge (admitted, withdrawn) signal the bridge condition, in the same way as request_polls, so the test waits on signals and not on sleeps.

Tests

  • New bridge test, "a request that leaves while it waits for the prompt lock opens no prompt": call A holds the prompt lock on a gate, call B waits for the lock, B's client closes, then A's gate opens.
    • Without the fix: expected 1, found 2 permission checks (B's check ran).
    • With the fix: passes 3 of 3 runs. A's reply is ok, and B's tool never runs.
  • New core test for awaitingPermission.
  • Focused mcp_call_bridge and mcp_call tests: 45 pass. Full zig build test: exit 0.
  • bun test mcp-stdio.test.ts -t "fx mcp call": 25 pass, 0 fail.
  • sh tests/tla/mcp_call/check.sh: pass. That covers the model check, spec to code (49,406 of 49,406 transitions), code to spec (313 traces), and 18 of 18 spec and code mutations.

Not covered

  • tests/tla/mcp_call/ models the core, not the bridge's prompt lock, so TLC does not check this rule. The core's transitions are unchanged.
  • A command that leaves after the check and before authorize opens its prompt still gets the prompt. The existing rule then keeps it until it is answered. Closing that window would hold bridge.mutex for the whole prompt.

Ship check

bin/check lists four findings:

  • tests/tla/mcp_call/ (model-covered): see "Not covered" above.
  • tests/tla/mcp_host/ (model-covered): its SubagentAccess spec models which bridged calls may run, not when a prompt opens. This change only turns a prompt for a withdrawn request into a deny, so a bridged call runs less, never more, and that model does not change.
  • agents_menu_selection and mcp_call_error_text (fuzz-reached): both reach this code only through imports. Neither calls serve or awaitingPermission. ReleaseSafe rounds of agents_menu_selection (20,000 inputs) and mcp_call_error_text (150,000 inputs) passed on the merged head.

One permission prompt runs at a time, so a call can wait for the prompt
lock behind another call's open prompt. When its command exited or was
killed during that wait, the core withdrew the request, but the bridge
still ran the permission check once it got the lock. The person then
saw a prompt for a command that was gone, and nothing ran after the
answer.

The bridge now asks the core, after it takes the prompt lock, whether
the request still waits for its check, and skips the check when it
does not. A prompt that is already open when its client leaves still
stays until it is answered, as before.
@fazxes fazxes added the type: bug Fixes incorrect behavior label Nov 25, 2026
awaitingPermission now finds the request with slotOf, the core's one slot search. The trace for a withdrawn request no longer says its prompt stays until answered, which a queued request no longer opens: nothing runs, and only a prompt that is already open stays.
@fazxes
fazxes marked this pull request as ready for review November 25, 2026 07:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Fixes incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant