openai/codex · error · anyhow::Error
DuplicateHandle failed for runner
Error message
DuplicateHandle failed for runner {pipe_label_for_thread} connect thread: {} What it means
Inside the runner-connect thread, DuplicateHandle failed to duplicate the current thread's HANDLE into the process so it can be published for parent-side cancellation. The error with GetLastError is sent over the thread_handle channel back to the parent, which converts it into this failure; the connect attempt then cannot support timeout cancellation.
Solutions
- Check the GetLastError code in the message for the DuplicateHandle failure reason
- Re-run the spawn; transient handle-table exhaustion can cause duplication failures
- Look for handle leaks in the spawning process if the failure recurs
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs:225 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/a28583f7cad3896d.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs:225
let mut connect_thread = Some(
thread::Builder::new()
.name(format!("codex-runner-connect-{pipe_label}"))
.spawn(move || {
let current_process = unsafe { GetCurrentProcess() };
let mut thread_handle = 0;
let duplicate_ok = unsafe {
DuplicateHandle(
current_process,
GetCurrentThread(),
current_process,
&mut thread_handle,
0,
0,
DUPLICATE_SAME_ACCESS,
)
};
if duplicate_ok == 0 {
let _ = thread_handle_tx.send(Err(anyhow::anyhow!(
"DuplicateHandle failed for runner {pipe_label_for_thread} connect thread: {}",
unsafe { GetLastError() }
)));
return;
}
// Publish the helper thread HANDLE before the blocking pipe connect so the
// parent can cancel this specific operation if it times out.
let _ = thread_handle_tx.send(Ok(thread_handle));
let result = connect_pipe(h_pipe, expected_runner_pid)
.map_err(anyhow::Error::from)
.context(format!("connect {pipe_label_for_thread}"));
let _ = connect_result_tx.send(result);
})?,
);
let thread_handle = thread_handle_rx.recv().map_err(|_| {
anyhow::anyhow!("runner {pipe_label} connect thread exited before publishing its handle")View on GitHub (pinned to 339751715c)