Windows Codex Tool Timeout 524: Switch to PowerShell 7

Diagnose Windows Codex reconnect loops, HTTP 524 responses, broken tool streams, and UTF-8 output issues caused by PowerShell environments.

Short answer

  1. Stop repeating the request and inspect the active shell.
  2. Switch from 5.1 / powershell.exe to PowerShell 7 / pwsh.exe.
  3. Set input, output, and native-command encoding to UTF-8.
  4. Verify a real Unicode string and JSON value locally.
  5. Start Codex from the verified PowerShell 7 window and run one minimal tool call.

This is a practical path for the combination of Windows shell, Unicode output, and streaming-tool symptoms. It is not proof that every 524 comes from PowerShell; short-session failures still require checking hooks, proxy routing, upstream services, and server logs.

What the error means

terminal-outputtext
Reconnecting... 1/5
Unexpected status 524: responses stream finished without usable output
url: https://<upstream>/v1/responses

Reconnecting means the client is trying to recover. A 524 usually means a gateway did not receive a usable upstream response in time. The empty stream means the client received no usable output. Authentication problems more commonly appear as 401 or 403.

Why PowerShell 5.1 can trigger it

PowerShell version, console encoding, native-command encoding, profile output, and agent protocol output can disagree. Unicode or JSON tool results may be truncated, altered, or polluted by profile banners and debug text, causing the client to retry a request whose real failure is local output handling.

Fastest repair path

install-and-launch.ps1powershell
winget install --id Microsoft.PowerShell --source winget
pwsh
Set-Location C:\path\to\your\project
git status --short
codex

# Compare against a clean shell
pwsh -NoLogo -NoProfile

Confirm the edition is Core, the version is 7.x, and the resolved command source is the actual pwsh.exe. Installing PowerShell 7 does not replace Windows PowerShell 5.1.

Set and verify UTF-8

utf8-check.ps1powershell
$PSVersionTable | Format-List PSVersion, PSEdition, OS
(Get-Command powershell -ErrorAction SilentlyContinue).Source
(Get-Command pwsh -ErrorAction SilentlyContinue).Source

$utf8 = [System.Text.UTF8Encoding]::new($false)
[Console]::InputEncoding = $utf8
[Console]::OutputEncoding = $utf8
$OutputEncoding = $utf8
Write-Output "UTF-8 test / tool-stream-ok"
{ text = "sample"; ok = $true } | ConvertTo-Json -Compress

A code-page command alone is not enough. Verify complete Unicode and JSON output, then compare withpwsh -NoLogo -NoProfile if a profile may print to standard output.

Layered diagnosis if 524 remains

  1. Compare a clean PowerShell 7 process without profiles.
  2. Check agent hooks, shell wrappers, and environment variables.
  3. Check proxy routing, upstream response, model, URL, and request ID.
  4. Reproduce one minimal tool call before returning to the long task.

Acceptance checklist

  • Edition is Core and version is 7.x.
  • pwsh.exe resolves from the expected path.
  • Unicode text and JSON are complete, without replacement characters or truncation.
  • The profile does not write unrelated text to standard output.
  • The agent's real launch command has been confirmed.
  • A minimal tool call succeeds before the original long task resumes.
  • If 524 remains, the request ID, time, URL, model, and clean-shell comparison are recorded.

For broader recovery, see Codex tool recovery and Codex CLI integration.