Skip to content

[codex] Run user shell commands in explicit remote environments#28364

Closed
rasmusrygaard wants to merge 3 commits into
mainfrom
dev/rasmus/remote-user-shell-env
Closed

[codex] Run user shell commands in explicit remote environments#28364
rasmusrygaard wants to merge 3 commits into
mainfrom
dev/rasmus/remote-user-shell-env

Conversation

@rasmusrygaard

@rasmusrygaard rasmusrygaard commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Why

A turn can select a remote environment, but user shell commands could only run on the local host. Callers that know which selected environment the user intends to target need a way to execute the command there without silently falling back to local execution.

What changed

  • Adds an optional environment_id to RunUserShellCommand; omitting it preserves the existing local app-server and TUI behavior.
  • Resolves explicit IDs against the selected environments for the turn and requires the target to be remote.
  • Runs the command through the remote environment exec backend using its working directory, shell, and configured shell environment policy.
  • Preserves user-shell lifecycle behavior, including begin/end events, streamed output, active-turn reuse, standalone turns, persisted output, cancellation, and the existing timeout.
  • Bounds remote read sizes, emitted deltas, and retained stdout, stderr, and aggregate output. Remote processes are terminated on cancellation, timeout, read errors, and backend failures.
  • Records selection and setup failures in command history instead of falling back to local execution.

Environment selection policy remains with the caller: core honors an explicit ID but does not infer a default when multiple environments are selected.

Test coverage

  • Adds an integration test that selects local and remote environments and verifies an explicitly targeted user shell command runs in the remote working directory.
  • Adds coverage confirming an unknown environment ID records a failure and never executes the command locally.
  • Existing local user-shell call sites and tests continue to use environment_id: None.

@rasmusrygaard rasmusrygaard force-pushed the dev/rasmus/remote-user-shell-env branch 3 times, most recently from 67fe692 to ecf2567 Compare June 15, 2026 18:48
@rasmusrygaard rasmusrygaard force-pushed the dev/rasmus/remote-user-shell-env branch from ecf2567 to fda28a2 Compare June 15, 2026 20:19
@rasmusrygaard rasmusrygaard changed the title [codex] Add remote environment user shell support [codex] Run user shell commands in explicit remote environments Jun 15, 2026
@rasmusrygaard rasmusrygaard marked this pull request as ready for review June 15, 2026 21:13
@rasmusrygaard rasmusrygaard requested a review from a team as a code owner June 15, 2026 21:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 0968f33680

ℹ️ 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 +602 to +604
Ok(crate::shell::get_shell_by_model_provided_path(
&info.shell.path.into(),
))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Use remote shell info without local path probing

For remotes on another OS or with a shell path absent locally, this host-side detection can fall back to /bin/sh and send that argv remotely, so explicit remote ! commands fail despite valid remote shell info. Use ShellInfo/turn_environment.shell directly. guidance

Useful? React with 👍 / 👎.

Comment on lines +486 to +489
stdout: StreamOutput::new(String::from_utf8_lossy(&stdout).into_owned()),
stderr: StreamOutput::new(String::from_utf8_lossy(&stderr).into_owned()),
aggregated_output: StreamOutput::new(
String::from_utf8_lossy(&aggregated_output).into_owned(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Decode remote output with the normal exec decoder

For remote Windows shells or commands emitting non-UTF-8, these lossy conversions bypass normal exec's smart decoder, so final stdout/stderr/history show replacement characters for supported code pages. Convert through StreamOutput<Vec<u8>>::from_utf8_lossy(). guidance

Useful? React with 👍 / 👎.

return RemoteUserShellResult::Error(format!("execution error: {err}"));
}
};
after_seq = Some(read.next_seq);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Advance remote reads to the last consumed sequence

When remote output spans multiple reads, setting after_seq to read.next_seq skips the next chunk: the exec-server read API returns chunks with seq > after_seq, so a later chunk whose sequence equals the previous next_seq is filtered out. This drops stdout/stderr and streamed deltas for longer-running or chatty remote ! commands; store the last consumed chunk seq instead (or next_seq - 1).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant