{"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":"fn 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}","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":"Generic defensive guard in write_all_handle: WriteFile reported success but advanced the written byte count by zero. Windows normally guarantees at least one byte is written on success (or the call fails with ERROR_IO_PENDING-like conditions), so this state is undefined behavior from the API contract; looping on it would spin forever, so it is converted into an error.","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":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}