Skip to content

fix(computer): isolate provider instances across concurrent runs - #3843

Merged
seratch merged 2 commits into
openai:mainfrom
russeell:fix/computer-tool-concurrent-runs
Jul 15, 2026
Merged

fix(computer): isolate provider instances across concurrent runs#3843
seratch merged 2 commits into
openai:mainfrom
russeell:fix/computer-tool-concurrent-runs

Conversation

@russeell

@russeell russeell commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes ComputerTool provider isolation when the same agent is reused by concurrent runs.

Per-run computer providers were introduced in #2191 so applications can reuse an agent while creating and disposing independent computer resources for each request. The existing initialization cache is run-scoped, but model serialization still observes the mutable computer field on the shared tool.

initialize_computer_tools() now returns run-local ComputerTool copies for provider/factory-backed tools, bound to the computer resolved for the current RunContextWrapper. The original tool continues to own the existing per-run cache and disposal lifecycle, while model serialization and action processing receive stable run-local state instead of reading a shared mutable field. Tools configured with an existing concrete Computer retain their original identity for hooks and custom-data callbacks.

This prevents preview-compatible Responses requests from serializing another run's computer dimensions or failing when a sibling run restores the shared tool to its provider during cleanup. The change does not alter the public API, the wire payload, or the GA computer tool behavior.

Test plan

  • Added a controlled concurrent Runner.run() regression test that interleaves two runs sharing one agent and provider-backed ComputerTool.
  • Verified that both runs serialize their own display width, both complete successfully, and each created computer is disposed exactly once.
  • Extended the existing non-streamed and streamed lifecycle tests to verify that the model receives a run-local tool bound to the correct computer.
  • Added a full runner tool-call regression test confirming that concrete ComputerTool instances preserve their identity in model input and run hooks.
  • Ran the focused lifecycle and affected runner tests.
  • Ran codex review --uncommitted with no actionable findings.
  • Ran the repository verification stack with the local provider override removed and localhost excluded from the system proxy:
env -u OPENAI_BASE_URL NO_PROXY=localhost,127.0.0.1 no_proxy=localhost,127.0.0.1 \
  bash .agents/skills/code-change-verification/scripts/run.sh

All formatting, lint, type-checking, and test steps passed.

Issue number

Closes #3842

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

@russeell
russeell marked this pull request as ready for review July 15, 2026 13:47

@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: 8113663664

ℹ️ 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 on lines +591 to +592
dataclasses.replace(tool, computer=resolved_by_tool[tool])
if isinstance(tool, ComputerTool)

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 Preserve concrete ComputerTool identity for hooks

When a ComputerTool already wraps a concrete Computer, this still replaces it with a fresh ComputerTool even though there is no provider state to isolate. That copy is later stored in ToolRunComputerAction, so ComputerAction.execute passes the copy to on_tool_start/on_tool_end and custom-data callbacks; hooks that key off the configured agent.tools[0] object stop recognizing their tool on ordinary concrete-computer runs. Please avoid cloning already-resolved computer tools, or otherwise preserve the original tool identity for hook-facing surfaces.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good catch. You're right that cloning a concrete ComputerTool unnecessarily changes its hook-facing identity. I'll update the implementation so only provider/factory-backed tools receive run-local copies, and add a regression test confirming concrete tools preserve their original identity.

@seratch seratch added this to the 0.18.x milestone Jul 15, 2026
@seratch
seratch merged commit 585053b into openai:main Jul 15, 2026
9 checks passed
@russeell
russeell deleted the fix/computer-tool-concurrent-runs branch July 16, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComputerTool provider instances are not isolated across concurrent runs

2 participants