Skip to content

fix(responses): keep the DNS error on a cancelled offline wait and label the resend (#7958) - #8833

Merged
lidge-jun merged 2 commits into
devfrom
fix/offline-resend-cancel-and-label
Nov 16, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/offline-resend-cancel-and-label

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refs #7958. This follow-up fixes the two Low review items left on the opt-in offline wait (offlineResendWaitSec). The DNS-only probe design (ENOTFOUND/EAI_AGAIN, proxy-aware since #8831) is unchanged.

1. Cancelling during the wait now returns the original error. The waiter used to call signal.throwIfAborted() and abortableDelay, so a client cancel during the wait surfaced AbortError instead of the pre-connect DNS error. On Codex forward-pool sends, classifyTransportFailureKind (passthrough-dispatch) then counted that host-wide connect_neutral failure as account-attributed connect_error. Now the waiter in src/lib/offline-resend.ts answers false when the signal aborts at the loop check, during a probe (the expiry race treats a rejection as the end of the wait), between probes, or after a DNS answer that lands once the client has gone. fetchWithResetRetry also refuses to resend when the signal is aborted after the waiter answers, so it rethrows the original error. The existing if (opts.abortSignal?.aborted) throw err; paths are unchanged. This makes the existing docs row ("a cancelled request returns the original error") true.

2. The resend has its own recovery kind. fetchWithResetRetry passed "connection-reset" for every send after the first, so the offline resend was logged as a connection-reset recovery. It now reports "offline-resend". A later reset retry in the same leg still reports "connection-reset". The new kind is in UpstreamSendRecovery, the ATTEMPT_RECOVERY_KIND_ROSTER (so AttemptRecoveryKind, usage-log read-back and telemetry), and RECOVERY_KIND_CAUSE as transport-unsent (the contract's "bytes provably never reached the origin… DNS failure"; request metrics therefore project it to connection). The GUI Logs label map covers both gui/src and gui/classic, and logs.detail.attempt.recovery.offlineResend is translated in all 11 locales.

Keep-alive decision: the offline resend still opts out (keepalive: false + Connection: close in applyUpstreamRecoveryInit). The wait follows a DNS outage, typically a sleep or a Wi-Fi change, so any socket still pooled for that origin or proxy was opened on the network that went away. Reusing one fails after the body may have left, which turns a provably unsent request into an ambiguous pre-header reset; for a non-replay-safe send that becomes the replay refusal instead of an answer. The resend needs a fresh connection anyway, so the only cost is one handshake. This keeps the old wire behaviour; only the label changes.

Neither src/server/responses/adapter-dispatch.ts nor passthrough-dispatch.ts is touched. structure/transports/timeouts.md documents both behaviours.

Failing before / passing after (tests/responses/responses-offline-resend.test.ts, the same file run against origin/dev 3ef14ad sources and then this branch: 7 fail / 16 pass → 23 pass / 0 fail):

Item Case Before (origin/dev) After
1 client abort during a failing probe rejects with DOMException AbortError rejects with the original ENOTFOUND
1 cancel during a stalled DNS probe AbortError original ENOTFOUND
1 cancel during the real abortable delay between probes; classifyTransportFailureKind on the rejection AbortError (→ connect_error) original ENOTFOUND, connect_neutral
1 DNS answers after the client left AbortError original ENOTFOUND, one send
2 fetchWithResetRetry recoveries for offline resend → reset retry [undefined, "connection-reset", "connection-reset"] [undefined, "offline-resend", "connection-reset"]; cause transport-unsent; keep-alive opted out
2 native Responses passthrough, opted in: logCtx.activeAttempt.recoveryKinds ["connection-reset"] ["offline-resend"], resend keepalive: false
2 translated Chat route (adapter-dispatch), opted in ["connection-reset"] ["offline-resend"], resend keepalive: false

The forward-pool classification is checked at the existing classifyTransportFailureKind seam, using the rejection fetchWithTransientRetry produces (the call passthrough-dispatch makes). No case drives a full Codex pool account through handleResponses.

Verification

The Mac was under heavy load, so tests ran only as focused single files under /usr/bin/lockf -k /tmp/ocx-test.lock:

  • bun test tests/responses/responses-offline-resend.test.ts: 23 pass / 0 fail. Against origin/dev sources: 7 fail, as in the table.
  • Roster consumers: tests/lib/failure-stage-model.test.ts 16 pass, tests/lib/failure-attribution.test.ts 16 pass, tests/usage/request-outcome-agreement.test.ts 24 pass, tests/lib/ambiguous-resend-gate.test.ts 10 pass.
  • GUI i18n: gui/tests/locale-parity.test.ts 5 pass, gui/tests/i18n-locales.test.ts 15 pass.
  • bun run typecheck clean (2,554 files); gui tsc -p tsconfig.app.json --noEmit clean; bun run lint:gui clean; bun run structure:check passed; bun run privacy:scan passed.
  • Live check: a real startServer on a scratch OPENCODEX_HOME with offlineResendWaitSec: 30, where the provider host's first send failed ENOTFOUND, answered 200 after one resend. The persisted usage.jsonl row carried "sendCount":2 and "recoveryKinds":["offline-resend"]. The dashboard (Vite dev against that server) renders the attempt as below:

Logs detail: the attempt's result reads "Resent after the network returned"

NOT RUN: full bun run test (host load; left to ci:full), bun run build:gui. The classic dashboard has no tsc project, so its one-line map entry is covered only by the CI build. Windows/macOS lanes were not run (no workflow dispatched).

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • New Features

    • Requests that fail before sending due to network unavailability can be resent after connectivity returns, when retries remain.
    • Request-attempt logs identify these resends, with labels available in supported languages.
  • Bug Fixes

    • Cancelling a wait for connectivity or a DNS check preserves the original network error instead of reporting an abort error.
    • Resends avoid reusing a potentially stale connection by closing it after the attempt.

…bel the resend (#7958)

A client cancel during the opt-in offline wait made the waiter reject with the
abort reason, so fetchWithResetRetry surfaced AbortError instead of the original
ENOTFOUND/EAI_AGAIN. On Codex pool sends classifyTransportFailureKind then charged
the account (connect_error) for a host-wide failure (connect_neutral). The waiter
now answers false on cancellation, during a probe, between probes, or after a
late DNS answer, and fetchWithResetRetry rethrows the original error.

The single resend after the wait was reported as "connection-reset". It now
carries its own recovery kind, "offline-resend" (cause transport-unsent), through
UpstreamSendRecovery, the attempt roster, the failure model and a localized Logs
label in all 11 locales and the classic dashboard. It keeps the keep-alive
opt-out: sockets pooled before the outage belong to the network that went away.

Refs #7958
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 16, 2026 13:18
@lidge-jun lidge-jun added the ci:full Run the four full Ubuntu test shards on this pull request label Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T15:54:46.871454Z ab904a9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The retry flow now records offline resends as a distinct recovery kind. Cancellation during an offline wait preserves the original failure. The Logs interface displays a localized label for the recovery kind.

Changes: Offline resend recovery

Layer / File(s) Summary
Offline wait cancellation behavior
src/lib/offline-resend.ts, tests/responses/responses-offline-resend.test.ts
The wait returns false on cancellation, expiry, or probe and delay failures. Tests check that cancellation preserves the original offline error and prevents another send.
Retry recovery metadata
src/lib/upstream-retry.ts, src/lib/request-failure-model.ts, src/usage/telemetry-contract.ts, tests/responses/responses-offline-resend.test.ts
The retry helper labels an offline resend and any later connection-reset retry. Offline resends disable keep-alive and map to the transport-unsent cause. Tests check recovery metadata and failure classification.
Recovery labels and documentation
gui/classic/src/pages/Logs.tsx, gui/src/pages/Logs.tsx, gui/src/i18n/*.ts, structure/transports/timeouts.md
The Logs pages map offline resends to a localized label. The transport documentation describes cancellation behavior, recovery cause, and keep-alive settings.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant fetchWithResetRetry
  participant offlineWait
  participant fetch
  fetchWithResetRetry->>fetch: Send request
  fetch-->>fetchWithResetRetry: Non-reset failure
  fetchWithResetRetry->>offlineWait: Wait for network recovery
  offlineWait-->>fetchWithResetRetry: Return true
  fetchWithResetRetry->>fetch: Retry with offline-resend metadata
Loading

Possibly related issues

  • lidge-jun/opencodex#7958: The changes address offline DNS-failure retries and cancellation behavior for the opt-in resend flow. The issue may include broader requirements beyond this opt-in behavior.
Merge Risk: Minimal · up to ab904

The change labels offline resends distinctly, preserves the original DNS error when the client cancels, and adds localized log labels. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two changes in this PR: keeping the original DNS error when an offline wait is cancelled, and labeling the resend with a recovery kind. The changeset touches the offline-resend wai…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two changes in this PR: keeping the original DNS error when an offline wait is cancelled, and labeling the resend with a recovery kind. The changeset touches the offline-resend wait logic in src/lib/offline-resend.ts, the recovery cause mapping in src/lib/request-failure-model.ts, the recovery kind type in src/lib/upstream-retry.ts, telemetry roster, i18n labels, and tests. The title covers the main fix and the labeling change, so it matches the changeset. The title uses the conventional commit prefix and stays within one line. The title number (#7958) differs from the PR objective's referenced PR (#8833), which is a metadata inconsistency and does not affect the title's relevance to the changes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 42f2a33 and ab904a9.

Files selected for processing: 2

  • structure/transports/timeouts.md
  • tests/responses/responses-offline-resend.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
Brings in #8832 (transparent-wrapper exemption). The only conflict was the import block of tests/responses/responses-offline-resend.test.ts: keep both markEgressTransparentExecutor (from #8832) and this branch's recovery-kind imports. src/lib/offline-resend.ts merged cleanly.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Brought current with dev as merge commit ab904a9 (no force-push) after #8832 merged. The only conflict was the import block of tests/responses/responses-offline-resend.test.ts: both markEgressTransparentExecutor (#8832) and this branch's recovery-kind imports are kept, and src/lib/offline-resend.ts merged cleanly. Per the owner's rule for this feature, the PR merges only on green CI for ab904a9 with Codex and CodeRabbit completed on that head and every finding fixed or answered.

@lidge-jun

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@lidge-jun

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ab904a997b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration of #8833 at ab904a9 (Refs #7958). These are the two Low items left from #8790's review, and the final follow-up for the opt-in offline wait.

  • Cancelling during the wait: the waiter now returns false on any abort (before a probe, during one, between probes, or on a late DNS answer), and no resend follows an abort after a yes. The original pre-connect DNS error is rethrown, so a Codex forward-pool failure stays connect_neutral rather than charging the account. The docs row now holds.
  • Recovery label: the resend is logged as its own offline-resend kind (cause transport-unsent) instead of connection-reset. The label is in all 11 locales and both Logs pages, with a screenshot in the PR. Keep-alive is still opted out for the resend: after a network change, a pooled socket could turn a clean unsent resend into an ambiguous reset.
  • Tests: 7 fail on dev and all 23 pass. A live run recorded "recoveryKinds":["offline-resend"].
  • Merge commit: ab904a9 merges dev after fix(responses): keep the offline wait for OpenCodex's own xAI and Mistral fetch wrappers (#7958) #8832 and keeps both import sets in the test file.
  • Gate: CI is green on this exact head, including enforce-target. Codex completed on this head with no unresolved findings, CodeRabbit reviewed this head with no actionable comments, and no thread is open. assert-mergeable-review: OK. The simulated merge onto the dev of this moment is clean, with no file over its size cap. Dev: batch lane=all 43896659099 on 8c948a4 was fully green, and only fix(images): enforce the resolved destination for video submit and poll #8838 has merged since.

@lidge-jun
lidge-jun merged commit 095b629 into dev Nov 16, 2026
38 checks passed
@lidge-jun
lidge-jun deleted the fix/offline-resend-cancel-and-label branch November 16, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant