{"record":{"id":"ca18af0da778f92e","repo":"openai/codex","slug":"failed-to-lock-conpty-handle","errorCode":null,"errorMessage":"failed to lock ConPTY handle","messagePattern":"failed to lock ConPTY handle","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs","lineNumber":283,"sourceCode":"        }\n        if let Ok(mut guard) = process_handle.lock()\n            && let Some(handle) = guard.take()\n        {\n            CloseHandle(handle);\n        }\n    }\n\n    if exit_code == 0 {\n        log_success(&command, logs_base_dir);\n    } else {\n        log_failure(&command, &format!(\"exit code {exit_code}\"), logs_base_dir);\n    }\n}\n\nfn resize_conpty_handle(hpc: &Arc<StdMutex<Option<HANDLE>>>, size: TerminalSize) -> Result<()> {\n    let guard = hpc\n        .lock()\n        .map_err(|_| anyhow::anyhow!(\"failed to lock ConPTY handle\"))?;\n    let hpc = guard\n        .as_ref()\n        .copied()\n        .ok_or_else(|| anyhow::anyhow!(\"process is not attached to a PTY\"))?;\n    let result = unsafe {\n        ResizePseudoConsole(\n            hpc,\n            COORD {\n                X: size.cols as i16,\n                Y: size.rows as i16,\n            },\n        )\n    };\n    if result == 0 {\n        Ok(())\n    } else {\n        Err(anyhow::anyhow!(\n            \"failed to resize console: HRESULT {result}\"","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs#L265-L301","documentation":"Error \"failed to lock ConPTY handle\" thrown in openai/codex.","triggerScenarios":"Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:283 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The ConPTY handle is held by another operation; retry once the concurrent resize or write completes."],"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"}