Repository navigation
Description
Summary
The process-cleanup module unconditionally registers uncaughtException and unhandledRejection handlers on the host Node process whenever any CleanupManager is created (src/features/background-agent/process-cleanup.ts, function registerManagerForCleanup). On any unhandled error/rejection these handlers call scheduleForcedExit(handler(error), 1, true) → process.exit(1), terminating the entire opencode process.
After PR #3639 (which I appreciate is intentional for users actively running background agents), this kills opencode for users who load the plugin but don't use background agents. Transient streaming errors from upstream LLM endpoints — e.g. SocketError { code: 'UND_ERR_SOCKET' } from undici when api.githubcopilot.com resets a long stream — surface as unhandled rejections in opencode's session.processor Effect runtime and trip these global handlers, exiting the app mid-response. This happens repeatedly on flaky networks/proxies and gives users a "opencode just dies after every response" experience.
This is distinct from #3731 (re-entrant log loop) — that fix prevents log spam during cleanup, but the forced exit on every transient unhandled rejection remains.
Reproduction
- Install
oh-my-openagent(current^4.0.0) into an opencode config dir, list it underplugininopencode.json. - Configure a
github-copilot/*model (or any provider with occasional transient socket resets). - Send a long streaming prompt over a flaky connection (corporate proxy, hotspot, etc.) so undici sees a mid-stream socket reset.
- opencode receives an
AI_APICallError { cause: SocketError UND_ERR_SOCKET }. The error propagates as an unhandled rejection. The plugin's listener fires and callsprocess.exit(1). The entire opencode process exits — the desktop window closes, the CLI returns to the shell prompt — even when the user never invoked any background-agent functionality.
The same applies to any unhandled rejection in opencode itself or any other plugin: the moment one bubbles up uncaught, the host dies.
Why I think this should be opt-in
The process-cleanup machinery is conceptually tied to the background-agent feature (src/features/background-agent/process-cleanup.ts), but registerManagerForCleanup is called unconditionally whenever a CleanupManager is constructed. A user who installs the plugin only for the multi-agent presets / model fallback / LSP tools effectively has no opt-out from the global handlers, and gets none of the benefit of background-agent forced cleanup either.
Suggested fix
One of:
- Feature-gate the global handler registration behind whatever flag enables background agents (config option, command-line flag, or only register when the first background-agent task is actually started rather than at plugin load).
- Provide an explicit opt-out env var like
OMO_DISABLE_PROCESS_CLEANUP=1that short-circuitsregisterManagerForCleanup(and document it in the troubleshooting README). - Default to
process.exitCode = 1(noprocess.exit) so the process exits naturally only when the event loop drains, and let opencode's own error handling decide whether to recover, log, and continue. The forced exit can still be opt-in for the bg-agent users who depend on it.
(1) seems cleanest. (2) is the lowest-risk near-term mitigation for impacted users.
Environment
oh-my-openagent4.0.0 (also reproduced on 3.17.14)opencode1.14.41 (Electron desktop) and 1.14.39 (npm CLI)- macOS 15.x, Node 24.x
- Provider:
github-copilot
Code references
- Listener registration:
src/features/background-agent/process-cleanup.ts—registerManagerForCleanup→cleanupErrorHandlers.set("uncaughtException", registerErrorEvent("uncaughtException", cleanupAll))and the equivalentunhandledRejectionline - Forced exit: same file,
scheduleForcedExitcallingprocess.exit(exitCode)after the cleanup promise resolves
Thanks for the active maintenance here — the recent work on #3639 / #3731 / #3793 shows you're already thinking carefully about this surface, and I'm hopeful a feature gate is a small ergonomic win for users in the unfortunate "loaded but innocent" position.
Activity
ottosulin commentedon May 14, 2026
+1, hit this on opencode Desktop v1.14.50 with
[email protected]and@4.1.2. Sidecar exits silently withcode: 1between 30 sec and ~10 min after server-ready, no stderr in opencode's main.log. The actual error (in my case aDrizzleError: file is not a databasefrom opencode's own session processor, unrelated to the plugin) is logged only to$TMPDIR/oh-my-opencode.log, thenscheduleForcedExit(…, 1, true)→process.exit(1). Removing the plugin fromopencode.jsonmakes the sidecar stay alive indefinitely. Cross-referencing my opencode-side report: anomalyco/opencode#27557.Strongly in favor of option (1) — feature-gate the global handler registration so users who only use the multi-agent presets don't pay for behavior they don't need.
fix(background-agent): add OMO_DISABLE_PROCESS_CLEANUP env opt-out fo…
Merge pull request #3947 from MoerAI/fix/process-cleanup-opt-out-env
refactor(signals): unified Signal class and exit code abstraction, bi…
refactor(signals): unified Signal class and exit code abstraction, bi…