Skip to content

feat: allow per-server request/init timeout overrides - #5

Merged
code-yeongyu merged 2 commits into
code-yeongyu:mainfrom
mixxer:feat/per-server-timeout-overrides
Sep 24, 2026
Merged

code-yeongyu merged 2 commits into
code-yeongyu:mainfrom
mixxer:feat/per-server-timeout-overrides

Conversation

@mixxer

@mixxer mixxer commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Some LSP servers (e.g. kotlin-language-server on a multi-module Gradle project) take far longer to answer initialize or individual requests than the global defaults (60s / 15s) allow, causing spurious timeouts even though the server would eventually respond.
  • Adds optional requestTimeoutMs / initTimeoutMs fields to a server entry in .pi/lsp-client.json / ~/.pi/lsp-client.json, so a slow server can be given more headroom without changing the defaults for every other server.
  • Global defaults (REQUEST_TIMEOUT_MS = 15s, INIT_TIMEOUT_MS = 60s) are unchanged; overrides are opt-in per server and fall back to the defaults when omitted.

Changes

  • src/lsp/types.ts: add requestTimeoutMs? / initTimeoutMs? to LspServerConfig / ResolvedServer.
  • src/lsp/config-loader.ts: parse the two new fields from LspEntry into the resolved server config.
  • src/lsp/transport.ts: sendRequest now uses this.server.requestTimeoutMs ?? REQUEST_TIMEOUT_MS.
  • src/lsp/manager.ts: track initTimeoutMs per managed client so the idle reaper and warmup path respect an override instead of the fixed manager-wide value.
  • README.md: document the new fields with a kotlin-language-server example.

Test plan

  • npm run check (tsgo + biome) passes
  • npm test passes: 81/81 (77 existing + 4 new)
    • test/manager.test.ts: override longer/shorter than manager default, reaper behavior in each case
    • test/transport.test.ts: new UnresponsiveHarness covers default timeout and a longer override not firing early

Summary by cubic

Allows per-server overrides for request and init timeouts so slow LSP servers (e.g. kotlin-language-server on a large multi-module Gradle project) don't spuriously time out against the global 15s/60s defaults.

  • Adds optional requestTimeoutMs / initTimeoutMs fields to a server entry in .pi/lsp-client.json / ~/.pi/lsp-client.json; only finite positive numbers are accepted, anything else is ignored.
  • Fixes propagation so the overrides reach the transport's request timeout and the manager's init reaper and warmup paths.
  • Overrides fall back to the global defaults when omitted; the defaults stay unchanged.

Written for commit 77738ec. Summary will update on new commits.

Review in cubic

Some LSP servers (e.g. kotlin-language-server on a multi-module Gradle
project) take far longer to answer `initialize` or individual requests
than the global defaults (60s / 15s) allow for, causing spurious
timeouts even though the server would have responded given more time.

Add optional `requestTimeoutMs` and `initTimeoutMs` fields to server
entries in `.pi/lsp-client.json` / `~/.pi/lsp-client.json`, so a slow
server can be given more headroom without changing the defaults for
every other server.
@mixxer

mixxer commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@code-yeongyu, I referenced this repository during the LSP configuration on my Pi agent. In the process, I needed to modify the timeout parameter; I am submitting a pull request that refactors this value into a configurable variable. Thank you for your work.

@code-yeongyu code-yeongyu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this - per-server timeouts are a good fit, and the manager and transport changes plus the reaper tests look right. I reviewed it against the head commit (da398a6) and found three problems. Because maintainer edits are enabled, I'm pushing a follow-up commit to this branch rather than asking you for another round:

  1. src/lsp/server-resolution.ts:13-20: findServerForExtension() rebuilds the ResolvedServer field by field and doesn't copy requestTimeoutMs or initTimeoutMs. Every LSP tool acquires its server through this function, so neither override ever reaches LspManager.getClient() or LspClientTransport.sendRequest() in practice. The new manager and transport tests pass only because they construct the server directly. Fix: carry both fields through, plus a test that goes from a config file to findServerForExtension().
  2. src/lsp/config-loader.ts:87-88: the values are passed through without validation. With 0, a negative number, or a string like "90000", setTimeout fires almost immediately (Node clamps non-positive or non-numeric delays to 1ms), so every request would time out at once. Fix: accept only finite positive numbers and ignore anything else, so the default applies.
  3. README.md:174-175: the example adds // comments inside the config block, but loadJsonFile() (src/lsp/config-loader.ts:40) uses plain JSON.parse and silently returns null on a parse error. A user who copies the example would lose the entire project config without any error. Fix: remove the comments, label the block json, and document the validation rule.

Not blocking: /lsp warmup (src/index.ts:283-297) still resolves ids only from the builtin list, so it ignores custom servers and their overrides. That is issue #4, and I'm fixing it separately in the dependency refresh PR.

findServerForExtension() dropped requestTimeoutMs/initTimeoutMs, so the
overrides never reached the manager or transport on the tool path.
Accept only finite positive numbers from config and drop comments from
the README example because the config file is parsed as plain JSON.
@code-yeongyu

Copy link
Copy Markdown
Owner

CI on 77738ec: both node 22 cells pass (ubuntu, macos). The two node 20 cells fail with webidl.util.markAsUncloneable is not a function, which comes from the undici copy bundled with @earendil-works/pi-coding-agent. That package requires node >=22.19, and main has failed the same way since June. The dependency refresh PR drops node 20 from the matrix. Merging with squash.

@code-yeongyu

Copy link
Copy Markdown
Owner

Correction: this repository allows only merge commits (squash is disabled), and the required checks still list the node 20 cells that fail on main for the reason above. I'm merging with a merge commit and an admin override for those two pre-existing failures. Your commit keeps your authorship.

@code-yeongyu
code-yeongyu merged commit cd19411 into code-yeongyu:main Sep 24, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants