openai/codex · error · anyhow::Error

missing parent directory

Error message

missing parent directory

What it means

write_atomic_create_new found the destination path has no parent directory (Path::parent is None). The atomic write strategy needs a parent for the temp file and hard-link dance, so the write aborts before touching the filesystem.

Solutions

  1. Treat as an internal bug: managed artifact paths always have a parent directory
  2. Verify the codex proxy directory layout is intact
  3. Report if a valid configuration can yield a parentless artifact path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/network-proxy/src/certs.rs:691 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at codex-rs/network-proxy/src/certs.rs:691

        KeyUsagePurpose::DigitalSignature,
        KeyUsagePurpose::KeyEncipherment,
    ];
    let mut dn = DistinguishedName::new();
    dn.push(DnType::CommonName, "network_proxy MITM CA");
    params.distinguished_name = dn;

    let key_pair = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256)
        .map_err(|err| anyhow!("failed to generate CA key pair: {err}"))?;
    let cert = params
        .self_signed(&key_pair)
        .map_err(|err| anyhow!("failed to generate CA cert: {err}"))?;
    Ok((cert.pem(), key_pair))
}

fn write_atomic_create_new(path: &Path, contents: &[u8], mode: u32) -> Result<()> {
    let parent = path
        .parent()
        .ok_or_else(|| anyhow!("missing parent directory"))?;

    let nanos = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap_or_default()
        .as_nanos();
    let pid = std::process::id();
    let file_name = path.file_name().unwrap_or_default().to_string_lossy();
    let tmp_path = parent.join(format!(".{file_name}.tmp.{pid}.{nanos}"));

    let mut file = open_create_new_with_mode(&tmp_path, mode)?;
    file.write_all(contents)
        .with_context(|| format!("failed to write {}", tmp_path.display()))?;
    file.sync_all()
        .with_context(|| format!("failed to fsync {}", tmp_path.display()))?;
    drop(file);

    // Create the final file using "create-new" semantics (no overwrite). `rename` on Unix can
    // overwrite existing files, so prefer a hard-link, which fails if the destination exists.

View on GitHub (pinned to 339751715c)