[Bug] LSP client resolves a pending request when the server sends its own request with the same id
Description
handleMessage treats any message with an id as the response to one of our requests. Language servers also send requests of their own (for example workspace/configuration or client/registerCapability) with their own ids. If an id matches one of our pending ids, our request is resolved with an empty result and the server never gets an answer.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at f92cce9c)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create
new LSPClient({name: 'x', command: 'x', languages: ['ts']}). - Add a pending request with id 1 (method
textDocument/formatting) toclient.pendingRequests. - Feed it this frame with
handleData:{"jsonrpc":"2.0","id":1,"method":"workspace/configuration","params":{"items":[{"section":"python"}]}}
Expected Behavior
The message is recognised as a server request (it has a method). The client replies to the server, for example with an empty result, and our formatting request stays pending.
Actual Behavior
Our formatting request is resolved with undefined. The server gets no reply.
Logs/Screenshots
our formatting request got: [["resolved", undefined]]
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/lsp/lsp-client.ts:589-591(handleMessage): check formethodfirst. If a message has bothidandmethod, send a response to the server and do not touchpendingRequests.- Add a test with a colliding id, and one that a normal response still resolves.
Related: #1515 / PR #1700 (LSP crash handling), #1301 (framing).
Hi, I'd like to work on this issue. I'll start by adding regression tests for the colliding server-request ID and for a normal response, then update the message handling so server-initiated requests don't resolve our pending requests.