Add explicit thread environment selection#18173
Conversation
There was a problem hiding this comment.
💡 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".
7555d6b to
404d2f3
Compare
pakrym-oai
left a comment
There was a problem hiding this comment.
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.
Adjust the remaining constructor and test callsites for the thread environment plumbing. 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>
90a8975 to
db419fb
Compare
| let environment = self | ||
| .environment_manager | ||
| .current() | ||
| let environment_manager = if environments |
There was a problem hiding this comment.
This looks surprisingly complicated.
| user_shell_override: None, | ||
| parent_trace: None, | ||
| analytics_events_client: None, | ||
| environments: vec![codex_protocol::protocol::TurnEnvironment { |
There was a problem hiding this comment.
Can we keep all tests to None for now?
| config.js_repl_node_path.clone(), | ||
| ), | ||
| environment: Some(Arc::clone(&environment)), | ||
| environment_manager: Arc::new(codex_exec_server::EnvironmentManager::new( |
There was a problem hiding this comment.
Why do we need environment manager on session?
| pub struct ThreadEnvironmentParams { | ||
| pub environment_id: String, | ||
| #[ts(optional = nullable)] | ||
| pub cwd: Option<PathBuf>, |
| @@ -495,6 +502,11 @@ pub enum Op { | |||
| /// turns that rely on persistent session-level context (for example, | |||
| /// [`Op::UserInput`]). | |||
| OverrideTurnContext { | |||
There was a problem hiding this comment.
Why have environment on OverrideTurnContext but not UserTurn?
| #[derive(Debug)] | ||
| pub struct EnvironmentManager { | ||
| exec_server_url: Option<String>, | ||
| current_environment_id: Option<EnvironmentId>, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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> { |
pakrym-oai
left a comment
There was a problem hiding this comment.
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.
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>
6912bdd to
0bb1f6e
Compare
Co-authored-by: Codex <noreply@openai.com>
Summary
EnvironmentManagerowned byThreadManagerStateand resolve protocol params intoSessionEnvironmentbefore session state sees themSessionEnvironment { environment_id, cwd, environment }list through spawn/session/turn statecodex.rsrebase churn and keep the modular main layoutValidation
git diff --checkrustfmtrun directly on touched Rust files because localcargois guarded in this shell