helix-gpt icon indicating copy to clipboard operation
helix-gpt copied to clipboard

[BUG] failed to initialize language server: request 0 timed out

Open xaverhimmelsbach opened this issue 1 year ago • 35 comments

device info Apple M2 Pro

helix-editor version helix 23.10 (1d1806c8)

helix-gpt version 0.31

Describe the bug The initialization request from Helix times out when opening a file for which helix-gpt is configured to run. helix-gpt waits in src/models/lsp.ts in line 207 for Chunks from. Bun.stdin.stream() but nothing ever arrives. I checked this by logging the chunkText.

If I start helix-gpt manually with

echo "Hello Helix-GPT" | bun run /Users/xaver.himmelsbach/Development/helix-gpt/src/app.ts --logFile /Users/xaver.himmelsbach/gpt.log

the input is read from stdin:

APP 2024-03-19T16:45:21.209Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:45:21.213Z --> Hello Helix-GPT

APP 2024-03-19T16:45:21.214Z --> failed to parse line:| failed to parse | Hello Helix-GPT

helix-gpt logs Most of the time, helix-gpt justs prints the triggerCharacters and receives nothing more. Sometimes, when repeatedly executing :lsp-restart in Helix, an initialization request comes through, but that still doesn't seem to be handled correctly.

These logs show the request showing up after repeatedly calling :lsp-restart:

APP 2024-03-19T16:48:07.090Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:49:41.674Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:50:33.410Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:51:46.195Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:51:49.266Z --> Content-Length: 2016

{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}

APP 2024-03-19T16:51:49.267Z --> received request: | {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}

APP 2024-03-19T16:51:49.267Z --> sent request | {"jsonrpc":"2.0","method":"initialize","id":0,"result":{"capabilities":{"codeActionProvider":true,"executeCommandProvider":{"commands":["resolveDiagnostics","generateDocs","improveCode","refactorFromComment","writeTest"]},"completionProvider":{"resolveProvider":false,"triggerCharacters":["{","("," "]},"textDocumentSync":{"change":1,"openClose":true}}}}

APP 2024-03-19T16:51:49.311Z --> triggerCharacters: | ["{","("," "]

helix logs Helix seems to send the initialization request and times out after 10 seconds (default LSP timeout). Increasing the timeout in languages.toml just led to longer waiting times.

2024-03-19T17:50:33.362 helix_lsp::transport [INFO] gpt -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}
2024-03-19T17:50:53.365 helix_lsp [ERROR] failed to initialize language server: request 0 timed out

xaverhimmelsbach avatar Mar 19 '24 16:03 xaverhimmelsbach

I face the same issue

My helix logs also shows

helix_lsp [ERROR] failed to initialize language server: request 0 timed out

I tried both using bun, and built my own executable using bun build. Same results for both.

My config (with the path edited and api key redacted):

[language-server.gpt]
command = "bun"
args = ["run", "/path/to/helix-gpt", "--handler", "copilot", "--copilotApiKey", "redacted"]

[[language]]
name = "go"
language-servers = [
  "gopls",
  "gpt"
]

nkobber avatar Mar 22 '24 11:03 nkobber

I am getting the same issue on NixOS using Codeium.

justinlovinger avatar Mar 28 '24 23:03 justinlovinger

I resolved this issue by going back to version 0.28. It seems 0.31 is simply broken.

justinlovinger avatar Mar 29 '24 11:03 justinlovinger

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

sigmaSd avatar Mar 29 '24 16:03 sigmaSd

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

Thanks @sigmaSd. I got it working using deno and your fork.

nkobber avatar Mar 29 '24 18:03 nkobber

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

Works flawlessly, thank you so much! I'm closing this issue for now, hopefully bun will fix this error. Otherwise @sigmaSd have you thought about opening a PR for deno support?

xaverhimmelsbach avatar Mar 29 '24 21:03 xaverhimmelsbach

I opened a PR already https://github.com/leona/helix-gpt/pull/45 but then I thought maybe its too many changes and its better kept as a fork, obviously if @leona is interested I can reopen it

sigmaSd avatar Mar 29 '24 22:03 sigmaSd

I narrowed the issue down to between Bun version 1.0.29, exclusive, and 1.0.35, inclusive.

justinlovinger avatar Mar 29 '24 23:03 justinlovinger

I think this issue should stay open for visibility while there's no warning on the README Thank you @sigmaSd

EDIT: what are version 0.30 and 0.31? there's no release logs and no changes in files as far as I can see

EDIT2: @justinlovinger

I resolved this issue by going back to version 0.28. I had no luck running 0.28 either, not sure what I'm doing wrong at this point.

adriangalilea avatar Mar 31 '24 16:03 adriangalilea

0.28 broken for me either

pheepa avatar Apr 01 '24 10:04 pheepa

[language-server.gpt]
command = "deno"
args = ["run", "--allow-env", "--allow-net",  "/usr/local/bin/helix-gpt-0.31.js",
 "--logFile",  "/Users/f.abapoov/gpt.log", "--handler", "copilot"]

Am I doing it right? deno installed with brew but nothing works

pheepa avatar Apr 01 '24 10:04 pheepa

@pheepa

  • are you using my fork ? https://github.com/sigmaSd/helix-gpt
  • run the same command on the cli to see if there is an error or not
  • also side note it would be better to report deno issue on the fork

sigmaSd avatar Apr 01 '24 10:04 sigmaSd

I was not sure how to do it, did not find releases in your fork

I can just clone repo and refer to src/app.ts instead of /usr/local/bin/helix-gpt-0.31.js?

pheepa avatar Apr 01 '24 11:04 pheepa

Yes or if you want to use the easiest way you can just deno run url_to_app.js for example deno run --allow-net --allow-env https://raw.githubusercontent.com/sigmaSd/helix-gpt/421f4ef14a7d23d102bfec3cba24899cbbeda682/src/app.ts will run the current latest commit on my fork

sigmaSd avatar Apr 01 '24 11:04 sigmaSd

I updated the usage instruction to make it simpler

**Usage:**

The fork have tags that follows upstream but with `-deno` suffix, for example `0.31-deno`

To run with deno


deno run --allow-env --allow-net https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts  --handler codeium` # make sure to use the latest deno tag


To compile to a standalone executable


deno compile --output helix-gpt --no-check --allow-env --allow-net https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts # make sure to use the latest deno tag

sigmaSd avatar Apr 01 '24 12:04 sigmaSd

@sigmaSd

Thanks, but, what do I put on the languages.toml with your fork then?

adriangalilea avatar Apr 01 '24 13:04 adriangalilea

[language-server.gpt]
command = "deno"
args = ["run", "--allow-net","--allow-env", "https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts"]
# HANDLER can be set to openai/copilot/codeium
environment = { HANDLER= "codeium" }

sigmaSd avatar Apr 01 '24 15:04 sigmaSd

Managed to make it work, thank you, it doesn't feel right to be executing a remote file with --allow-net tho, any thoughts on that?

adriangalilea avatar Apr 02 '24 07:04 adriangalilea

I just cloned and refered to helix-gpt/src/app.ts, everything works

pheepa avatar Apr 02 '24 12:04 pheepa

Managed to make it work, thank you, it doesn't feel right to be executing a remote file with --allow-net tho, any thoughts on that?

My arguments

  • bun gives all permissions, so any improvement is welcome
  • the remote module is cached locally by deno on first access
  • the net permission is needed to speak with the ai apis (codeium/openai ,etc)
  • there is no read or write permission!, only net and env, I can't imagine you can do many things with it

tldr deno only uses net and env permission but no read/write/ffi/run, I think this is secure

sigmaSd avatar Apr 02 '24 12:04 sigmaSd

  • the remote module is cached locally by deno on first access

I guess it'll eventually retrieve it again, right?

  • the net permission is needed to speak with the ai apis (codeium/openai ,etc)

I personally did this for copilot: --allow-net=api.github.com,copilot-proxy.githubusercontent.com,api.githubcopilot.com

  • there is no read or write permission!, only net and env, I can't imagine you can do many things with it

Well, you never know, just check the xz drama lately.

tldr deno only uses net and env permission but no read/write/ffi/run, I think this is secure

Just to be sure I did:

deno compile --output helix-gpt --no-check --allow-env --allow-net=api.github.com,copilot-proxy.githubusercontent.com,api.githubcopilot.com https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts

Then move that to /bin sudo mv helix-gpt /usr/local/bin/helix-gpt

And then on languages.toml

[language-server.gpt]
command = "helix-gpt"
environment = { HANDLER= "copilot", COPILOT_API_KEY="***"}

So with this approach I'm not executing a remote file and only has the net permission for what it needs.

Out of curiosity, is it easy to see what changes on your fork from main somehow?

Regardless, thank you again.

adriangalilea avatar Apr 02 '24 12:04 adriangalilea

https://github.com/leona/helix-gpt/compare/master...sigmaSd:helix-gpt:deno

sigmaSd avatar Apr 02 '24 13:04 sigmaSd

Hi, this is such an awesome project. Makes helix so much better. The nix package is also giving me this issue. Would be great if @leona could give an idea of whether we should use the fork or if there is another option. The fork with deno is working for me in the interim.

stephenstubbs avatar Apr 14 '24 14:04 stephenstubbs

Hi, this is such an awesome project. Makes helix so much better. The nix package is also giving me this issue. Would be great if @leona could give an idea of whether we should use the fork or if there is another option. The fork with deno is working for me in the interim.

For Nixpkgs, you can pin bun to a working version. This is what I did using Flakes,

helix-gpt = nixpkgs-unstable.legacyPackages.${system}.helix-gpt.override {
  bun = inputs.nixpkgs-working-bun.legacyPackages.${system}.bun;
};

where inputs.nixpkgs-working-bun is nixpkgs-working-bun.url = "github:nixos/nixpkgs/9e58aca561e18f5197029926db8dbde1738a2ff5";. You can do the similar without Flakes if you are not using them.

justinlovinger avatar Apr 14 '24 19:04 justinlovinger

@justinlovinger You're a lifesaver!

sbrow avatar May 23 '24 19:05 sbrow

Isn't there any workaround for this? where can I find more info about the bug on bun?

3ynm avatar May 24 '24 20:05 3ynm

What version of bun should I use then?

neel04 avatar Aug 11 '24 15:08 neel04

I'm having a similar issue but with I am using the precompiled release rather than running the js file with bun. Does this still apply ?

iokoli91 avatar Oct 08 '24 10:10 iokoli91

It seems to be a MacOS specific problem. I am running a Mac Studio with 15.0.1 (24A348) and Bun 1.1.33 and the language server times out.

On the Ubuntu Machine with 24.04.1 LTS and the same Bun version 1.1.33 it works.

gobijan avatar Oct 26 '24 14:10 gobijan

I'm having same issue with wsl/ubuntu and precompiled version.

seobaeksol avatar Oct 30 '24 08:10 seobaeksol