#1142

Device WebSocket drop leaves in-flight tunnel MCP calls hanging for the full 120 s timeout

Openaryanranderiyaopened 3mo ago

Symptom

When a paired device's WebSocket drops while a tunnel MCP tool call is in flight, the call does not fail — it hangs until MCP_SESSION_CALL_TIMEOUT_SECONDS (120 s, apps/api/app/constants/device_bridge.py:71) expires. For the user that is a two-minute frozen tool call before the agent sees an error, on every call that was open at the moment the laptop closed its lid / lost Wi-Fi.

Where

apps/api/app/services/mcp/device_connector.py

  • _drain_inbox (≈L140) only learns about the device through frames arriving in the session inbox: mcp.opened, mcp.error, mcp.msg. A transport drop produces no frame, so inbox.get() just keeps waiting.
  • The device's disconnect is observed elsewhere — the bridge WebSocket handler / connection_manager.py — but nothing there fans out to the open MCP sessions for that device_id, so their read streams are never failed.
  • The 120 s read timeout on ClientSession (L124–128) is the only thing that eventually unblocks the caller.

Expected

On device disconnect, every open session for that device should get DeviceConnectionError("device tunnel closed") on its read stream immediately (the same path _drain_inbox already uses when its own loop ends), so in-flight calls fail within milliseconds and the agent can tell the user the device went away.

Notes

  • Observed while running tests/integration/real/test_device_bridge_e2e.py under load on the self-hosted CI box (pairing round-trip calls sat for the full timeout after the fake device was torn down); the analysis above is from reading the code — the exact fan-out point has not been implemented or tested yet.
  • Related: #1143 (a local MCP server dying after mcp.opened is not reported as mcp.error by the CLI bridge) — same user-visible symptom from the other side of the tunnel.
  • A regression test belongs in the bridge e2e: open a session, drop the device WebSocket mid-call, assert the call fails in < 1 s with DeviceConnectionError.

Activity

0

No activity yet.