GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: prevent orphaned worker process when killed by jogi47 · Pull Request #11603 · anomalyco/opencode

Conversation

@jogi47

@jogi47 jogi47 commented Feb 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Fixes #11527

When OpenCode is spawned programmatically and then killed, the worker process was left orphaned (PPID becomes 1), blocking the parent process from exiting.

Changes

  • thread.ts: Add SIGTERM/SIGINT handlers to properly shutdown worker before exit
  • worker.ts: Add parent death detection using process.ppid polling (1-second interval)
  • worker.ts: Add SIGTERM/SIGINT handlers for direct signal handling

How it works

  1. Signal handlers in main thread: When SIGTERM or SIGINT is received, the main thread now calls the worker's shutdown RPC before exiting
  2. Parent death detection: Worker polls every 1 second to check if parent is still alive using process.kill(parentPid, 0). If parent dies (even via SIGKILL), worker detects and shuts down
  3. Worker signal handlers: Direct signals to worker are also handled properly

Test plan

  • All 842 existing tests pass
  • Manual verification with reproduction script from issue

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jhult

jhult commented Feb 6, 2026

Copy link
Copy Markdown

I believe this may also resolve #10563.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shjeong92

shjeong92 commented Feb 8, 2026

Copy link
Copy Markdown

Nice work on the ppid polling approach — that's a solid safety net for SIGKILL scenarios.

One gap I noticed: this PR handles SIGTERM and SIGINT but not SIGHUP, which is the actual signal sent when a terminal tab/window is closed. That's the core trigger for #10563 (orphaned processes on terminal close).

The fix for #10563 specifically needs process.on("SIGHUP", ...) in both thread.ts and worker.ts. SIGTERM/SIGINT cover kill <pid> and Ctrl+C, but terminal closure sends SIGHUP.

Additionally, attach.ts (#11225) and serve.ts (headless server mode) have the same problem — no signal handling at all, so they also become orphans on terminal close.

I'm working on a broader fix that covers SIGHUP across all long-running entry points (tui, attach, serve) plus a safety net in index.ts. Happy to coordinate if useful.

jhult reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 8, 2026
fix(cli): handle SIGHUP to prevent orphaned processes on terminal close #12718
Closed
fix: add signal handlers to prevent orphaned processes #12877
Closed
fix: resolve memory leaks and zombie processes from missing cleanup handlers #13186
Closed
This was referenced Feb 16, 2026
fix(tui): add signal handlers to prevent orphaned processes on terminal close #13848
Closed
fix(opencode): run tui worker shutdown on signal/terminal-exit paths #14238
Closed
fix: add SIGHUP/SIGTERM/SIGPIPE handlers to prevent orphaned processes #14505
Closed
@jogi47 @claude
fix: prevent orphaned worker process when killed
7a5a9bd
When OpenCode is spawned programmatically and then killed, the worker
process was left orphaned (PPID becomes 1), blocking the parent process
from exiting.

Changes:
- Add SIGTERM/SIGINT handlers in thread.ts to properly shutdown worker
- Add parent death detection in worker.ts using process.ppid polling
- Add SIGTERM/SIGINT handlers in worker.ts for direct signal handling

The worker now detects if its parent dies (even via SIGKILL) and shuts
itself down within 1 second.

Fixes anomalyco#11527

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jogi47
jogi47 force-pushed the fix/orphaned-worker-process-11527 branch from c61fd2a to 7a5a9bd Compare February 23, 2026 16:42
@jogi47

jogi47 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated this PR and it is ready for another look.

  • Rebasing: rebased onto current dev and resolved conflicts
  • Signal handling: added SIGHUP handling in tui/thread.ts and tui/worker.ts
  • Coverage gap from prior feedback: added terminal-close signal handling to tui/attach.ts and serve.ts
  • Existing behavior retained: worker shutdown RPC is now reused across TUI exit and signal paths

Could someone re-review when convenient?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions

github-actions Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

OpenCode leaves an orphaned process when it itself is killed

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jogi47 @jhult @shjeong92
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.