openai/codex · error
CopySid(TokenUser) failed
Error message
CopySid(TokenUser) failed: {} What it means
Bailed by the token-inspection path when CopySid fails to duplicate the token user's SID into the allocated buffer. GetLastError is included; the SID bytes needed for identity comparison could not be copied from the token.
Solutions
- Verify sid_len matches the source SID (IsValidSid)
- Re-query the token and retry the copy
- Inspect the Win32 error for the concrete cause
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at codex-rs/windows-sandbox-rs/src/token.rs:314 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/8778761958b4f880.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/windows-sandbox-rs/src/token.rs:314
GetLastError()
));
}
let token_user: TOKEN_USER = std::ptr::read_unaligned(user_buf.as_ptr() as *const TOKEN_USER);
let sid_len = GetLengthSid(token_user.User.Sid);
if sid_len == 0 {
return Err(anyhow!(
"GetLengthSid(TokenUser) failed: {}",
GetLastError()
));
}
let mut user_sid_bytes = vec![0u8; sid_len as usize];
if CopySid(
sid_len,
user_sid_bytes.as_mut_ptr() as *mut c_void,
token_user.User.Sid,
) == 0
{
return Err(anyhow!("CopySid(TokenUser) failed: {}", GetLastError()));
}
Ok(user_sid_bytes)
}
unsafe fn enable_single_privilege(h_token: HANDLE, name: &str) -> Result<()> {
let mut luid = LUID {
LowPart: 0,
HighPart: 0,
};
let ok = LookupPrivilegeValueW(std::ptr::null(), to_wide(name).as_ptr(), &mut luid);
if ok == 0 {
return Err(anyhow!("LookupPrivilegeValueW failed: {}", GetLastError()));
}
let mut tp: TOKEN_PRIVILEGES = std::mem::zeroed();
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = 0x00000002; // SE_PRIVILEGE_ENABLED
let ok2 = AdjustTokenPrivileges(View on GitHub (pinned to 339751715c)