Conversation
Fix multiple issues that could crash the agent process: - Add global unhandledRejection and uncaughtException handlers - Fix fire-and-forget async in session-index.ts file watcher - Fix fire-and-forget async in eager-pull.ts image pull - Add catch handler to SSE stream IIFE in opencode adapter - Add catch handlers to process.exited promises in adapters These fixes prevent unhandled promise rejections from crashing the entire agent process. Errors are now logged instead of crashing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment on lines
+5
to
+12
| process.on('unhandledRejection', (reason, promise) => { | ||
| console.error('[agent] Unhandled promise rejection:', reason); | ||
| console.error('[agent] Promise:', promise); | ||
| }); | ||
|
|
||
| process.on('uncaughtException', (err) => { | ||
| console.error('[agent] Uncaught exception:', err); | ||
| }); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Sentry code review correctly identified that uncaughtException leaves the process in an undefined state. Exit with code 1 so systemd can restart the agent cleanly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.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.
Summary
Fix multiple issues that could crash the agent process with unhandled promise rejections.
Root Cause
The agent crashed while you were away with:
This was caused by an unhandled promise rejection in the OpenCode SSE stream processing.
Fixes
Global error handlers (
src/agent/index.ts)process.on('unhandledRejection')handlerprocess.on('uncaughtException')handlerSession index file watcher (
src/worker/session-index.ts).catch()Eager image pull (
src/docker/eager-pull.ts).catch()to all fire-and-forget async callsOpenCode SSE stream (
src/session-manager/adapters/opencode.ts).catch()to IIFE async blockProcess exit handlers (
src/session-manager/adapters/claude.ts,src/terminal/base-handler.ts).catch()toprocess.exitedpromise chainsTest plan
🤖 Generated with Claude Code