Preserve executor paths in Guardian approval reviews (#42838)

## Why

Guardian approval actions can contain paths from a remote executor whose path convention differs from the host, such as Windows paths reviewed on a POSIX host. Converting those paths to host-native absolute paths prevents the action from being reviewed.

## What changed

- Render command working directories using the executor's reported path convention, and preserve URI-backed paths for attribution.
- Carry foreign command and patch paths through Guardian events and app-server schemas as legacy path strings.
- Bound remote plugin attribution within the overall review deadline and reject Guardian action payloads that exceed the review byte limit.

## Testing

- Cover Windows and POSIX executor path rendering, foreign patch paths, protocol round trips, oversized payload rejection, and remote Guardian review context.

GitOrigin-RevId: 38be0fcdac897139519e74e077eb5cb4f8f8017e
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-09-04 19:56:31 +00:00
1 parent 83b62a02fa
commit 773f0b081d
27 files changed
+442 -203

No files matched your search

+38 -30
View File
@@ -43,6 +43,7 @@ use codex_protocol::protocol::ReviewDecision;
use codex_protocol::request_permissions::RequestPermissionProfile;
use codex_tools::ToolName;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
use std::collections::HashMap;
use std::path::PathBuf;
@@ -274,6 +275,7 @@ impl ApprovalAction {
pub(crate) fn into_guardian_request(
self,
exec_command_cwd_convention: Option<PathConvention>,
) -> std::io::Result<crate::guardian::GuardianApprovalRequest> {
Ok(match self {
Self::ExecCommand {
@@ -288,8 +290,16 @@ impl ApprovalAction {
..
} => crate::guardian::GuardianApprovalRequest::ExecCommand {
id,
environment_id,
command,
cwd: guardian_cwd(&environment_id, cwd)?,
guardian_cwd: codex_utils_path_uri::LegacyAppPathString::from_path_uri(
&cwd,
exec_command_cwd_convention.ok_or_else(|| {
std::io::Error::other("missing exec command cwd convention")
})?,
)
.map_err(std::io::Error::other)?,
cwd,
sandbox_permissions,
additional_permissions,
justification,
@@ -335,18 +345,14 @@ impl ApprovalAction {
},
Self::ApplyPatch {
id,
environment_id,
cwd,
files,
patch,
..
} => crate::guardian::GuardianApprovalRequest::ApplyPatch {
id,
cwd: guardian_cwd(&environment_id, cwd)?,
files: files
.into_iter()
.map(|path| path.to_abs_path())
.collect::<std::io::Result<Vec<_>>>()?,
cwd,
files,
patch,
},
Self::McpToolCall {
@@ -408,28 +414,6 @@ impl ApprovalAction {
}
}
fn guardian_cwd(environment_id: &str, cwd: PathUri) -> std::io::Result<AbsolutePathBuf> {
match cwd.to_abs_path() {
Ok(cwd) => Ok(cwd),
Err(err) if environment_id != codex_exec_server::LOCAL_ENVIRONMENT_ID => Err(err),
Err(_) => {
let cwd_display = cwd.to_string();
let path = cwd.to_url().to_file_path().map_err(|()| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("local cwd URI `{cwd_display}` is not a host-native path"),
)
})?;
AbsolutePathBuf::from_absolute_path_checked(path).map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("local cwd URI `{cwd_display}` is not absolute: {err}"),
)
})
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum ApprovalReviewer {
Guardian,
@@ -620,7 +604,31 @@ impl Session {
}
let is_network_approval = matches!(&action, ApprovalAction::NetworkAccess { .. });
let review_id = new_guardian_review_id();
let action = match action.into_guardian_request() {
let exec_command_cwd_convention = match &action {
ApprovalAction::ExecCommand {
environment_id,
cwd,
..
} => Some(
match ctx
.review_context
.environments()
.turn_environments()
.find(|environment| environment.selection.environment_id == *environment_id)
.and_then(|environment| environment.executor_platform_os.as_deref())
{
Some("windows") => PathConvention::Windows,
Some(_) => PathConvention::Posix,
// Legacy executors did not report their OS. Preserve the
// previous spelling-based behavior for those executors.
None => cwd
.infer_path_convention()
.unwrap_or_else(PathConvention::native),
},
),
_ => None,
};
let action = match action.into_guardian_request(exec_command_cwd_convention) {
Ok(action) => action,
Err(err) => {
tracing::error!(%err, "failed to build automatic approval action");