Repository navigation
Conversation
In readLoginShellPath(), parsing output inside child.once('exit') races with Node's stdout pipe flush: 'exit' can fire before the final stdout chunk carrying __PIBOT_PATH_END__ is delivered, silently returning undefined and dropping the user's login-shell PATH.
Extract collectLoginShellPath() to wait for buffered stdout chunks/end/close after exit 0 when the closing marker has not yet arrived, while still resolving immediately once both exit 0 and the closing marker are observed so detached shell helpers (e.g. gitstatusd) holding stdout open do not stall until timeout. Also enforce idempotent settlement, release listeners and destroy stdout on early completion, and add offline Vitest coverage.
Signed-off-by: Yue Arc <135290367+yuearc@users.noreply.github.com>
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 and why
Cause
readLoginShellPath()inapps/desktop/src/main/brain/login-shell-path.tspreviously parsedoutputsynchronously insidechild.once("exit"). In Node.js,"exit"can fire as soon as the child process terminates, beforechild.stdoutfinishes emitting its last buffered"data"chunk. When the closing marker (__PIBOT_PATH_END__) arrives in a trailing chunk after"exit", the regex match fails and the function silently returnsundefined(login_shell_path_unavailable).Changes
collectLoginShellPath()(keepingreadLoginShellPath(platform, env)unchanged) with an idempotent settlement state machine:exit === 0and__PIBOT_PATH_END__has already been buffered, parse and resolve immediately (preserving fast return when detached shell helpers such asgitstatusdinherit and holdstdoutopen).exit === 0arrives before the closing marker, continue waiting for remainingstdout"data"/"end"/"close"events (bounded byTIMEOUT_MS).childandstdoutevent listeners on settlement and destroystdoutif settled before stream end.maxOutputoverflow kills the process group and settles at most once.apps/desktop/src/main/brain/login-shell-path.test.tsreproducing theexit-before-stdoutrace (including a closing marker split across chunks), immediate resolution with an unclosed helper pipe, marker-less drain,maxOutputsingle-kill settlement, andwin32no-op.Local verification
biome@2.5.15 checkon both files: passed (0 diagnostics).typescript@7.0.2(strict,noUncheckedIndexedAccess,verbatimModuleSyntax,declaration: true) against@types/node@26.6.4andvitest@5.0.3: passed.vitest@5.0.3 runonlogin-shell-path.test.ts: 5/5 passed.node tools/dev/run-as-node-check.ts: passed.readLoginShellPath(process.platform, process.env)on macOS/bin/zsh.Checks
pnpm verifypasses locally (CI runspnpm checkon macOS, Windows and Linux; ran targeted Biome, TypeScript 7 strict declaration check, and Vitest 5 locally).envfiles or local pathsgit commit -s, see CONTRIBUTING.md)