{"record":{"id":"a28583f7cad3896d","repo":"openai/codex","slug":"duplicatehandle-failed-for-runner-pipe-label-for","errorCode":null,"errorMessage":"DuplicateHandle failed for runner {pipe_label_for_thread} connect thread: {}","messagePattern":"DuplicateHandle failed for runner (.+?) connect thread: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs","lineNumber":225,"sourceCode":"    let mut connect_thread = Some(\n        thread::Builder::new()\n            .name(format!(\"codex-runner-connect-{pipe_label}\"))\n            .spawn(move || {\n                let current_process = unsafe { GetCurrentProcess() };\n                let mut thread_handle = 0;\n                let duplicate_ok = unsafe {\n                    DuplicateHandle(\n                        current_process,\n                        GetCurrentThread(),\n                        current_process,\n                        &mut thread_handle,\n                        0,\n                        0,\n                        DUPLICATE_SAME_ACCESS,\n                    )\n                };\n                if duplicate_ok == 0 {\n                    let _ = thread_handle_tx.send(Err(anyhow::anyhow!(\n                        \"DuplicateHandle failed for runner {pipe_label_for_thread} connect thread: {}\",\n                        unsafe { GetLastError() }\n                    )));\n                    return;\n                }\n\n                // Publish the helper thread HANDLE before the blocking pipe connect so the\n                // parent can cancel this specific operation if it times out.\n                let _ = thread_handle_tx.send(Ok(thread_handle));\n\n                let result = connect_pipe(h_pipe, expected_runner_pid)\n                    .map_err(anyhow::Error::from)\n                    .context(format!(\"connect {pipe_label_for_thread}\"));\n                let _ = connect_result_tx.send(result);\n            })?,\n    );\n    let thread_handle = thread_handle_rx.recv().map_err(|_| {\n        anyhow::anyhow!(\"runner {pipe_label} connect thread exited before publishing its handle\")","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs#L207-L243","documentation":"Error \"DuplicateHandle failed for runner {pipe_label_for_thread} connect thread: {}\" thrown in openai/codex.","triggerScenarios":"Thrown at codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs:225 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"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"}