Collect plugin metrics from remote executors (#38283)

## What changed

- Resolve manifest-declared metric operations against the executor filesystem for remote plugin commands.
- Create the measurement sidecar in an executor-native, owner-private temporary directory, stream its bounded output back for validation, and clean up the directory afterward.
- Extend the exec-server protocol with the executor temporary directory and atomic private-directory creation.

## Testing

- Cover remote unified-exec measurements for foreground and background commands.
- Verify private directories use owner-only permissions on Unix and fail closed on unsupported platforms.

GitOrigin-RevId: dbbd0a84717b91237fc5728e510e18994eb46dd4
This commit is contained in:
Kyle Brown
2026-08-13 00:39:04 +00:00
committed by copyberry
parent 1e71e35df6
commit 9579479d28
18 changed files with 416 additions and 82 deletions
@@ -153,6 +153,27 @@ impl FileSystemHandler {
&self,
params: FsCreateDirectoryParams,
) -> Result<FsCreateDirectoryResponse, JSONRPCErrorError> {
if params.private.unwrap_or(false) {
if params.recursive.unwrap_or(false) || params.sandbox.is_some() {
return Err(invalid_request(
"private directories must be non-recursive and unsandboxed".to_string(),
));
}
#[cfg(unix)]
{
let path = params.path.to_abs_path().map_err(map_fs_error)?;
let mut builder = tokio::fs::DirBuilder::new();
builder.mode(0o700);
builder.create(path.as_path()).await.map_err(map_fs_error)?;
return Ok(FsCreateDirectoryResponse {});
}
#[cfg(not(unix))]
{
return Err(invalid_request(
"owner-private directories are unsupported on this platform".to_string(),
));
}
}
let recursive = params.recursive.unwrap_or(true);
self.file_system
.create_directory(
@@ -289,6 +310,9 @@ fn map_fs_error(err: io::Error) -> JSONRPCErrorError {
#[cfg(test)]
mod tests {
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use codex_protocol::protocol::NetworkAccess;
use codex_protocol::protocol::SandboxPolicy;
use codex_utils_path_uri::PathUri;
@@ -299,6 +323,62 @@ mod tests {
use crate::protocol::FsReadFileParams;
use crate::protocol::FsWriteFileParams;
#[cfg(unix)]
#[tokio::test]
async fn private_directories_are_created_with_owner_only_permissions() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let runtime_paths = ExecServerRuntimePaths::new(
std::env::current_exe().expect("current exe"),
/*codex_linux_sandbox_exe*/ None,
)
.expect("runtime paths");
let handler = FileSystemHandler::new(runtime_paths);
let directory = temp_dir.path().join("private-metrics");
handler
.create_directory(FsCreateDirectoryParams {
path: PathUri::from_host_native_path(&directory).expect("directory URI"),
recursive: Some(false),
sandbox: None,
private: Some(true),
})
.await
.expect("create private directory");
assert_eq!(
std::fs::metadata(directory)
.expect("directory metadata")
.permissions()
.mode()
& 0o777,
0o700
);
}
#[cfg(windows)]
#[tokio::test]
async fn private_directories_are_rejected_when_owner_only_permissions_are_unsupported() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let runtime_paths = ExecServerRuntimePaths::new(
std::env::current_exe().expect("current exe"),
/*codex_linux_sandbox_exe*/ None,
)
.expect("runtime paths");
let handler = FileSystemHandler::new(runtime_paths);
let directory = temp_dir.path().join("private-metrics");
let error = handler
.create_directory(FsCreateDirectoryParams {
path: PathUri::from_host_native_path(&directory).expect("directory URI"),
recursive: Some(false),
sandbox: None,
private: Some(true),
})
.await
.expect_err("private directories must fail closed");
assert!(error.message.contains("owner-private directories"));
assert!(!directory.exists());
}
#[tokio::test]
async fn no_platform_sandbox_policies_do_not_require_configured_sandbox_helper() {
let temp_dir = tempfile::tempdir().expect("tempdir");