mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve app-server thread working directories across platforms (#62375)
## Why A remote app server can report a working directory in a different path convention from the client. Decoding a Windows drive path as a client-native absolute path can make a Unix client reject the thread response. ## What changed Keep thread `cwd` values as server-native strings in summaries, settings, and start, resume, and fork responses. Preserve the JSON and generated SDK types. In the TUI, store the session directory as a `PathUri` using the server's path convention when available. Use that directory to match diff and skill results and to display the project name in the terminal title. ## Testing Add regression coverage for foreign-path response round trips, diff results matched against a remote session directory, and terminal titles derived from a Windows path. Verify that the server rejects a working directory that cannot be encoded as UTF-8. GitOrigin-RevId: 600f0b531939db4cd4ec884de166224082995e00
This commit is contained in:
@@ -3379,7 +3379,7 @@ mod tests {
|
||||
recency_at: Some(3),
|
||||
status: v2::ThreadStatus::Idle,
|
||||
path: None,
|
||||
cwd: cwd.clone(),
|
||||
cwd: cwd.clone().into(),
|
||||
cli_version: "0.0.0".to_string(),
|
||||
source: v2::SessionSource::Exec,
|
||||
can_accept_direct_input: None,
|
||||
@@ -3394,7 +3394,7 @@ mod tests {
|
||||
model: "gpt-5".to_string(),
|
||||
model_provider: "openai".to_string(),
|
||||
service_tier: None,
|
||||
cwd,
|
||||
cwd: cwd.into(),
|
||||
runtime_workspace_roots: Vec::new(),
|
||||
instruction_sources: vec![
|
||||
codex_utils_path_uri::LegacyAppPathString::from_abs_path(&absolute_path(
|
||||
@@ -4644,7 +4644,7 @@ mod tests {
|
||||
thread_settings: v2::ThreadSettings {
|
||||
disabled_plugin_ids: Vec::new(),
|
||||
environments: Some(Vec::new()),
|
||||
cwd: absolute_path("/tmp/repo"),
|
||||
cwd: absolute_path("/tmp/repo").into(),
|
||||
approval_policy: v2::AskForApproval::Never,
|
||||
approvals_reviewer: v2::ApprovalsReviewer::User,
|
||||
sandbox_policy: v2::SandboxPolicy::DangerFullAccess,
|
||||
|
||||
@@ -324,7 +324,7 @@ fn thread_resume_response_round_trips_initial_turns_page() {
|
||||
recency_at: Some(1),
|
||||
status: ThreadStatus::Idle,
|
||||
path: None,
|
||||
cwd: absolute_path("tmp"),
|
||||
cwd: absolute_path("tmp").into(),
|
||||
cli_version: "0.0.0".to_string(),
|
||||
source: SessionSource::Exec,
|
||||
can_accept_direct_input: None,
|
||||
@@ -339,7 +339,7 @@ fn thread_resume_response_round_trips_initial_turns_page() {
|
||||
model: "gpt-5".to_string(),
|
||||
model_provider: "openai".to_string(),
|
||||
service_tier: None,
|
||||
cwd: absolute_path("tmp"),
|
||||
cwd: absolute_path("tmp").into(),
|
||||
runtime_workspace_roots: Vec::new(),
|
||||
instruction_sources: Vec::new(),
|
||||
approval_policy: AskForApproval::OnRequest,
|
||||
@@ -5162,6 +5162,11 @@ fn thread_start_params_preserve_explicit_null_service_tier() {
|
||||
|
||||
#[test]
|
||||
fn thread_lifecycle_responses_default_missing_optional_fields() {
|
||||
let cwd = if cfg!(windows) {
|
||||
"/home/alice/repo"
|
||||
} else {
|
||||
r"D:\repo"
|
||||
};
|
||||
let response = json!({
|
||||
"thread": {
|
||||
"id": "thread-id",
|
||||
@@ -5174,7 +5179,7 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
|
||||
"updatedAt": 1,
|
||||
"status": { "type": "idle" },
|
||||
"path": null,
|
||||
"cwd": absolute_path_string("tmp"),
|
||||
"cwd": cwd,
|
||||
"cliVersion": "0.0.0",
|
||||
"source": "exec",
|
||||
"agentNickname": null,
|
||||
@@ -5186,7 +5191,7 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
|
||||
"model": "gpt-5",
|
||||
"modelProvider": "openai",
|
||||
"serviceTier": null,
|
||||
"cwd": absolute_path_string("tmp"),
|
||||
"cwd": cwd,
|
||||
"approvalPolicy": "on-request",
|
||||
"approvalsReviewer": "user",
|
||||
"sandbox": { "type": "dangerFullAccess" },
|
||||
@@ -5200,6 +5205,10 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
|
||||
let fork: ThreadForkResponse =
|
||||
serde_json::from_value(response.clone()).expect("thread/fork response");
|
||||
|
||||
for encoded in [json!(start), json!(resume), json!(fork)] {
|
||||
assert_eq!(encoded["thread"]["cwd"], cwd);
|
||||
assert_eq!(encoded["cwd"], cwd);
|
||||
}
|
||||
assert_eq!(start.instruction_sources, Vec::<LegacyAppPathString>::new());
|
||||
assert_eq!(start.thread.parent_thread_id, None);
|
||||
assert_eq!(start.thread.recency_at, None);
|
||||
|
||||
@@ -196,7 +196,9 @@ pub struct ThreadStartResponse {
|
||||
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
|
||||
#[serde(default)]
|
||||
pub disabled_plugin_ids: Vec<String>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
#[schemars(with = "AbsolutePathBuf")]
|
||||
#[ts(as = "AbsolutePathBuf")]
|
||||
pub cwd: LegacyAppPathString,
|
||||
/// Thread-scoped runtime workspace roots used to materialize
|
||||
/// `:workspace_roots`.
|
||||
#[experimental("thread/start.runtimeWorkspaceRoots")]
|
||||
@@ -314,7 +316,9 @@ pub struct ThreadSettings {
|
||||
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
|
||||
#[serde(default)]
|
||||
pub disabled_plugin_ids: Vec<String>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
#[schemars(with = "AbsolutePathBuf")]
|
||||
#[ts(as = "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.
|
||||
#[experimental("thread/settings.environments")]
|
||||
@@ -455,7 +459,9 @@ pub struct ThreadResumeResponse {
|
||||
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
|
||||
#[serde(default)]
|
||||
pub disabled_plugin_ids: Vec<String>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
#[schemars(with = "AbsolutePathBuf")]
|
||||
#[ts(as = "AbsolutePathBuf")]
|
||||
pub cwd: LegacyAppPathString,
|
||||
/// Thread-scoped runtime workspace roots used to materialize
|
||||
/// `:workspace_roots`.
|
||||
#[experimental("thread/resume.runtimeWorkspaceRoots")]
|
||||
@@ -672,7 +678,9 @@ pub struct ThreadForkResponse {
|
||||
/// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
|
||||
#[serde(default)]
|
||||
pub disabled_plugin_ids: Vec<String>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
#[schemars(with = "AbsolutePathBuf")]
|
||||
#[ts(as = "AbsolutePathBuf")]
|
||||
pub cwd: LegacyAppPathString,
|
||||
/// Thread-scoped runtime workspace roots used to materialize
|
||||
/// `:workspace_roots`.
|
||||
#[experimental("thread/fork.runtimeWorkspaceRoots")]
|
||||
|
||||
@@ -14,7 +14,7 @@ use codex_protocol::protocol::SessionSource as CoreSessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource as CoreSubAgentSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode as CoreThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadSource as CoreThreadSource;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
#[cfg(test)]
|
||||
use schemars::r#gen::SchemaGenerator;
|
||||
#[cfg(test)]
|
||||
@@ -265,7 +265,10 @@ pub struct Thread {
|
||||
/// [UNSTABLE] Path to the thread on disk.
|
||||
pub path: Option<PathBuf>,
|
||||
/// Working directory captured for the thread.
|
||||
pub cwd: AbsolutePathBuf,
|
||||
// Preserve the published SDK type for this server-native absolute path.
|
||||
#[schemars(with = "codex_utils_absolute_path::AbsolutePathBuf")]
|
||||
#[ts(as = "codex_utils_absolute_path::AbsolutePathBuf")]
|
||||
pub cwd: LegacyAppPathString,
|
||||
/// Version of the CLI that created the thread.
|
||||
pub cli_version: String,
|
||||
/// Originator recorded when the thread was created, independent of its current client or executor.
|
||||
@@ -328,7 +331,7 @@ struct ThreadCompatibility {
|
||||
recency_at: Option<i64>,
|
||||
status: ThreadStatus,
|
||||
path: Option<PathBuf>,
|
||||
cwd: AbsolutePathBuf,
|
||||
cwd: LegacyAppPathString,
|
||||
cli_version: String,
|
||||
originator: Option<String>,
|
||||
source: SessionSource,
|
||||
|
||||
Reference in New Issue
Block a user