Skip to content

[Bug]: Windows Desktop app fails to start: Codex app-server websocket closed (code=3221225495 / 0xC0000017) due to environment block overflow #46374

Open

Description

@aamirovich

What version of the Codex App are you using?

Microsoft Store / MSIX build 26.911.7940.0 (Codex CLI 0.141.0+)

What platform is your computer?

Windows 11 / Windows 10 x64

What issue are you seeing?

The desktop app fails immediately upon launch with the following error dialog:

ChatGPT failed to start.
(code=3221225495, signal=null).
Most recent error: Codex app-server websocket closed (code=3221225495)

Clicking "Check for Updates" results in net::ERR_BLOCKED_BY_CLIENT.


Root Cause Analysis (Reverse-Engineered from app.asar)

1. What 3221225495 Actually Means

Converting decimal 3221225495 to hex gives 0xC0000017.
In Windows NTSTATUS, this is STATUS_NO_MEMORY (ERROR_NOT_ENOUGH_QUOTA).
This is not an actual RAM exhaustion issue (the machine had 40 GB physical RAM with 20 GB free).

2. The Mechanism in Desktop Code

In oW / StdioConnection.spawnProcess() inside app.asar:

let r = {
  ...process.env,
  LOG_FORMAT: 'json',
  RUST_LOG: process.env.RUST_LOG ?? 'warn',
  CODEX_INTERNAL_ORIGINATOR_OVERRIDE: e.defaultOriginator ?? zU
};
// ...
let n = spawn(executablePath, args, {
  stdio: ['pipe', 'pipe', 'pipe'],
  env: sanitizedEnv,
  cwd: options.cwd
});
  • When CreateProcessW / ZwCreateUserProcess is called on Windows inside the MSIX / AppContainer boundary, the kernel allocates memory for RTL_USER_PROCESS_PARAMETERS->Environment.
  • On Windows NT, the serialized environment block buffer has an allocation quota limit of 32,767 characters (32 KB).
  • When spawn() passes process.env down to codex.exe, if the serialized environment block exceeds 32 KB, the Windows kernel refuses to allocate the environment block, immediately failing process creation with NTSTATUS 0xC0000017 (3221225495).

3. Misleading UI Error

Because StdioConnection wraps process termination in a generic transport close handler, it prints:
Codex app-server websocket closed (code=3221225495)
even though the transport kind is stdio rather than websocket, leading users to mistakenly assume a network or proxy problem.


Real-World Case Study: How an Autonomous Agent Session Triggered This Bug

This issue occurred directly as a result of an autonomous development session driven by the agent:

  1. Autonomous Execution Loop:
    The agent was autonomously running extensive test and verification loops during project development.
  2. Ephemeral Directory Build Side Effects:
    Each test run created an isolated temporary directory via mkdtemp (e.g. AppData\Local\Temp\test-runner-<id>\dotnet-home) and invoked .NET SDK (dotnet build).
  3. Registry Pollution:
    On Windows, the .NET SDK checks if %DOTNET_CLI_HOME%\.dotnet\tools exists in the persistent user environment and registers it into HKCU:\Environment\Path.
  4. Self-Sabotaging Environment Bloat:
    Across 290+ autonomous test iterations, 291 unique temporary paths were permanently appended to the Windows registry, inflating the User PATH to 31,686 characters.
  5. The Crash:
    Once the desktop app was closed and restarted, the environment block exceeded the 32 KB kernel limit, permanently bricking the desktop app until manual registry remediation was performed.

This reveals a critical need for environment isolation and guardrails during autonomous tool execution.


Workaround for Affected Users

Cleaning bloated User PATH immediately resolves the startup crash without losing any chat history or sessions:

# 1. Check if User PATH is bloated (>10,000 chars)
((Get-ItemProperty "HKCU:\Environment").Path).Length

# 2. Backup registry
reg export "HKCU\Environment" "$HOME\Environment_backup.reg" /y

# 3. Deduplicate and filter out stale/missing directories
$currentPath = (Get-ItemProperty "HKCU:\Environment").Path
$cleanEntries = ($currentPath -split ';' | Where-Object { 
    $_ -and (Test-Path $_ -ErrorAction SilentlyContinue)
}) | Select-Object -Unique
Set-ItemProperty -Path "HKCU:\Environment" -Name "Path" -Value ($cleanEntries -join ';')

# 4. Broadcast change (no reboot required)
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
[Win32.NativeMethods]::SendMessageTimeout([IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, "Environment", 0x0002, 5000, [ref][UIntPtr]::Zero)

Once the User PATH was pruned from 31,686 chars to ~1,500 chars, ChatGPT.exe and codex.exe started cleanly without any issues.


Proposed Fix & Security Recommendations for Maintainers

  1. Sanitize PATH before spawning codex.exe:
    In oW (where the sidecar environment dictionary is constructed), sanitize and deduplicate r.PATH on Windows, or prune non-existent folders so the environment block never exceeds 32 KB.
  2. Environment Isolation for Agent Tool Execution:
    Autonomous agents running shell commands should have their environment modifications sandboxed to process-scope. Modifications to HKCU:\Environment or calls to setx by child processes during autonomous tasks should be blocked or isolated in a virtualized hive.
  3. Accurate Error Reporting:
    • In StdioConnection, don't report "websocket closed" when the transport is stdio.
    • If process.platform === 'win32' and code === 3221225495 (0xC0000017), display a clear diagnostic message:
      "Failed to spawn backend engine due to environment block size limit (0xC0000017). Please ensure your PATH variable does not exceed 32,767 characters."

Activity

  1. added
    bug
    app
    windows-os
    app-server
    on Sep 18, 2026
  2. changed the title [-][Bug]: Windows Desktop app fails to start with code 3221225495 (0xC0000017 STATUS_NO_MEMORY) due to environment block buffer overflow[/-] [+][Bug]: Windows Desktop app fails to start: Codex app-server websocket closed (code=3221225495 / 0xC0000017) due to environment block overflow[/+] on Sep 18, 2026
  3. antilogicrule commented on Oct 30, 2026

    @antilogicrule

    I independently reproduced this exact issue, and it is an unacceptable system-level reliability failure.

    My Windows 11 machine (build 26200.9711) became partially unusable after an autonomous Codex development session running repeated .NET builds and tests.

    My persistent user PATH had grown to 32,744 characters, containing 316 stale, project-specific .dotnet\tools entries created through different DOTNET_CLI_HOME locations.

    After restarting Windows, Task Manager, PowerShell, ChatGPT Desktop, the Start menu, search, and several other system components failed, often with 0xC0000017, despite ample available physical and virtual memory.

    We conducted controlled experiments:

    • A child process with a roughly 1,500-character PATH launched Task Manager and PowerShell successfully.
    • With a 32,744-character PATH, both reproduced 0xC0000017.
    • Removing the 316 stale entries reduced my user PATH from 32,744 to 725 characters.
    • After applying the fix and restarting, the affected Windows functionality recovered.

    An autonomous coding workflow should never be able to progressively break its host operating system through persistent environment pollution.

    This is not merely a Codex app crash. It can disrupt Windows itself and force users through hours of recovery and diagnosis.

    Please treat this as a high-priority reliability issue. Codex should isolate build environments, prevent unintended persistent PATH modification, detect abnormal environment growth, and provide an actionable error instead of misleading memory failures.

  4. tonym001 commented on Nov 5, 2026

    @tonym001

    Additional Windows data point with the same 0xC0000017, but affecting child launches after the desktop app has already started.

    • Codex desktop MSIX build: 26.1029.7803.0; Windows x64 26H2, build 26300.9818.
    • Git launched by Codex repeatedly showed a git.exe - Application Error dialog with 0xC0000017. In one reproduction the command runner reported exit code 0 with no output for git --version, despite the Windows dialog. rg, psql and dotnet launches also reported insufficient memory resources from the Codex shell.
    • After reboot, standalone Windows PowerShell 5.1 successfully ran git --version (2.51.0.windows.2), created a worktree, and built .NET projects. The Codex-side Git dialog recurred. PowerShell built-in file reads still work inside Codex.
    • Read-only diagnostics: persistent user PATH 31,291 characters across 244 entries, 237 ending in .dotnet\tools; Codex PowerShell process PATH 32,634 characters and its environment block approximately 36,146 characters. No PATH values or logs are attached. No settings were changed and no cleanup A/B test was performed.

    The symptoms were noticed after an app update, but the update and PATH growth are not proven causes. This may be useful as a related reproduction where the app stays open but tool subprocesses fail, and the tool result can misleadingly appear successful. Expected: successful child launch or an accurate startup-failure result.

  5. pedroformagini commented on Nov 9, 2026

    @pedroformagini

    Additional independent reproduction from my own Windows workstation, including system-tool failures and a recovery that worked.

    Environment and evidence

    • Windows 11 Pro 26H2, build 26300.9818; Windows-native agent execution with full access. I am not claiming a sandbox escape.
    • Automated validations repeatedly used different temporary DOTNET_CLI_HOME directories. The corresponding SDK markers were 10.0.400.toolpath.sentinel and 10.0.403.toolpath.sentinel.
    • My persistent user Path reached 36,666 characters in the raw registry value / 36,670 after expansion, including 326 generated .dotnet\tools entries.
    • All 326 corresponding .dotnet parent directories contained SDK tool-path sentinel files.
    • Taskmgr.exe, sfc.exe, and Dism.exe failed to initialize with 0xc0000017. There was still approximately 14 GB of available physical RAM during diagnosis.

    How we recovered this installation

    1. Backed up the original user environment value.
    2. Removed only the 326 identified temporary SDK tool-path entries, preserving legitimate entries and the machine-level PATH.
    3. Refreshed the environment for new processes. User PATH dropped to 658 raw / 662 expanded characters, and Task Manager opened normally.
    4. An elevated Command Prompt opened before the cleanup still had the old environment. Correcting PATH for that console allowed SFC to start. SFC subsequently finished; CBS.log recorded “Repairing 0 components” and “Repair complete”.

    This current recovery demonstrates a persistent environment configuration problem; it does not establish permanent corruption of Windows system files.

    Earlier installation lost after reboot

    A few days earlier, I experienced the same observable failure pattern on an earlier Windows installation after restarting. The Start menu and taskbar were invisible/unavailable for about ten minutes; they eventually appeared, but the system remained effectively unusable and I could not launch applications or system tools. I did not know about the PATH recovery at the time and ended up formatting/reinstalling Windows, losing that installation.

    I now suspect that incident was related, but the old registry state was not preserved, so I cannot verify that earlier installation's exact root cause retrospectively.

    Project-level prevention that matters

    We traced the current accumulation to a project-specific preflight helper created during agent-assisted development. It set a fresh DOTNET_CLI_HOME for each validation and rebuilt the child environment from an allowlist. Setting DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=false in the persistent user environment alone was insufficient for that helper, because its allowlist discarded the variable.

    For projects that have their own development plugins, skills, or build helpers invoking .NET, it would be useful to update the relevant plugin/skill instructions and the project's AGENTS.md (or equivalent agent instruction file) with this guardrail, and enforce it in the actual launcher:

    • When running Windows .NET builds/validations with a temporary CLI home, explicitly set DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=false in each actual SDK subprocess environment, after any environment filtering.
    • Do not persist temporary build/tool directories into the user or machine PATH.
    • Verify that the persistent PATH is unchanged by repeated isolated validations.

    Documentation is useful, but the subprocess configuration must enforce the prevention too. The related SDK-side report is dotnet/sdk#56512. Stronger detection and clearer diagnostics for this failure would help users avoid mistaking an unusable Windows session for an installation that needs reinstalling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appapp-serverbugwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions