fix(core): report process exit before stdio close#29476
Conversation
|
The following comment was made by an LLM, it may be inaccurate: I found a highly related PR: PR #29108: fix(core): resolve spawn on exit not close to avoid bg-child hang This PR appears to be addressing the same underlying issue - preventing background child process hangs by completing on the The other results (PRs #29378, #29340) are related to stdio flushing/draining but address different contexts (export/CLI exit) rather than the core spawn behavior. |
|
Verified against #29108 in an isolated worktree: it covers the same root cause and the full shell tool test suite passes there. Closing this duplicate to avoid splitting review across two PRs.\n\nThe only extra coverage I had here was a core-level regression for handle.exitCode resolving before inherited stdout closes; maintainers can lift that idea if useful. |
Issue for this PR
Closes #29294
Type of change
What does this PR do?
The cross-spawn process handle used
closeto completeexitCode/isRunning/kill. If a command exited while a detached descendant still held the stdout pipe open,closecould be delayed indefinitely and the shell tool stayedrunning.This changes the process signal to complete on the child
exitevent, withcloseonly kept as a fallback if it fires first. The shell tool now waits for its output reader to drain after exit, but only for a short bounded window, so normal output is preserved while inherited pipes can no longer wedge the tool forever.How did you verify your code works?
TDD check:
PATH="$HOME/.bun/bin:$PATH" bun test test/effect/cross-spawn-spawner.test.ts -t "returns exit code before inherited stdout pipe closes"failed by timing out after 5000ms.From
packages/core:PATH="$HOME/.bun/bin:$PATH" bun test test/effect/cross-spawn-spawner.test.ts- 25 pass, 0 failPATH="$HOME/.bun/bin:$PATH" bun typecheck- passedFrom
packages/opencode:PATH="$HOME/.bun/bin:$PATH" bun test test/tool/shell.test.ts -t "returns when command exits before inherited stdout closes"- passedPATH="$HOME/.bun/bin:$PATH" bun test test/tool/shell.test.ts- 24 pass, 0 failPATH="$HOME/.bun/bin:$PATH" bun typecheck- passedFrom the repo root:
PATH="$HOME/.bun/bin:$PATH" bunx prettier --check packages/core/src/cross-spawn-spawner.ts packages/core/test/effect/cross-spawn-spawner.test.ts packages/opencode/src/tool/shell.ts packages/opencode/test/tool/shell.test.ts- passedgit diff --check- passedPATH="$HOME/.bun/bin:$PATH" .husky/pre-push- failed in unrelated@opencode-ai/console-supporttypecheck because local dependencies/generated files are missing (@solidjs/*,solid-js/jsx-runtime,vite, and generated@opencode-ai/console-core/*schema modules).@opencode-ai/core:typecheckandopencode:typecheckcompleted before that failure.Screenshots / recordings
Not a UI rendering change.
Checklist