Skip to content

fix: wake E2B PTY collection on process exit#3618

Closed
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/e2b-exit-wakeup
Closed

fix: wake E2B PTY collection on process exit#3618
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/e2b-exit-wakeup

Conversation

@he-yufeng

Copy link
Copy Markdown

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:

python -m py_compile src\agents\extensions\sandbox\e2b\sandbox.py tests\extensions\sandbox\test_e2b.py
PYTHONPATH=src python -m pytest tests\extensions\sandbox\test_e2b.py -q
python -m ruff check src\agents\extensions\sandbox\e2b\sandbox.py tests\extensions\sandbox\test_e2b.py
git diff --check

@he-yufeng

Copy link
Copy Markdown
Author

Closing this as a duplicate of #3610. My earlier issue-number search missed that open PR because it does not reference #3609 directly, but the implementation scope overlaps with the same E2B PTY exit-wakeup path.

@he-yufeng he-yufeng closed this Jun 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1063 to +1066
except Exception:
pass
finally:
entry.done = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2B PTY output collection can wait until yield timeout after process exit

1 participant