Hmbown/CodeWhale · error

xAI OAuth path {} contains invalid Unicode and cannot be com

Error message

xAI OAuth path {} contains invalid Unicode and cannot be compared safely

What it means

normalize_windows_path_for_comparison converts both the resolved and expected paths to &str; if either contains unpaired surrogates (invalid UTF-16 as Unicode scalar values) the comparison is impossible and the open fails closed rather than skipping the identity check. Normal Windows APIs refuse to create such names, so this is near-unreachable in practice.

Source

Thrown at crates/config/src/xai_credentials.rs:1250

        GetFinalPathNameByHandleW(handle, buffer.as_mut_ptr(), buffer.len() as u32, flags)
    };
    if written == 0 || written as usize >= buffer.len() {
        return Err(std::io::Error::last_os_error())
            .context("resolving Codewhale-owned xAI OAuth handle path");
    }
    let actual = OsString::from_wide(&buffer[..written as usize]);
    anyhow::ensure!(
        normalize_windows_path_for_comparison(Path::new(&actual))?
            == normalize_windows_path_for_comparison(expected)?,
        "Codewhale-owned xAI OAuth path was redirected while opening"
    );
    Ok(metadata)
}

#[cfg(windows)]
fn normalize_windows_path_for_comparison(path: &Path) -> Result<String> {
    let text = path.to_str().ok_or_else(|| {
        anyhow::anyhow!(
            "xAI OAuth path {} contains invalid Unicode and cannot be compared safely",
            crate::quote_os_path(path)
        )
    })?;
    let without_device_prefix = text.strip_prefix(r"\\?\").unwrap_or(text);
    let normalized_prefix = without_device_prefix.strip_prefix("UNC\\").map_or_else(
        || without_device_prefix.to_string(),
        |rest| format!(r"\\{rest}"),
    );
    Ok(normalized_prefix
        .replace('/', "\\")
        .trim_end_matches('\\')
        .to_lowercase())
}

#[cfg(windows)]
fn secure_windows_owner_only_handle(file: &File, inherit_to_children: bool) -> Result<()> {
    use std::os::windows::io::AsRawHandle as _;

View on GitHub (pinned to 8880682c63)

Solutions

  1. Rename the offending component (or CODEWHALE_HOME) to valid Unicode
  2. Recreate $CODEWHALE_HOME under an ASCII-safe path and re-authenticate
Defensive patterns

Strategy: fallback

Try / catch

if let Err(e) = codewhale_config::with_xai_oauth_lifecycle_lock(&op) {
    if e.to_string().contains("invalid Unicode") {
        // cannot compare this path; fall back to a clean ASCII home
        std::env::set_var("CODEWHALE_HOME", fallback_home.display().to_string());
        return codewhale_config::with_xai_oauth_lifecycle_lock(&op);
    }
    return Err(e);
}

Prevention

When it happens

Trigger: A path component created with unpaired-surrogate characters by low-level/raw NTFS tooling; filesystem corruption producing invalid UTF-16 names.

Common situations: Exotic tools writing raw name streams; effectively never seen in normal usage.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/0e84ef092632531a. Report an issue: GitHub.