openai/codex · error
WriteFile returned success but wrote 0 bytes
Error message
WriteFile returned success but wrote 0 bytes
What it means
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.
Solutions
- Retry the write; a zero-byte successful write usually means the pipe buffer is full, so ensure the reader side is draining.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:230 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/1263f3614095bbf6.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:230
fn write_all_handle(handle: HANDLE, mut bytes: &[u8]) -> Result<()> {
while !bytes.is_empty() {
let mut written = 0u32;
let ok = unsafe {
WriteFile(
handle,
bytes.as_ptr() as *const _,
bytes.len() as u32,
&mut written,
ptr::null_mut(),
)
};
if ok == 0 {
let err = unsafe { GetLastError() } as i32;
return Err(anyhow::anyhow!("WriteFile failed: {err}"));
}
if written == 0 {
anyhow::bail!("WriteFile returned success but wrote 0 bytes");
}
bytes = &bytes[written as usize..];
}
Ok(())
}View on GitHub (pinned to 339751715c)