cloudaxe-opencode/packages/opencode
Kit Langton 69f7182f05 fix: bound LSP diagnostic enrichment in write/edit/apply_patch (#22872)
Issue #22872 reports the write tool hanging indefinitely after a file
is written. Two underlying causes, both in the post-write LSP
enrichment path:

1. LSPClient.create wraps the `initialize` request in a 45s
   withTimeout. If the spawned LSP process is wedged (happens with
   pyright under certain conditions), every write that matches that
   LSP blocks the tool for up to 45s even though the file is on disk.

2. Server.spawn for npm-distributed LSPs (pyright, tsserver,
   biome, ...) calls Npm.which, which internally uses arborist.reify
   with no timeout. In sandboxed containers with no network access
   this promise never resolves — the write tool hangs forever.

Fix applied at three layers of defense:

- write.ts / edit.ts / apply_patch.ts: wrap the touchFile +
  diagnostics tail in a 5s Effect.timeout with catch-to-empty.
  Diagnostics are a best-effort enrichment; they must not block the
  tool's return after the file is already written.
- lsp.ts schedule(): bound server.spawn with a 10s Promise.race
  timeout. On timeout the server is added to s.broken so subsequent
  touches short-circuit instantly instead of re-racing.
- client.ts: lower the `initialize` withTimeout from 45_000 to
  10_000. If a server hasn't responded to initialize in 10s it's
  wedged; 45s was punishing for no benefit.

Reproducer tests (added in earlier commits on this branch) now pass:
- write-lsp-hang.test.ts  (branch A, 45s initialize timeout)
- write-lsp-spawn-hang.test.ts  (branch B, forever Npm.which)
Both complete in ~5s.

Full opencode test suite: 1934 pass, 0 fail.
2026-04-16 17:36:04 -04:00
..
bin
migration chore: generate 2026-04-13 18:02:12 +00:00
script move useful scripts to script folder 2026-04-16 10:09:14 -04:00
specs refactor: unwrap BashArity namespace to flat exports + self-reexport (#22874) 2026-04-16 15:24:24 -04:00
src fix: bound LSP diagnostic enrichment in write/edit/apply_patch (#22872) 2026-04-16 17:36:04 -04:00
test fix: bound LSP diagnostic enrichment in write/edit/apply_patch (#22872) 2026-04-16 17:36:04 -04:00
.gitignore CLI perf: reduce deps (#22652) 2026-04-16 02:03:03 -04:00
AGENTS.md perf: make vcs init non-blocking by forking git branch resolution (#22771) 2026-04-16 03:02:19 -04:00
BUN_SHELL_MIGRATION_PLAN.md sync 2026-02-25 01:48:10 -05:00
bunfig.toml tui plugins (#19347) 2026-03-27 15:00:26 +01:00
Dockerfile
drizzle.config.ts
git feat: interactive update flow for non-patch releases (#18662) 2026-03-22 23:12:40 +00:00
package.json chore: bump ai sdk deps for opus 4.7 (#22869) 2026-04-16 13:28:20 -05:00
parsers-config.ts feat(tui): add syntax highlighting for kotlin, hcl, lua, toml (#18198) 2026-03-23 16:15:24 +01:00
README.md
sst-env.d.ts
tsconfig.json CLI perf: reduce deps (#22652) 2026-04-16 02:03:03 -04:00

js

To install dependencies:

bun install

To run:

bun run index.ts

This project was created using bun init in bun v1.2.12. Bun is a fast all-in-one JavaScript runtime.