Skip to content

[Bug]: Resume active Codex requests after offline DNS failure #7958

Closed

Description

@alexph-dev

Client or integration

Codex App

Area

Proxy and routing / streaming

Summary

When a MacBook running a Codex task loses its network connection during sleep or a Wi-Fi transition, OpenCodex can return a 502 for an upstream DNS failure. The active task stops and requires a manual continue after connectivity returns.

Could OpenCodex keep an eligible active request waiting and retry once its upstream provider is reachable, allowing the task to continue automatically? Waiting should respect cancellation, avoid retrying requests with uncertain upstream effects, and avoid consuming a short retry budget while offline.

Reproduction

  1. Run the Codex App with OpenCodex as its local Responses provider.
  2. Start an active task, close the MacBook and move away from its Wi-Fi network.
  3. Open the laptop and connect to Wi-Fi again.
  4. Observe the error below and the stopped task. Sending continue resumes work.

This is an observed interruption; a controlled reproduction and the precise timing of the network transition have not yet been verified. The screenshot shows a DNS failure through the local proxy, not the complete upstream request history.

Version

OpenCodex 2.93.0 installed at time of report; Codex CLI 0.164.0 installed. The Codex App's bundled runtime version was not verified.

Operating system

macOS 26.7

Provider and model

The failed upstream hostname was chatgpt.com. Model not established from the screenshot.

Error output

unexpected status 502 Bad Gateway: Provider unreachable: getaddrinfo ENOTFOUND chatgpt.com, url: http://127.0.0.1:10100/v1/responses

Additional context

OpenCodex classifies pre-connection reachability errors such as ENOTFOUND, while its Responses handler can return a 502 for an upstream connection failure. Codex has a separate connection-failure retry mechanism (openai/codex#37485); whether the proxy's 502 bypasses that mechanism in this exact scenario needs verification. A connection lost after upstream dispatch or after streaming begins may need different handling because the request's outcome can be uncertain.

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. lidge-jun commented on Oct 30, 2026

    @lidge-jun
    Owner

    Maintainer triage (2026-10-30, against dev 3a70dd4788):

    Current behaviour matches the report. src/lib/upstream-reachability.ts classifies ENOTFOUND, EAI_AGAIN, ECONNREFUSED and Bun's ConnectionRefused (from the error code and a bounded cause chain, never the message) as failures before any connection was made. src/lib/upstream-retry.ts deliberately does not retry those: its retries cover connection resets proven safe to resend and short backoff after a received transient 5xx. So when the network drops (laptop sleep, Wi-Fi switch), the Responses path returns 502 Provider unreachable: … immediately (src/server/responses/passthrough-dispatch.ts, src/server/responses/upstream-error.ts), and the turn depends on whatever retry Codex itself applies to a 5xx.

    A bounded improvement looks feasible: only when the first send fails with a proven pre-connection error, and there is no evidence the upstream was reached (no earlier response, no reset), probe DNS/TCP reachability of the same host for a short cancellable window without sending the model POST, then resend the original request at most once under the existing physical-attempt budget and admission rules. Implementation notes: the pre-connection classifier should move into a leaf module (reachability already imports the retry helper), structure/transports/responses-failover.md needs the contract, and the regression belongs in tests/providers/upstream-transient-retry.test.ts (initial ENOTFOUND → failed probes → recovery → one resend succeeds; plus cancellation, timeout, exhausted budget, DNS error after an earlier 5xx/reset, and failure after the response started).

    It needs one product decision before anyone builds it: how long a request may wait for the network (the reporter's case suggests tens of seconds, but every second is held against the client's own timeout, auth expiry and concurrent requests), and whether it should be on by default. Keeping this open for that decision; no change lands in this maintenance pass.

  3. Ingwannu commented on Oct 30, 2026

    @Ingwannu
    Owner

    The report distinguishes a DNS failure from an already-dispatched/streaming interruption correctly. Against dev 3ea89653f5727aea41948ddbd5e833f74afe3e36, the existing transport/retry owner already separates reachability errors from ambiguous upstream resets; a screenshot of a final 502 does not show whether an earlier physical attempt in that logical request sent bytes. Holding an offline request would also need an explicit bounded wait/deadline, cancellation, wake/reconnect, and single-owner retry contract.

    Please retain a synthetic/redacted attempt trace with selected HTTP/WS transport, exact build, physical send count, transport-owned failure phase and client cancellation/deadline. No request body or account identifiers are needed. A focused proposal should first exercise an initial DNS failure followed by recovery, cancellation while offline, deadline expiry and a prior ambiguous/partial send; the last case must not acquire replay permission. I have not reproduced the laptop transition or changed any running service. Keeping this open; a proxy 502's interaction with the installed client retry path is still unverified.

  4. lidge-jun commented on Nov 10, 2026

    @lidge-jun
    Owner

    Rechecked on dev df0e6ccc41: unchanged since the 2026-10-30 triage. A pre-connection ENOTFOUND/EAI_AGAIN/ECONNREFUSED is still classified in src/lib/upstream-reachability.ts and still answers 502 Provider unreachable immediately. fetchWithResetRetry does not retry it.

    The design questions from that triage still decide this, so it stays open:

    1. Opt-in bounded wait (recommended). A new provider or server setting, default off: after a proven pre-connection failure on the first send, probe the same host for up to N seconds (capped, for example at 120), honor cancellation and the request's send budget, and resend once. Existing users see no change.
    2. On by default with a short window (for example 20–30 s). This covers the laptop-sleep case without configuration, but every request to an unreachable host holds a slot and the client's own timeout for that long.
    3. No proxy change. Rely on the client's retry of a 5xx. First we would have to confirm whether Codex's connection-failure retry treats this proxy 502 as retryable.

    The window length and the default are product choices for the owner. The regression set from the triage (recovery, cancellation, deadline, prior ambiguous send) applies whichever option is chosen.

  5. lidge-jun commented on Nov 16, 2026

    @lidge-jun
    Owner

    Owner decision (lidge-jun, 2026-11-16): add an opt-in wait (default off): after an offline DNS/connect failure, wait up to N seconds for reachability and resend once, under the existing replay-safety rules.

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

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions