mirror of
https://github.com/openai/codex.git
synced 2026-12-05 01:00:54 +00:00
Batch filesystem metadata checks for instruction and skill discovery (#63266)
## Why Discovering project instructions and repository skill directories can require several metadata checks per ancestor directory. Batching those checks reduces remote executor round trips and sandbox helper launches. ## What changed Add bounded metadata batches that return a result or error for each path in input order. Remote executors advertise support for `fs/getMetadataBatch`, and sandboxed filesystems can process a batch in one helper invocation. Check project root markers alongside the first working-directory instruction candidate, then batch the next candidate across unresolved directories in filename priority order. Batch checks for `.agents/skills` directories between the project root and the working directory. Fall back to individual checks when batching is unsupported. ## Testing Extend tests to assert batch counts for shallow and nested `AGENTS.md` discovery and verify that metadata batches preserve result order and per-path errors. GitOrigin-RevId: 6cb04202a905d783454908348d008def95b9a5d6
This commit is contained in:
@@ -26,6 +26,8 @@ use crate::protocol::FsCopyParams;
|
||||
use crate::protocol::FsCopyResponse;
|
||||
use crate::protocol::FsCreateDirectoryParams;
|
||||
use crate::protocol::FsCreateDirectoryResponse;
|
||||
use crate::protocol::FsGetMetadataBatchParams;
|
||||
use crate::protocol::FsGetMetadataBatchResponse;
|
||||
use crate::protocol::FsGetMetadataParams;
|
||||
use crate::protocol::FsGetMetadataResponse;
|
||||
use crate::protocol::FsOpenParams;
|
||||
@@ -235,6 +237,38 @@ impl FileSystemHandler {
|
||||
Ok(FsCreateDirectoryResponse {})
|
||||
}
|
||||
|
||||
pub(crate) async fn get_metadata_batch(
|
||||
&self,
|
||||
params: FsGetMetadataBatchParams,
|
||||
) -> Result<FsGetMetadataBatchResponse, JSONRPCErrorError> {
|
||||
if !codex_file_system::metadata_batch_fits(¶ms.paths) {
|
||||
return Err(invalid_request(
|
||||
"metadata batch exceeds size limit".to_string(),
|
||||
));
|
||||
}
|
||||
let options = GetMetadataOptions {
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
};
|
||||
let results = match self
|
||||
.file_system
|
||||
.get_metadata_batch(¶ms.paths, options, params.sandbox.as_ref())
|
||||
.await
|
||||
{
|
||||
Err(error) if error.kind() == io::ErrorKind::Unsupported => {
|
||||
codex_file_system::resolve_metadata_batch(
|
||||
&self.file_system,
|
||||
¶ms.paths,
|
||||
options,
|
||||
params.sandbox.as_ref(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
result => result,
|
||||
}
|
||||
.map_err(map_fs_error)?;
|
||||
Ok(crate::fs_helper::encode_metadata_batch(results))
|
||||
}
|
||||
|
||||
pub(crate) async fn get_metadata(
|
||||
&self,
|
||||
params: FsGetMetadataParams,
|
||||
|
||||
@@ -39,6 +39,8 @@ use crate::protocol::FsCopyParams;
|
||||
use crate::protocol::FsCopyResponse;
|
||||
use crate::protocol::FsCreateDirectoryParams;
|
||||
use crate::protocol::FsCreateDirectoryResponse;
|
||||
use crate::protocol::FsGetMetadataBatchParams;
|
||||
use crate::protocol::FsGetMetadataBatchResponse;
|
||||
use crate::protocol::FsGetMetadataParams;
|
||||
use crate::protocol::FsGetMetadataResponse;
|
||||
use crate::protocol::FsOpenParams;
|
||||
@@ -419,6 +421,14 @@ impl ExecServerHandler {
|
||||
.map_err(|error| crate::rpc::internal_error(error.to_string()))?
|
||||
}
|
||||
|
||||
pub(crate) async fn fs_get_metadata_batch(
|
||||
&self,
|
||||
params: FsGetMetadataBatchParams,
|
||||
) -> Result<FsGetMetadataBatchResponse, JSONRPCErrorError> {
|
||||
self.require_initialized_for("filesystem")?;
|
||||
self.file_system.get_metadata_batch(params).await
|
||||
}
|
||||
|
||||
pub(crate) async fn fs_get_metadata(
|
||||
&self,
|
||||
params: FsGetMetadataParams,
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::protocol::FS_CANONICALIZE_METHOD;
|
||||
use crate::protocol::FS_CLOSE_METHOD;
|
||||
use crate::protocol::FS_COPY_METHOD;
|
||||
use crate::protocol::FS_CREATE_DIRECTORY_METHOD;
|
||||
use crate::protocol::FS_GET_METADATA_BATCH_METHOD;
|
||||
use crate::protocol::FS_GET_METADATA_METHOD;
|
||||
use crate::protocol::FS_OPEN_METHOD;
|
||||
use crate::protocol::FS_READ_BLOCK_METHOD;
|
||||
@@ -31,6 +32,7 @@ use crate::protocol::FS_WALK_METHOD;
|
||||
use crate::protocol::FS_WRITE_BLOCK_METHOD;
|
||||
use crate::protocol::FS_WRITE_FILE_METHOD;
|
||||
use crate::protocol::FsCloseParams;
|
||||
use crate::protocol::FsGetMetadataBatchParams;
|
||||
use crate::protocol::FsReadBlockParams;
|
||||
use crate::protocol::FsWriteBlockParams;
|
||||
use crate::protocol::HTTP_REQUEST_METHOD;
|
||||
@@ -193,6 +195,12 @@ pub(crate) fn build_router() -> RpcRouter<ExecServerHandler> {
|
||||
handler.fs_watch_missing(params).await
|
||||
},
|
||||
);
|
||||
router.request(
|
||||
FS_GET_METADATA_BATCH_METHOD,
|
||||
|handler: Arc<ExecServerHandler>, params: FsGetMetadataBatchParams| async move {
|
||||
handler.fs_get_metadata_batch(params).await
|
||||
},
|
||||
);
|
||||
router.request(
|
||||
FS_GET_METADATA_METHOD,
|
||||
|handler: Arc<ExecServerHandler>, params: WireFsGetMetadataParams| async move {
|
||||
|
||||
Reference in New Issue
Block a user