Skip to content

Add explicit thread environment selection#18173

Closed
starr-openai wants to merge 22 commits intomainfrom
starr/thread-env-id-minimal
Closed

Add explicit thread environment selection#18173
starr-openai wants to merge 22 commits intomainfrom
starr/thread-env-id-minimal

Conversation

@starr-openai
Copy link
Copy Markdown
Contributor

@starr-openai starr-openai commented Apr 16, 2026

Summary

  • add ordered thread/turn environment selection for app-server callers, with required absolute cwd per environment
  • keep EnvironmentManager owned by ThreadManagerState and resolve protocol params into SessionEnvironment before session state sees them
  • collapse the prior dual environment carriers so core passes one resolved SessionEnvironment { environment_id, cwd, environment } list through spawn/session/turn state
  • remove spurious codex.rs rebase churn and keep the modular main layout

Validation

  • git diff --check
  • rustfmt run directly on touched Rust files because local cargo is guarded in this shell
  • Not run: tests/builds for the latest push, per request to update the PR first while review continues

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: 346e04c12e

ℹ️ 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/thread_manager.rs Outdated
Comment thread codex-rs/core/src/thread_manager.rs Outdated
@starr-openai starr-openai force-pushed the starr/thread-env-id-minimal branch from 7555d6b to 404d2f3 Compare April 16, 2026 20:14
Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
Comment thread codex-rs/app-server/tests/suite/v2/thread_start.rs Outdated
Comment thread codex-rs/app-server/tests/suite/v2/thread_start.rs Outdated
Comment thread codex-rs/app-server/tests/suite/v2/thread_start.rs Outdated
Comment thread codex-rs/core/src/codex.rs Outdated
Comment thread codex-rs/core/src/codex.rs Outdated
Comment thread codex-rs/exec-server/src/environment.rs
Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
Comment thread codex-rs/app-server-protocol/src/protocol/v2.rs Outdated
Comment thread codex-rs/exec-server/src/environment.rs Outdated
Comment thread codex-rs/exec-server/src/environment.rs Outdated
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.

Let's not have a global per-env cwd and make env_manager less hardcoded - imagine we do have a dynamic list of environments but for now populate it from env var/local.

@starr-openai
Copy link
Copy Markdown
Contributor Author

Superseded by stacked PRs #18225 and #18226.

@starr-openai starr-openai reopened this Apr 16, 2026
starr-openai added a commit that referenced this pull request Apr 17, 2026
Adjust the remaining constructor and test callsites for the thread environment plumbing.

Co-authored-by: Codex <noreply@openai.com>
starr-openai added a commit that referenced this pull request Apr 17, 2026
Adjust the remaining constructor and test callsites for the thread environment plumbing.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the starr/thread-env-id-minimal branch from 90a8975 to db419fb Compare April 17, 2026 01:15
@starr-openai starr-openai requested a review from pakrym-oai April 17, 2026 01:15
Comment thread codex-rs/core/src/thread_manager.rs Outdated
let environment = self
.environment_manager
.current()
let environment_manager = if environments
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.

This looks surprisingly complicated.

user_shell_override: None,
parent_trace: None,
analytics_events_client: None,
environments: vec![codex_protocol::protocol::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.

Can we keep all tests to None for now?

Comment thread codex-rs/core/src/codex_tests.rs Outdated
config.js_repl_node_path.clone(),
),
environment: Some(Arc::clone(&environment)),
environment_manager: Arc::new(codex_exec_server::EnvironmentManager::new(
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.

Why do we need environment manager on session?

pub struct ThreadEnvironmentParams {
pub environment_id: String,
#[ts(optional = nullable)]
pub cwd: Option<PathBuf>,
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.

AbsolutePathBuf

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.

Not optional

@@ -495,6 +502,11 @@ pub enum Op {
/// turns that rely on persistent session-level context (for example,
/// [`Op::UserInput`]).
OverrideTurnContext {
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.

Why have environment on OverrideTurnContext but not UserTurn?

Comment thread codex-rs/exec-server/src/environment.rs Outdated
#[derive(Debug)]
pub struct EnvironmentManager {
exec_server_url: Option<String>,
current_environment_id: Option<EnvironmentId>,
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 environment manager should stay shared and not have a current id. Just the list of available environments. Then each thread get it's own list of Environment structs

local_runtime_paths: Option<ExecServerRuntimePaths>,
) -> Result<Self, ExecServerError> {
let (exec_server_url, disabled) = normalize_exec_server_url(exec_server_url);
let id = if disabled {
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.

This doesn't look right. Env manager should have either:
1 env when REMOTE_ENV_ENV_VAR=none or not set.
2 envs local and remote when REMOTE_ENV_ENV_VAR is set.

}
}

fn normalize_environment_id(environment_id: Option<&str>) -> Option<EnvironmentId> {
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.

why?

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.

I don't think we should mutate and clone EnvironmentManager per turn. There is a global environment manager that contains a list of all environments registered with app server when a turn is started we create/attach a set of environments to a specific turn.

starr-openai and others added 21 commits April 16, 2026 20:12
Add thread/start environment_id plumbing and explicit local/remote selection support while preserving the current default environment behavior. Include focused exec-server and app-server coverage for the new thread environment selection paths.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Use only the first id for now and fall back to the legacy
environmentId field when the list is absent or empty.

Co-authored-by: Codex <noreply@openai.com>
Keep current behavior by collapsing to the first id at the
app-server boundary for now, and leave a TODO to plumb the
full list downstream in a follow-up PR.

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>
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>
Adjust the remaining constructor and test callsites for the thread environment plumbing.

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>
Keep EnvironmentManager owned by ThreadManagerState as the shared environment registry, and pass resolved per-thread environments into sessions as an attached list. Preserve the existing first-environment runtime behavior while carrying the selected environment descriptors for inheritance and future multi-environment support.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the starr/thread-env-id-minimal branch from 6912bdd to 0bb1f6e Compare April 17, 2026 03:24
Co-authored-by: Codex <noreply@openai.com>
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.

2 participants