@bitkyc08/opencodex 2.100.3 → 2.100.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/AGENTS_INSTALL.md +23 -1
  2. package/bin/ocx.mjs +8 -1
  3. package/gui/dist/assets/{App-Dnb6VMsP.js → App-DcpyI78f.js} +20 -19
  4. package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-CzjPJprT.js} +1 -1
  5. package/gui/dist/assets/brand-mark-BTIi7e69.js +1 -0
  6. package/gui/dist/assets/index-DJxM-imn.css +2 -0
  7. package/gui/dist/assets/index-DVgU6S3y.js +138 -0
  8. package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bn6Y-g3R.js} +1 -1
  9. package/gui/dist/classic/assets/{App-DA-scMPq.js → App-eYJAyNHM.js} +19 -18
  10. package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-xHMYxLkV.js} +1 -1
  11. package/gui/dist/classic/assets/index-DSaVRW4F.js +138 -0
  12. package/gui/dist/classic/assets/quota-summary-DyzHlkFl.js +1 -0
  13. package/gui/dist/classic/index.html +1 -1
  14. package/gui/dist/index.html +2 -2
  15. package/native/ocx-child/src/cli.rs +5 -3
  16. package/native/ocx-child/src/codex_home.rs +1 -0
  17. package/package.json +2 -2
  18. package/src/adapters/anthropic/per-message-effort.ts +296 -0
  19. package/src/adapters/anthropic.ts +3 -0
  20. package/src/adapters/claude-cli/adapter.ts +1 -0
  21. package/src/adapters/devin/cloud-direct/chat.ts +71 -14
  22. package/src/adapters/google-errors.ts +14 -2
  23. package/src/adapters/qoder/adapter.ts +9 -1
  24. package/src/adapters/zed.ts +4 -2
  25. package/src/claude/desktop-remote-store.ts +60 -10
  26. package/src/cli/account-api.ts +4 -0
  27. package/src/cli/account-auth.ts +30 -2
  28. package/src/cli/account-extended.ts +33 -2
  29. package/src/cli/capabilities-access-remote.ts +3 -3
  30. package/src/cli/capabilities-accounts.ts +3 -3
  31. package/src/cli/capabilities-base.ts +11 -6
  32. package/src/cli/capabilities-observe-system.ts +2 -2
  33. package/src/cli/claude.ts +3 -3
  34. package/src/cli/disconnect-runtime.ts +16 -6
  35. package/src/cli/dispatch.ts +7 -1
  36. package/src/cli/index.ts +2 -2
  37. package/src/cli/link-apply-restart.ts +4 -2
  38. package/src/cli/link-routes.ts +4 -1
  39. package/src/cli/link.ts +5 -4
  40. package/src/cli/preflight-exemptions.ts +3 -0
  41. package/src/cli/registry.ts +5 -2
  42. package/src/cli/resolve.ts +23 -8
  43. package/src/cli/restart-failure.ts +11 -1
  44. package/src/cli/runtime-api.ts +4 -0
  45. package/src/cli/status.ts +4 -1
  46. package/src/cli/system-command.ts +1 -1
  47. package/src/cli/system-restart-client.ts +9 -3
  48. package/src/cli/system-settings-parity.ts +2 -1
  49. package/src/client/connect.ts +63 -9
  50. package/src/client/desktop-refusal.ts +38 -0
  51. package/src/client/lifecycle-lock.ts +29 -4
  52. package/src/client/runtime-restart.ts +27 -15
  53. package/src/client/runtime.ts +4 -2
  54. package/src/client/state.ts +14 -0
  55. package/src/codex/account-pause.ts +4 -0
  56. package/src/codex/account-runtime-state.ts +4 -0
  57. package/src/codex/auth-api/main-account-probe.ts +3 -1
  58. package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
  59. package/src/codex/auth-context.ts +40 -2
  60. package/src/codex/catalog/build-entries.ts +10 -0
  61. package/src/codex/catalog/derive-entry.ts +7 -0
  62. package/src/codex/catalog/reserve-warn.ts +7 -5
  63. package/src/codex/catalog/reserve.ts +4 -3
  64. package/src/codex/catalog/retained-sync.ts +2 -0
  65. package/src/codex/catalog/routed-defaults.ts +35 -0
  66. package/src/codex/convergence.ts +2 -0
  67. package/src/codex/loopback-target.ts +22 -8
  68. package/src/codex/main-account.ts +88 -29
  69. package/src/codex/native-main-auth-file.ts +14 -0
  70. package/src/codex/native-main-credentials.ts +270 -0
  71. package/src/codex/native-main-owner.ts +3 -0
  72. package/src/codex/native-main-refresh-mode.ts +14 -1
  73. package/src/codex/quota.ts +63 -14
  74. package/src/combos/failover.ts +12 -1
  75. package/src/combos/index.ts +5 -0
  76. package/src/combos/resolve.ts +115 -19
  77. package/src/config/diagnostics.ts +3 -0
  78. package/src/config/live-reconcile.ts +6 -3
  79. package/src/config/load-degrade.ts +2 -0
  80. package/src/config/persisted-mutation.ts +2 -2
  81. package/src/config/persisted-projections.ts +18 -0
  82. package/src/config/process-state.ts +4 -3
  83. package/src/config/reserve-capability.ts +96 -0
  84. package/src/config/schema/config-schema.ts +6 -0
  85. package/src/config/schema/leaf-validators.ts +2 -0
  86. package/src/config/schema/routed-catalog-defaults.ts +49 -0
  87. package/src/config.ts +7 -7
  88. package/src/desktop-update/acquire.ts +202 -0
  89. package/src/desktop-update/cli.ts +168 -0
  90. package/src/desktop-update/drain.ts +40 -0
  91. package/src/desktop-update/headless.ts +285 -0
  92. package/src/desktop-update/image.ts +85 -0
  93. package/src/desktop-update/install.ts +53 -0
  94. package/src/desktop-update/msi.ts +72 -0
  95. package/src/desktop-update/release.ts +128 -0
  96. package/src/desktop-update/runtime.ts +155 -0
  97. package/src/desktop-update/staging.ts +118 -0
  98. package/src/desktop-update/trust.ts +45 -0
  99. package/src/generated/compatibility-version.json +246 -130
  100. package/src/images/fulfill-video.ts +3 -3
  101. package/src/images/loop.ts +6 -2
  102. package/src/images/plan.ts +147 -11
  103. package/src/images/types.ts +13 -4
  104. package/src/images/xai-video-client.ts +72 -10
  105. package/src/lib/gcp-adc.ts +48 -4
  106. package/src/lib/offline-resend.ts +150 -0
  107. package/src/lib/paced-stream.ts +3 -3
  108. package/src/lib/provider-outbound.ts +17 -6
  109. package/src/lib/request-failure-model.ts +2 -0
  110. package/src/lib/response-body-inactivity.ts +23 -1
  111. package/src/lib/upstream-retry.ts +38 -5
  112. package/src/link/explicit-route.ts +4 -4
  113. package/src/link/remote-windows.ts +79 -31
  114. package/src/link/residual-recovery.ts +20 -8
  115. package/src/messaging/budget.ts +23 -5
  116. package/src/messaging/rpc.ts +4 -4
  117. package/src/oauth/antigravity-risk.ts +126 -0
  118. package/src/oauth/generic-account-failover.ts +89 -18
  119. package/src/oauth/generic-session-affinity.ts +10 -3
  120. package/src/oauth/login-cli.ts +35 -1
  121. package/src/oauth/pool-kernel.ts +3 -3
  122. package/src/providers/anthropic-billing-refusal.ts +27 -3
  123. package/src/providers/google-vertex-model-discovery.ts +6 -1
  124. package/src/providers/model-rename-fields.ts +2 -0
  125. package/src/providers/quota/workbuddy.ts +6 -2
  126. package/src/providers/workbuddy-credit-balance.ts +125 -16
  127. package/src/responses/effort-history.ts +732 -0
  128. package/src/routing/history/integrity.ts +41 -4
  129. package/src/server/auth-cors.ts +13 -3
  130. package/src/server/codex-model-list.ts +2 -1
  131. package/src/server/direct-local-http.ts +26 -3
  132. package/src/server/index/link-listener.ts +20 -14
  133. package/src/server/index/serve-options.ts +1 -0
  134. package/src/server/index.ts +3 -2
  135. package/src/server/link-turn.ts +17 -5
  136. package/src/server/management/config-routes.ts +39 -3
  137. package/src/server/management/link-child-preflight.ts +1 -1
  138. package/src/server/management/link-route-edit.ts +20 -1
  139. package/src/server/management/oauth-account-routes.ts +22 -5
  140. package/src/server/management/provider-overwrite-carry.ts +3 -0
  141. package/src/server/management/provider-routes.ts +4 -4
  142. package/src/server/management/static-catalog-probe.ts +33 -0
  143. package/src/server/proxy-liveness.ts +54 -9
  144. package/src/server/relay.ts +6 -1
  145. package/src/server/request-log-conversation.ts +2 -2
  146. package/src/server/request-log.ts +5 -1
  147. package/src/server/reserve-capability-startup.ts +32 -0
  148. package/src/server/responses/adapter-delivery.ts +2 -0
  149. package/src/server/responses/adapter-dispatch.ts +31 -10
  150. package/src/server/responses/antigravity-fault-rotation.ts +24 -0
  151. package/src/server/responses/antigravity-validation-refusal.ts +43 -6
  152. package/src/server/responses/combo-selection-keepalive.ts +254 -0
  153. package/src/server/responses/core-combo.ts +24 -9
  154. package/src/server/responses/core-errors.ts +9 -6
  155. package/src/server/responses/core-options.ts +8 -0
  156. package/src/server/responses/core.ts +21 -0
  157. package/src/server/responses/estimated-usage.ts +115 -0
  158. package/src/server/responses/jev-model-invoke.ts +7 -2
  159. package/src/server/responses/passthrough-completion.ts +6 -3
  160. package/src/server/responses/passthrough-delivery.ts +47 -8
  161. package/src/server/responses/passthrough-dispatch.ts +3 -0
  162. package/src/server/responses/request-prepare.ts +9 -5
  163. package/src/server/responses/sidecar-execution.ts +5 -0
  164. package/src/service/desktop-supervision.d.mts +2 -0
  165. package/src/service/desktop-supervision.mjs +5 -0
  166. package/src/stall-timeout.ts +11 -0
  167. package/src/types/config.ts +15 -92
  168. package/src/types/provider.ts +13 -0
  169. package/src/types/request.ts +19 -0
  170. package/src/types/routed-catalog-defaults.ts +17 -0
  171. package/src/types/routing-profile.ts +90 -0
  172. package/src/types.ts +1 -0
  173. package/src/update/index.ts +1 -1
  174. package/src/usage/log.ts +14 -4
  175. package/src/usage/telemetry-contract.ts +1 -0
  176. package/src/web-search/passthrough-bridge.ts +7 -0
  177. package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
  178. package/gui/dist/assets/index-DCdXsMyZ.js +0 -105
  179. package/gui/dist/assets/index-DQtCRNAw.css +0 -2
  180. package/gui/dist/classic/assets/index-BqOaGLf5.js +0 -105
  181. package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
@@ -0,0 +1,150 @@
1
+ import { lookup } from "node:dns/promises";
2
+ import { isIP } from "node:net";
3
+ import type { OcxProviderConfig } from "../types";
4
+ import { isEgressTransparentExecutor, resolveProviderEgress } from "./provider-egress";
5
+ import { effectiveProxyFor, noProxyMatches } from "./proxy-env";
6
+ import { UpstreamRetryEvidenceError } from "./upstream-retry";
7
+
8
+ /** Longest configurable offline wait (#7958): five minutes, the span of a laptop sleep/Wi-Fi hop. */
9
+ export const MAX_OFFLINE_RESEND_WAIT_SEC = 300;
10
+ /** Interval between reachability probes while offline. */
11
+ export const OFFLINE_REACHABILITY_PROBE_INTERVAL_MS = 1_000;
12
+
13
+ /**
14
+ * Only a DNS resolution failure qualifies (#7958): DNS answering again is exactly the evidence that
15
+ * failure lacked. A refused or unreachable connection would resend into the same failure, and with
16
+ * an outbound proxy a direct reachability probe would not test the path the request takes.
17
+ */
18
+ const DNS_FAILURE_CODES = new Set(["ENOTFOUND", "EAI_AGAIN"]);
19
+ const MAX_CAUSE_DEPTH = 3;
20
+
21
+ /** A DNS resolution failure, read from `code` through a bounded cause chain; never from message text. */
22
+ export function isDnsResolutionFailure(error: unknown): boolean {
23
+ let current: unknown = error instanceof UpstreamRetryEvidenceError ? undefined : error;
24
+ for (let depth = 0; depth < MAX_CAUSE_DEPTH && current instanceof Error; depth++) {
25
+ const code = (current as { code?: unknown }).code;
26
+ if (typeof code === "string" && DNS_FAILURE_CODES.has(code)) return true;
27
+ current = current.cause;
28
+ }
29
+ return false;
30
+ }
31
+
32
+ /**
33
+ * Decides, at most once per logical request, whether a pre-connect failure may be resent after
34
+ * the destination became reachable again. Returns false for every later call, and never rejects
35
+ * with the abort reason: a cancelled wait answers false so the caller keeps the original failure.
36
+ */
37
+ export type OfflineResendWait = (error: unknown, signal?: AbortSignal) => Promise<boolean>;
38
+
39
+ export interface OfflineResendDependencies {
40
+ /** Resolves when the host resolves; rejects while it does not. */
41
+ resolveHost?: (hostname: string) => Promise<unknown>;
42
+ /** Abortable delay between probes. */
43
+ delay?: (ms: number, signal?: AbortSignal) => Promise<void>;
44
+ /** Abortable timer that ends a probe still pending when the wait runs out. */
45
+ expire?: (ms: number, signal?: AbortSignal) => Promise<void>;
46
+ now?: () => number;
47
+ }
48
+
49
+ let testDependencies: OfflineResendDependencies | undefined;
50
+
51
+ /** Test-only seam for the DNS probe, delay and clock; `undefined` restores the real ones. */
52
+ export function setOfflineResendDependenciesForTests(dependencies: OfflineResendDependencies | undefined): void {
53
+ testDependencies = dependencies;
54
+ }
55
+
56
+ /** The configured wait in milliseconds, or 0 when the opt-in is off or malformed. */
57
+ export function resolveOfflineResendWaitMs(configuredSec: unknown): number {
58
+ if (typeof configuredSec !== "number" || !Number.isFinite(configuredSec) || configuredSec <= 0) return 0;
59
+ return Math.ceil(Math.min(configuredSec, MAX_OFFLINE_RESEND_WAIT_SEC) * 1_000);
60
+ }
61
+
62
+ /**
63
+ * Opt-in offline wait for one request (#7958). After a send fails because the destination's name
64
+ * did not resolve (`isDnsResolutionFailure`), poll its DNS until it resolves or `maxWaitMs` passes,
65
+ * then allow one resend. An IP-literal destination never qualifies: DNS proves nothing about it.
66
+ * Nothing was delivered, so the resend cannot repeat an upstream effect; the caller's send budget
67
+ * still counts it. A rejection that is not pre-connect, a second failure, an exhausted wait or a
68
+ * client abort returns the original failure. A client abort answers false rather than throwing:
69
+ * the abort reason would replace the DNS error, and a Codex pool send would then classify a
70
+ * host-wide `connect_neutral` failure as account-attributed `connect_error`.
71
+ */
72
+ export function createOfflineResendWait(url: string, maxWaitMs: number): OfflineResendWait | undefined {
73
+ if (!(maxWaitMs > 0)) return undefined;
74
+ let hostname: string;
75
+ try { hostname = new URL(url).hostname.replace(/^\[|\]$/g, ""); } catch { return undefined; }
76
+ if (isIP(hostname) !== 0) return undefined;
77
+ let claimed = false;
78
+ return async (error, signal) => {
79
+ if (claimed || !isDnsResolutionFailure(error)) return false;
80
+ claimed = true;
81
+ const deps = testDependencies ?? {};
82
+ const resolveHost = deps.resolveHost ?? ((host: string) => lookup(host));
83
+ const delay = deps.delay ?? abortableDelay;
84
+ const expire = deps.expire ?? abortableDelay;
85
+ const now = deps.now ?? Date.now;
86
+ const deadline = now() + maxWaitMs;
87
+ for (;;) {
88
+ if (signal?.aborted) return false;
89
+ let remaining = deadline - now();
90
+ if (remaining <= 0) return false;
91
+ // A stalled system resolver must not outlive the wait or the client: race each probe against
92
+ // the remaining budget and cancellation, and accept a success only inside the budget. An
93
+ // expiry that rejects (cancellation) ends the wait the same way as one that fires.
94
+ const settle = new AbortController();
95
+ const raceSignal = signal ? AbortSignal.any([signal, settle.signal]) : settle.signal;
96
+ const expiry = new Promise<void>(resolve => resolve(expire(remaining, raceSignal)))
97
+ .then(() => "expired" as const, () => "expired" as const);
98
+ const probe = new Promise(resolve => resolve(resolveHost(hostname))).then(() => true, () => false);
99
+ let outcome: boolean | "expired";
100
+ try { outcome = await Promise.race([probe, expiry]); } finally { settle.abort(); }
101
+ if (outcome === "expired" || signal?.aborted) return false;
102
+ if (outcome) return now() <= deadline;
103
+ remaining = deadline - now();
104
+ if (remaining <= 0) return false;
105
+ try { await delay(Math.min(OFFLINE_REACHABILITY_PROBE_INTERVAL_MS, remaining), signal); } catch { return false; }
106
+ }
107
+ };
108
+ }
109
+
110
+ function abortableDelay(ms: number, signal?: AbortSignal): Promise<void> {
111
+ if (signal?.aborted) return Promise.reject(signal.reason);
112
+ return new Promise<void>((resolve, reject) => {
113
+ const onAbort = () => { clearTimeout(timer); reject(signal?.reason); };
114
+ const timer = setTimeout(() => { signal?.removeEventListener("abort", onAbort); resolve(); }, ms);
115
+ signal?.addEventListener("abort", onAbort, { once: true });
116
+ });
117
+ }
118
+
119
+ /**
120
+ * The URL whose name the provider's send actually resolves, or `undefined` when that is unknown.
121
+ * A proxied send resolves the proxy's name, and its DNS failure is the proxy's, so the wait probes
122
+ * the proxy; probing the provider instead could resend into a proxy that still fails, or wait out
123
+ * a provider name only the proxy can resolve. The route follows `configuredOutboundFetch`: the
124
+ * provider's own `proxy`/`noProxy` first, then the global proxy unless `NO_PROXY` exempts the URL.
125
+ * A caller-supplied executor picks its own transport, so it gets no probe; OpenCodex's own wrappers
126
+ * (xAI, Mistral Chat) carry the egress-transparent mark because they send through that same route.
127
+ * A malformed route fails the send anyway.
128
+ */
129
+ export function offlineResendProbeUrl(providerName: string, provider: OcxProviderConfig, url: string): string | undefined {
130
+ const executor = (provider as { fetch?: unknown }).fetch;
131
+ if (typeof executor === "function" && !isEgressTransparentExecutor(executor)) return undefined;
132
+ let target: URL;
133
+ try { target = new URL(url); } catch { return undefined; }
134
+ let egress: ReturnType<typeof resolveProviderEgress>;
135
+ try { egress = resolveProviderEgress({ providerName, provider, url: target }); } catch { return undefined; }
136
+ if (egress.kind === "proxy") return egress.proxyUrl;
137
+ if (egress.kind === "direct") return url;
138
+ const globalProxy = effectiveProxyFor(target);
139
+ return globalProxy !== null && !noProxyMatches(target) ? globalProxy : url;
140
+ }
141
+
142
+ /** The request's offline waiter (#7958), probing the name its send resolves; `undefined` when off. */
143
+ export function createProviderOfflineResendWait(
144
+ providerName: string, provider: OcxProviderConfig, url: string, configuredSec: unknown,
145
+ ): OfflineResendWait | undefined {
146
+ const maxWaitMs = resolveOfflineResendWaitMs(configuredSec);
147
+ if (maxWaitMs <= 0) return undefined;
148
+ const probeUrl = offlineResendProbeUrl(providerName, provider, url);
149
+ return probeUrl === undefined ? undefined : createOfflineResendWait(probeUrl, maxWaitMs);
150
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Pacing that travels with a stream (#8601).
3
3
  *
4
- * A Remote Link turn while the link WebSocket feature is on reads its upstream body only as its client drains. Each
5
- * relay stage between the upstream and the client normally keeps one chunk queued ahead of its reader; a stage whose
6
- * source is paced queues none instead and marks its own output, so the whole chain pulls on demand. Streams that were
4
+ * Every relayed Remote Link turn reads its upstream body only as its client drains, with or without the link WebSocket
5
+ * feature. Each relay stage between the upstream and the client normally keeps one chunk queued ahead of its reader; a
6
+ * stage whose source is paced queues none instead and marks its own output, so the whole chain pulls on demand. Streams that were
7
7
  * never marked keep their default queue: every other request is unchanged.
8
8
  */
9
9
  const paced = new WeakSet<ReadableStream<Uint8Array>>();
@@ -32,7 +32,8 @@ export interface ProviderOutboundDependencies {
32
32
  /** Recheck caller-owned credential authority after DNS and immediately before transport. */
33
33
  beforeSend?: () => boolean;
34
34
  /**
35
- * Caller opt-in for a cleartext `http:` POST to a self-hosted service. Honoured only when the
35
+ * Caller opt-in for a cleartext `http:` POST (or credentialed GET, see `cleartextPolicy`) to a
36
+ * self-hosted service. Honoured only when the
36
37
  * URL host is exactly `localhost` or an address literal in the narrow local allowlist
37
38
  * (`localCleartextAddressAllowed`) AND the provider row itself sets `allowPrivateNetwork: true`
38
39
  * (a registry default does not count). Every resolved answer must stay inside the same
@@ -40,6 +41,13 @@ export interface ProviderOutboundDependencies {
40
41
  * LAN. Every other destination keeps the HTTPS-only POST gate. Defaults to refusing.
41
42
  */
42
43
  allowLocalCleartextPost?: boolean;
44
+ /**
45
+ * Which requests the cleartext rules above bind. A POST always obeys them. `"credentialed"`
46
+ * also holds a GET to them, for a caller whose GET carries the same credential as its POST (the
47
+ * video poll): HTTPS, or the local cleartext opt-in with its allowlisted answers and direct
48
+ * route. Without it a GET keeps the discovery behaviour, which admits `http:`.
49
+ */
50
+ cleartextPolicy?: "credentialed";
43
51
  }
44
52
 
45
53
  function ipv4Octets(address: string): number[] | null {
@@ -234,10 +242,13 @@ async function providerOutboundRequest(
234
242
  const assertSendAllowed = () => {
235
243
  if (dependencies.beforeSend?.() === false) throw new ProviderOutboundSendCancelledError("provider credential changed before send");
236
244
  };
237
- const postUrl = method === "POST" ? new URL(url) : undefined;
245
+ // A POST, and a GET whose caller declared it carries the POST's credential, must not cross the
246
+ // network in cleartext. The messages name a GET explicitly so a refusal says which call failed.
247
+ const label = method === "POST" ? "POST" : "credentialed GET";
248
+ const postUrl = method === "POST" || dependencies.cleartextPolicy === "credentialed" ? new URL(url) : undefined;
238
249
  if (postUrl?.protocol !== undefined && postUrl.protocol !== "https:"
239
250
  && !localCleartextPostAllowed(provider, postUrl, dependencies)) {
240
- throw new ProviderOutboundPolicyError("provider POST URL must use HTTPS");
251
+ throw new ProviderOutboundPolicyError(`provider ${label} URL must use HTTPS`);
241
252
  }
242
253
  // Only reachable after the narrow opt-in above admitted it.
243
254
  const localCleartextPost = postUrl?.protocol === "http:";
@@ -248,7 +259,7 @@ async function providerOutboundRequest(
248
259
  if (typeof provider.fetch === "function") {
249
260
  // An executor resolves names itself, so a cleartext POST through one must name an address.
250
261
  if (localCleartextPost && !isIP(unbracketedHostname(postUrl!))) {
251
- throw new ProviderOutboundPolicyError("a cleartext provider POST through a caller-supplied executor must use an address literal");
262
+ throw new ProviderOutboundPolicyError(`a cleartext provider ${label} through a caller-supplied executor must use an address literal`);
252
263
  }
253
264
  // A caller-owned executor decides its own transport, so a provider egress route cannot be
254
265
  // applied to it. Refusing is the only honest answer: running the executor anyway would send
@@ -310,7 +321,7 @@ async function providerOutboundRequest(
310
321
  // the DNS-failure proxy degradation below, which needs one) would carry it off-host unencrypted.
311
322
  if (localCleartextPost && proxyApplies) {
312
323
  throw new ProviderOutboundPolicyError(
313
- `a cleartext provider POST cannot use an outbound proxy; add ${normalizeProxyHostname(parsed.hostname)} to NO_PROXY`,
324
+ `a cleartext provider ${label} cannot use an outbound proxy; add ${normalizeProxyHostname(parsed.hostname)} to NO_PROXY`,
314
325
  );
315
326
  }
316
327
  const isCanonicalUrl = dependencies.isCanonicalUrl ?? (() => false);
@@ -390,7 +401,7 @@ async function providerOutboundRequest(
390
401
  }
391
402
  if (localCleartextPost
392
403
  && !resolved.addresses.every(answer => localCleartextAddressAllowed(answer.address))) {
393
- throw new ProviderOutboundPolicyError("a cleartext provider POST resolved outside the local address allowlist");
404
+ throw new ProviderOutboundPolicyError(`a cleartext provider ${label} resolved outside the local address allowlist`);
394
405
  }
395
406
  const requestOptions = {
396
407
  headers: init.headers,
@@ -216,6 +216,8 @@ const RECOVERY_KIND_CAUSE = {
216
216
  // turn. One kind cannot say both, so it says the weaker thing.
217
217
  "transient-5xx": "upstream-fault",
218
218
  "connection-reset": "transport-ambiguous",
219
+ // The send it replaced failed DNS resolution, so those bytes provably never left (#7958).
220
+ "offline-resend": "transport-unsent",
219
221
  "oauth-401": "credential-rejected",
220
222
  "oauth-account-403": "credential-rejected",
221
223
  "key-401": "credential-rejected",
@@ -11,6 +11,25 @@ export class ResponseBodyInactivityError extends DOMException {
11
11
  }
12
12
  }
13
13
 
14
+ /**
15
+ * The same expiry from a guard armed by the operator's explicit `stallTimeoutSec` (#8206). Only this
16
+ * one reaches clients as `upstream_stall_timeout`; a guard on a default budget keeps its old terminal.
17
+ */
18
+ export class ExplicitBodyStallError extends ResponseBodyInactivityError {}
19
+
20
+ // Published responses whose upstream reads already run under a positive inactivity guard.
21
+ const guardedResponses = new WeakSet<Response>();
22
+
23
+ /** Record that `response` relays bytes from guarded upstream reads, so no second clock is armed. */
24
+ export function markResponseBodyInactivityGuarded(response: Response): Response {
25
+ guardedResponses.add(response);
26
+ return response;
27
+ }
28
+
29
+ export function isResponseBodyInactivityGuarded(response: Response): boolean {
30
+ return guardedResponses.has(response);
31
+ }
32
+
14
33
  /**
15
34
  * Bound silence only while the consumer is waiting for upstream bytes.
16
35
  *
@@ -23,13 +42,16 @@ export function guardResponseBodyInactivity(
23
42
  response: Response,
24
43
  signal: AbortSignal | undefined,
25
44
  timeoutMs: number,
45
+ options: { explicitBudget?: boolean } = {},
26
46
  ): ResponseBodyInactivityGuard {
27
47
  const source = response.body;
28
48
  if (!source) return { response, dispose: () => {} };
29
49
 
30
50
  const reader = source.getReader();
31
51
  const timeoutEnabled = Number.isFinite(timeoutMs) && timeoutMs > 0;
32
- const timeoutError = new ResponseBodyInactivityError(timeoutMs);
52
+ const timeoutError = options.explicitBudget === true
53
+ ? new ExplicitBodyStallError(timeoutMs)
54
+ : new ResponseBodyInactivityError(timeoutMs);
33
55
  let output!: ReadableStreamDefaultController<Uint8Array>;
34
56
  let settled = false;
35
57
  let timer: ReturnType<typeof setTimeout> | undefined;
@@ -552,6 +552,12 @@ export interface ResetRetryOptions {
552
552
  * `attempts`, exactly like every other send this leg makes.
553
553
  */
554
554
  claimAmbiguousResend?: () => boolean;
555
+ /**
556
+ * Opt-in offline wait (#7958): asked once a send failed before reaching the origin; true means
557
+ * the destination is reachable again and one resend may follow inside `attempts`. See
558
+ * `createOfflineResendWait` in offline-resend.ts, which owns the single-use and pre-connect rules.
559
+ */
560
+ offlineWait?: (error: unknown, signal?: AbortSignal) => Promise<boolean>;
555
561
  }
556
562
 
557
563
  export interface TransientRetryOptions extends ResetRetryOptions {
@@ -568,7 +574,8 @@ export interface TransientRetryOptions extends ResetRetryOptions {
568
574
  retryAfterCeilingMs?: number;
569
575
  }
570
576
 
571
- export type UpstreamSendRecovery = "connection-reset" | "transient-5xx";
577
+ /** `offline-resend` is the single send after an offline wait (#7958), never a reset retry. */
578
+ export type UpstreamSendRecovery = "connection-reset" | "transient-5xx" | "offline-resend";
572
579
  type ReplayableFetch = (recovery?: UpstreamSendRecovery) => Promise<Response>;
573
580
 
574
581
  /**
@@ -604,20 +611,25 @@ export class UpstreamRetryEvidenceError extends Error {
604
611
  }
605
612
 
606
613
  /**
607
- * Opt out of Bun's keep-alive pool after a connection-reset retry.
614
+ * Opt out of Bun's keep-alive pool after a connection-reset retry or an offline resend.
608
615
  *
609
616
  * Prefer the Bun fetch extension `keepalive: false` (transport-level) over
610
617
  * relying on the hop-by-hop `Connection: close` header alone — Bun has ignored
611
618
  * that header in past releases (oven-sh/bun#20492), so a header-only retry can
612
619
  * still reuse the same half-closed pooled socket. Still set Connection: close
613
620
  * as a belt-and-suspenders signal for intermediaries that honor it.
621
+ *
622
+ * An offline resend (#7958) follows a DNS outage, typically a sleep or a network change, so any
623
+ * socket still pooled for that origin or proxy was opened on the network that went away. Reusing
624
+ * one fails after the body may have left, which turns a provably unsent request into an ambiguous
625
+ * reset; a fresh connection is what the resend needs anyway.
614
626
  */
615
627
  export function applyUpstreamRecoveryInit<T extends RequestInit>(
616
628
  init: T,
617
629
  recovery?: UpstreamSendRecovery,
618
630
  ): T & { headers: Headers } {
619
631
  const headers = new Headers(init.headers);
620
- if (recovery !== "connection-reset") {
632
+ if (recovery !== "connection-reset" && recovery !== "offline-resend") {
621
633
  return { ...init, headers };
622
634
  }
623
635
  headers.set("connection", "close");
@@ -664,6 +676,8 @@ export async function fetchWithResetRetry(
664
676
  // settles as the refusal or an unambiguous answer: a second send of a possibly-executed turn
665
677
  // is already out, and handing the client anything it would retry compounds it.
666
678
  let spentOperatorReplacement = false;
679
+ // The recovery the next send reports: the caller's for the first, then whichever path resent it.
680
+ let recovery = firstRecovery;
667
681
  for (let attempt = 0; attempt < attempts; attempt++) {
668
682
  if (opts.abortSignal?.aborted) throw abortError(opts.abortSignal);
669
683
  // Reported before the await, one physical send at a time: a send that rejects has still
@@ -673,7 +687,7 @@ export async function fetchWithResetRetry(
673
687
  if (!opts.onSendsConsumed?.beforeSend) opts.onSendsConsumed?.(1);
674
688
  try {
675
689
  let response: Response;
676
- try { const run = () => doFetch(attempt === 0 ? firstRecovery : "connection-reset");
690
+ try { const sendRecovery = recovery; const run = () => doFetch(sendRecovery);
677
691
  response = await (opts.onSendsConsumed?.execute ? opts.onSendsConsumed.execute(run) : run()); }
678
692
  finally { if (opts.onSendsConsumed?.beforeSend) opts.onSendsConsumed(1); }
679
693
  return spentOperatorReplacement ? settleOperatorReplacement(response) : response;
@@ -688,6 +702,13 @@ export async function fetchWithResetRetry(
688
702
  // evidence: keep it attached so the terminal rejection cannot be
689
703
  // downgraded to the pre-connection neutral class (#914 review).
690
704
  if (sawReset) throw new UpstreamRetryEvidenceError([], err, true);
705
+ // Nothing reached the origin, so one resend after reachability returns cannot repeat an effect.
706
+ // A client that left during the wait gets this failure back, never the abort reason.
707
+ if (attempt + 1 < attempts && opts.offlineWait && await opts.offlineWait(err, opts.abortSignal)
708
+ && !opts.abortSignal?.aborted) {
709
+ recovery = "offline-resend";
710
+ continue;
711
+ }
691
712
  throw err;
692
713
  }
693
714
  if (opts.replaySafe === true) {
@@ -707,6 +728,7 @@ export async function fetchWithResetRetry(
707
728
  }
708
729
  sawReset = true;
709
730
  lastError = err;
731
+ recovery = "connection-reset";
710
732
  console.warn(
711
733
  `[upstream-retry] connection reset${opts.label ? ` (${opts.label})` : ""} — ${
712
734
  spentOperatorReplacement ? "replacing" : "retrying"
@@ -844,6 +866,8 @@ export async function fetchWithTransientRetry(
844
866
  ...opts,
845
867
  attempts: remaining(),
846
868
  onSendsConsumed: undefined,
869
+ // The offline wait belongs to the request's first send only (see below); later legs never wait.
870
+ offlineWait: undefined,
847
871
  });
848
872
  // Reported in `finally` rather than at each exit: this function returns from five places
849
873
  // and throws from one, and a caller sharing the budget across request legs must be told the
@@ -851,7 +875,16 @@ export async function fetchWithTransientRetry(
851
875
  try {
852
876
  if (budget === 0) throw new SendBudgetExhaustedError(opts.destination ?? (opts.label ? errorDestinationLabel(opts.label) : undefined));
853
877
  let attemptStart = Date.now();
854
- let res = await fetchWithResetRetry(countedFetch, innerResetOptions());
878
+ // Time spent waiting for the network to return is not part of the resend's own attempt.
879
+ const offlineWait = opts.offlineWait;
880
+ let res = await fetchWithResetRetry(countedFetch, {
881
+ ...innerResetOptions(),
882
+ ...(offlineWait ? { offlineWait: async (error: unknown, signal?: AbortSignal) => {
883
+ const resumed = await offlineWait(error, signal);
884
+ if (resumed) attemptStart = Date.now();
885
+ return resumed;
886
+ } } : {}),
887
+ });
855
888
  for (let attempt = 0; sent < budget; attempt++) {
856
889
  // A non-replayable gateway status was settled after the request body had already left
857
890
  // for the origin; retrying it here is the automatic resend the marker exists to forbid.
@@ -109,10 +109,10 @@ export type IdentityFileProblem = "identity_file_missing" | "identity_file_not_r
109
109
  export const IDENTITY_FILE_GUIDANCE: Readonly<Record<IdentityFileProblem, string>> = {
110
110
  identity_file_missing: "The identity file does not exist.",
111
111
  identity_file_not_regular: "The identity file must be a regular file, not a symlink or a directory.",
112
- identity_file_permissions: "The identity file must be owned by this user with no group or other permissions (chmod 600 on it). Use a key file of this user's own; never chown another user's or the system's key.",
113
- identity_file_directory: "The directory that holds the identity file must be owned by this user or root and not writable by group or others. Move the key to a path that passes; if a tool chose the path, run chmod go-w on that tool's own private folder or have it use a path that passes. Never change a shared or system directory such as /tmp, even when the Home runs as root.",
114
- identity_file_ancestor: "Every directory above the identity file must be owned by this user or root and not writable by group or others unless sticky, and every symlink on its path must be owned by this user or root; a folder made under umask 002 is group-writable. Run chmod go-w on such a private folder of this user's or of the tool that chose the path, or use a path that passes. Never change a shared or system directory or another user's symlink, even as root.",
115
- identity_file_unreadable: "This user cannot read the identity file or a directory on its path, or the path is too long or has too many symlinks. Use a shorter path without symlink loops; fix read access only on this user's own file or folder.",
112
+ identity_file_permissions: "The identity file must be owned by this user with no group or other permissions. Use a key file of this user's own and run chmod 600 on it; never chown or chmod another user's or the system's key.",
113
+ identity_file_directory: "The directory that holds the identity file must be owned by this user or root and not writable by group or others. Move the key to a path that passes, or run chmod go-w on that directory only if it is a private folder this user owns (its own, or one a tool made for it); a tool that chose the path can instead be set to use a path that passes. Never change a shared or system directory such as /tmp, even when the Home runs as root.",
114
+ identity_file_ancestor: "Every directory above the identity file must be owned by this user or root and not writable by group or others unless sticky, and every symlink on its path must be owned by this user or root; a folder made under umask 002 is group-writable. Run chmod go-w on such a folder only if it is a private folder this user owns (its own, or one a tool made for it), or use a path that passes. Never change a shared or system directory or another user's symlink, even as root.",
115
+ identity_file_unreadable: "This user cannot read the identity file or a directory on its path, or the path is too long or has too many symlinks. Use a shorter path without symlink loops; fix read access only on this user's own file or folder, with chmod u+r on the file or u+rx on a folder, and never add group or other access.",
116
116
  identity_file_unsupported_platform: "A Windows Home does not support an identity file yet.",
117
117
  };
118
118