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:
dozaki-openai
2026-11-23 05:39:53 +00:00
committed by copyberry
parent 794584993e
commit 5f645d732c
17 changed files with 537 additions and 45 deletions
@@ -131,6 +131,49 @@ async fn file_system_get_metadata_reports_files_and_directories(
);
assert!(directory_metadata.modified_at_ms > 0);
let nested = directory_path.join("note.txt");
std::fs::write(&nested, "nested")?;
let paths = [
PathUri::from_host_native_path(&nested)?,
PathUri::from_host_native_path(tmp.path().join("missing"))?,
PathUri::from_host_native_path(&directory_path)?,
];
let batch = file_system
.get_metadata_batch(&paths, Default::default(), /*sandbox*/ None)
.await;
if matches!(implementation, FileSystemImplementation::Local) {
assert_eq!(
batch
.expect_err("unrestricted local metadata keeps the original short-circuit path")
.kind(),
std::io::ErrorKind::Unsupported
);
return Ok(());
}
let results = batch?;
assert_eq!(results.len(), paths.len());
assert!(results[0].as_ref().expect("file metadata").is_file);
assert_eq!(
results[1].as_ref().expect_err("missing metadata").kind(),
std::io::ErrorKind::NotFound
);
assert!(
results[2]
.as_ref()
.expect("directory metadata")
.is_directory
);
#[cfg(unix)]
{
std::fs::remove_file(&nested)?;
std::os::unix::fs::symlink("note.txt", &nested)?;
let results = file_system
.get_metadata_batch(&paths, Default::default(), /*sandbox*/ None)
.await?;
assert!(results[0].is_err(), "individual path errors are preserved");
assert!(results[2].as_ref().expect("later result").is_directory);
}
Ok(())
}