refactor(coding-agent): await the spawn event instead of a startup sleep - #1744
Closed
snimu wants to merge 6 commits into
Closed
refactor(coding-agent): await the spawn event instead of a startup sleep#1744snimu wants to merge 6 commits into
snimu wants to merge 6 commits into
Conversation
This was referenced Aug 27, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
RpcClient.start()guessed process readiness by sleeping 100ms and then sampling the exit code — a timer standing in for a real signal. Children that died at 150ms were "ready"; healthy children paid 100ms for nothing (audit: timeouts as synchronization, timeouts.md finding 6).The fix
The sleep and exit-code sampling are deleted.
start()awaits the child's OSspawnevent (node:events.once) — the readiness signal the child actually emits. Pre-spawn errors surface through the recorded transport error with the existing message format; fast post-spawn exits surface on first use via the stdout-close handler with captured stderr — strictly more honest than the old sample. +14/−6.How it's verified
Reviewer traced both failure orderings (error-before-spawn, exit-after-spawn), confirmed
events.oncecleans its listeners on both paths with no missed-event race, and validated the new fake-timer test is meaningful (old code hangs under fake timers, new code resolves). Focused RPC suites green; full CI-style failures match the stack base exactly (dist-build extras pass after building). Two-model implement/review loop, approved first pass.Stacked on #1743 (test the whole stack at the leaf; merge base-first).
Note: intentionally no Linear ticket for this cleanup stack, so that check stays red.
Note
Low Risk
Local change to RPC client startup synchronization with clearer event-driven readiness; no auth or data-handling impact, with a small behavior change for very fast child exits after spawn.
Overview
RpcClient.start() no longer waits 100ms or throws when
exitCodeis already set right after that delay. Startup readiness now awaits the child process"spawn"event viaoncefromnode:events, so healthy clients avoid a fixed latency and failures before spawn still surface through the existing transport error path.Behavior shift: immediate post-start exit is no longer detected inside
start(); a child that dies quickly after spawn is treated as started until stdout closes or the first RPC use fails. A changelog note and a fake-timer test lock in thatstart()completes from spawn without relying on timers (the old sleep would hang under fake timers).Reviewed by Cursor Bugbot for commit fd62101. Bugbot is set up for automated code reviews on this repo. Configure here.
Linear ticket: ENG-5662
(ticket linked above)
Note
Await child process
spawnevent instead of fixed 100ms sleep inRpcClient.startRemoves the hard-coded 100ms startup delay in rpc-client.ts.
RpcClient.start()now waits for the child's"spawn"event viaonce(child, "spawn")and rethrows a storedtransportErrorif one occurs. Adds a test confirmingstartresolves from the spawn signal without timer reliance.start()no longer throws immediately on a non-nullexitCoderight after startup; it rejects only if an"error"event fires before spawn.Macroscope summarized fd62101.