Repository navigation
fix(rust-lsp): bring the spawn client in line with the lifecycle spec - #102
Conversation
The Rust spawn client had no initialize bound, did not notice a server exit, never read stderr, took no cancel for a start, and shut down with no bounds. It now follows design spec sections 5.3 to 5.5 and 8 the way the TypeScript client does, with the same error codes and messages. - The start runs in its own task, bounded by DEFAULT_INITIALIZE_TIMEOUT_MS (the 60s session backstop, overridable through SpawnLspClientOptions). The call budget covers the start: a slow start returns TIMEOUT and goes on, a later call gets server_starting, and a start that fails after its call gave up is reported once as SERVER_NOT_AVAILABLE. - A process watcher fails every waiting call at once when the server exits, with the exit code or signal and the stderr tail. A ready server that exits while idle is replaced by the next call. A broken stdin, or a stdout that closes while the process lives, retires the server. - stderr is always drained; the last 4 KB is kept. - LspSessionConfig gains a cancel signal and ensure_server takes one. A call cancelled before it started starts nothing. - close_session stops servers in parallel with bounded steps: shutdown, exit, SIGTERM, SIGKILL, and waits for each process. Writes go through one writer task, so nothing is cut off midway or written after the pipe is gone. LspClient methods return LspClientError instead of String, which breaks the public API: harness-lsp goes to 0.3.0 and harness-tools to 0.6.0. The new tests run the TypeScript fake server, so both ports run the same cases. The 15 tests that use only main's API all fail on main. Closes #100
There was a problem hiding this comment.
This is an auto review done by revuto.
The rewrite follows the TypeScript lifecycle closely. Two steps that run in a single turn in TypeScript (one synchronous run of the event loop) can interleave under Rust's multi-threaded tokio runtime:
ensure_serverchecks for an existing entry and inserts the new one under two separate locks, with the spawn (fork/exec) in between. Two parallel first calls for the same language and root both spawn a server. The losing server ends up in neitherserversnorstops, soclose_sessionnever stops it. That breaks the PR's own promise that every server is stopped.- The start task checks
running()outside the status lock, then setsReady. If the process exits in that window, the entry staysReadyafter the exit. From then on, every call for that key returnsSERVER_CRASHEDand no new server is ever started.
| if *cancel.borrow() { | ||
| return Err(LspClientError::Aborted); | ||
| } | ||
|
|
||
| let entry = self.spawn_server(language, root, profile)?; | ||
| self.servers.lock().unwrap().insert(key, Arc::clone(&entry)); |
There was a problem hiding this comment.
This is an auto review done by revuto.
Race: two parallel first calls can each spawn a server, and one process leaks.
The servers lock is dropped at line 1128 and taken again here. spawn_server runs in between, and it forks and execs. On a multi-threaded runtime, two lsp calls for the same (language, root) can both find no entry, and both spawn a server. An agent sending parallel tool calls on first use, say a hover and a definition together, is the obvious trigger. Then:
- The losing process leaks. The second
insertoverwrites the first entry. That entry is now in neitherserversnorstops, soclose_sessionnever stops its process.watch_processowns theChildand holds anArcto the entry until the process exits, sokill_on_dropnever fires. On main the losingArc<ServerEntry>owned theChildand was dropped after the call, which killed it. - The first caller gets the wrong server. Its
hoverlooks the server up withentry_for(handle), which returns the second entry. That entry is stillStarting, so the call fails withIO_ERROR"not ready (state=starting)".
TypeScript doesn't hit this because servers.get … servers.set runs in one synchronous turn.
Fix: keep the servers StdMutex held from the lookup through the insert. spawn_server is synchronous, so that works. Or, after spawning, re-check under the lock and drop or kill the loser.
There was a problem hiding this comment.
Fixed in a0d0701. ensure_server now holds the servers lock from the lookup through spawn_server, the insert and start, so concurrent first calls on one key share one server and every spawned process is in the map. New test: 8 tasks behind a barrier call lsp hover on one key, 10 rounds, then close_session. It checks one spawned pid per round and none alive afterwards. On ddacdb3 it fails in round 0 with IO_ERROR "not ready (state=starting)"; now it passes, and so does a 16-task, 50-round stress run.
| Ok(()) if !entry.running() => Err(entry.wait_gone().await), | ||
| Ok(()) => Ok(()), | ||
| }, | ||
| }; | ||
| match &result { | ||
| Ok(()) => { | ||
| let mut st = entry.status.lock().unwrap(); | ||
| if st.state == EntryState::Starting { | ||
| st.state = EntryState::Ready; |
There was a problem hiding this comment.
This is an auto review done by revuto.
Race: an exit right after the handshake can leave the entry Ready for good.
Line 1000 checks entry.running(), and lines 1006–1008 later take the status lock to set Ready. In watch_process, the watcher sets exited (line 604) and then, under the status lock, changes the state only if it is Ready (lines 606–609). Possible interleaving:
- The start sees
running() == true. - The watcher sets
exited, findsStarting, and leaves it alone. - The start sets
Ready.
The entry is now Ready with the process dead. fire_gone marks it gone 100ms later, but nothing ever sets it to Crashed: retire/stop are never started for it, and write_failed only waits for the gone reason. From then on ensure_server keeps returning this entry (its state is not Crashed), and ready_entry returns the gone reason. So every later call fails with SERVER_CRASHED "The next call starts it again.", which stops being true. The window is narrow, but once hit it lasts until close_session.
Fix: check running() again after setting Ready, while still holding the status lock, and mark the entry Crashed if the process has exited. Since the watcher sets exited before it takes that lock, one of the two sides is then sure to see the other.
There was a problem hiding this comment.
Fixed in a0d0701. The start sets Ready only under the status lock, in the same step as the liveness check; a dead process fails the start with its exit instead. The watcher flips exited before it takes that lock, so one side always sees the other. New unit test: a server that exits 100ms after initialized, with a test-only 300ms pause between the handshake and the readiness check. The start fails with "exited with code 0" and the next call spawns a new server. With the old check-then-lock order and the same pause, it stays Ready and never re-spawns.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ddacdb3. Configure here.
| let me = Arc::clone(self); | ||
| let handle = tokio::spawn(async move { me.stop().await }); | ||
| self.stops.lock().unwrap().push(handle); | ||
| } |
There was a problem hiding this comment.
close_session can miss in-flight stop
Medium Severity
begin_stop sets stopping and only later pushes the JoinHandle onto stops. close_session treats an already-stopping server as registered and then drains stops. If that drain runs in the gap, the handle is never awaited and close_session returns while the process is still being shut down.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit ddacdb3. Configure here.
There was a problem hiding this comment.
Fixed in a0d0701. begin_stop now holds the stops lock while it marks the server stopping and pushes the handle, so close_session, which drains under that lock, either sees the stop or runs before it begins. It also drops finished stops before pushing, and a unit test checks that four failed starts leave at most one handle.
| ))); | ||
| } | ||
| Ok(entry) | ||
| } |
There was a problem hiding this comment.
In-flight call misses crash replacement
Medium Severity
ready_entry looks up the server by language and root, not the instance ensure_server just handed back. After a ready crash, a concurrent call can insert a replacement while this call is between ensure_server and the operation, so the operation binds to the new Starting server and returns IO_ERROR instead of SERVER_CRASHED.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit ddacdb3. Configure here.
There was a problem hiding this comment.
Not changed in this PR. Both clients look the server up by key, so a call that sits between ensure_server and its operation while another call replaces a crashed server binds to the replacement, which is still starting, and gets IO_ERROR "not ready". Fixing it means carrying an instance id in ServerHandle on both the TS and Rust sides and reporting the old instance's crash. That is a public-type change on both ports, so I would do it as its own change.
|
Verdict: needs changes. Three blocking findings. Two are the ones revuto raised, and I reproduced both. The third is new: dropping the client leaks every server. The rewrite is careful and close to the TS client. The 15 main-compatible tests fail on main and pass here. Each of the 8 API tests and the unit test fails when its fix is undone. The loops were clean. The blockers sit where the tests do not reach: concurrent calls, and cleanup without Blocking1. Parallel first calls spawn several servers, and the extra ones outlive
2. A server that exits right after the handshake can stay
3. Dropping the client without
Please add all three probes as tests. Each fails on this branch today. Not blocking
Parity and concurrency checked
What I ranOwn worktree at ddacdb3. Scratch,
|
… drop Address review on the Rust spawn client. - ensure_server does the lookup, the spawn and the insert in one critical section. Concurrent first calls on one key started several servers, and the overwritten ones were never stopped, not even by close_session. - The start decides readiness under the status lock, together with the liveness check. A server that exited between the check and setting Ready stayed Ready for good, so no call ever re-spawned it. - Dropping the client without close_session sends SIGKILL to each server. The background tasks kept the entries alive, so a dropped client left every server running. - begin_stop drops finished stops, and marks and registers a stop under one lock, so close_session cannot miss a stop that is just beginning. - file_uri_to_path percent-decodes, as the TypeScript client does. - Versions stay at the unpublished 0.2.0 and 0.5.0, one breaking minor over crates.io's 0.1.1 and 0.4.1. - The Rust CI and release jobs set up Node, which the tests need. - Parity tests with the TypeScript suite: stdin breaking during the start, an error reply to initialize plus a late exit of the old process, and one didOpen for concurrent operations on one file.
|
Re #102 (comment): all nine points are in a0d0701.
Each unit-only test (2, 5, 9) fails with its fix undone on this branch. Bugbot's two threads: the stop-registration gap is fixed with point 5, since a stop is now marked and registered under the Reran on a0d0701: |
There was a problem hiding this comment.
This is an auto review done by revuto.
Revuto completed the review and found no evidence-backed concerns.
|
Verdict: needs changes. One blocking finding: the Rust CI job is red on a0d0701, from a timing race in a unit test. The nine points from the last review are fixed. I reproduced the three earlier blockers on ddacdb3, and each one is gone on a0d0701. Blocking1. CI is red:
The last review's points, rechecked
Lock and Drop
Not blocking
What I ranOwn worktrees at a0d0701 and ddacdb3. Scratch,
|
Address re-review on the Rust spawn client. - The exit-write test raced the fake server's 200ms shutdown reply: on a busy runner the reply won and `exit` was written ahead of the filler, which made CI red. It now orders by events. A new fake-server mode, hold-shutdown-reply, answers shutdown only once a marker file exists. The test waits until the server has read shutdown, pushes a pre-built frame onto the writer, then creates the marker. - The readiness test hook waits for the server to exit instead of sleeping. - ensure_server claims a key with a Spawning placeholder under the lock and spawns outside it, so one key still has one server, but a slow exec on one key no longer holds up every other key. A concurrent call that finds the placeholder gets server_starting. A failed spawn drops the placeholder, and a spawn that outlives a closed session is stopped. - On Unix each server runs in its own process group, and SIGTERM, SIGKILL and Drop signal the group, so the server's children stop with it. The fake server gains a -with-child suffix for the tests.
There was a problem hiding this comment.
This is an auto review done by revuto.
Shutdown can return before an outstanding spawn is stopped, and process-group cleanup misses descendants when the server exits first.
| .drain() | ||
| .filter_map(|(_, slot)| match slot { | ||
| Slot::Server(e) => Some(e), | ||
| Slot::Spawning(_) => None, |
There was a problem hiding this comment.
This is an auto review done by revuto.
[P2] Wait for outstanding spawns before completing shutdown. If close_session runs while spawn_server is outside the lock, this branch discards its placeholder and the stop list can be empty, so shutdown returns immediately. The spawn subsequently completes and only then registers retirement at line 1242. A process can therefore start or remain alive after close_session returns, violating the shutdown guarantee in section 5.4. Track spawn completion in the slot and await its resulting cleanup during close.
There was a problem hiding this comment.
Fixed in d5d90ef. The Spawning slot now holds a channel that closes once its spawn is handled: the server is in the map, or its stop has begun. close_session takes these channels with the map and waits on each, up to one stop step (2s), before it waits for the stops. The stop of a spawn that lost its slot is then in the list close_session waits on.
New unit test close_session_waits_for_a_spawn_in_flight: a test-only hook holds one spawn for 500ms, and close_session runs during it. When close_session returns, the spawned server must be gone. With the wait removed, it fails: "close_session returned before the spawn ended".
| tokio::select! { | ||
| s = child.wait() => break s.ok(), | ||
| Some(k) = kills.recv() => match k { | ||
| KillSignal::Term => signal_server(&mut child, false), |
There was a problem hiding this comment.
This is an auto review done by revuto.
[P2] Clean up the process group even when its leader exits first. Group SIGTERM can terminate the server while a descendant ignores it; child.wait() then ends this watcher, and stop() observes the leader's exit and skips SIGKILL. Graceful shutdown skips group signalling entirely: the new well-behaved-with-child fixture explicitly exits on exit, leaving its child's interval running indefinitely after close_session. The new tests cover Drop and a stubborn leader, which miss both paths. Track group cleanup independently of the leader's lifetime.
There was a problem hiding this comment.
Fixed in d5d90ef. Once the watcher reaps the server, it sends SIGKILL to the server's process group. A child still in the group goes too, however the server ended: on exit, on its own, or on a group SIGTERM that the child ignored.
New unit test a_graceful_exit_does_not_leave_the_server_s_children: the server exits on exit and has a child that ignores SIGTERM. After close_session, the child must be gone within 1s. Without the group kill it fails: "the server's child outlived a graceful exit".
|
Re #102 (comment): addressed in 9f806fb. The Rust CI job is green on it (run 41963228710) and ran every spawn-client test: 7 unit tests, 20 in
Reran on 9f806fb:
|
Address the two review findings on 9f806fb, and test flakes under load. - close_session waits, up to one stop step, for each spawn still running outside the lock. The Spawning slot holds a channel that closes once the spawn is handled, so the stop of a spawn that lost its slot is in the list close_session waits on. - Once the watcher reaps a server, it sends SIGKILL to the server's process group. A child that ignored SIGTERM, or outlived a graceful exit, goes with the server. - Two integration tests need the write after the fake server closed its stdin to fail. A server that another test spawned at the same moment could still hold that stdin, as a child that had not exec'd yet, and under load for longer than the start took. Those two tests now run alone; every other test holds the same lock shared. - Tests wait for events instead of fixed pauses: the spawn record of a new server, the end of a start, the reap after kill -9. The TS test with the same spawn-count check polls for it too.
|
d5d90ef addresses revuto's two findings on 9f806fb and three test flakes that showed under load.
The client has the same pipe window: a server that closes its stdin while another server in the process is being spawned can see its next write succeed, and that call ends at its timeout instead of Reran on d5d90ef:
|
|
Ready to land. No blockers. The last two commits fix both revuto findings on 9f806fb. Each new test fails with its fix undone, and the loops were clean. Six follow-ups below. None breaks the spec or a test today. Earlier points, rechecked
Placeholder, close and signals: checked
Follow-ups (not blocking)
What I ranOwn worktrees at d5d90ef. Scratch,
|


Closes #100.
The Rust spawn client (
crates/lsp) now follows the lifecycle inagent-knowledge/design/lsp.mdsections 5.3 to 5.5 and 8, the way the TypeScript client does. Error codes and messages match the TypeScript side.What changed
crates/lsp/src/spawn_client.rsis rewritten around background tasks:initialize, so the start goes on when the caller gives up.run.rsgives one budget, and one cancel signal, to the start and the operation together.1. A bounded start
initializeis bounded byDEFAULT_INITIALIZE_TIMEOUT_MS, the 60s session backstop.SpawnLspClient::with_options(SpawnLspClientOptions { initialize_timeout_ms })overrides it. A server that misses the limit is stopped (SIGTERM, then SIGKILL after 2s).TIMEOUT"... while the fake server was starting. The start goes on in the background; retry.", the server keeps starting, and a later call getsserver_starting.SERVER_NOT_AVAILABLEwith the reason, and the call after that starts fresh.2. A server exit is noticed
SERVER_CRASHED. The message names the exit code or signal and carries the stderr tail.SERVER_NOT_AVAILABLE.LspClientmethods now returnLspClientError(Crashed,Aborted,Other) instead ofString, sorunmaps a crash toSERVER_CRASHEDwithout parsing text.3. stderr
It is always drained, and the crash error keeps its last 4 KB. After an exit, the watcher waits up to 100ms for stderr to reach end of file, so the error carries the server's last words. That only takes the full 100ms when another process inherited the pipe.
4. Cancellation
LspSessionConfiggainssignal: Option<CancelSignal>, the caller's cancel.ensure_servertakes aCancelSignal. A cancel releases the caller only; the start goes on.5. Bounded shutdown (spec 5.4)
close_sessionstops every server in parallel. For each:shutdownraced against the exit (2s), a boundedexitwrite (2s), up to 2s for the exit, then SIGTERM, SIGKILL 2s later, and a wait for the exit.close_sessionreturns only after every server, retired ones included, has been stopped.Tests
The Rust tests use the same fake stdio server as the TypeScript tests (
packages/lsp/test/fixtures/fake-lsp-server.mjs), so both ports run the same cases. They neednodeon PATH, which the CI runner has, and run on Linux only, since they read/proc.tests/spawn_client.rsuses only API that exists on main. These 15 tests fail on main (d0556f9); the tests added in review are under Review changes:TIMEOUT"exceeded 5000ms"SERVER_CRASHED, exit code 1, stderr textSERVER_NOT_AVAILABLE, exit code 3, stderr textTIMEOUT,server_starting, hover, 1 spawnTIMEOUT, thenSERVER_NOT_AVAILABLEwith exit code 3 and stderr, 1 spawn, then a fresh startIO_ERROR"Broken pipe"IO_ERROR"Broken pipe"SERVER_CRASHED"stopped reading its input", then hover from a new server; old one gone after closeTIMEOUT"exceeded 8000ms"SERVER_CRASHED"closed its output"; new server next callclose_session, well-behaved serverexitand is goneclose_session, server dies onshutdownclose_session, server ignoresexitand SIGTERMclose_session, server closed stdin before answeringshutdownclose_sessionTIMEOUT, thenclose_sessionreturnstests/spawn_client_api.rs(8 tests) and one unit test inspawn_client.rsneed the new API (with_options,signal,ensure_server's cancel), so they cannot build on main. Instead, I undid each fix and checked that its test fails:exitwrite unboundedexitensure_serverignores its cancelThe other API tests cover:
Versions
This breaks the public API:
LspClient::ensure_servertakes a cancel signal, everyLspClientmethod returnsLspClientError, andLspSessionConfighas a new public field, which breaks struct literals. So:harness-lspat 0.2.0 (crates.io has 0.1.1);harness-toolscrate at 0.5.0 (crates.io has 0.4.1), since it re-exportsharness-lsp.Both versions were set by #95 and never published, so they stay: one breaking minor over the published crates. Both READMEs pin that minor.
harness-lspnow depends onlibcon Unix, for SIGTERM. The npm packages are unchanged.Spec
Only names change: the spec now says the Rust port exists, and names the Rust equivalents of
initializeTimeoutMsand the crash error classes.Checks
cargo test --workspace --locked: 315 passed, 0 failed.cargo clippy -p harness-lsp --all-targets: no warnings in the files this PR touches. The remaining ones were already on main, informat.rs,manifest.rsandtests/lsp.rs.taskset -c 0. The unit tests passed 25 of 25 runs on two CPUs each shared with a busyyes. No fake server was left after any run.pnpm test:dependencies,pnpm lint:harnessandturbo run build typecheck testwithout harness-e2e: 39 of 39 tasks./tmp.Review changes (a0d0701)
ensure_serverdoes the lookup, the spawn and the insert in one critical section; spawning and starting do not await. Concurrent first calls now share one server, and every spawned process is in the map, soclose_sessionstops it.Ready. The start decides readiness under the status lock, together with the liveness check. The watcher marks the exit before it takes that lock, so whichever side runs second sees the other.Drop for SpawnLspClientsends SIGKILL to each server. The watcher then reaps the process and the background tasks end, which frees the entry.harness-lsp0.2.0 andharness-tools0.5.0. crates.io has 0.1.1 and 0.4.1, so that is still one breaking minor. The READMEs andCargo.lockmatch.begin_stopdrops finished stops. It marks and registers a stop under thestopslock, soclose_sessioncannot miss one that is just beginning.lib.rsand the touched files are rustfmt-clean.ci.ymlandrelease-rust.yml) set up Node with the pinnedactions/setup-nodethe TypeScript job uses.initializegets an error reply, and the old process exits late without touching the re-spawned entry;didOpen.file_uri_to_pathpercent-decodes, as the TS client does.IO_ERROR"not ready (state=starting)" from an overwritten serverclose_sessioninitialized, 300ms test pause before the readiness checkReady, no re-spawn (with the old check-then-lock order)file:///tmp/a%20b/c%23d.ts/tmp/a%20b/c%23d.ts/tmp/a b/c#d.tsinitializeerror reply plus late exit, onedidOpenThe readiness, stop-list and path tests are unit tests that use test-only access, so each was checked by undoing its fix on this branch: each fails without its fix.
Review changes (9f806fb)
The exit-write test orders by events, not time. It uses a new fake-server mode,
hold-shutdown-reply. That mode writesgot-shutdownwhen it readsshutdown, stops reading, and answers only oncereply-shutdownexists. The test waits forgot-shutdown, pushes a pre-built 4 MiB frame straight onto the writer, and only then createsreply-shutdown, soexitis always queued behind the filler. Under load, on two CPUs each shared with a busyyes, the old test failed 6 of 10 runs. The new unit tests passed 25 of 25 runs, and the integration tests 10 of 10. The test still hangs to its 10s limit if theexitbound is removed.The readiness test orders by events too. The test hook now waits for the server to exit, not for 300ms, before the readiness check. With the old check-then-lock order it fails at once.
The spawn runs outside the
serverslock. The key is claimed under the lock with aSpawningplaceholder, so concurrent first calls still share one server: a call that finds the placeholder getsserver_starting. The spawn then runs unlocked, and the entry is filled in under the lock. If the spawn fails, the placeholder is removed. If the session closed meanwhile, the new server is stopped. New unit test: a test-only hook blocks one key's spawn for 3s. Another key then starts and gets ready within 2s while the slow spawn is still running. On the previous head, with only the hook added, it times out. The 16-task, 50-round concurrency stress still passes.Process groups. On Unix each server starts in its own process group, and SIGTERM, SIGKILL and
Dropsignal the group, so the server's own children stop with it. A new fake-server suffix,-with-child, starts a child that ignores SIGTERM. New unit tests:Drop, the server and its child are gone;exitand SIGTERM, the final SIGKILL takes its child too.With only the leader signalled, both children survive.
Handle rebinding is tracked in lsp: an operation can be bound to a replacement server and get IO_ERROR instead of SERVER_CRASHED #103 as the next change.
On 9f806fb the Rust CI job is green and ran every spawn-client test: 7 unit tests, 20 in
tests/spawn_client.rsand 8 intests/spawn_client_api.rs.Review changes (d5d90ef)
close_sessionwaits for a spawn in flight. TheSpawningslot holds a channel that closes once its spawn is handled: the server is in the map, or its stop has begun.close_sessiontakes these channels with the map and waits on each, up to one stop step, before it waits for the stops. New unit test: a test-only hook holds one spawn for 500ms whileclose_sessionruns, and the server must be gone when it returns. Without the wait it fails: "close_session returned before the spawn ended".exit, goes too. New unit test: the server exits onexit, its child ignores SIGTERM, and the child must be gone within 1s ofclose_session. Without the group kill it fails: "the server's child outlived a graceful exit".a_broken_stdin_...anda_stdin_that_breaks_during_the_start_...failed 5 of 410 runs withTIMEOUT. A new child holds a copy of every pipe end its parent has open until it execs. So a server that another test spawned at that moment still held the read end of the test server's stdin, and under load it held it past the start. The write after the server closed its stdin then succeeded, and no reply came. In a failing run, the fake server scanned/procright after it closed its stdin and found that reader: a child of the test binary, not yet exec'd, named after another test's thread. These two tests now take a lock that every other test in the binary holds shared.past_startcalls until the result is no longerserver_starting), or the reap afterkill -9. The TypeScript test with the same spawn-count check now polls for it.Under the same load, after these changes:
tests/spawn_client.rspassed 400 of 400 runs andtests/spawn_client_api.rs200 of 200 (two copies).The client has the same pipe window. A server that closes its stdin while another server in the same process is being spawned can see its next write succeed. That call then ends at its timeout instead of
SERVER_CRASHED.Note
Medium Risk
Large rewrite of child-process I/O and shutdown paths with a breaking public API, though behavior is spec-driven and heavily covered by new integration tests.
Overview
Brings the Rust
harness-lspspawn client in line withagent-knowledge/design/lsp.md(sections 5.3–5.5 and 8), matching the TypeScript client’s lifecycle and error semantics.spawn_client.rsis rebuilt around background tasks: a single writer queue (no mid-message cuts on cancel), process watcher (exit → fail in-flight calls with stderr tail), stderr drain (last 4 KB), stdout reader (pipe loss → retire server), and a backgroundinitializethat can outlive the call that started it.run.rsapplies one timeout/cancel budget to server start plus the operation, distinguishes tool timeout vs session cancel in messages, and mapsLspClientError(Crashed,Aborted,Other) toSERVER_CRASHED,TIMEOUT, andSERVER_NOT_AVAILABLEinstead of string parsing.close_sessionnow does bounded graceful shutdown (shutdown → exit → SIGTERM → SIGKILL).Breaking API:
LspClient::ensure_servertakes a cancel signal; methods returnLspClientError;LspSessionConfigadds optionalsignal; newSpawnLspClientOptions/DEFAULT_INITIALIZE_TIMEOUT_MS. Bumpsharness-lspto 0.3.0 andharness-toolsto 0.6.0; adds Unixlibcfor SIGTERM. Linux integration tests share the TS fake LSP server fixture.Reviewed by Cursor Bugbot for commit ddacdb3. Configure here.