fix(orchestrate): graceful IPC disconnect to prevent race condition#164
Merged
laynepenney merged 1 commit intomainfrom Jan 26, 2026
Merged
fix(orchestrate): graceful IPC disconnect to prevent race condition#164laynepenney merged 1 commit intomainfrom
laynepenney merged 1 commit intomainfrom
Conversation
The IPC client was using socket.destroy() which immediately closes the socket without waiting for pending writes to complete. This caused a race condition where: 1. Child agent sends task_complete message 2. Child immediately calls disconnect() which destroys the socket 3. Server receives 'close' event before processing the completion message 4. Reader/worker marked as "disconnected unexpectedly" Fix: Use socket.end() with a drain wait and 1-second timeout to ensure pending writes complete before closing the connection. Also fixes non-interactive mode (-P flag) where readline was being created and immediately closing, triggering premature exit before the prompt could be processed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
14bac09 to
015f62a
Compare
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
socket.destroy()tosocket.end()with proper drain handlingProblem 1: IPC Disconnect Race
The IPC client was using
socket.destroy()which immediately closes the socket without waiting for pending writes to complete. This caused a race condition:task_completemessagedisconnect()which destroys the socketcloseevent before processing the completion messageProblem 2: Non-Interactive Mode Exit
In non-interactive mode (
-Pflag), readline was still being created. When stdin closed (non-TTY mode), readline's close event triggeredhandleExit()before the prompt was processed.Solution
IPC Client
Use
socket.end()with a drain wait to ensure pending writes complete:Non-Interactive Mode
Skip readline creation when
-Pflag is used:Test plan
codi -P "what is 2+2?"→ "Four"🤖 Generated with Claude Code