{"record":{"id":"1263f3614095bbf6","repo":"openai/codex","slug":"writefile-returned-success-but-wrote-0-bytes","errorCode":null,"errorMessage":"WriteFile returned success but wrote 0 bytes","messagePattern":"WriteFile returned success but wrote 0 bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs","lineNumber":230,"sourceCode":"\nfn write_all_handle(handle: HANDLE, mut bytes: &[u8]) -> Result<()> {\n    while !bytes.is_empty() {\n        let mut written = 0u32;\n        let ok = unsafe {\n            WriteFile(\n                handle,\n                bytes.as_ptr() as *const _,\n                bytes.len() as u32,\n                &mut written,\n                ptr::null_mut(),\n            )\n        };\n        if ok == 0 {\n            let err = unsafe { GetLastError() } as i32;\n            return Err(anyhow::anyhow!(\"WriteFile failed: {err}\"));\n        }\n        if written == 0 {\n            anyhow::bail!(\"WriteFile returned success but wrote 0 bytes\");\n        }\n        bytes = &bytes[written as usize..];\n    }\n    Ok(())\n}\n\n#[allow(clippy::too_many_arguments)]\nfn finalize_exit(\n    exit_tx: oneshot::Sender<i32>,\n    process_handle: Arc<StdMutex<Option<HANDLE>>>,\n    thread_handle: HANDLE,\n    output_join: std::thread::JoinHandle<()>,\n    logs_base_dir: Option<&Path>,\n    command: Vec<String>,\n) {\n    let exit_code = {\n        let mut raw_exit = 1u32;\n        if let Ok(guard) = process_handle.lock()","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs#L212-L248","documentation":"Error \"WriteFile returned success but wrote 0 bytes\" thrown in openai/codex.","triggerScenarios":"Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:230 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the write; a zero-byte successful write usually means the pipe buffer is full, so ensure the reader side is draining."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}