GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(proxy): opt-in same-target 429 wait-and-retry before key failover (#487) by harryzhou2000 · Pull Request #865 · lidge-jun/opencodex Conversation
|
📝 WalkthroughWalkthroughAdds opt-in, same-key HTTP 429 retries for API-key providers. Retries use bounded delays, ChangesRate-limit retry policy and implementation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ResponsesCore
participant ProviderTransport
participant UpstreamProvider
Client->>ResponsesCore: Submit request
ResponsesCore->>ProviderTransport: Send with current API key
ProviderTransport->>UpstreamProvider: Forward request
UpstreamProvider-->>ResponsesCore: HTTP 429
ResponsesCore->>ResponsesCore: Release body and wait
ResponsesCore->>ProviderTransport: Replay identical request
ProviderTransport->>UpstreamProvider: Forward on same key
UpstreamProvider-->>ResponsesCore: Response or final 429
ResponsesCore->>Client: Return response or error
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- usage/log: whitelist the rate-limit-429 recovery kind so persisted usage rows and post-restart /api/logs keep the reason - key-failover: gate retryOn429 to key-auth providers (no same-token OAuth replays, no silent no-op on forward passthrough); accept Retry-After 0 as immediate - config: cap maxIntervalMs at the effective 10-minute cooldown ceiling - core: hoist the retry budget outside the recovery loop so 413/401 replays cannot re-arm it; cancel the unread 429 body before aborting on client cancel - gui: add rate-limit-429 (and pre-existing anthropic-oauth-429) to the Logs union - tests: OAuth/forward gating, HTTP-date Retry-After, Retry-After 0, persisted recovery-kind, and a deterministic direct-handler abort test (real-socket disconnect propagation is async in Bun, so the e2e version was timing-flaky) - docs: key-auth-only note, maxIntervalMs cap, abort-propagation nuance, locale rows
… xhigh) - core: the Responses passthrough wire (openai-responses key-auth gateways, e.g. the built-in DeepSeek preset) now replays 429 on the same key pre-relay, before the forward-pool logic; Anthropic terminal-guard continuations replay before key/account failover - images/loop + web-search/loop: same-target replay before on429 key rotation via a new retryOn429Policy dep (abort-aware, heartbeat seams preserved) - key-failover: the fixed fallback is now capped at maxIntervalMs (a single wait never exceeds the cap); authMode local runtimes are gated out alongside oauth/forward, so the knob matches the documented API-key scope exactly - tests: key-auth openai-responses passthrough e2e, terminal-guard continuation replay, image/web-search same-key replay (rotation stays zero), fallback cap, local-mode gating - docs: coverage and cap wording in devlog 010, structure/04, and all five configuration locale rows
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@devlog/_plan/260802_429_same_target_retry/010_design.md`:
- Around line 57-67: Update the latency and concurrency sections of the retry
design to distinguish retry-wait time from total request latency, noting that
connection, response, and configured timeout durations also contribute. Revise
the request-volume bound to account for multi-key failover, including the
possibility of exhausting the retry budget on one key before attempting another,
and document the combined bound alongside the existing failover behavior.
- Around line 7-9: Update same-key retry handling around the
continuation-request rebuild in core response processing so every retry replays
a cached, body-safe representation of the identical upstream request, including
serialized body and authentication headers, rather than rebuilding it each time.
Apply this to passthrough Responses and Anthropic terminal continuations; only
rebuild after the target or adapter changes, defining deterministic equivalence
where adapters must rebuild. Extend the rate-limit retry and terminal-guard
tests to assert body and authentication/header equality, not just send counts.
- Around line 32-34: Update rate-limit retry authentication handling to fail
closed: normalize omitted key-provider auth modes to "key", preserve "local" in
providerConfigSeed (including the mapping in derive), and make
rateLimitRetryPolicyFor allow retries only when authMode === "key". Add
regression coverage for omitted, local, and unknown authentication modes while
preserving existing key-provider behavior.
In `@docs-site/src/content/docs/reference/configuration.md`:
- Line 353: Update the retryOn429 documentation across the English, Japanese,
Korean, Russian, and Chinese provider and adapter reference pages. State that it
applies only to authMode: "key" and excludes oauth, forward, and local
providers; document same-key replay, raw openai-responses passthrough,
translated openai-chat/Anthropic requests, and that custom runTurn transports
are excluded. Keep the existing defaults and behavior description consistent
across all pages.
In `@src/images/loop.ts`:
- Around line 467-490: The 429 retry waits must not consume the cumulative
header deadline in either loop. In src/images/loop.ts lines 467-490, update the
flow around the headerDeadline and rateLimitRetryPolicy retry loop so each
deliberate wait is excluded, while preserving the configured retry outcome and
preventing the 504 header-timeout path from firing due to that wait; apply the
identical change in src/web-search/loop.ts lines 361-384 around its
headerDeadline and retry loop.
In `@src/providers/key-failover.ts`:
- Around line 76-96: Ensure local providers cannot enter the key-failover retry
path when authMode is undefined: preserve authMode: "local" through the provider
derivation/routing flow or pass the registry auth kind into
rateLimitRetryPolicyFor, while retaining undefined as the default for custom
API-key providers. Add a regression test covering a local provider configured
with retryOn429: {}.
In `@src/server/responses/core.ts`:
- Around line 1631-1671: Update the retry closure in the passthrough 429 loop to
pass `"rate-limit-429"` to `noteAttemptSend` whenever `fetchWithTransientRetry`
provides no recovery kind, while preserving any recovery kind it does provide.
Keep the existing `rateLimitPolicy` retry flow unchanged.
- Around line 2629-2665: Hoist the rateLimitPolicy and rateLimitRetries
declarations out of the terminal continuation while loop, placing them beside
imageTierBias so the retry budget persists across key rotation, account
rotation, and image-tier 413 continues. Resolve rateLimitPolicy once from the
initial route.provider and preserve the existing retry loop behavior while
preventing the budget from resetting per iteration.
In `@tests/rate-limit-retry.test.ts`:
- Around line 99-159: The retry tests lack coverage proving the retry budget is
scoped per request rather than reset during failover. Add focused regression
coverage near the existing retry-loop tests using a two-key provider pool,
retryOn429 with attempts set to 1, and upstream responses that always return
429; assert the total upstream send count remains within the request-wide bound,
covering both the main recovery loop and terminal-continuation path.
In `@tests/usage-log.test.ts`:
- Around line 39-62: Replace the as never cast in the
persists-the-rate-limit-429-recovery-kind-on-attempts test with a
PersistedUsageEntry-typed object. Keep the recoveryKinds literal type-checked
against the recovery-kind union, and cast only individual fields that genuinely
require it while preserving the existing round-trip assertion.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: a0cd7539-4937-4e9d-bf2a-e78d059e114a
devlog/_plan/260802_429_same_target_retry/000_research.mddevlog/_plan/260802_429_same_target_retry/010_design.mddocs-site/src/content/docs/ja/reference/configuration.mddocs-site/src/content/docs/ko/reference/configuration.mddocs-site/src/content/docs/reference/configuration.mddocs-site/src/content/docs/ru/reference/configuration.mddocs-site/src/content/docs/zh-cn/reference/configuration.mdgui/src/pages/Logs.tsxsrc/config.tssrc/images/loop.tssrc/providers/key-failover.tssrc/server/responses/core.tssrc/types.tssrc/usage/log.tssrc/web-search/loop.tsstructure/04_transports-and-sidecars.mdtests/images/loop.test.tstests/rate-limit-retry.test.tstests/server-rate-limit-retry-e2e.test.tstests/terminal-guard-server.test.tstests/usage-log.test.tstests/web-search.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: a06a416024
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
… deadlines, recovery labels) - key-failover: fail closed - only authMode key (or the documented omitted default) may replay; unknown modes rejected; an already-expired HTTP-date Retry-After retries immediately (like Retry-After: 0) - derive: providerConfigSeed preserves the registry auth kind (incl. local) so the gate survives the seed round-trip and routing - core: release the unread 429 body BEFORE every backoff (main loop, passthrough, continuations); passthrough and continuation replay sends record the rate-limit-429 recovery kind; continuation budget hoisted outside the failover loop so rotation/413 cannot re-arm it; continuation waits sleep on the upstream signal so an SSE body-cancel aborts them too - images/web-search loops: release the 429 body before the wait, restart the response-header deadline after each deliberate wait (backoffs never consume the connect budget or surface as 504), and record rate-limit-429 on replay sends - config: load-time degradation for invalid optional retryOn429 fields (warn + drop the field) instead of tripping the whole schema and hiding all providers behind a default config; the management write boundary still rejects - tests: fail-closed auth modes (incl. unknown), expired HTTP-date, per-request budget across 2-key pools (e2e + terminal continuation), byte-identical replay bodies/auth (passthrough + continuation), recovery telemetry in both loops, config load degradation, registry auth-kind preservation, typed usage-log entry - docs: retry-wait vs total-latency and attempts+poolKeys volume bounds, identical-replay equivalence, deadline/backoff behavior in devlog 010 and structure/04; retryOn429 boundary notes in the provider guide and adapter reference (English + ja/ko/ru/zh-cn)
|
All 17 inline review comments are addressed in 58c36c9 (plus docstrings in 0feede1 for the coverage check). Highlights: fail-closed auth (registry now preserves authMode "local"), expired Retry-After dates retry immediately, unread 429 bodies are released before every backoff, rate-limit-429 is recorded on every retry surface, bridge loops restart their header deadline after each wait, the continuation budget is per-request, invalid optional retryOn429 fields degrade at load instead of discarding the config, and replay identity is asserted byte-for-byte in tests. Replies were posted on each thread; the 7 open threads are resolved. The PR remains a draft. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
src/server/responses/core.ts (1)
2647-2685: 🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy liftEmit upstream heartbeats during 429 backoff
The bridge checks upstream activity every 2,000 ms. It increments
stallTickswhen no adapter event arrives and aborts atceil(stallTimeoutSec * 1000 / 2000)ticks. Wire heartbeats do not reset this counter.The retry waits can be silent for up to 600,000 ms. This exceeds the default 300-second core budget and the default 330-second web-search budget.
Apply the fix to these live generators:
src/server/responses/core.ts:2647-2685src/web-search/loop.ts:363-393src/images/loop.ts:469-498Split each
sleepWithAbortcall into chunks shorter than 2,000 ms, such as 1,000 ms. Yield{ type: "heartbeat" }after every chunk, including the final chunk. Add regression coverage for a backoff longer thanstallTimeoutSec. The pre-stream retry loops insrc/server/responses/core.tsdo not require this change.Update the web-search timeout documentation and tests to state that retry backoff remains live through these upstream heartbeats.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/responses/core.ts` around lines 2647 - 2685, Update the live retry-backoff loops in src/server/responses/core.ts:2647-2685, src/web-search/loop.ts:363-393, and src/images/loop.ts:469-498 to split sleepWithAbort waits into sub-2,000 ms chunks, yielding a heartbeat after every chunk including the final one, while preserving abort handling; leave pre-stream retry loops unchanged. Add regression coverage for backoffs exceeding stallTimeoutSec, and update web-search timeout documentation and tests to describe continued liveness through upstream heartbeats.src/images/loop.ts (1)
469-476: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick winKeep the retry budget scoped consistently.
src/images/loop.tsinitializesrateLimitRetriesinsideprepareIterationEvents, while onerunWithImageBridgerequest can execute multiple image-loop iterations. This can re-arm the same-key budget and exceed the documented per-request send bound.
src/images/loop.ts#L469-L476: move the policy and counter to request scope, or explicitly define the budget per iteration.structure/04_transports-and-sidecars.md#L235-L235: update theattempts + poolKeysbound if per-iteration scope is intentional.devlog/_plan/260802_429_same_target_retry/010_design.md#L95-L110: add a multi-iteration image-bridge regression test.#!/usr/bin/env bash set -euo pipefail rg -n -C 8 'prepareIterationEvents|rateLimitRetries|rateLimitRetryPolicy|HARD_CAP|retryOn429Policy' \ src/images/loop.ts tests/images/loop.test.tsAs per path instructions, add a focused regression in the flat Bun tests for this
src/**behavior change.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/images/loop.ts` around lines 469 - 476, Keep the 429 retry policy and counter request-scoped in prepareIterationEvents/runWithImageBridge so multiple image-loop iterations cannot reset the same-key retry budget; preserve the documented per-request send bound. Update structure/04_transports-and-sidecars.md:235 to reflect the chosen request-scoped bound, and extend devlog/_plan/260802_429_same_target_retry/010_design.md:95-110 with a multi-iteration image-bridge regression scenario. Add a focused regression to the flat Bun tests covering this behavior.Source: Path instructions
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@devlog/_plan/260802_429_same_target_retry/010_design.md`:
- Around line 88-89: Align the design and associated tests with the current
implementation: update the expired HTTP-date and numeric Retry-After: 0 cases to
expect the configured fallback interval when the parser returns undefined,
unless the parser and rateLimitRetryDelayMs are intentionally changed to
propagate a zero delay. Keep the documented behavior, parser expectations, and
tests consistent.
In `@docs-site/src/content/docs/ja/reference/adapters.md`:
- Around line 41-43: Update the retry descriptions in
docs-site/src/content/docs/ja/reference/adapters.md:41-43,
docs-site/src/content/docs/ko/reference/adapters.md:48-50,
docs-site/src/content/docs/ru/reference/adapters.md:51-53, and
docs-site/src/content/docs/zh-cn/reference/adapters.md:46-48 to state that
same-key 429 replay occurs before other handling or failover, while preserving
the existing translated behavior and custom runTurn exception.
In `@docs-site/src/content/docs/zh-cn/guides/providers.md`:
- Around line 37-40: Update the Chinese provider guide passage describing
retryOn429 to explicitly state that it is opt-in and disabled by default unless
configured, while preserving the existing API-key-only restriction and OAuth,
forward, and local exclusions. Keep the wording consistent with the
corresponding English provider guide.
In `@src/config.ts`:
- Around line 1135-1149: Update the retryOn429 sanitization around the fields
definition and loop to iterate over all keys in policy, warning and ignoring any
key not in the recognized field set. Preserve the existing validators and
warning behavior for known fields with invalid values, and continue rebuilding
p.retryOn429 from only accepted entries.
In `@src/images/loop.ts`:
- Around line 479-486: Await the unread 429 response body cancellation in the
retry flow around sleepWithAbort, while preserving handling for already-closed
bodies and cancellation failures. Update
devlog/_plan/260802_429_same_target_retry/010_design.md lines 53-55 and
structure/04_transports-and-sidecars.md lines 236-237 only as needed to keep
their “release before backoff” claims accurate after the implementation change.
- Around line 482-498: The retry flow around sleepWithAbort in
src/images/loop.ts lines 482-498 must clear headerDeadline before sleeping,
check signal.aborted immediately afterward and throw the existing 499 LoopError
before telemetry or replay, then create the replacement deadline before
onRateLimitRetrySend and fetchOnce. Update
structure/04_transports-and-sidecars.md lines 238-242 to preserve and document
the 499-before-replay guarantee; no other behavior needs changing.
---
Outside diff comments:
In `@src/images/loop.ts`:
- Around line 469-476: Keep the 429 retry policy and counter request-scoped in
prepareIterationEvents/runWithImageBridge so multiple image-loop iterations
cannot reset the same-key retry budget; preserve the documented per-request send
bound. Update structure/04_transports-and-sidecars.md:235 to reflect the chosen
request-scoped bound, and extend
devlog/_plan/260802_429_same_target_retry/010_design.md:95-110 with a
multi-iteration image-bridge regression scenario. Add a focused regression to
the flat Bun tests covering this behavior.
In `@src/server/responses/core.ts`:
- Around line 2647-2685: Update the live retry-backoff loops in
src/server/responses/core.ts:2647-2685, src/web-search/loop.ts:363-393, and
src/images/loop.ts:469-498 to split sleepWithAbort waits into sub-2,000 ms
chunks, yielding a heartbeat after every chunk including the final one, while
preserving abort handling; leave pre-stream retry loops unchanged. Add
regression coverage for backoffs exceeding stallTimeoutSec, and update
web-search timeout documentation and tests to describe continued liveness
through upstream heartbeats.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9881d8f6-9808-4382-a953-a3a067cfc38b
devlog/_plan/260802_429_same_target_retry/010_design.mddocs-site/src/content/docs/guides/providers.mddocs-site/src/content/docs/ja/guides/providers.mddocs-site/src/content/docs/ja/reference/adapters.mddocs-site/src/content/docs/ko/guides/providers.mddocs-site/src/content/docs/ko/reference/adapters.mddocs-site/src/content/docs/reference/adapters.mddocs-site/src/content/docs/ru/guides/providers.mddocs-site/src/content/docs/ru/reference/adapters.mddocs-site/src/content/docs/zh-cn/guides/providers.mddocs-site/src/content/docs/zh-cn/reference/adapters.mdsrc/config.tssrc/images/loop.tssrc/providers/derive.tssrc/providers/key-failover.tssrc/server/responses/core.tssrc/web-search/loop.tsstructure/04_transports-and-sidecars.mdtests/config-user-edits.test.tstests/images/loop.test.tstests/provider-registry-parity.test.tstests/rate-limit-retry.test.tstests/server-rate-limit-retry-e2e.test.tstests/terminal-guard-server.test.tstests/usage-log.test.tstests/web-search.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…ne race, config warnings, locale docs) - images/web-search loops: AWAIT the unread 429 body cancellation before the backoff; clear the old header deadline BEFORE the sleep; re-check client cancellation after the wait so 499 wins over stale-deadline edges; start the fresh deadline before telemetry and replay - config: sanitizeRetryOn429ForLoad warns about misnamed keys (e.g. attempt) instead of silently dropping them - docs: locale adapter pages state same-key replay runs before other handling/failover; provider guide (English + ja/ko/ru/zh-cn) states retryOn429 is opt-in (absent = off); devlog and structure/04 note the awaited cancellation and the 499-before-replay guarantee - test: config-user-edits covers the misnamed-key drop
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
devlog/_plan/260802_429_same_target_retry/010_design.md (1)
47-53: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winDocument the
runTurnexception for bridge retries.
src/images/loop.tsenters theadapter.runTurnbranch at Lines 355-433 and returns before the HTTP 429 retry loop at Lines 477-513. A key-auth customrunTurnadapter therefore does not receive this HTTP retry policy. State that bridge retries apply to HTTP adapters only and exclude customrunTurntransports.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@devlog/_plan/260802_429_same_target_retry/010_design.md` around lines 47 - 53, Update the retry-policy documentation near the bridge retry references to state that image/video bridge retries apply only to HTTP adapters. Explicitly exclude custom adapters using the adapter.runTurn path in src/images/loop.ts, which returns before the HTTP 429 retry loop; do not imply that runTurn transports receive the same wait-and-replay behavior.src/server/responses/core.ts (1)
2668-2707: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winAwait terminal-continuation body cancellation before the backoff.
At Line 2679,
response.body.cancel()is detached withvoid.sleepWithAbort()then starts at Line 2681 while cancellation can still be pending. Under repeated 429 responses, unread bodies can remain active through the retry wait and replay.Await cancellation before sleeping.
Proposed fix
- try { void response.body?.cancel().catch(() => {}); } catch { /* already closed */ } + try { await response.body?.cancel().catch(() => {}); } catch { /* already closed */ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/responses/core.ts` around lines 2668 - 2707, In the terminal-continuation retry loop, update the response body cleanup before sleepWithAbort to await response.body cancellation rather than detaching the promise. Preserve the existing safe handling for absent or already-closed bodies, and ensure the backoff starts only after cancellation has settled.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@devlog/_plan/260802_429_same_target_retry/010_design.md`:
- Around line 47-53: Update the retry-policy documentation near the bridge retry
references to state that image/video bridge retries apply only to HTTP adapters.
Explicitly exclude custom adapters using the adapter.runTurn path in
src/images/loop.ts, which returns before the HTTP 429 retry loop; do not imply
that runTurn transports receive the same wait-and-replay behavior.
In `@src/server/responses/core.ts`:
- Around line 2668-2707: In the terminal-continuation retry loop, update the
response body cleanup before sleepWithAbort to await response.body cancellation
rather than detaching the promise. Preserve the existing safe handling for
absent or already-closed bodies, and ensure the backoff starts only after
cancellation has settled.
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 72915daa-eace-482c-83cd-3c1d098cc169
devlog/_plan/260802_429_same_target_retry/010_design.mddocs-site/src/content/docs/guides/providers.mddocs-site/src/content/docs/ja/guides/providers.mddocs-site/src/content/docs/ja/reference/adapters.mddocs-site/src/content/docs/ko/guides/providers.mddocs-site/src/content/docs/ko/reference/adapters.mddocs-site/src/content/docs/ru/guides/providers.mddocs-site/src/content/docs/ru/reference/adapters.mddocs-site/src/content/docs/zh-cn/guides/providers.mddocs-site/src/content/docs/zh-cn/reference/adapters.mdsrc/config.tssrc/images/loop.tssrc/providers/derive.tssrc/providers/key-failover.tssrc/server/responses/core.tssrc/types.tssrc/web-search/loop.tsstructure/04_transports-and-sidecars.mdtests/config-user-edits.test.tstests/images/loop.test.tstests/server-rate-limit-retry-e2e.test.tstests/terminal-guard-server.test.tstests/usage-log.test.tstests/web-search.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 1af83c39cb
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
… send telemetry, invalid master switch, secret-safe warnings)
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: d4e1978821
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…ncel, post-sleep abort re-checks, pinned xAI req-id)
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
src/server/responses/core.ts (1)
2617-2666: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReduce the duplicated recovery-label expression in
fetchContinuation.Lines 2638 and 2647 both derive the same label from
replay. The second one additionally merges the transient-retry kind. The logic is correct, but the label rule now lives in two places, so a future change to the label (for example a distinct kind for continuation replays) can easily update only one branch.♻️ Optional consolidation
if (continuationEstimate !== undefined) logCtx.usageLogInputTokens = continuationEstimate; + const replayKind: AttemptRecoveryKind | undefined = replay ? "rate-limit-429" : undefined; try { if (activeAdapter.fetchResponse) { - noteAttemptSend(logCtx.activeAttempt, continuationEstimate, replay ? "rate-limit-429" : undefined); + noteAttemptSend(logCtx.activeAttempt, continuationEstimate, replayKind); return await activeAdapter.fetchResponse(continuationRequest, { @@ return await fetchWithResetRetry( recovery => { - noteAttemptSend(logCtx.activeAttempt, continuationEstimate, recovery ?? (replay ? "rate-limit-429" : undefined)); + noteAttemptSend(logCtx.activeAttempt, continuationEstimate, recovery ?? replayKind);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/responses/core.ts` around lines 2617 - 2666, Consolidate the replay-derived recovery label in fetchContinuation by computing it once before the fetch branches, then reuse that value in both noteAttemptSend calls while preserving the fetchWithResetRetry recovery override behavior.src/config.ts (1)
1144-1158: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueInclude the accepted range in the warning for out-of-range numbers.
The validators at Lines 1146-1148 reject both wrong types and out-of-range numbers, but the warning at Line 1157 reports only
typeof value. A user who writes"attempts": 999seesproviders.x.retryOn429.attempts (number) is invalid, which gives no hint about the accepted bound. Numbers and booleans cannot carry secret material, so the range can be stated safely while the value itself stays unlogged.♻️ Proposed diagnostic improvement
- const fields: Array<[string, (value: unknown) => boolean]> = [ - ["enabled", value => typeof value === "boolean"], - ["attempts", value => typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 20], - ["intervalMs", value => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 600_000], - ["maxIntervalMs", value => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 600_000], - ["respectRetryAfter", value => typeof value === "boolean"], + const fields: Array<[string, (value: unknown) => boolean, string]> = [ + ["enabled", value => typeof value === "boolean", "expected boolean"], + ["attempts", value => typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 20, "expected integer 1-20"], + ["intervalMs", value => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 600_000, "expected integer 100-600000"], + ["maxIntervalMs", value => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 600_000, "expected integer 100-600000"], + ["respectRetryAfter", value => typeof value === "boolean", "expected boolean"], ]; const cleaned: Record<string, unknown> = {}; - for (const [key, isValid] of fields) { + for (const [key, isValid, expectation] of fields) { const value = policyRecord[key]; if (value === undefined) continue; if (isValid(value)) cleaned[key] = value; // Log only the received type, never the value (provider config can hold secrets). - else console.warn(`⚠️ config.json providers.${name}.retryOn429.${key} (${typeof value}) is invalid — ignoring the field`); + else console.warn(`⚠️ config.json providers.${name}.retryOn429.${key} (${typeof value}) is invalid — ${expectation}; ignoring the field`); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/config.ts` around lines 1144 - 1158, Update the validation warning in the retry policy field loop around the `fields` validators to include the accepted ranges for numeric keys such as `attempts`, `intervalMs`, and `maxIntervalMs`, while retaining type-only reporting and never logging the received value. Keep boolean warnings unchanged and preserve the existing validation and field-cleaning behavior.src/images/loop.ts (1)
483-515: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winBound pre-header 429 retries before creating SSE
For non-
runTurnimage requests and all web-search requests,prepareIterationDrainedconsumes the retry heartbeat beforebridgeToResponsesSSEis created. The client receives no response headers while same-target 429 retries wait. The default policy can wait 3 minutes; valid configuration can wait up to 200 minutes (20 × 600_000ms). Bound the aggregate eager-phase wait to the request header budget, or move these retries into the liveproduce()phase. Apply the fix to both loops.runTurnimage requests already skip the eager drain.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/images/loop.ts` around lines 483 - 515, Bound same-target 429 retry waiting during the eager preparation phase so it cannot exceed the request header-timeout budget before SSE creation, or defer the retries into the live produce phase. Apply the corresponding fix to the retry loop in src/images/loop.ts lines 483-515 and src/web-search/loop.ts lines 380-412; preserve the existing runTurn image behavior, which already skips eager draining.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/providers/xai-transport.ts`:
- Around line 135-138: Rename the second parameter of withGeneratedRequestId to
reflect that it receives the already-resolved request ID, whether configured or
generated. Update all references within the helper while preserving the single
fallback in the request setup where configuredRequestId ?? randomUUID() is
computed, ensuring retries continue using the same ID.
In `@tests/config-user-edits.test.ts`:
- Around line 183-185: In the test assertion for the retryOn429 diagnostic,
replace the loose "string" substring check with an assertion anchored to the
retryOn429 field and its parenthesized received type. Keep the secret-redaction
assertion unchanged and ensure the expectation specifically verifies the
type-only warning from loadConfig().
---
Outside diff comments:
In `@src/config.ts`:
- Around line 1144-1158: Update the validation warning in the retry policy field
loop around the `fields` validators to include the accepted ranges for numeric
keys such as `attempts`, `intervalMs`, and `maxIntervalMs`, while retaining
type-only reporting and never logging the received value. Keep boolean warnings
unchanged and preserve the existing validation and field-cleaning behavior.
In `@src/images/loop.ts`:
- Around line 483-515: Bound same-target 429 retry waiting during the eager
preparation phase so it cannot exceed the request header-timeout budget before
SSE creation, or defer the retries into the live produce phase. Apply the
corresponding fix to the retry loop in src/images/loop.ts lines 483-515 and
src/web-search/loop.ts lines 380-412; preserve the existing runTurn image
behavior, which already skips eager draining.
In `@src/server/responses/core.ts`:
- Around line 2617-2666: Consolidate the replay-derived recovery label in
fetchContinuation by computing it once before the fetch branches, then reuse
that value in both noteAttemptSend calls while preserving the
fetchWithResetRetry recovery override behavior.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3f71039b-4261-460f-853e-cf5dc91ff470
src/config.tssrc/images/loop.tssrc/providers/xai-transport.tssrc/server/responses/core.tssrc/web-search/loop.tstests/config-user-edits.test.tstests/images/loop.test.tstests/rate-limit-retry.test.tstests/terminal-guard-server.test.tstests/web-search.test.tstests/xai-transport.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
CodeRabbit round on 4650bae: - images/web-search loops: move onAttemptSend into the fetchWithResetRetry callback (retryRecovery ?? recovery) so helper-driven connection-reset sends are recorded; classify rotated-adapter fetches as key-429 like core recovery. - providers docs (en/ja/ko/ru/zh-cn): state explicitly that exhausting attempts only stops same-key replays, with normal failover or final-error handling next. - structure/04: scope retryOn429 to HTTP-capable API-key adapters and exclude custom runTurn transports. - ko/zh-cn providers ref: keep routing links inside each locale tree.
|
@coderabbitai resume Addressed all five findings from the 4650bae round in 6fb4fe2:
Verified: typecheck, privacy scan, 99 bridge/retry tests pass. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs-site/src/content/docs/reference/configuration/providers.md`:
- Line 95: Correct the duplicate sentence terminator in the retryOn429
documentation row by changing the ending after “surfaces as-is” to a single
period. Keep the rest of the retry description unchanged and ensure equivalent
localized documentation remains synchronized if applicable.
In `@docs-site/src/content/docs/ru/reference/configuration/providers.md`:
- Line 98: In the retryOn429 documentation entry, replace the semicolon
immediately before the sentence beginning “Исчерпание attempts” with a period,
preserving all surrounding Russian text and punctuation.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c9e7857b-57d8-41ee-80e2-5994209cbb06
docs-site/src/content/docs/ja/reference/configuration/providers.mddocs-site/src/content/docs/ko/reference/configuration/providers.mddocs-site/src/content/docs/reference/configuration/providers.mddocs-site/src/content/docs/ru/reference/configuration/providers.mddocs-site/src/content/docs/zh-cn/reference/configuration/providers.mdsrc/images/loop.tssrc/web-search/loop.tsstructure/04_transports-and-sidecars.md
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
🧩 Analysis chain🏁 Script executed: #!/bin/bash set -euo pipefail commit="6fb4fe26" printf '%s\n' '=== Commit and current head ===' git rev-parse HEAD git show --no-patch --format='commit=%H%nparents=%P%nsubject=%s' "$commit" printf '%s\n' '=== Changed paths ===' git diff-tree --no-commit-id --name-status -r "$commit" printf '%s\n' '=== Production file outlines ===' ast-grep outline src/images/loop.ts --items all --type function,interface --match 'fetchOnce|fetchWithResetRetry|ImageBridgeDeps' --view expanded || true ast-grep outline src/web-search/loop.ts --items all --type function,interface --match 'fetchOnce|fetchWithResetRetry|WebSearchLoopDeps' --view expanded || true printf '%s\n' '=== Exact patch ===' git show --format= --unified=35 "$commit" -- \ src/images/loop.ts \ src/web-search/loop.ts \ structure/04_transports-and-sidecars.md \ docs-site/src/content/docs/reference/configuration/providers.md \ docs-site/src/content/docs/ja/reference/configuration/providers.md \ docs-site/src/content/docs/ko/reference/configuration/providers.md \ docs-site/src/content/docs/ru/reference/configuration/providers.md \ docs-site/src/content/docs/zh-cn/reference/configuration/providers.md \ docs-site/src/content/docs/ko/guides/providers.md \ docs-site/src/content/docs/zh-cn/guides/providers.md \ tests printf '%s\n' '=== Image telemetry and failover context ===' rg -n -C 14 \ 'fetchWithResetRetry|onAttemptSend|retryRecovery|recovery|fetchOnce\(|deps\.on429|key-429' \ src/images/loop.ts printf '%s\n' '=== Web-search telemetry and failover context ===' rg -n -C 14 \ 'fetchWithResetRetry|onAttemptSend|retryRecovery|recovery|fetchOnce\(|deps\.on429|key-429' \ src/web-search/loop.ts printf '%s\n' '=== Documentation scope, exhaustion behavior, and locale routing links ===' rg -n -C 5 \ 'retryOn429|attempts|exhaust|failover|final.error|runTurn|HTTP.capable|/ko/reference/configuration/routing/|/zh-cn/reference/configuration/routing/' \ structure/04_transports-and-sidecars.md \ docs-site/src/content/docs/reference/configuration/providers.md \ docs-site/src/content/docs/ja/reference/configuration/providers.md \ docs-site/src/content/docs/ko/reference/configuration/providers.md \ docs-site/src/content/docs/ru/reference/configuration/providers.md \ docs-site/src/content/docs/zh-cn/reference/configuration/providers.md \ docs-site/src/content/docs/ko/guides/providers.md \ docs-site/src/content/docs/zh-cn/guides/providers.md \ 2>/dev/null || true printf '%s\n' '=== Relevant tests changed by this commit ===' git show --format= --name-only "$commit" -- tests | sed '/^$/d' Length of output: 174826
The five reported findings are addressed.
One minor documentation defect remains: The reported test results were not independently runnable in this sandbox. Source inspection confirms the implementation changes. ✅ Action performedReviews resumed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@coderabbitai resume 38278f2 fixes the punctuation defect you flagged: the en and ru retryOn429 rows now end the exhaustion clause cleanly (no double period, sentence boundary after the budget clause). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
🧩 Analysis chain🏁 Script executed: #!/bin/bash set -euo pipefail commit="38278f20" printf '%s\n' '=== Commit metadata and changed paths ===' git show --no-patch --format='commit=%H%nsubject=%s' "$commit" git diff-tree --no-commit-id --name-status -r "$commit" printf '%s\n' '=== Exact documentation patch ===' git show --format= --unified=16 "$commit" -- \ docs-site/src/content/docs/reference/configuration/providers.md \ docs-site/src/content/docs/ru/reference/configuration/providers.md printf '%s\n' '=== Final retryOn429 row contexts ===' rg -n -C 5 'retryOn429|as-is\.\.|attempts|failover|final' \ docs-site/src/content/docs/reference/configuration/providers.md \ docs-site/src/content/docs/ru/reference/configuration/providers.md Length of output: 41241
The punctuation finding is addressed. Normal review is resumed. ✅ Action performedReviews resumed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@lidge-jun could you take a look? The PR is ready for review: all 49 review threads are resolved, the conflicts with the latest dev (incl. #671 exact account routing) are merged, CI gates are green, and the PR is mergeable. Recent rounds addressed the bridge send-telemetry findings, the retryOn429 documentation contract (all locales), the locale link paths, and the JSDoc attachment defects. The only open pre-merge item is the CodeRabbit Docstring Coverage warning (last evaluated at 64.10% before the final doc fixes; the bot has not re-run the full check due to its review rate limit) — it is a warning, not a merge block. Happy to adjust anything you flag in your review. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@lidge-jun one more ask: the full CI suite has not run on this fork PR — only the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
[GD] Addressed feedback feedbacks:
commit: eb9890e |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[GD] Verdict: approve-commentTLDR
Full verdictSemantic propagation
Linked: none ( UsefulnessUseful and strategically aligned with the owner review. Codex does not retry HTTP 429 client-side, so single-key providers currently fail over or surface 429 immediately. This PR adds an opt-in provider policy that waits ( Bugs / correctness
Security
Spec / standards
Reviews
Base / CI
Simplification (for the PR owner)No edits/pushes applied (foreign PR). High-confidence optional candidates only:
If neither is worth the risk, leave as-is. Nothing else was high-confidence enough to recommend. Gatenone Bottom lineApprove-comment on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[GD] Merge readyPR: Reviews
Tip freshness
Checks
Residualoptional owner follow-ups only: continuation redaction consistency, continuation recovery-kind parity, optional shared 429 wait helper Ready to merge. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Redact terminal-continuation provider errors, tag failover continuation sends with the matching recovery kind, and consolidate same-target 429 body-release + wait into prepareSameTarget429Wait for core, image, and web-search paths.
|
[GD] Addressed feedback feedbacks:
commit: 70c80b4 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@coderabbitai resume |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
✅ Action performedReviews resumed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[GD] Verdict: approve-commentTLDR
Full re-review after residual + simplifyUsefulnessThe PR still solves a real operational gap: Codex never retries 429s client-side, and single-key pools have no failover. Opt-in Semantic propagation
No unmapped producers/consumers found for the residual delta. Bug
SecurityRequired surfaces reviewed (secrets/config, authn, authz, logging/privacy, outbound, etc.). Residual change is privacy-positive (more redaction) and does not widen OAuth/forward/local replay. Public disclosure: no exploit detail needed. Spec + StandardsMatches the PR contract and maintainer architecture review items already fixed earlier (watchdog heartbeats, immutable same-target cache, deadline restart). Residual simplify reduces duplication without behavior change. Feedback
Checks
Bottom lineApprove and merge. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @harryzhou2000 — merging this. Why it helps: Codex never retries HTTP 429 client-side and single-key pools have no failover, so providers that rate-limit would fail hard. This lands opt-in Ship it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
- Merge upstream/dev (851b092) into feat/429-same-target-retry. - Resolve src/server/responses/core.ts: combine registry import (providerModelWebsocketUpstreamStreaming) with the 429-retry key-failover imports, and keep upstream's applyServiceTierGate alongside the handleResponses docstring.
Merge upstream/dev (a836b70, incl. lidge-jun#671 exact account routing) into feat/429-same-target-retry. Resolve src/server/responses/core.ts: keep the same-target 429 wait-and-retry loop on the passthrough wire and take upstream's !authCtx.fixedAccount guard on the forward-pool retry branch. Typecheck, privacy scan, 240 retry/passthrough tests, and 184 account-routing tests pass.
…get-retry feat(proxy): opt-in same-target 429 wait-and-retry before key failover (lidge-jun#487)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.