Repository navigation
Wait for nested agent tool cleanup on cancellation - #6130
markstuart-oai wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: dd7f90bcaf
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
There was a problem hiding this comment.
Approved after comprehensive static review and an independent second review. Reviewed attached task ownership, repeated cancellation, producer/consumer teardown, iterator closure, nested stream settlement, provider/sandbox cleanup, and concurrent manager isolation. No confirmed actionable defect in the reviewed changes.
Rechecked the cleanup availability finding. The mechanism is real: a nested application tool that never finishes cleanup can delay cancellation indefinitely, including repeated cancellation. The PR explicitly documents this tradeoff in order to preserve ownership of delegated work. The finding does not identify a concrete SDK-owned cleanup path stalled by untrusted input or an applicable bounded-cancellation guarantee; an unsafe application-defined cleanup alone does not establish an SDK security boundary bypass. This approval does not claim bounded cancellation latency. A concrete built-in cleanup operation lacking an I/O timeout would merit separate review.
Hosted CI is complete: 33 passed and 4 skipped; no failures. Static review only; no candidate code or local tests executed.
There was a problem hiding this comment.
Approved after static re-review and an independent second review of the update. The cleanup wait now uses a fixed 250 ms grace period, repeated cancellation does not extend that deadline, and late task errors are observed. The stopped flag prevents queued callbacks from being delivered after failure even when an in-flight callback suppresses cancellation or raises during cleanup. Iterator closure remains sequenced after its producer stops; callers owning closure externally retain a full join. No actionable findings.
This addresses the unbounded-wait mechanism in the earlier cleanup finding. As documented, timing out the wait does not stop an uncooperative application tool or callback from continuing or causing side effects. Reviewed cooperative/stalled cleanup, repeated cancellation, overflow, late callback failure, and independent-manager regression coverage.
Hosted CI is complete: 33 passed and 4 skipped; no failures. Static review only; no candidate code or local tests executed.
Summary
Cancelling a manager could leave a streamed
Agent.as_tool()child running after the caller receivedCancelledError. Repeated cancellation could also interrupt cleanup, and an event callback that raised during cleanup could receive more queued events.The manager now gives active delegated calls and their nested tools the SDK's existing 250 ms cleanup grace period. Repeated cancellation leaves the deadline intact. Stream teardown stops new callback deliveries and closes the iterator after its producer stops. Independent runs can keep using the same tool and call ID.
The caller still receives cancellation. If cleanup exceeds the deadline, the SDK stops waiting and observes late errors. An in-flight tool or callback can still run and have side effects. No public API or configuration changes.
Test plan
Checks
.agents/skills/code-change-verification/scripts/run.sh