Repository navigation
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Link for the related issue: |
|
Any news on this one? Codex should be able to terminate commands itself after a while,.like github copilot does by verifying the process response every x seconds. |
|
@codex review |
|
Thanks for the contribution, and apologies for the slow response. We received a large number of PRs and are just now catching up on our backlog. If you're still interested in pursuing this PR, could you please resolve the merge conflicts? |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| maybe_chunk = agg_rx.recv() => { | ||
| if let Ok(chunk) = maybe_chunk { | ||
| append_all(&mut combined_buf, &chunk); | ||
| } else { | ||
| // aggregate channel closed; keep draining others until deadline |
There was a problem hiding this comment.
Starvation leaves stdout/stderr always empty
After switching to tokio::select! to drain the three channels, the first branch listens to agg_rx.recv() and the macro is biased toward the first ready future. Once the aggregate channel closes (which happens as soon as the readers finish), recv() immediately returns Err each iteration and the loop never polls stdout_rx or stderr_rx before the 300 ms deadline. As a result, stdout_buf and stderr_buf remain empty for normal commands, so ExecToolCallOutput.stdout and .stderr will always be blank even when the process produced output. Consider removing closed channels from the select or iterating until each per-stream channel is drained.
Useful? React with 👍 / 👎.
Some commands (e.g. test runners like Playwright) spawn grandchildren that inherit stdout/stderr. Those descendants may keep the inherited FDs open after the main child process exits. Our previous implementation waited for EOF on the pipes, so we could wait forever even though we already observed the child exit (or timeout), leaving Codex blocked. This change ensures we don’t block indefinitely: - Stream stdout/stderr into channels while the child is alive. - After the child exits, drain available output for a short grace period (300ms). - Abort the reader tasks if they’re still blocked, so we don’t rely on EOF from descendants. Behavioral notes: - We may miss late bytes that arrive after the grace window in pathological cases. This is an intentional trade-off to guarantee termination. - Aggregated output still collects during runtime; the grace period just sweeps remaining buffered data. Files: - codex-rs/core/src/exec.rs: adjust consume_truncated_output and read_capped to use per-stream channels and timed drain, then abort readers. Rationale: - Fixes a class of hangs observed after commands report a non-zero exit (e.g. npm run e2e) but stdout/stderr aren’t closed due to lingering descendants.
…in-exectoolcalloutput Fix exec drain loop after aggregate channel closes
|
After reviewing the fix proposed in this PR, we think that there is a simpler way to address the bug. We're pursuing that fix here. I'm going to close this one. Thanks again for taking the time to submit this PR. |
Codex was hanging after executing playwright on a project, and I had it fix itself, explaining the problem with:
"Some commands (e.g. test runners like Playwright) spawn grandchildren that inherit stdout/stderr. Those descendants may keep the inherited FDs open after the main child process exits. Our previous implementation waited for EOF on the pipes, so we could wait forever even though we already observed the child exit (or timeout), leaving Codex blocked."
It's changes seem correct, and it also corrected one of the tests that had a bug running on a non-US machine, adding a formatter with a fixed US locale.
I verified that the problem happens on the main branch and the change fixed it.