nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] LSP client resolves a pending request when the server sends its own request with the same id

Open addyCooks opened this issue 2 weeks ago • 1 comments

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

  1. Create new LSPClient({name: 'x', command: 'x', languages: ['ts']}).
  2. Add a pending request with id 1 (method textDocument/formatting) to client.pendingRequests.
  3. 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 for method first. If a message has both id and method, send a response to the server and do not touch pendingRequests.
  • Add a test with a colliding id, and one that a normal response still resolves.

Related: #1515 / PR #1700 (LSP crash handling), #1301 (framing).

addyCooks avatar Nov 14 '26 06:11 addyCooks

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.

anshikagrover15 avatar Nov 14 '26 07:11 anshikagrover15