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
@@ -36,6 +36,7 @@ use codex_app_server_protocol::UserInput as V2UserInput;
use codex_config::types::AuthCredentialsStoreMode;
use codex_features::Feature;
use codex_utils_absolute_path::test_support::PathExt;
use codex_utils_path_uri::LegacyAppPathString;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use pretty_assertions::assert_eq;
@@ -604,7 +605,10 @@ async fn thread_compact_start_triggers_compaction_and_returns_empty_response() -
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(
(cwd.as_path(), runtime_workspace_roots),
(updated_cwd.path(), updated_roots)
(
updated_cwd.path(),
LegacyAppPathString::from_abs_paths(&updated_roots)
)
);
Ok(())
@@ -1,3 +1,4 @@
use codex_utils_path_uri::LegacyAppPathString;
use std::path::Path;
use std::time::Duration;
@@ -73,7 +74,7 @@ async fn thread_start_reports_selected_environment_metadata() -> Result<()> {
(
// TODO(anp): Return the selected environment's native cwd from thread/start.
host_cwd,
selected_workspace_roots,
LegacyAppPathString::from_abs_paths(&selected_workspace_roots),
// TODO(anp): Report the implicit built-in permission profile instead of None.
None,
)
@@ -110,13 +110,8 @@ async fn thread_environments_follow_the_loaded_thread_selection() -> Result<()>
timeout(DEFAULT_READ_TIMEOUT, second.read_response(request)).await??;
let expected = Some(vec![ThreadEnvironment {
environment_id: second.auto_env_params()?.environment_id,
cwd: resumed.cwd.clone(),
runtime_workspace_roots: resumed
.runtime_workspace_roots
.iter()
.cloned()
.map(Into::into)
.collect(),
cwd: resumed.cwd,
runtime_workspace_roots: resumed.runtime_workspace_roots,
}]);
assert_eq!(resumed.thread.environments, expected);
assert_read_and_list_environments(&mut second, &thread_id, &expected).await?;
@@ -784,7 +784,7 @@ async fn thread_resume_restores_startup_and_updated_runtime_workspace_roots() ->
.send_thread_start_request(ThreadStartParams {
model: Some("gpt-5.4".to_string()),
cwd: Some(initial_cwd.to_string_lossy().into_owned()),
runtime_workspace_roots: Some(initial_roots.clone()),
runtime_workspace_roots: Some(LegacyAppPathString::from_abs_paths(&initial_roots)),
environments: Some(explicit_environments.clone()),
..Default::default()
})
@@ -828,7 +828,7 @@ async fn thread_resume_restores_startup_and_updated_runtime_workspace_roots() ->
runtime_workspace_roots,
..
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(runtime_workspace_roots, vec![explicit_cwd.clone()]);
assert_eq!(runtime_workspace_roots, vec![explicit_cwd.clone().into()]);
// A cwd-only update must retain the fallback's additional folder, not the live roots.
mcp.clear_message_buffer();
@@ -901,7 +901,10 @@ async fn thread_resume_restores_startup_and_updated_runtime_workspace_roots() ->
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(
(cwd, runtime_workspace_roots),
(initial_cwd.clone().into(), expected_roots)
(
initial_cwd.clone().into(),
LegacyAppPathString::from_abs_paths(&expected_roots)
)
);
Ok(())
@@ -1003,7 +1006,9 @@ sandbox = "unelevated"
.send_thread_resume_request(ThreadResumeParams {
thread_id: thread_id.clone(),
cwd: cwd_override.map(|cwd| cwd.to_string_lossy().into_owned()),
runtime_workspace_roots: roots_override,
runtime_workspace_roots: roots_override
.as_deref()
.map(LegacyAppPathString::from_abs_paths),
service_tier: (index == 2).then_some(Some("priority".to_string())),
personality: (index == 2).then_some(Personality::None),
config: (index == 1).then(|| {
@@ -1019,7 +1024,10 @@ sandbox = "unelevated"
timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(
(resumed.cwd, resumed.runtime_workspace_roots),
(expected_cwd.clone().into(), expected_roots.clone())
(
expected_cwd.clone().into(),
LegacyAppPathString::from_abs_paths(&expected_roots)
)
);
if index < 3 {
mcp.start_turn_and_wait_for_completion(TurnStartParams {
@@ -1236,7 +1244,11 @@ async fn cold_resume_workspace_roots_validate_foreign_startup_paths() -> Result<
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(
(thread.id, cwd, runtime_workspace_roots),
(thread_id, local_cwd.clone().into(), expected_roots)
(
thread_id,
local_cwd.clone().into(),
LegacyAppPathString::from_abs_paths(&expected_roots)
)
);
} else {
let error = timeout(
@@ -1983,7 +1995,7 @@ async fn cold_resume_reresolves_persisted_active_permission_profile() -> Result<
);
assert_eq!(
runtime_workspace_roots,
vec![previous_workspace_root.path().abs()]
vec![previous_workspace_root.path().abs().into()]
);
}
Ok(())
@@ -45,6 +45,7 @@ use codex_protocol::protocol::MultiAgentVersion;
use codex_rollout::RolloutItem;
use codex_rollout::read_session_meta_line;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use core_test_support::load_default_config_for_test;
use core_test_support::responses;
use pretty_assertions::assert_eq;
@@ -384,7 +385,10 @@ async fn thread_revert_preserves_fork_cutoff_after_cold_resume() -> Result<()> {
.await?;
assert_eq!(
(cwd.as_path(), runtime_workspace_roots),
(saved_cwd.as_path(), saved_roots.clone())
(
saved_cwd.as_path(),
LegacyAppPathString::from_abs_paths(&saved_roots)
)
);
mcp.start_turn_and_wait_for_completion(TurnStartParams {
thread_id: child.id.clone(),
@@ -559,10 +559,26 @@ async fn thread_start_accepts_absolute_runtime_workspace_roots() -> Result<()> {
.build_initialized()
.await?;
let invalid_id = mcp
.send_thread_start_request(ThreadStartParams {
runtime_workspace_roots: Some(vec![
codex_utils_path_uri::LegacyAppPathString::from_string("relative"),
]),
..Default::default()
})
.await?;
let invalid = timeout(
DEFAULT_READ_TIMEOUT,
mcp.read_stream_until_error_message(RequestId::Integer(invalid_id)),
)
.await??;
assert_eq!(invalid.error.code, INVALID_REQUEST_ERROR_CODE);
assert!(invalid.error.message.contains("runtimeWorkspaceRoots"));
let req_id = mcp
.send_thread_start_request(ThreadStartParams {
cwd: Some(cwd.to_string_lossy().to_string()),
runtime_workspace_roots: Some(vec![extra_root.abs()]),
runtime_workspace_roots: Some(vec![extra_root.abs().into()]),
sandbox: Some(SandboxMode::WorkspaceWrite),
..Default::default()
})
@@ -576,7 +592,7 @@ async fn thread_start_accepts_absolute_runtime_workspace_roots() -> Result<()> {
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(req_id)).await??;
assert_eq!(response_cwd, cwd.abs().into());
assert_eq!(runtime_workspace_roots, vec![extra_root.abs()]);
assert_eq!(runtime_workspace_roots, vec![extra_root.abs().into()]);
#[cfg(windows)]
let _ = sandbox;
#[cfg(not(windows))]
@@ -596,7 +612,7 @@ async fn thread_start_accepts_absolute_runtime_workspace_roots() -> Result<()> {
environment.runtime_workspace_roots = Some(vec![environment_root.abs().into()]);
let req_id = mcp
.send_thread_start_request(ThreadStartParams {
runtime_workspace_roots: Some(vec![extra_root.abs()]),
runtime_workspace_roots: Some(vec![extra_root.abs().into()]),
environments: Some(vec![environment]),
sandbox: Some(SandboxMode::WorkspaceWrite),
..Default::default()
@@ -607,7 +623,7 @@ async fn thread_start_accepts_absolute_runtime_workspace_roots() -> Result<()> {
sandbox,
..
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(req_id)).await??;
assert_eq!(runtime_workspace_roots, vec![environment_root.abs()]);
assert_eq!(runtime_workspace_roots, vec![environment_root.abs().into()]);
#[cfg(windows)]
let _ = sandbox;
#[cfg(not(windows))]
@@ -656,7 +672,7 @@ async fn thread_start_excludes_profile_workspace_roots_from_runtime_workspace_ro
assert_eq!(
runtime_workspace_roots,
vec![cwd.path().to_path_buf().abs()]
vec![cwd.path().to_path_buf().abs().into()]
);
Ok(())