Race: late response after timeout → misleading -32601 in protocol-dispatcher.js
In src/mcp/core/protocol-dispatcher.js, if requestFromClient timeout fires (deletes entry + rejects promise) before response arrives, the late response falls through to generic handler → -32601 Method not found on stdout.
Should be silently ignored since caller already got timeout error.
Fix: track settled IDs and early-return. Low impact.
Found during awesome-gemini-cli code review by @toller892.
I verified this against current main at a80e605c7cdef8c33aca5a93ca41e393cf093d05 and added regression coverage in #76.
The reported race does not reproduce for valid JSON-RPC response frames:
- timeout removes the pending request entry before rejecting: https://github.com/josstei/maestro-orchestrate/blob/a80e605c7cdef8c33aca5a93ca41e393cf093d05/src/mcp/core/protocol-dispatcher.js#L113-L115
- a late response with the same
idthen cannot settle because the pending entry is gone: https://github.com/josstei/maestro-orchestrate/blob/a80e605c7cdef8c33aca5a93ca41e393cf093d05/src/mcp/core/protocol-dispatcher.js#L93-L95 respond()returns early for messages without a stringmethod: https://github.com/josstei/maestro-orchestrate/blob/a80e605c7cdef8c33aca5a93ca41e393cf093d05/src/mcp/core/protocol-dispatcher.js#L133-L138- the
-32601 Method not foundbranch is only reached later for request-like frames with a stringmethod: https://github.com/josstei/maestro-orchestrate/blob/a80e605c7cdef8c33aca5a93ca41e393cf093d05/src/mcp/core/protocol-dispatcher.js#L236-L247
#76 adds regression tests for both valid late response forms:
- late
{ id, result }after timeout emits no additional stdout frame - late
{ id, error }after timeout emits no additional stdout frame
Validation:
node --test tests/unit/protocol-dispatcher.test.js
31 passed, 0 failed
node --test tests/unit/*.test.js tests/transforms/*.test.js tests/integration/*.test.js
1089 passed, 0 failed
The only way I found to produce -32601 after timeout is with a malformed hybrid frame that includes a response payload and a request method, for example:
{ "jsonrpc": "2.0", "id": "server-1", "method": "roots/list", "result": { "roots": [] } }
That is treated as an incoming request-like frame with an unknown method. A valid JSON-RPC response should not include method.
Recommendation: close this as not reproducible unless there is an actual wire frame showing a valid late response producing -32601.