mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
handleFailoverExhausted returned a fixed 413 for IsOpenAIRequestBodyTooLarge() before reaching the generic error-passthrough rule lookup further down, so a rule configured with error_codes [413] could never match on this path. The service layer already returns the same failover sentinel ahead of applyErrorPassthroughRule, so both layers short-circuit and the rule vocabulary silently excludes 413. Extract the existing rule application into applyOpenAIFailoverPassthroughRule and call it first inside the body-limit branch (and reuse it for the generic branch). Failover on 413 is left intact: different accounts can front proxies with different body limits, so switching may still succeed. The rule only decides the client-facing response once failover is exhausted. This matters for clients that treat 413 as retryable. Codex CLI maps a non-2xx HTTP status to CodexErr::UnexpectedStatus, whose is_retryable() returns true, and retries the sampling request up to stream_max_retries (default 5) times. When the payload can never fit, every retry is wasted work, and an operator has no supported way to signal "do not retry". Mapping the same upstream 413 to 400 makes Codex map it to InvalidRequest, which is not retryable, so it fails fast. Tests cover the override on both unary and started-stream paths, the unchanged built-in 413 when no rule matches, and skip_monitoring.