Repository navigation
Conversation
When images are submitted in exec mode, two threads compete for events from the same conversation stream: the background event-forwarding thread and the main thread waiting for TaskComplete. This causes the main thread to hang indefinitely when the background thread wins the race. Fix by reading from the rx channel instead of calling conversation.next_event() directly, ensuring all events flow through the background thread's channel. Credit to @AdsQnn for diagnosing this issue in openai#5773. Signed-off-by: Jet Sanchez <[email protected]>
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks for the contribution! I agree with your diagnosis, but I think the proposed fix has a problem. By switching the image-upload wait loop to rx.recv() the code consumes events from the same channel that feeds the main event-processing loop. Any events read here are removed from the channel and never delivered to event_processor.process_event. When a user supplies --images, the assistant’s response for that upload is now silently dropped. |
|
Right ! The Rust fix resolves a race condition, but it introduces a new problem. ❌ Incorrect fix: The main loop will never see these events: Effect: All events between sending the images and TaskComplete (e.g. assistant responses about the images) Correct solution: ✅ Read from rx AND process every event Key difference: Every event MUST go through the event_processor, Good point — it might help with something. What I posted earlier wasn’t meant as a complete, ready-to-deploy solution — it was more of a suggestion pointing to where the problem lies :) |
|
Thanks both for catching that. You're right, I was consuming events without processing them. I'll update the fix to process events in the wait loop. |
When images are submitted in exec mode, two threads compete for events from the same conversation stream: the background event-forwarding thread and the main thread waiting for TaskComplete. This causes the main thread to hang indefinitely when the background thread wins the race. Additionally, events consumed during the wait were not being processed, silently dropping the assistant's response to image uploads. Fix by reading from the rx channel (avoiding the race) and processing each event before checking if it is the TaskComplete signal. Credit to @AdsQnn for diagnosing the race condition in openai#5773. Thanks to @etraut-openai for catching the dropped events issue. Signed-off-by: Jet Sanchez <[email protected]>
|
Thanks, the logic looks good to me. Just need to fix some remaining lint errors. |
|
Merged latest upstream/main which already included a fix for the content_items compilation error (d7b333b). All tests passing locally. :) |
|
Closing this pull request because we decided to go with a different (simpler) solution. |
What
Fixes a race condition and dropped events in
codex execwhen using the--imageflag that causes the process to hang indefinitely.Why
Race Condition: When images are submitted via
codex exec --json --image <path>, two threads compete for the same event stream:conversation.next_event()→ forwards to channelrxconversation.next_event()→ waits forTaskCompleteBoth consume from the same
async_channel::Receiver(cloned viaconversation.clone()). When the background thread wins the race (which happens deterministically), the main thread hangs forever.Dropped Events: Additionally, even after fixing the race by reading from
rx, events were not being processed during the wait. This silently dropped the assistant's response to image uploads.Impact: Makes
codex exec --imagecompletely unusable. Affects any programmatic integration using images (CI/CD, API wrappers, etc.).How
The fix has two parts:
rx.recv()instead ofconversation.next_event()(fixes the race)event_processor.process_event(event)inside the loop (fixes dropped events)This ensures events are both consumed from the correct channel and properly processed.
Credit
Race condition diagnosed by @AdsQnn in #5773.
Dropped events issue caught by @etraut-openai during review.
Testing
cargo fmt --all -- --config imports_granularity=Item- passedcargo clippy --tests- passed (no warnings)cargo test --package codex-exec- all tests passedcodex exec --json --image <path>now completes successfullyTested on macOS ARM (aarch64-apple-darwin).
Fixes #5773