Tool approval is not honored on resume when Runner.run is given a context - #4245
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bfa6fb8b80
ℹ️ 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".
There was a problem hiding this comment.
Thanks for the contribution. The underlying issue is valid, but please revise the context-resolution change so the restored RunContextWrapper remains authoritative and only its application context value is replaced. Copying selected private fields into a new wrapper omits persisted metadata such as tool_input and will drift as additional run-owned state is added.
Please also add a regression covering the issue's serialized to_json() / from_json() resume path, plus the equivalent Runner.run_streamed() path. Both should prove that the approved call executes, the supplied application context is visible, and SDK-managed wrapper state survives the override.
Also, getting 👍 from Codex's PR review is required before merging in this repo, so please continue resolving all the review comments by Codex here (you don't need to mention codex; Codex automatically reviews all commits for this repo).
Replace only the application context value on the restored wrapper so approvals, usage, turn_input, and tool_input survive context= on resume. Add JSON and streamed regression coverage for issue openai#4244. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks @seratch — revised in 6a0c0ae:
|
Add a unit test that proves resolve_resumed_context keeps the restored wrapper identity and run-owned state, and share HITL setup across the JSON and streamed regressions with approvals-identity assertions. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d05ddd9826
ℹ️ 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".
When Runner.run resumes with context=, also update cached Agent.as_tool() RunState application contexts for the resume scope so nested tools see the override while keeping nested approvals and tool_input intact. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c042f22d7
ℹ️ 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".
Walk only the resumed RunState's pending function tool calls instead of every unscoped agent-tool cache entry, so concurrent live interruptions cannot leak a context= override into each other. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0ce12a92a
ℹ️ 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".
Recurse through live Agent.as_tool() wrappers so A→B→C overrides reach C, only consider _is_agent_tool function runs, and avoid unscoped signature fallback so ordinary functions cannot overwrite unrelated nested context. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
seratch
left a comment
There was a problem hiding this comment.
Thanks for continuing to work through the feedback. The underlying issue is valid, and keeping the restored RunContextWrapper authoritative is the correct direction. However, the current head has expanded into recursive traversal and mutation of the shared agent-tool cache.
Please simplify this to one context-resolution path: keep the restored wrapper and replace only its application .context; when a pending Agent.as_tool() run is actually resumed, pass the current parent application context into its nested Runner.run() or Runner.run_streamed() call so the same resolver applies there. Please remove apply_application_context_to_agent_tool_states and the synthetic cache-propagation tests.
Keep the JSON round-trip and streaming regressions, and add an end-to-end nested Agent.as_tool() regression proving that the new application context is visible while nested approvals and tool_input remain owned by the restored wrapper.
Keep a single resolve_resumed_context path that only replaces the restored wrapper's application context, and pass the parent application context into nested Runner.run/run_streamed on Agent.as_tool() resume instead of mutating the shared agent-tool cache. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks @seratch — simplified as requested in the latest commits.
|
seratch
left a comment
There was a problem hiding this comment.
Thanks for the update. The latest head now has the right ownership model: it keeps the restored RunContextWrapper authoritative, replaces only the application context, and routes nested Agent.as_tool() resumes through the same resolver. The JSON round-trip, streaming, and nested regressions cover the required behavior, and CI is green.
One small repository-style fix remains before re-review: in the resolve_resumed_context docstring, replace the Unicode ellipsis after tool input, with three ASCII dots (tool input, ...) as required by AGENTS.md. After that change, this looks ready for final review.
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks, updated the |
|
@ojassharma7 oops, can you resolve the conflicts? |
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Resolved, merged latest |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b95b07708a
ℹ️ 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".
seratch
left a comment
There was a problem hiding this comment.
hmm, codex pointed a new issue out. Can you resolve it as well?
When resuming an approved nested agent-tool interruption, keep the restored wrapper's approvals/tool_input but point its Usage back at the parent ToolContext accumulator so post-resume nested turns are not undercounted. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@seratch addressed the Codex usage note as well — nested |
Fixes #4244.
What changed
src/agents/run_internal/agent_runner_helpers.pytests/test_run_state.pyVerification
The project's own test suite was run before and after this change; it introduces no new test failures or lint violations.