Preserve workspace roots across client and server platforms (#62377)

## Why

A TUI connected to an app server on another platform can receive workspace
roots that its own filesystem cannot represent. For example, a Windows
drive path from the server cannot be stored as a native absolute path on
a Unix client.

## What changed

Keep `runtimeWorkspaceRoots` as native path strings on the wire for thread
start, resume, and fork. Validate absolute paths on the server and store
the returned roots as `PathUri` values in the TUI. Use the session's roots
for active remote forks, including side chats, and preserve permissions
for those roots in the TUI's permission display.

## Testing

Cover thread startup with workspace and writable roots from another
platform, remote root retention through start, turn, resume, and fork,
and server rejection of relative roots.

GitOrigin-RevId: 1e9e3bff64a6e7ddadb941f16c4952c44724af54
This commit is contained in:
Eric Traut
2026-11-18 22:40:03 +00:00
committed by copyberry
parent 7d458c8fc5
commit b967993f35
41 changed files with 492 additions and 169 deletions
@@ -5231,6 +5231,7 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
"cwd": cwd,
"approvalPolicy": "on-request",
"approvalsReviewer": "user",
"runtimeWorkspaceRoots": [cwd],
"sandbox": { "type": "workspaceWrite", "writableRoots": [cwd] },
"reasoningEffort": null
});
@@ -5245,6 +5246,7 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
for encoded in [json!(start), json!(resume), json!(fork)] {
assert_eq!(encoded["thread"]["cwd"], cwd);
assert_eq!(encoded["cwd"], cwd);
assert_eq!(encoded["runtimeWorkspaceRoots"], json!([cwd]));
assert_eq!(encoded["sandbox"]["writableRoots"], json!([cwd]));
}
assert_eq!(start.instruction_sources, Vec::<LegacyAppPathString>::new());
@@ -37,7 +37,6 @@ use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::ThreadGoalStatus as CoreThreadGoalStatus;
use codex_protocol::protocol::TokenUsage as CoreTokenUsage;
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathUri;
use serde::Deserialize;
@@ -85,7 +84,9 @@ pub struct ThreadStartParams {
/// Replace the thread's runtime workspace roots. Paths must be absolute.
#[experimental("thread/start.runtimeWorkspaceRoots")]
#[ts(optional = nullable)]
pub runtime_workspace_roots: Option<Vec<AbsolutePathBuf>>,
#[schemars(with = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
#[ts(as = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
pub runtime_workspace_roots: Option<Vec<LegacyAppPathString>>,
#[experimental(nested)]
#[ts(optional = nullable)]
pub approval_policy: Option<AskForApproval>,
@@ -196,14 +197,16 @@ pub struct ThreadStartResponse {
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
#[schemars(with = "AbsolutePathBuf")]
#[ts(as = "AbsolutePathBuf")]
#[schemars(with = "codex_utils_absolute_path::AbsolutePathBuf")]
#[ts(as = "codex_utils_absolute_path::AbsolutePathBuf")]
pub cwd: LegacyAppPathString,
/// Thread-scoped runtime workspace roots used to materialize
/// `:workspace_roots`.
#[experimental("thread/start.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
#[schemars(with = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
#[ts(as = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
pub runtime_workspace_roots: Vec<LegacyAppPathString>,
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<LegacyAppPathString>,
@@ -316,8 +319,8 @@ pub struct ThreadSettings {
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
#[schemars(with = "AbsolutePathBuf")]
#[ts(as = "AbsolutePathBuf")]
#[schemars(with = "codex_utils_absolute_path::AbsolutePathBuf")]
#[ts(as = "codex_utils_absolute_path::AbsolutePathBuf")]
pub cwd: LegacyAppPathString,
/// Environments configured for future turns, in priority order, primary first.
/// `null` means the server does not expose the selection; [] means none are selected.
@@ -409,7 +412,9 @@ pub struct ThreadResumeParams {
/// Replace the thread's runtime workspace roots. Paths must be absolute.
#[experimental("thread/resume.runtimeWorkspaceRoots")]
#[ts(optional = nullable)]
pub runtime_workspace_roots: Option<Vec<AbsolutePathBuf>>,
#[schemars(with = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
#[ts(as = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
pub runtime_workspace_roots: Option<Vec<LegacyAppPathString>>,
#[experimental(nested)]
#[ts(optional = nullable)]
pub approval_policy: Option<AskForApproval>,
@@ -459,14 +464,16 @@ pub struct ThreadResumeResponse {
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
#[schemars(with = "AbsolutePathBuf")]
#[ts(as = "AbsolutePathBuf")]
#[schemars(with = "codex_utils_absolute_path::AbsolutePathBuf")]
#[ts(as = "codex_utils_absolute_path::AbsolutePathBuf")]
pub cwd: LegacyAppPathString,
/// Thread-scoped runtime workspace roots used to materialize
/// `:workspace_roots`.
#[experimental("thread/resume.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
#[schemars(with = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
#[ts(as = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
pub runtime_workspace_roots: Vec<LegacyAppPathString>,
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<LegacyAppPathString>,
@@ -620,7 +627,9 @@ pub struct ThreadForkParams {
/// Replace the thread's runtime workspace roots. Paths must be absolute.
#[experimental("thread/fork.runtimeWorkspaceRoots")]
#[ts(optional = nullable)]
pub runtime_workspace_roots: Option<Vec<AbsolutePathBuf>>,
#[schemars(with = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
#[ts(as = "Option<Vec<codex_utils_absolute_path::AbsolutePathBuf>>")]
pub runtime_workspace_roots: Option<Vec<LegacyAppPathString>>,
#[experimental(nested)]
#[ts(optional = nullable)]
pub approval_policy: Option<AskForApproval>,
@@ -678,14 +687,16 @@ pub struct ThreadForkResponse {
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
#[schemars(with = "AbsolutePathBuf")]
#[ts(as = "AbsolutePathBuf")]
#[schemars(with = "codex_utils_absolute_path::AbsolutePathBuf")]
#[ts(as = "codex_utils_absolute_path::AbsolutePathBuf")]
pub cwd: LegacyAppPathString,
/// Thread-scoped runtime workspace roots used to materialize
/// `:workspace_roots`.
#[experimental("thread/fork.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
#[schemars(with = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
#[ts(as = "Vec<codex_utils_absolute_path::AbsolutePathBuf>")]
pub runtime_workspace_roots: Vec<LegacyAppPathString>,
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<LegacyAppPathString>,