Skip to content

Defer nimsuggest instance init out of MCP initialize handler - #408

Closed
ZoomRmc wants to merge 1 commit into
nim-lang:masterfrom
ZoomRmc:zdeferinit
Closed

ZoomRmc wants to merge 1 commit into
nim-lang:masterfrom
ZoomRmc:zdeferinit

Conversation

@ZoomRmc

@ZoomRmc ZoomRmc commented May 15, 2026

Copy link
Copy Markdown
Contributor

The MCP initialize handler previously awaited initNimsuggestInstances before returning a response. This can be slow or hang (running nimble dump, starting nimsuggest processes). With some harnesses time-outs (30 second for OpenCode), a delayed initialize response causes the MCP connection to fail entirely, before any tool can be used.

MCP protocol expects the server to respond to initialize promptly, then handle the notifications/initialized message. Heavy initialization should happen after the handshake.

Fix: replace await with asyncSpawn so the initialize response is sent immediately and nimsuggest startup proceeds in the background.

The MCP `initialize` handler previously awaited `initNimsuggestInstances`
before returning a response. This can be slow or hang (running `nimble dump`,
starting nimsuggest processes). With some harnesses time-outs (30 second for
OpenCode), a delayed initialize response causes the MCP connection to fail
entirely, before any tool can be used.

MCP protocol expects the server to respond to `initialize` promptly,
then handle the `notifications/initialized` message.
Heavy initialization should happen after the handshake.

Fix: replace `await` with `asyncSpawn` so the initialize response is sent
immediately and nimsuggest startup proceeds in the background.
@ZoomRmc

ZoomRmc commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@moigagoo pinging per your request, though there's just 16 open PRs ATM.

This and my other 3 PRs arose when used with OpenCode but since May I moved to another harness and haven't worked much on Nim code, unfortunately. So reproducing this now might be harder, depending on how both projects evolved since then.

All 4 PRs are LLM-assisted (I was a bit annoyed and wanted fast results dealing with a foreign codebase) but are small and focused so hope it's not too much trouble.

@moigagoo

Copy link
Copy Markdown
Collaborator

This PR seems to be a duplicate of #416 , which is merged. This other PR also tried using asyncSpawn first but be cause asyncSpawn means "fire and forget," you lose control over concurrently spawned nimsuggest instances.

The idea to not block while nimsuggest is starting up is spot on and it has been implemented in that PR.

@moigagoo moigagoo closed this Aug 31, 2026
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