From 38846d7f1a193526e7134a2b6aa2c703fcfe3e99 Mon Sep 17 00:00:00 2001 From: Matthew Zeng Date: Tue, 16 Jun 2026 18:43:27 -0700 Subject: [PATCH] Preserve legacy symlink scan behavior --- codex-rs/core-skills/src/loader.rs | 24 +++++++++-- codex-rs/exec-server/src/local_file_system.rs | 2 +- codex-rs/exec-server/src/protocol.rs | 40 ++++++++++++++++- .../exec-server/tests/file_system/shared.rs | 4 +- .../exec-server/tests/file_system_unix.rs | 4 +- .../tests/executor_file_system_authority.rs | 43 +++++++++++++++++-- codex-rs/file-system/src/lib.rs | 3 +- 7 files changed, 105 insertions(+), 15 deletions(-) diff --git a/codex-rs/core-skills/src/loader.rs b/codex-rs/core-skills/src/loader.rs index bd425090c2..09eac2ed4b 100644 --- a/codex-rs/core-skills/src/loader.rs +++ b/codex-rs/core-skills/src/loader.rs @@ -558,8 +558,24 @@ async fn discover_skills_under_root( } let path = dir.join(&file_name); - if entry.is_symlink { - if follow_symlinks && entry.is_directory { + let (is_directory, is_file, is_symlink) = match entry.is_symlink { + Some(is_symlink) => (entry.is_directory, entry.is_file, is_symlink), + None => { + // Older remote exec servers omit symlink identity from directory entries. + let path_uri = PathUri::from_abs_path(&path); + let metadata = match fs.get_metadata(&path_uri, /*sandbox*/ None).await { + Ok(metadata) => metadata, + Err(e) => { + error!("failed to stat skills path {}: {e:#}", path.display()); + continue; + } + }; + (metadata.is_directory, metadata.is_file, metadata.is_symlink) + } + }; + + if is_symlink { + if follow_symlinks && is_directory { let resolved_dir = canonicalize_for_skill_identity(fs, &path).await; enqueue_dir( &mut queue, @@ -572,7 +588,7 @@ async fn discover_skills_under_root( continue; } - if entry.is_directory { + if is_directory { let resolved_dir = canonicalize_for_skill_identity(fs, &path).await; enqueue_dir( &mut queue, @@ -584,7 +600,7 @@ async fn discover_skills_under_root( continue; } - if entry.is_file && file_name == SKILLS_FILENAME { + if is_file && file_name == SKILLS_FILENAME { match parse_skill_file(fs, &path, scope, plugin_id, plugin_root.as_ref()).await { Ok(skill) => { outcome.skills.push(skill); diff --git a/codex-rs/exec-server/src/local_file_system.rs b/codex-rs/exec-server/src/local_file_system.rs index 36fae4c0f1..4c813716fd 100644 --- a/codex-rs/exec-server/src/local_file_system.rs +++ b/codex-rs/exec-server/src/local_file_system.rs @@ -613,7 +613,7 @@ impl DirectFileSystem { file_name: entry.file_name().to_string_lossy().into_owned(), is_directory, is_file, - is_symlink, + is_symlink: Some(is_symlink), }); } Ok(entries) diff --git a/codex-rs/exec-server/src/protocol.rs b/codex-rs/exec-server/src/protocol.rs index 08564b6dc6..daf71f088e 100644 --- a/codex-rs/exec-server/src/protocol.rs +++ b/codex-rs/exec-server/src/protocol.rs @@ -320,8 +320,8 @@ pub struct FsReadDirectoryEntry { pub file_name: String, pub is_directory: bool, pub is_file: bool, - #[serde(default)] - pub is_symlink: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub is_symlink: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -496,6 +496,7 @@ mod base64_bytes { #[cfg(test)] mod tests { + use super::FsReadDirectoryEntry; use super::FsReadFileParams; use super::HttpRequestParams; use codex_file_system::FileSystemSandboxContext; @@ -503,6 +504,41 @@ mod tests { use codex_utils_path_uri::PathUri; use pretty_assertions::assert_eq; + #[test] + fn read_directory_entry_preserves_unknown_legacy_symlink_state() { + let entry: FsReadDirectoryEntry = serde_json::from_value(serde_json::json!({ + "fileName": "skill", + "isDirectory": true, + "isFile": false, + })) + .expect("legacy directory entry should deserialize"); + + assert_eq!( + entry, + FsReadDirectoryEntry { + file_name: "skill".to_string(), + is_directory: true, + is_file: false, + is_symlink: None, + } + ); + assert_eq!( + serde_json::to_value(FsReadDirectoryEntry { + file_name: "linked-skill".to_string(), + is_directory: true, + is_file: false, + is_symlink: Some(true), + }) + .expect("current directory entry should serialize"), + serde_json::json!({ + "fileName": "linked-skill", + "isDirectory": true, + "isFile": false, + "isSymlink": true, + }) + ); + } + #[test] fn filesystem_protocol_accepts_legacy_absolute_paths_and_serializes_path_uris() { let legacy_path = std::env::current_dir() diff --git a/codex-rs/exec-server/tests/file_system/shared.rs b/codex-rs/exec-server/tests/file_system/shared.rs index ea4c2fa50f..4818476598 100644 --- a/codex-rs/exec-server/tests/file_system/shared.rs +++ b/codex-rs/exec-server/tests/file_system/shared.rs @@ -343,13 +343,13 @@ async fn file_system_read_directory_lists_entries( file_name: "nested".to_string(), is_directory: true, is_file: false, - is_symlink: false, + is_symlink: Some(false), }, ReadDirectoryEntry { file_name: "root.txt".to_string(), is_directory: false, is_file: true, - is_symlink: false, + is_symlink: Some(false), }, ] ); diff --git a/codex-rs/exec-server/tests/file_system_unix.rs b/codex-rs/exec-server/tests/file_system_unix.rs index 1da24da0f3..9e1a36fac0 100644 --- a/codex-rs/exec-server/tests/file_system_unix.rs +++ b/codex-rs/exec-server/tests/file_system_unix.rs @@ -111,13 +111,13 @@ async fn file_system_read_directory_reports_symlink_target_kind( file_name: "directory-link".to_string(), is_directory: true, is_file: false, - is_symlink: true, + is_symlink: Some(true), }, ReadDirectoryEntry { file_name: "file-link".to_string(), is_directory: false, is_file: true, - is_symlink: true, + is_symlink: Some(true), }, ] ); diff --git a/codex-rs/ext/skills/tests/executor_file_system_authority.rs b/codex-rs/ext/skills/tests/executor_file_system_authority.rs index 604f0fbbbc..3418b76428 100644 --- a/codex-rs/ext/skills/tests/executor_file_system_authority.rs +++ b/codex-rs/ext/skills/tests/executor_file_system_authority.rs @@ -33,6 +33,7 @@ static NEXT_TEST_ROOT_ID: AtomicUsize = AtomicUsize::new(0); struct SyntheticFileSystem { alias_root: AbsolutePathBuf, canonical_root: AbsolutePathBuf, + entry_is_symlink: Option, } impl SyntheticFileSystem { @@ -60,14 +61,14 @@ impl SyntheticFileSystem { file_name: "skill".to_string(), is_directory: true, is_file: false, - is_symlink: false, + is_symlink: self.entry_is_symlink, }]) } else if path == self.canonical_root.join("skill") { Ok(vec![ReadDirectoryEntry { file_name: "SKILL.md".to_string(), is_directory: false, is_file: true, - is_symlink: false, + is_symlink: self.entry_is_symlink, }]) } else { Err(io::Error::new(io::ErrorKind::NotFound, "not found")) @@ -150,7 +151,7 @@ impl ExecutorFileSystem for SyntheticFileSystem { ) -> ExecutorFileSystemFuture<'a, FileMetadata> { Box::pin(async move { let path = path.to_abs_path()?; - if path == self.canonical_root { + if path == self.canonical_root || self.entry_is_symlink.is_none() { self.metadata(&path) } else { Err(io::Error::new( @@ -206,6 +207,7 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() { file_system: Arc::new(SyntheticFileSystem { alias_root, canonical_root: canonical_root.clone(), + entry_is_symlink: Some(false), }), plugin_id: None, plugin_root: None, @@ -227,6 +229,41 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() { ); } +#[tokio::test] +async fn skill_loading_falls_back_for_legacy_directory_entries() { + let test_root = std::env::temp_dir().join(format!( + "codex-legacy-executor-skill-fs-{}", + std::process::id() + )); + let alias_root = AbsolutePathBuf::from_absolute_path_checked(test_root.join("alias")) + .expect("absolute path"); + let canonical_root = AbsolutePathBuf::from_absolute_path_checked(test_root.join("canonical")) + .expect("absolute path"); + + let outcome = load_skills_from_roots([SkillRoot { + path: alias_root.clone(), + scope: SkillScope::User, + file_system: Arc::new(SyntheticFileSystem { + alias_root, + canonical_root, + entry_is_symlink: None, + }), + plugin_id: None, + plugin_root: None, + }]) + .await; + + assert_eq!(outcome.errors, Vec::new()); + assert_eq!( + outcome + .skills + .iter() + .map(|skill| skill.name.as_str()) + .collect::>(), + vec!["synthetic"] + ); +} + #[tokio::test] async fn selected_root_id_distinguishes_identical_executor_paths() { let test_root = create_local_skill_root("root-identity").expect("create local skill root"); diff --git a/codex-rs/file-system/src/lib.rs b/codex-rs/file-system/src/lib.rs index 4b37ef5176..d037b6d82e 100644 --- a/codex-rs/file-system/src/lib.rs +++ b/codex-rs/file-system/src/lib.rs @@ -54,7 +54,8 @@ pub struct ReadDirectoryEntry { pub file_name: String, pub is_directory: bool, pub is_file: bool, - pub is_symlink: bool, + /// `None` when the backing filesystem cannot report symlink identity. + pub is_symlink: Option, } #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]