From 60655e8b41fd2904cc2c2428742135774f58002f Mon Sep 17 00:00:00 2001 From: jif-oai Date: Fri, 26 Jun 2026 02:43:14 +0100 Subject: [PATCH] Fall back when remote filesystem walk is unavailable --- codex-rs/exec-server/src/remote_file_system.rs | 17 +++++++++++++++-- codex-rs/file-system/src/lib.rs | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/codex-rs/exec-server/src/remote_file_system.rs b/codex-rs/exec-server/src/remote_file_system.rs index acc86f7584..0d10c3aece 100644 --- a/codex-rs/exec-server/src/remote_file_system.rs +++ b/codex-rs/exec-server/src/remote_file_system.rs @@ -29,6 +29,7 @@ use crate::protocol::FsWalkParams; use crate::protocol::FsWriteFileParams; const INVALID_REQUEST_ERROR_CODE: i64 = -32600; +const METHOD_NOT_FOUND_ERROR_CODE: i64 = -32601; const NOT_FOUND_ERROR_CODE: i64 = -32004; #[path = "remote_file_stream.rs"] @@ -194,14 +195,26 @@ impl RemoteFileSystem { ) -> FileSystemResult { trace!("remote fs walk"); let client = self.client.get().await.map_err(map_remote_error)?; - let response = client + let response = match client .fs_walk(FsWalkParams { path: path.clone(), options, sandbox: remote_sandbox_context(sandbox), }) .await - .map_err(map_remote_error)?; + { + Ok(response) => response, + Err(ExecServerError::Server { + code: METHOD_NOT_FOUND_ERROR_CODE, + .. + }) => { + return ::walk_via_directory_reads( + self, path, options, sandbox, + ) + .await; + } + Err(error) => return Err(map_remote_error(error)), + }; Ok(response) } diff --git a/codex-rs/file-system/src/lib.rs b/codex-rs/file-system/src/lib.rs index fcdecc8cb5..737412f463 100644 --- a/codex-rs/file-system/src/lib.rs +++ b/codex-rs/file-system/src/lib.rs @@ -316,7 +316,19 @@ pub trait ExecutorFileSystem: Send + Sync { options: WalkOptions, sandbox: Option<&'a FileSystemSandboxContext>, ) -> ExecutorFileSystemFuture<'a, WalkOutcome> { - Box::pin(walk(self, path, options, sandbox)) + self.walk_via_directory_reads(path, options, sandbox) + } + + /// Performs a bounded walk using the primitive filesystem operations. + /// + /// Implementations with an optimized walk transport can use this as a compatibility fallback. + fn walk_via_directory_reads<'a>( + &'a self, + path: &'a PathUri, + options: WalkOptions, + sandbox: Option<&'a FileSystemSandboxContext>, + ) -> ExecutorFileSystemFuture<'a, WalkOutcome> { + Box::pin(walk_via_directory_reads(self, path, options, sandbox)) } fn remove<'a>( @@ -335,7 +347,7 @@ pub trait ExecutorFileSystem: Send + Sync { ) -> ExecutorFileSystemFuture<'a, ()>; } -async fn walk( +async fn walk_via_directory_reads( file_system: &F, root: &PathUri, options: WalkOptions,