Skip to content

[codex] resolve environment shell metadata eagerly - #27709

Merged
pakrym-oai merged 1 commit into
mainfrom
pakrym/full-ci-resolve-environment-shell
Jun 12, 2026
Merged

[codex] resolve environment shell metadata eagerly#27709
pakrym-oai merged 1 commit into
mainfrom
pakrym/full-ci-resolve-environment-shell

Conversation

@pakrym-oai

Copy link
Copy Markdown
Contributor

Why

Turn construction passed resolved environments through several layers while leaving the environment shell unresolved. As a result, model-visible environment context could fall back to the session shell instead of reporting the selected remote environment's shell.

Resolve environment metadata at the turn-context boundary so each turn carries the shell that belongs to its selected environment. Keep request validation in app-server, where invalid selections can be returned as straightforward JSON-RPC errors without coupling core turn construction to that policy.

What changed

  • resolve environment selections eagerly in new_turn_context_from_configuration
  • store the full resolved Shell on each TurnEnvironment
  • simplify the now-redundant resolved-environment constructor plumbing
  • keep duplicate and unknown-environment validation as a small app-server preflight
  • add a remote-environment integration test that runs a full test_codex turn and verifies the model-visible environment message reports bash

Testing

  • cargo check -p codex-core --test all -p codex-app-server
  • remote_test_env_exposes_bash_shell_to_model on the Linux remote-executor harness

@pakrym-oai
pakrym-oai marked this pull request as ready for review June 11, 2026 23:40
@pakrym-oai
pakrym-oai requested a review from a team as a code owner June 11, 2026 23:40

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

ℹ️ 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".

Comment on lines 50 to 54
shell: environment
.shell
.clone()
.as_ref()
.map(|shell| shell.name().to_string())
.unwrap_or_else(|| shell.name().to_string()),

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 Use the selected environment shell for remote exec

When the remote environment shell differs from the host shell (for example the local session is zsh but the exec-server reports bash), this now advertises the remote shell in <environment_context>, but exec_command still builds commands from session.user_shell() before sending them to the selected environment. The model will omit an explicit shell because it was told bash is available, yet the runtime can still invoke the host shell path on the remote environment and fail before the command runs.

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.

Followup./

Comment on lines +708 to +710
.unwrap_or_else(|err| {
warn!("failed to resolve turn environments: {err}");
ResolvedTurnEnvironments::default()

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 Reject invalid turn environments instead of defaulting

For callers that reach Op::UserInput without the app-server pre-validation, an unknown or duplicate thread_settings.environments value is now applied to session_configuration and then silently converted to an empty environment list here. That turns a bad turn override into a successful local/default turn and leaves the session with the invalid environment selection, whereas this path used to return InvalidRequest before mutating state.

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.

Ok for the sake of simplification

.ok_or_else(|| {
CodexErr::InvalidRequest(format!("unknown turn environment id `{environment_id}`"))
})?;
let shell = match environment.info().await {

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 Avoid connecting to remote environments while resolving turns

When a selected remote exec-server is offline or slow to initialize, this environment.info().await forces the lazy remote client to connect just to populate an optional shell name. Because callers use this during thread/turn setup and the error is only swallowed after the connect/initialize attempt, a configured remote environment can add the full transport timeout to startup or every turn before the user even invokes a remote tool.

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.

Ok for now. We'll fix this more holistically later

@pakrym-oai
pakrym-oai merged commit be338ee into main Jun 12, 2026
128 of 173 checks passed
@pakrym-oai
pakrym-oai deleted the pakrym/full-ci-resolve-environment-shell branch June 12, 2026 03:35
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants