{"record":{"id":"42b10a7e15ddce67","repo":"openai/codex","slug":"helperfirewallcominitfailed","errorCode":"HelperFirewallComInitFailed","errorMessage":"CoInitializeEx failed: {hr:?}","messagePattern":"CoInitializeEx failed: (.+?)","errorType":"error_code","errorClass":"SetupFailure","httpStatus":null,"severity":"error","filePath":"codex-rs/windows-sandbox-rs/src/bin/setup_main/win/firewall.rs","lineNumber":65,"sourceCode":"    friendly_desc: &'a str,\n    protocol: i32,\n    local_user_spec: &'a str,\n    offline_sid: &'a str,\n    remote_addresses: Option<&'a str>,\n    remote_ports: Option<&'a str>,\n}\n\npub fn ensure_offline_proxy_allowlist(\n    offline_sid: &str,\n    proxy_ports: &[u16],\n    allow_local_binding: bool,\n    log: &mut dyn Write,\n) -> Result<()> {\n    let local_user_spec = format!(\"O:LSD:(A;;CC;;;{offline_sid})\");\n\n    let hr = unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) };\n    if hr.is_err() {\n        return Err(anyhow::Error::new(SetupFailure::new(\n            SetupErrorCode::HelperFirewallComInitFailed,\n            format!(\"CoInitializeEx failed: {hr:?}\"),\n        )));\n    }\n\n    let result = unsafe {\n        (|| -> Result<()> {\n            let policy: INetFwPolicy2 = CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER)\n                .map_err(|err| {\n                    anyhow::Error::new(SetupFailure::new(\n                        SetupErrorCode::HelperFirewallPolicyAccessFailed,\n                        format!(\"CoCreateInstance NetFwPolicy2 failed: {err:?}\"),\n                    ))\n                })?;\n            ensure_local_policy_rules_take_effect(&policy)?;\n            let rules = policy.Rules().map_err(|err| {\n                anyhow::Error::new(SetupFailure::new(\n                    SetupErrorCode::HelperFirewallPolicyAccessFailed,","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/firewall.rs#L47-L83","documentation":"Fires in ensure_offline_proxy_allowlist when the COM runtime cannot be initialized via CoInitializeEx(COINIT_APARTMENTTHREADED) — required to use the Windows Firewall COM API (INetFwPolicy2) for adding the offline proxy allowlist rule. A failing HRESULT means COM init failed (e.g. RPC_E_CHANGED_MODE if the thread is already MTA).","triggerScenarios":"Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win/firewall.rs:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the HRESULT: RPC_E_CHANGED_MODE means the thread already initialized COM as MTA; adapt or run on a fresh thread","Ensure CoInitializeEx is called before any other COM usage on this thread","Wrap the setup step so firewall rule application failures are logged as SetupFailure with the helper-firewall code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}