fix: wake E2B PTY collection on process exit#3618
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf7fa92097
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| except Exception: | ||
| pass | ||
| finally: | ||
| entry.done = True |
There was a problem hiding this comment.
Avoid marking PTY done when wait fails
When E2B's wait() raises for a stream/RPC error rather than because the process exited, this catch-all still falls through to finally and sets entry.done. The next _finalize_pty_update treats that as an exited process, removes the session, and calls kill, so a long-running PTY/background command can be reported as process_id=None/exit_code=None and be terminated just because the waiter connection failed. Only mark the entry done after a successful wait or a CommandExitException/result that proves the process actually ended.
Useful? React with 👍 / 👎.
Summary
Fixes #3609.
E2B PTY output collection already checks the process exit code while draining output, but process exit itself did not wake the collector. If a background command or PTY session exited after its final chunk, or exited without producing output,
pty_exec_start()/pty_write_stdin()could wait until the full yield window before noticing the exit.This adds a small waiter task for E2B command handles that expose
wait(). When the handle exits, the waiter captures the exit code when available, marks the PTY entry done, and sets the existing output notification event. The collector can then return promptly on process exit even when no more stdout/stderr data arrives.Tests
To verify: