Repository navigation
Description
Area
Proxy and routing
What are you trying to accomplish?
I want a policy/<id> request to survive a terminal failure from the candidate it selected — specifically a 429 on a provider with no key pool, or a 400 that is really a provider-side defect rather than a malformed request.
The concrete shape: I route through a profile whose candidates span several providers. The evaluator picks candidate A. Candidate A returns 429 (quota exhausted) or 400. I want the request to be re-evaluated against the remaining eligible candidates and served by B, rather than the error reaching the client.
That is the reason I reached for routing profiles in the first place. On a single-provider setup the failure is just a failure; the value of declaring three candidates is that one of them can cover for another.
What prevents this today?
The policy evaluator runs exactly once, on the inbound routing decision, and never again for that request.
resolvePolicyProfileId has a single call site in the whole request path (src/router.ts:507 on v2.14.0), and re-entry is prevented deliberately:
// Only explicit requests reach this branch; concrete recursive targets skip policy
// resolution entirely (bypassCombos) so an alias matching a selected candidate can
// never recurse …
const policyId = !bypassCombos ? resolvePolicyProfileId(config, modelId) : null;Once a concrete candidate is chosen, the profile is out of the picture. What exists downstream is scoped narrower than the profile:
429triggers key-pool rotation within the same provider —src/server/responses/core.ts:3422: "rotate to the next pool key … and retry the SAME request once per remaining key. OAuth/forward providers and single-key pools return null immediately." It never moves to a different candidate.400has no failover path at all. Reasonable as a general rule, since 400 is nominally a client error — but it means a provider that answers 400 for its own reasons is indistinguishable from a genuinely malformed request.
So the profile's remaining influence on failures is indirect and slow: errors degrade a candidate's health, which lowers its score on future requests. On my install the gap between first and second candidate is 0.1256, and the effective weight of health in the total is 0.387, so the leader has to lose about 0.33 of health — roughly 98% → 66% success — before the order flips. That is recovery from sustained collapse, not from the request that just failed.
I am not claiming the current behaviour is a bug. Selection-time-only is a coherent design. But it is not discoverable from the configuration surface: a profile that lists three candidates and weights health reads like a failover chain, and it is not one.
What should OpenCodex do?
On a terminal failure from the selected candidate, re-run the policy evaluator with that candidate excluded, and serve the request from the next eligible one. Bounded by the candidate list, so at most N attempts and no recursion.
Minimum viable scope, if the full shape is too broad:
429when the provider has no key pool to rotate (today: a hard stop, even with two other candidates sitting idle).- An opt-in list of statuses treated as candidate-terminal, so
400can be included by operators who know their provider emits it spuriously, without changing the default for everyone.
What I would want preserved: the existing bypassCombos guard against recursion, and the dry-run contract, so an operator can still see which candidate would be chosen first.
If failover is deliberately out of scope for profiles, then the documentation is the ask instead: state plainly that a profile chooses before the request and does not react to its outcome. I read the reference page and the dry-run output and still expected otherwise.
Example usage or interface
Today, with TR rate-limited and two healthy candidates configured:
POST /v1/responses model=policy/fast-free
→ evaluator picks TR/moonshotai/kimi-k3-free (highest score)
→ upstream 429, single-key provider, no pool to rotate
→ 429 reaches the client
→ google-antigravity/gemini-3.6-flash and opencode-zen/deepseek-v4-flash-free were both
eligible in the same evaluation and are never tried
Desired:
POST /v1/responses model=policy/fast-free
→ evaluator picks TR/moonshotai/kimi-k3-free
→ upstream 429, no pool rotation available
→ re-evaluate with TR excluded → google-antigravity/gemini-3.6-flash
→ 200
Opt-in shape for the second half, so the default stays conservative:
{
"routingProfiles": {
"fast-free": {
"candidates": [ "…" ],
"failover": { "onStatus": [429, 503], "maxCandidates": 3 }
}
}
}Alternatives or workarounds
apiKeyPool— what I use today, and it does cover429for the providers where I hold several keys. It cannot help a single-key or OAuth provider, and it never crosses to a different model.upstreamFailoverThreshold— account-level, on the native OpenAI forward path. Different axis: it fails over between accounts of one provider after consecutive transient failures, not between profile candidates.- Client-side retry with a different model. Works, and is arguably where this belongs. The reason I am asking here anyway: the proxy already holds the candidate list, the health evidence, and the exclusion logic. The client has none of that and would be re-deriving a decision the evaluator already made a moment earlier.
- Waiting for health to shift the order. Measured above — needs a ~33-point health collapse, so it does not address a single failed request.
Additional context
Measured on 2.14.0, Windows 11. Score components from POST /api/routing-profiles/dry-run on a three-candidate profile:
google-antigravity/gemini-3.6-flash cp=1.000 health=0.985 quota=0.3 cost=0.3 total=0.8134
nvidia/nemotron-3-ultra-550b-a55b cp=0.667 health=0.966 quota=0.3 cost=0.3 total=0.6879
opencode-zen/deepseek-v4-flash-free cp=0.333 health=0.958 quota=0.3 cost=0.3 total=0.5665
Two observations from that table, offered as data rather than as separate asks:
quota and cost are 0.3 for all three candidates in every evidence shape I tried, including with an explicit costPerMTokUsd in the request. Weighting them appears to have no effect on ordering — only configuredPriority (list order) and health move, and health spreads just 0.019 across the three.
unknownEvidence.capability: "penalize" does not lower the score. With contextWindow: 900000, a candidate that lacks modelContextWindows keeps a byte-identical total (0.8061478786883453 with and without the evidence) and only gains an exclusions entry. It stays ahead of the one candidate that actually satisfies the requirement. "penalize" reads like it will reorder; it does not.
Checks
- I searched existing issues and documentation.
- This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
- I removed secrets and personal data.
Activity
Ingwannu commentedon Aug 13, 2026
Confirmed: your description matches current
dev. A routing profile is a deterministic selection-time policy, not a request-attempt failover chain. The evaluator chooses one concrete route, and the recursion guard intentionally removes the profile from the child dispatch. Cross-candidate retry today belongs tocombos; key/account rotation remains narrower and provider-local.The scoring observations are also consistent with the documented contract:
unknownEvidence.capability: "penalize"currently behaves likeallowbecause capability does not yet have a score component; the reference docs state this explicitly.costPerMTokUsdis not a candidate price source, and an unbound OAuth/account candidate intentionally remains unknown until account selection.The failover direction is valuable, but I would not add implicit cross-provider replay to profiles as proposed without a larger contract. It needs to preserve request-body replay safety, stream-commit boundaries, account/key retry ordering, combo interaction, per-attempt usage/health accounting, exact candidate exclusion traces, and non-retryable 4xx behavior. A generic operator list containing
400is especially unsafe because it can replay malformed or policy-rejected requests across paid providers.The conservative minimum I would accept is one of these two scoped directions:
429/502/503/connection failures, with a strict attempt cap and immutable exclusion trace. Any400retry must use a provider-specific classified error contract, not status alone.I am keeping this open as an enhancement/design item. It should not be implemented by wiring
resolvePolicyProfileIdback into the recursive child route; that would violate the existing recursion and trace invariants.Wibias commentedon Aug 14, 2026
Hey @brunoflma! Policy was introduced pretty recently and is not quiet finished, hardened as how I would like it to be, but thanks for your enhancement request! Will take that into accountant!
lidge-jun commentedon Aug 18, 2026
Maintainer direction decided: option 2 from the earlier triage comment — a separate, opt-in profile failover phase, designed as its own unit rather than wiring
resolvePolicyProfileIdback into the recursive child route. Initial scope stays limited to pre-stream429/502/503/connection failures with a strict attempt cap and an immutable exclusion trace; any400retry requires a provider-classified error contract, not status alone. Keeping this open as the design tracker for that unit; profiles remain selection-only until it ships.lidge-jun commentedon Aug 19, 2026
리뷰 · 우선순위 50 / 80
routing profile이 고른 후보가 429나 일부 400으로 끝나면, 남은 후보로 다시 평가해 달라는 요청입니다. 지금은 평가가 요청 시작에 한 번만 돌아가서, 프로필이 페일오버 체인처럼 보이지 않습니다. 콤보 피커 회색 처리(#1711)나 워크스페이스 UI(#1702)와는 다른 런타임 축입니다.
현재 dev의 src/router.ts는 bypassCombos가 아닐 때만 resolvePolicyProfileId()를 호출합니다. 주석도 재귀 타깃은 정책 해석을 건너뛴다고 합니다. 429는 src/server/responses/core.ts에서 같은 프로바이더의 다음 풀 키로만 재시도하고, OAuth/단일 키는 바로 null입니다. 다른 후보 모델로 넘어가는 코드는 이 경로에 없습니다. 400 페일오버도 없습니다.
원하는 최소 범위는 풀이 없는 429와, 운영자가 고른 상태 코드를 후보 종료로 보는 옵트인입니다. bypassCombos와 dry-run 계약은 유지해야 합니다. 프로필이 페일오버가 아니라면 문서에 선택 시점 전용이라고 밝히는 것도 이슈가 허용한 대안입니다.
해결방안: 터미널 실패 후 해당 후보를 제외하고 평가기를 다시 돌리되, 후보 수만큼만 시도하면 됩니다. 기본값은 429(풀 없음) 정도로 좁히고, 400은 onStatus 옵트인이 안전합니다. health가 나중에 순서를 바꾸는 현재 동작은 한 요청의 복구가 아니므로 대체재가 아닙니다. 재귀 가드를 풀면 안 됩니다.
이 댓글은 grok-bot이 작성했습니다
brunoflma commentedon Aug 20, 2026
Re-validation against the v2.28.0 migration stack confirms that this remains open and is still distinct from quota/input-admission fallback work.
Current behavior remains selection-only: resolvePolicyProfileId() is called once on the request path (current location in this tag: src/router.ts:541), and a terminal provider response does not re-run the profile evaluator against the remaining candidates. The existing 429 handling can rotate within a provider’s key pool, but there is no profile-candidate failover for a pool-less 429, provider 502/503, or connection failure. A generic 400 retry would also be unsafe without provider-classified error semantics.
The maintainer direction already recorded here is the right minimum scope: an opt-in, pre-stream failover phase with a strict attempt cap, immutable exclusion trace, and an explicit status/error policy. Keep recursive-target and bypassCombos guards intact; do not turn profile selection into an unbounded retry loop.
This was rechecked after rebasing the customization stack onto v2.28.0 (upstream base 5840591); no upstream change in this release reintroduces candidate re-evaluation after a terminal failure.
Ingwannu commentedon Aug 20, 2026
Thanks for re-validating on v2.28.0. I checked the current
devboundary again and your update matches it; no release change has made profiles outcome-aware.The maintainer decision remains unchanged: keep this open as the tracker for a separate opt-in, pre-stream failover phase. A future implementation must exclude the failed candidate immutably, cap attempts by the declared candidate set, preserve the existing recursive-target/
bypassCombosguards, account for each attempt, and initially classify only pool-exhausted 429, 502/503, and connection failures. A generic status-only 400 retry is not accepted. No code change is being made from this re-validation comment alone.lidge-jun commentedon Sep 3, 2026
Closing as implemented on
dev. Thank you @brunoflma — this was a real gap and the request described the behavior precisely enough to build against.A routing profile now re-evaluates its remaining candidates when the selected one fails terminally, which is what you asked for:
rankPolicyFallbackCandidatesinsrc/server/responses/policy-fallback.tsranks the remaining eligible candidates from the original policy trace and skips the ones already tried (landed in cd7ea8a, wired through the Responses path in 457c336).attempts[]rather than rewriting the decision, so the reason a request ended up on its final target stays auditable.src/combos/failover.ts.If your case involves a failure class that still does not trigger re-evaluation, please open a new issue with the upstream status and error body — that is a concrete follow-up rather than a reopen of this one.