Skip to content

fix: preserve streamed cancellation and pending guardrail cleanup - #5224

Merged
jbeckwith-oai merged 2 commits into
mainfrom
codex/fix-stream-guardrail-cancellation
Sep 28, 2026
Merged

jbeckwith-oai merged 2 commits into
mainfrom
codex/fix-stream-guardrail-cancellation

Conversation

@jbeckwith-oai

@jbeckwith-oai jbeckwith-oai commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

This pull request fixes consumer cancellation being swallowed while stream_events() waits for a pending input guardrail or run-loop finalization. It also prevents cancellation of a pending parallel input guardrail from skipping computer disposal and trace/span completion.

Terminal waits distinguish consumer cancellation from child cancellation, settle the cancelled child, and await registered provider/sandbox cleanup before propagating cancellation. The guardrail-verdict helper tolerates cancelled children only during final cleanup, preserving cancellation before turn-output persistence. Explicit result.cancel() behavior and existing late-error handling remain intact.

Five event-gated regressions exercise the public runner's terminal waits, disposal, trace closure, registered cleanup, and session persistence. Cancellation during already-running asynchronous cleanup and repeated cancellation remain separate work; this change does not guarantee that interrupted cleanup completes.

Test plan

  • The original three regressions fail against the original runtime; the two feedback regressions fail against the initial PR runtime. All pass with this fix.
  • Focused cancellation, guardrail, computer, provider, and sandbox tests: 309 passed, 6 native sandbox skips.
  • Streamed-runner tests, including finalizer error logging: 206 passed.
  • Two independent reviews of the final diff: clean.
  • Full verification: formatting, lint, mypy, pyright, and tests passed (11,510 parallel tests and 89 serial tests; 69 skipped).
  • Native macOS sandbox tests were excluded locally under the repository's Codex policy; the dedicated CI job covers them.

Issue number

Closes #5213

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

The implementation-final-review workflow completed with two independent clean reviews; the separate /review command was not invoked.

@jbeckwith-oai
jbeckwith-oai requested review from a team, rm-openai and seratch as code owners September 28, 2026 16:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T17:15:42.666839Z 846e167 New commits
🔒 Security Review ✅ Completed 2026-09-28T17:16:06.321086Z 846e167 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread tests/test_cancel_streaming.py Fixed
Comment thread tests/test_cancel_streaming.py Fixed

@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: 211fe74d44

ℹ️ 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".

Comment thread src/agents/result.py
Comment thread src/agents/run_internal/guardrails.py Outdated
Comment thread tests/test_cancel_streaming.py

@markstuart-oai markstuart-oai 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.

Reviewed the full diff at 846e167. The terminal waits now distinguish consumer cancellation from child cancellation, preserve guardrail cancellation before output persistence, and reach the existing registered cleanup owners. The event-gated regressions cover the intended lifecycle boundaries. No actionable correctness or structural findings within the stated scope; interruption of cleanup already in progress remains outside this fix.

Validation: pinned-source review and all 22 successful checks on this commit, including Windows and native macOS sandbox coverage. I did not run tests locally.

@jbeckwith-oai
jbeckwith-oai merged commit 0d6b741 into main Sep 28, 2026
22 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/fix-stream-guardrail-cancellation branch September 28, 2026 17:36
@github-actions github-actions Bot mentioned this pull request Sep 28, 2026
@gomission

Copy link
Copy Markdown

@jbeckwith-oai, thanks for landing the fix. The run_loop regression covers the additional no-guardrail/active-disposal checkpoint we documented in #5213. The PR also keeps the distinction between propagating cancellation and completing already-running cleanup clear.

If our reproduction informed that coverage or scope, could you add a short acknowledgment of @gomission in the PR description, linked to that comment? The attribution would be for the additional reproduction and boundary check; @hsusul supplied the original report and proposed fix, and you implemented and landed the merged change.

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.

Streamed runs swallow consumer cancellation and skip run cleanup while a parallel input guardrail is running

3 participants