Skip to content

Add turn-scoped environment selections#18416

Merged
starr-openai merged 7 commits intomainfrom
turn-environments-20260417
Apr 22, 2026
Merged

Add turn-scoped environment selections#18416
starr-openai merged 7 commits intomainfrom
turn-environments-20260417

Conversation

@starr-openai
Copy link
Copy Markdown
Contributor

Summary

  • add experimental turn/start.environments params for per-turn environment id + cwd selections
  • pass selections through core protocol ops and resolve them with EnvironmentManager before TurnContext creation
  • treat omitted selections as default behavior, empty selections as no environment, and non-empty selections as first environment/cwd as the turn primary

Testing

  • ran just fmt
  • ran just write-app-server-schema
  • not run: unit tests for this stacked PR

@starr-openai starr-openai force-pushed the turn-environments-20260417 branch 4 times, most recently from 7986b94 to 8fa3ca6 Compare April 18, 2026 01:41
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from 127619c to 74bfde4 Compare April 18, 2026 01:48
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from 8fa3ca6 to 890e4cb Compare April 18, 2026 01:49
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from 74bfde4 to b1dcb7a Compare April 18, 2026 01:56
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch 2 times, most recently from 1578eb9 to 88861aa Compare April 18, 2026 02:20
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from b1dcb7a to bf60062 Compare April 20, 2026 18:52
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from 88861aa to 0fcde7d Compare April 20, 2026 18:53
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from bf60062 to dd5a687 Compare April 20, 2026 18:54
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch 2 times, most recently from d28fd65 to 7fdd192 Compare April 20, 2026 18:56
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from dd5a687 to ec3596e Compare April 20, 2026 18:58
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from 7fdd192 to fa62276 Compare April 20, 2026 18:58
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from ec3596e to 8f1d61b Compare April 20, 2026 19:04
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from fa62276 to 410171c Compare April 20, 2026 19:04
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from 8f1d61b to 70d3a74 Compare April 20, 2026 19:32
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch 3 times, most recently from af9a36d to 21807b7 Compare April 20, 2026 20:01
@starr-openai starr-openai marked this pull request as ready for review April 20, 2026 21:26
@starr-openai starr-openai requested a review from a team as a code owner April 20, 2026 21:26
Copy link
Copy Markdown
Contributor

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

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: 82608fb065

ℹ️ 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 thread codex-rs/core/src/session/turn_context.rs
access: proc_macro2::TokenStream,
ty: &Type,
) -> proc_macro2::TokenStream {
if let Some(inner) = option_inner(ty) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ooc why did this have to change?

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.

weird - maybe a rebase conflict or other change i had.- let me remove

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.

ah this was for the experimental config stuff. removing that, I don't think we really need to gate it

}

#[tokio::test]
async fn turn_environment_selection_sets_primary_environment() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

up to you but I don't find these unit tests that assert internal implementation details particularly useful long-term.

#[tokio::test]
async fn turn_environment_selection_sets_primary_environment() {
let (session, _turn_context, _rx) = make_session_and_context_with_rx().await;
let selected_cwd =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we turning AbsolutePath into pathbuf just to parse it back?

models_manager: &ModelsManager,
network: Option<NetworkProxy>,
environment: Option<Arc<Environment>>,
environments: Option<Vec<TurnEnvironment>>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should this be optional?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feels like it should be materialized either into an empty list or non-empty list but never None.

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.

we're still using the Option state to determine if env is enabled or not for tool access. will make this explicit in the later pr once this is attached to persistent thread state

.services
.environment_manager
.get_environment(&environment_selection.environment_id)
.ok_or_else(|| codex_config::ConstraintError::InvalidValue {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this the correct error type?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think ConstraintError::InvalidValue is for requirements.toml

sub_id,
session_configuration,
/*final_output_json_schema*/ None,
/*turn_environments*/ None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this correct? WebSocket prewarm uses this.
We establish a websocket connection and send an initial empty responses api request to warm up inference. That request includes tools. If we pass None environemnt here the first request will be sent without tools even for local environment which will break prewarming.

We might want to add environments onto thread/start to help the prewarm send the right request.

&per_turn_config.to_models_manager_config(),
)
.await;
let environment = match turn_environments.as_ref() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: maybe grab turn_environments.first() first and then set both environment and cwd

Comment on lines 614 to 615
per_turn_config.cwd = cwd.clone();
let plugin_outcome = self
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: can we pass cwd into build_per_turn_config and have it build the correct value from the getgo?

Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

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

Should we make environments non-optional?

@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch from 3b5e90b to 154be3f Compare April 21, 2026 17:36
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch 5 times, most recently from c2fbdee to 675777c Compare April 21, 2026 20:13
@starr-openai starr-openai force-pushed the env-manager-map-20260417 branch 2 times, most recently from 981cdd6 to 3ec48a2 Compare April 21, 2026 21:50
Base automatically changed from env-manager-map-20260417 to main April 21, 2026 22:29
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from b49f5c0 to 3fdd893 Compare April 21, 2026 23:40
starr-openai and others added 6 commits April 21, 2026 16:41
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from 3fdd893 to 8dac6ca Compare April 21, 2026 23:41
Use the generated executable path directly in the Unix script execution test so the assertion covers shebang execution without depending on PATH lookup behavior in the test runner.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the turn-environments-20260417 branch from 15b61dc to 734e853 Compare April 22, 2026 00:12
@starr-openai starr-openai merged commit 1d4cc49 into main Apr 22, 2026
25 checks passed
@starr-openai starr-openai deleted the turn-environments-20260417 branch April 22, 2026 00:48
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 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