openai/codex · error · std::io::Error

local cwd URI `{cwd_display}` is not a host-native path

Error message

local cwd URI `{cwd_display}` is not a host-native path

What it means

guardian_cwd converts a session cwd PathUri to an AbsolutePathBuf for approval requests (ExecCommand, ApplyPatch). It first tries PathUri::to_abs_path(); for the LOCAL environment only, a failure falls back to URL→filesystem-path conversion via to_url().to_file_path(). This io::Error(InvalidInput) fires when that conversion is impossible — the URI is not a convertible file URL on this host, e.g. a non-file scheme or a file URL carrying a host authority (file://host/share) that has no meaning as a host-native path.

Source

Thrown at codex-rs/core/src/tools/approvals.rs:358

                permissions,
            } => crate::guardian::GuardianApprovalRequest::RequestPermissions {
                id,
                turn_id,
                reason,
                permissions,
            },
        })
    }
}

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,
    User,

View on GitHub (pinned to 339751715c)

Solutions

  1. Pass cwd as a plain absolute file URI (file:///abs/path, empty authority) from the client/app-server side
  2. Verify the session is not marked LOCAL when the cwd actually belongs to a remote environment — non-local environments fail earlier at to_abs_path and never hit this branch
  3. Fix upstream URI construction: strip scheme/authority and rebuild a file URL from the absolute path
  4. Upgrade the integration if a newer version normalizes workspace URIs before sending approval requests

Example fix

// before — editor workspace URI passed through
request.cwd = PathUri::from("vscode-remote://ssh-remote%2Bbox/workspace/app");
// → local cwd URI `vscode-remote://ssh-remote%2Bbox/workspace/app` is not a host-native path

// after — send the host-native file URI for local sessions
request.cwd = PathUri::from("file:///home/user/workspace/app");
Defensive patterns

Strategy: validation

Validate before calling

// Before building an approval request for a LOCAL environment:
fn local_cwd_ok(cwd: &PathUri) -> bool {
    if cwd.to_abs_path().is_ok() { return true; }
    let u = cwd.to_url();
    u.scheme() == "file" && u.host_str().is_none() && u.to_file_path().is_ok()
}

Type guard

fn is_native_file_uri(cwd: &PathUri) -> bool {
    let u = cwd.to_url();
    u.scheme() == "file" && u.host_str().is_none() && u.to_file_path().is_ok()
}

Try / catch

match guardian_cwd(env_id, cwd.clone()) {
    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => {
        reject_request_with_retryable_hint(e); // ask client to resend absolute file URI
    }
    r => r?,
}

Prevention

When it happens

Trigger: An approval request on the local environment whose cwd PathUri is a remote/virtual-scheme URI (vscode-remote://, https://) or a file URL with an authority component, so to_file_path() returns Err(()).

Common situations: IDE/app-server integrations passing editor workspace URIs verbatim as cwd; remote-development workspaces incorrectly marked local; URI rewriting bugs that preserve scheme/authority where a plain file:///path was expected.

Related errors


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/fad3bd215f4cdb24. Report an issue: GitHub.