openai/codex · error · anyhow::Error

InitializeProcThreadAttributeList failed

Error message

InitializeProcThreadAttributeList failed: {}

What it means

The second (real) call to InitializeProcThreadAttributeList returned zero; the message embeds GetLastError. Windows could not initialize the attribute-list buffer that was sized by the preceding sizing call — typically an allocation or invalid-parameter failure when spawning a ConPTY child.

Solutions

  1. Retry the spawn; transient attribute-list failures can clear
  2. Check the last OS error for the underlying cause (memory, invalid flags)
  3. Ensure the sizing call and the real call use the same parameters
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/utils/pty/src/win/procthreadattr.rs:58 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/e1e429671cc49c0e. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/utils/pty/src/win/procthreadattr.rs:58

impl ProcThreadAttributeList {
    pub fn with_capacity(num_attributes: DWORD) -> Result<Self, Error> {
        let mut bytes_required: usize = 0;
        unsafe {
            InitializeProcThreadAttributeList(
                ptr::null_mut(),
                num_attributes,
                0,
                &mut bytes_required,
            )
        };
        let mut data = Vec::with_capacity(bytes_required);
        unsafe { data.set_len(bytes_required) };

        let attr_ptr = data.as_mut_slice().as_mut_ptr() as *mut _;
        let res = unsafe {
            InitializeProcThreadAttributeList(attr_ptr, num_attributes, 0, &mut bytes_required)
        };
        ensure!(
            res != 0,
            "InitializeProcThreadAttributeList failed: {}",
            IoError::last_os_error()
        );
        Ok(Self {
            data,
            job_list: Vec::new(),
        })
    }

    pub fn as_mut_ptr(&mut self) -> LPPROC_THREAD_ATTRIBUTE_LIST {
        self.data.as_mut_slice().as_mut_ptr() as *mut _
    }

    pub fn set_pty(&mut self, con: HPCON) -> Result<(), Error> {
        // SAFETY: `con` is the Windows-defined value and size for this attribute.
        unsafe {
            self.update(

View on GitHub (pinned to 339751715c)