Skip to content

Handle OpenCode process exit events and prevent hanging - #8

Merged
marchingphoenix merged 3 commits into
mainfrom
claude/fix-chat-connecting-hang-NJ6p3
Feb 13, 2026
Merged

Handle OpenCode process exit events and prevent hanging#8
marchingphoenix merged 3 commits into
mainfrom
claude/fix-chat-connecting-hang-NJ6p3

Conversation

@marchingphoenix

Copy link
Copy Markdown
Owner

Summary

This PR adds proper handling for OpenCode process exit events to prevent chat responses from hanging indefinitely when the process terminates unexpectedly.

Key Changes

  • Process exit event handling: Added listener for process "exit" events in opencodeBridge.ts that fires an error event when the process exits with code 0 or null (unexpected clean exit), and transitions to "error" state for non-zero exit codes
  • Safety net for chat responses: Added a state change listener in chatParticipant.ts that resolves the chat promise if the bridge stops or errors without emitting an event (e.g., process killed externally)
  • Proper listener cleanup: Ensured the state listener is disposed after the chat request completes to prevent memory leaks
  • Comprehensive test coverage: Added three test cases covering clean exit (code 0), null exit code, and non-zero exit scenarios

Implementation Details

  • The process exit handler distinguishes between unexpected clean exits (code 0 or null) which fire an error event and transition to "stopped" state, versus actual errors (non-zero codes) which transition to "error" state
  • The state listener acts as a safety net to catch edge cases where the process terminates without emitting an event, ensuring the chat response doesn't hang
  • Version bumped to 0.1.3

https://claude.ai/code/session_01H4amgmKjeCoRweW1fK9PDc

The handleAsk promise in chatParticipant only listened for "done" and
"error" events from bridge.onEvent.  When the OpenCode process exited
cleanly (code 0 or null), handleExit only called setState("stopped")
without firing any event, so the promise never resolved and the UI
hung indefinitely.

Two fixes:
- opencodeBridge: fire an error event in handleExit for clean exits so
  listeners are always notified when the process ends
- chatParticipant: add an onStateChanged listener as a safety net so
  the promise resolves even if a state change fires without an event

https://claude.ai/code/session_01H4amgmKjeCoRweW1fK9PDc
@marchingphoenix
marchingphoenix merged commit 26b4e33 into main Feb 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants