fix(codex): add panic recovery in readLoop to prevent process crash#332
Open
LigphiDonk wants to merge 1 commit intochenhg5:mainfrom
Open
fix(codex): add panic recovery in readLoop to prevent process crash#332LigphiDonk wants to merge 1 commit intochenhg5:mainfrom
LigphiDonk wants to merge 1 commit intochenhg5:mainfrom
Conversation
When handleItemCompleted encounters an unexpected event structure from the Codex CLI (e.g., a new item type or malformed JSON fields), it can panic. Since readLoop runs in a goroutine with no recover(), this crashes the entire cc-connect process. Add a deferred recover() at the top of readLoop that: - Catches any panic from handleEvent and its callees - Logs the panic value and full stack trace via slog.Error - Emits an EventError to the events channel so the caller is notified - Allows the process to continue serving other projects/platforms Also add TestHandleEvent_RecoverFromPanic to verify that malformed item.completed events (nil item, unknown types, unexpected nested structures) do not cause panics.
Owner
|
Thanks for this — panic recovery in Merge status: GitHub reports the PR as conflicting with Quick notes (non-blocking):
Appreciate the contribution. |
chenhg5
approved these changes
Mar 28, 2026
Owner
chenhg5
left a comment
There was a problem hiding this comment.
LGTM. Good defensive programming with panic recovery.
Review notes:
- ✅ CI passes
- ✅ Correct approach: recover() in readLoop prevents process crash
- ✅ Error properly propagated via Event channel
- ✅ Test coverage for malformed events
- ✅ Stack trace logged for debugging
This prevents cascading failures when codex CLI produces unexpected output. Approved for merge.
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.
When handleItemCompleted encounters an unexpected event structure from the Codex CLI (e.g., a new item type or malformed JSON fields), it can panic. Since readLoop runs in a goroutine with no recover(), this crashes the entire cc-connect process.
Add a deferred recover() at the top of readLoop that:
Also add TestHandleEvent_RecoverFromPanic to verify that malformed item.completed events (nil item, unknown types, unexpected nested structures) do not cause panics.