Skip to content

Codex App should identify unreachable custom openai_base_url in connection-refused errors #40435

Open

Description

@ngel8844

What version of the Codex App are you using (From “About Codex” dialog)?

penAI.Codex_26.818.8289.0_x64

What subscription do you have?

Pro

What platform is your computer?

Windows 11 - 10.0.26200.9168

What issue are you seeing?

Codex Desktop on Windows repeatedly failed with:

Reconnecting /5

stream disconnected before completion: No connection could be made because the target machine actively refused it. (os error 10061)

Reconnecting... waiting for network

Connection failed: error sending request

The failure was caused by a stale custom base URL in %USERPROFILE%.codex\config.toml:

openai_base_url = "http://127.0.0.1:8787/v1"

Nothing was listening on 127.0.0.1:8787, but Codex continued trying to connect to it. The UI only reported a generic network/reconnect error and did not indicate that the failing connection was the configured openai_base_url.

Removing the openai_base_url override and restarting Codex immediately restored normal operation.

What steps can reproduce the bug?

On Windows 11:

  1. Add the following to %USERPROFILE%.codex\config.toml:
    openai_base_url = "http://127.0.0.1:8787/v1"
  2. Make sure no process is listening on TCP port 8787.
  3. Start/restart Codex Desktop.
  4. Send any prompt.
  5. Codex begins reconnecting and eventually reports:
    stream disconnected before completion: No connection could be made because the target machine actively refused it. (os error 10061)
  6. Find the Codex process PID and inspect its connections:
tasklist | findstr /I codex
netstat -ano | findstr <CODEX_PID>

During the failure I observed:

TCP    127.0.0.1:<ephemeral-port>    127.0.0.1:8787       SYN_SENT
TCP    <local-ip>:<ephemeral-port>   104.18.32.47:443     ESTABLISHED

I also verified that the normal Codex backend was reachable independently:

curl.exe -i -X POST https://chatgpt.com/backend-api/codex/responses

This returned:

HTTP/1.1 401 Unauthorized
{"detail":"Unauthorized"}

The 401 is expected without authentication and confirmed that DNS, TCP, TLS, and connectivity to the normal Codex backend were working.

I also confirmed there was no Windows proxy involved:

netsh winhttp show proxy

Result:

Direct access (no proxy server).

And:

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable

Result:

ProxyEnable REG_DWORD 0x0

Finally, I removed:

openai_base_url = "http://127.0.0.1:8787/v1"

from config.toml, restarted Codex Desktop, and prompts immediately worked again.

Codex Desktop package observed during testing:

OpenAI.Codex_26.818.8289.0_x64

Windows build:

10.0.26200.9168

What is the expected behavior?

If a non-default openai_base_url is configured and that endpoint refuses the connection, Codex should surface that information in the error.

For example:

Unable to connect to configured OpenAI base URL:
http://127.0.0.1:8787/v1

The endpoint refused the connection. Check your openai_base_url setting in config.toml or verify that the local proxy/service is running.

Codex should not present only a generic network/reconnection error when it already knows that requests are being routed to a user-configured custom endpoint.

This would make it clear that general internet connectivity, authentication, firewall, or the OpenAI service itself may not be the problem.

Additional information

The stale openai_base_url appears to have originated from a third-party local proxy integration. I am not claiming Codex created the stale configuration.

The Codex-side issue is that the current error does not identify the actual failing destination, which makes a straightforward local endpoint failure look like a general Codex/OpenAI network outage.

The diagnostic evidence was fairly clear:

Codex -> 127.0.0.1:8787     SYN_SENT / failing
Codex -> remote :443         ESTABLISHED

while the normal chatgpt.com/backend-api/codex/responses endpoint remained reachable.

A more specific error for unreachable custom openai_base_url configurations would significantly reduce troubleshooting time

Activity

  1. added
    app
    on Aug 24, 2026
  2. added
    enhancement
    windows-os
    connectivity
    config
    custom-model
    on Aug 24, 2026
  3. SalehAhmed10 commented on Aug 31, 2026

    @SalehAhmed10

    Windows ChatGPT / Codex app: same 10061, different leftover port

    Hit this on the ChatGPT / Codex desktop app (Windows):

    stream disconnected before completion: No connection could be made because the target machine actively refused it. (os error 10061)
    Reconnecting /5
    Reconnecting... waiting for network
    

    A full quit + reopen of the app did not fix it.

    Root cause

    %USERPROFILE%\.codex\config.toml had a stale local override:

    openai_base_url = "http://127.0.0.1:17841/v1"

    Nothing was listening on 127.0.0.1:17841 (confirmed with Get-NetTCPConnection). Codex kept sending the stream there, so Windows returned 10061. The UI only said “waiting for network”, which made it look like an OpenAI outage.

    Checks that were fine:

    • chatgpt.com:443 reachable
    • GET https://chatgpt.com/backend-api/codex/responses returned 405 (endpoint alive)
    • No WinHTTP / IE proxy
    • No %USERPROFILE%\.codex\.env
    • Docker Desktop / WSL Ubuntu were stopped (not the live cause)

    Fix

    Comment out the line:

    # openai_base_url = "http://127.0.0.1:17841/v1"

    Fully quit ChatGPT (end all ChatGPT processes), reopen, start a new Codex chat. Streams worked again.

    This matches this issue: connection-refused to a dead openai_base_url. Here the leftover port was 17841, not 8787. Restarting the app never brought the local helper back.

    If the UI named the refused destination (127.0.0.1:17841 / configured openai_base_url) instead of “waiting for network”, this would have been obvious.

  4. jianggabi4-bot commented on Sep 5, 2026

    @jianggabi4-bot

    Superseded by the final consolidated report and recovery guide below: #40435 (comment)

  5. jianggabi4-bot commented on Sep 5, 2026

    @jianggabi4-bot

    Superseded by the final consolidated report and recovery guide below: #40435 (comment)

  6. jianggabi4-bot commented on Sep 5, 2026

    @jianggabi4-bot

    Final consolidated Windows recovery + prevention summary from this case:

    User impact

    The stale custom openai_base_url caused 3–4 days of unusable Codex Desktop. The misleading UI (Reconnecting... waiting for network / Connection failed: error sending request) led to repeated troubleshooting of Wi‑Fi, VPN, TLS, Cloudflare, and OpenAI availability even though general OpenAI connectivity was healthy.

    Root cause

    A third-party OpenCodex integration had previously injected:

    openai_base_url = "http://127.0.0.1:10100/v1"

    into %USERPROFILE%\.codex\config.toml.

    That loopback proxy later stopped / failed to autostart, but the override remained. Codex Desktop therefore kept routing model requests to a dead localhost endpoint.

    Successful recovery

    1. Fully exit Codex Desktop.
    2. Back up the Codex config:
    copy "%USERPROFILE%\.codex\config.toml" "%USERPROFILE%\.codex\config.toml.backup"
    1. Check for a custom base URL:
    findstr /I "openai_base_url base_url" "%USERPROFILE%\.codex\config.toml"
    1. Remove only the stale line:
    openai_base_url = "http://127.0.0.1:10100/v1"
    1. Relaunch Codex and test a new thread. It works immediately.

    OpenCodex cleanup / safer configuration

    The machine also had a partially broken OpenCodex lifecycle setup:

    • proxy not running
    • codexAutoStart: enabled
    • stale/missing background service assets
    • no Codex autostart shim

    To make official Codex the safe default while preserving third-party models as an on-demand fallback:

    1. Disable OpenCodex autostart in ~/.opencodex/config.json:
    "codexAutoStart": false
    1. Remove the stale background service:
    ocx service uninstall
    1. If Windows Task Scheduler still contains \opencodex-proxy, confirm with:
    schtasks /Query /FO LIST | findstr /I "opencodex"

    and remove it from an elevated Command Prompt:

    schtasks /Delete /TN "\opencodex-proxy" /F
    1. Verify the clean state:
    Codex autostart: disabled
    Service: not installed
    Codex autostart shim is not installed
    

    Recommended dual-mode workflow

    Normal/default mode — official Codex

    • Leave OpenCodex proxy stopped.
    • Keep codexAutoStart disabled.
    • config.toml should contain no openai_base_url override.

    Safety check:

    findstr /I "openai_base_url base_url" "%USERPROFILE%\.codex\config.toml"

    No output = native Codex routing.

    Fallback mode — third-party models via OpenCodex
    When official Codex quota is exhausted:

    ocx start
    ocx status

    Confirm the proxy is healthy, then launch Codex and use the configured third-party model (e.g. Anthropic/Kimi/etc.).

    Return to official Codex
    Exit Codex, then:

    ocx stop

    or explicitly:

    ocx restore

    Then run the safety check again to ensure no localhost openai_base_url remains.

    Product improvement request

    Codex Desktop should surface the actual failing destination whenever a non-default openai_base_url is configured. For loopback targets (127.0.0.1 / localhost), an error like this would have prevented days of wasted troubleshooting:

    Unable to connect to configured OpenAI base URL http://127.0.0.1:10100/v1. The local proxy is not reachable. Check config.toml or restart the local proxy.

    This case also shows that generic waiting for network wording is too broad when the app already knows requests are being routed to a user-configured localhost endpoint.

  7. 0chanu commented on Sep 13, 2026

    @0chanu

    Additional reproduction detail: an additive custom model-picker setup can unintentionally make Codex depend globally on a localhost openai_base_url. If that local endpoint is down, even official OpenAI models fail with Windows os error 10061, so a change intended only to add one provider can make the entire app unusable.

    Suggested safeguards:

    • Scope custom routing per provider/model instead of globally when possible.
    • Validate localhost openai_base_url endpoints before use.
    • Show the actual failing configured endpoint in the error.
    • Provide an in-app action to revert to the default OpenAI endpoint.
    • Avoid letting a dead custom provider block native OpenAI model routing when fallback is safe and unambiguous.

    This would make custom model catalogs genuinely additive and reduce the risk of a stale local proxy breaking all Codex model access.

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

    appconfigconnectivitycustom-modelenhancementwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions