fix(opencode): robust process exit detection for child processes#15757
Open
NachoFLizaur wants to merge 2 commits intoanomalyco:devfrom
Open
fix(opencode): robust process exit detection for child processes#15757NachoFLizaur wants to merge 2 commits intoanomalyco:devfrom
NachoFLizaur wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my searches, I found one potentially related PR: Related PR Found:
All other search results only returned the current PR (#15757) itself. The searches did not find any open PRs that are direct duplicates of this process exit detection fix. PR #13186 is adjacent in addressing process-related issues but focuses on memory leaks and cleanup handlers rather than the specific exit detection problem. |
Contributor
Author
|
fixed description according to template |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
f36ae38 to
9da397e
Compare
This was referenced Mar 3, 2026
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.
Issue for this PR
Closes #14769
Possible related issue that might get fixed by this: #15675 (it seems related based on the description)
Type of change
What does this PR do?
The bash tool and
Process.spawnrely solely on Bun'sproc.once("exit")to detect when a child process finishes. In containerized environments, this event is not reliably delivered (due to Bun), causing the completion promise to hang forever, tool calls get permanently stuck atstatus=running.The fix removes the runtime dependency on Bun for process exit detection, replacing it with a multi-layer strategy that uses OS-level primitives:
closeevent: independent signal path fromexitin Bun's internalsproc.exitCodeandprocess.kill(pid, 0)to detect dead processes via OS-level signals, completely bypassing Bun's event systemprompt.ts): external safety net that force-completes processes stuck past their timeoutAll detection paths funnel through a single
done()function guarded by aresolvedboolean, ensuring exactly-once Promise resolution.Also improves
Shell.killTree()with analive()check before escalating from SIGTERM to SIGKILL.How did you verify your code works?
Polling watchdog isolation tests directly prove exit detection works WITHOUT exit/close events firing (simulates the exact Bun failure mode).
Regression tests verify normal bash tool execution is unaffected by the additional detection layers. Shell.killTree tests verify SIGTERM->alive check->SIGKILL escalation.
I also tested it in containerized opencode serve mode, bash tool calls now complete reliably instead of hanging.
Screenshots / recordings
No UI changes.
Checklist