Uh oh!
There was an error while loading. Please reload this page.
fix: close model providers created by Runner - #4785
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ 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 Review
Here are some automated review suggestions for this pull request.
Reviewed commit:55c0e3874f
ℹ️ 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".
| def _normalize_run_config_for_runner( | ||
| value: RunConfig | dict[str, Any] | None, | ||
| ) -> tuple[RunConfig, bool]: |
There was a problem hiding this comment.
Move provider cleanup policy into run_internal
Move the new ownership normalization and cancellation-resistant provider cleanup helpers into src/agents/run_internal/ and leave only their orchestration calls here. These functions introduce substantive resource-lifecycle policy directly into the public runtime entrypoint, contrary to the repository requirement that new runtime logic live under run_internal; keeping them here further concentrates lifecycle behavior in the already-large run.py.
AGENTS.md reference: AGENTS.md:L190-L191
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks — moved the run-config ownership normalization and cancellation-resistant provider cleanup helpers into src/agents/run_internal/model_provider_lifecycle.py. src/agents/run.py now retains only the orchestration imports and call sites, with behavior and coverage unchanged.
seratch
left a comment
There was a problem hiding this comment.
Please move the ownership normalization and cancellation-resistant provider cleanup policy out of run.py and into run_internal/, leaving only orchestration calls in the public runtime entrypoint.
Summary
This pull request fixes a resource leak when
Runnercreates the default model provider for asingle run. Direct Responses WebSocket runs could finish successfully while the provider retained
its cached connection because the existing provider
aclose()chain was never called.Runner now closes only providers it creates implicitly after async, sync, or streamed execution
settles. A caller-supplied
RunConfigormodel_providerremains caller-owned and reusable, andcleanup preserves the primary result, exception, and cancellation behavior.
Test plan
streamed completion, cancellation, repeated cancellation, cancel-before-start, cleanup failure,
sandbox wrapping, and a real loopback Responses WebSocket connection.
.agents/skills/code-change-verification/scripts/run.sh: format, lint, mypy, pyright, and thefull test suite passed (
9301 passed,29 skipped).Issue number
N/A
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR