Route process tools to selected environments#20647
Merged
Merged
Conversation
765736f to
f1b873f
Compare
db43360 to
3acd99c
Compare
7b87996 to
625359a
Compare
cc4be64 to
a477948
Compare
a477948 to
79874e0
Compare
326f101 to
0888b48
Compare
79874e0 to
508399c
Compare
0888b48 to
281edbc
Compare
ba48976 to
2d15bcb
Compare
281edbc to
d57209c
Compare
2d15bcb to
68ecaca
Compare
d57209c to
b6984c4
Compare
4749c07 to
642d669
Compare
6ae16cb to
5ee157f
Compare
642d669 to
3fa2aba
Compare
Allow the remote exec routing e2e to wait longer for the first remote unified exec turn, which can include container startup overhead on devboxes. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Cover the no-environment e2e case by asserting exec_command is omitted from the model tool surface instead of sending an unavailable tool call. Keep the local/remote cases as actual routing executions. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Ensure the remote exec routing e2e drains the no-env turn before submitting the single-env routing case. Without this wait, the next turn can time out even though the routing logic is correct. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Use a fresh TestCodex session for each no-env, single-env, and multi-env remote exec routing scenario so the e2e validates routing rather than cross-turn sequencing. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Give each remote exec routing scenario its own mock responses server so broad response matchers cannot intercept requests from a later scenario. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Use an explicit bash non-login command and short yield timeout in the remote routing e2e so the test varies only environment selection. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Use the resolved exec cwd when applying granted shell permissions and building sandbox approval metadata so selected turn environments do not fall back to turn.cwd. Also remove an extra remote-env test wait; submit_turn_with_environments already waits for TurnComplete. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
Bazel clippy denies expect_used for the core integration test binary, so keep the helper assertion explicit instead of using expect. Co-authored-by: Codex <noreply@openai.com>
starr-openai
added a commit
that referenced
this pull request
May 4, 2026
Allow apply_patch freeform calls to include optional environment metadata immediately after the begin marker. The handler strips that metadata before invoking the existing patch parser, resolves the selected turn environment, and carries the selected environment filesystem into the apply_patch runtime. Co-authored-by: Codex <noreply@openai.com>
The remote test container does not guarantee the host shell path exists. Request /bin/sh in the routing e2e so the same command can run locally and remotely. Co-authored-by: Codex <noreply@openai.com>
Run the remote exec routing assertion from /tmp with a unique marker file so the test focuses on selected-environment routing instead of the remote-aware test cwd. Co-authored-by: Codex <noreply@openai.com>
This was referenced May 5, 2026
Co-authored-by: Codex <noreply@openai.com>
pakrym-oai
reviewed
May 5, 2026
| @@ -17,6 +17,13 @@ pub struct ShellToolOptions { | |||
| } | |||
|
|
|||
| pub fn create_exec_command_tool(options: CommandToolOptions) -> ToolSpec { | |||
Collaborator
There was a problem hiding this comment.
nit: ideally we delete this one. nobody should be creating exec without knowing whether to add env or not.
pakrym-oai
reviewed
May 5, 2026
| environment_id: REMOTE_ENVIRONMENT_ID.to_string(), | ||
| cwd: remote_cwd.clone(), | ||
| }; | ||
| let multi_env_output = exec_command_routing_output( |
Collaborator
There was a problem hiding this comment.
can we inline, nobody else uses exec_command_routing_output
pakrym-oai
reviewed
May 5, 2026
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn exec_command_routes_to_selected_remote_environment() -> Result<()> { |
Collaborator
There was a problem hiding this comment.
should this go into exec tests?
pakrym-oai
reviewed
May 5, 2026
| use std::time::SystemTime; | ||
| use std::time::UNIX_EPOCH; | ||
| use tempfile::TempDir; | ||
| async fn unified_exec_test(server: &wiremock::MockServer) -> Result<TestCodex> { |
pakrym-oai
reviewed
May 5, 2026
Comment on lines
62
to
+63
| pub cwd: AbsolutePathBuf, | ||
| pub environment: Arc<Environment>, |
Collaborator
There was a problem hiding this comment.
supernit for the future: might be good to start using TurnEnvironment in places like this where we already store cwd+evn
pakrym-oai
approved these changes
May 5, 2026
Co-authored-by: Codex <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When a turn exposes multiple selected environments, shell-style tools need a model-facing way to identify the intended target environment and handlers need to resolve that target before parsing cwd-relative permission fields or launching processes.
This PR scopes that rollout to process tools. Filesystem-oriented tools such as
apply_patch,view_image, andlist_dirare intentionally left for follow-up slices.What Changed
include_environment_idoption to shell-style tool schema builders.environment_idonshell,shell_command, andexec_commandonly whenToolEnvironmentMode::Multipleis active.environment_idandworkdirfrom JSON function-call arguments and returns the selectedEnvironmentplus effective absolute cwd.shell,shell_command, andexec_commandhandling so process execution uses the selected environment filesystem and cwd.ExecCommandRequestto carry a required resolvedcwd, removing the process-manager fallback to the primary turn cwd for new exec commands.write_stdinunchanged because it targets an existing process id, not a new environment.Testing
exec_commandrouting across explicit zero environments, one local environment, and local+remote environments.just fmtandgit diff --check.