core: move workspace roots onto environments#31655
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76ec0b291f
ℹ️ 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".
| .map(PathUri::to_abs_path) | ||
| .collect::<std::io::Result<Vec<_>>>() | ||
| }) | ||
| .transpose() | ||
| .ok() |
There was a problem hiding this comment.
Keep foreign environment roots out of host path conversion
For cross-OS remote environments, such as a Linux app-server selecting a Windows exec environment with runtimeWorkspaceRoots: ["C:\\repo"], PathUri::to_abs_path rejects the Windows URI because it is not host-native, and the error is discarded before falling back to the legacy host roots. The turn context and model-visible filesystem permissions are then built for the host fallback instead of the selected environment-native roots, despite the API accepting those roots.
AGENTS.md reference: AGENTS.md:L317-L322
Useful? React with 👍 / 👎.
| let legacy_fallback_workspace_roots = workspace_roots.unwrap_or(snapshot.workspace_roots); | ||
| let environment_selections = environment_selections.unwrap_or_else(|| { | ||
| self.thread_manager.default_environment_selections( | ||
| &legacy_fallback_cwd, | ||
| &legacy_fallback_workspace_roots, | ||
| ) |
There was a problem hiding this comment.
Retarget implicit workspace roots on cwd-only turns
When turn/start changes only cwd, this reuses the previous snapshot roots unchanged, so a normal thread whose roots were implicitly [old_cwd] creates the next default environment with cwd = new_cwd but workspace_roots = [old_cwd]. Profiles that grant :workspace_roots therefore keep permitting the old directory and not the new working directory, regressing the prior cwd-retargeting behavior for app-server turns that move between workspaces.
AGENTS.md reference: AGENTS.md:L102-L110
Useful? React with 👍 / 👎.
| .unwrap_or_else(|| PathUri::from_abs_path(&turn_ctx.cwd)); | ||
| let workspace_roots = turn_ctx.config.effective_workspace_roots(); | ||
| let workspace_roots = tool.workspace_roots(req); | ||
| let permissions = workspace_roots |
| windows_sandbox_private_desktop: self.windows_sandbox_private_desktop, | ||
| }) | ||
| .map_err(CodexErr::from)?; | ||
| let workspace_roots = self |
| .and_then(|turn_environment| turn_environment.cwd().to_abs_path().ok()) | ||
| .unwrap_or_else(|| session_configuration.cwd().clone()); | ||
| let per_turn_config = Self::build_per_turn_config(&session_configuration, cwd.clone()); | ||
| let workspace_roots = primary_turn_environment |
aa1b8e8 to
78b99eb
Compare
78b99eb to
2917cdb
Compare
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e215b3e109
ℹ️ 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".
| let environment_selections = environment_selections.unwrap_or_else(|| { | ||
| let workspace_roots = workspace_roots.unwrap_or(snapshot.workspace_roots); | ||
| self.thread_manager | ||
| .default_environment_selections(&legacy_fallback_cwd, &workspace_roots) |
There was a problem hiding this comment.
Rebind implicit roots on cwd-only updates
When a thread started with the default workspace root later receives only a cwd update, this path reuses snapshot.workspace_roots from the previous cwd instead of rebinding the implicit root to legacy_fallback_cwd. The next turn then runs in the new cwd while :workspace_roots still points at the old directory, so workspace-write commands or patches in the new cwd are denied unless the client also sends runtimeWorkspaceRoots (which thread/settings/update cannot do).
AGENTS.md reference: AGENTS.md:L102-L110
Useful? React with 👍 / 👎.
Depends on #31892.
Why
Workspace roots describe the filesystem available in a selected execution environment, but core stored them as separate thread-global session state. That split allowed the selected
cwdand workspace roots to diverge and made remote executor sandbox context depend on app-server-host paths.What changed
runtimeWorkspaceRootsto app-server environment selectionscwdruntimeWorkspaceRootsonly when app-server synthesizes default environmentsPathUrivalues through core and into filesystem/process sandbox contexts:workspace_rootsfor the selected environmentExplicit empty environment roots remain empty. When explicit environments and top-level roots are both supplied, the explicit environments determine the roots.
Validation
just test -p codex-app-server-protocolcwddefaultingcodex-core,codex-app-server, andcodex-app-server-protocol