Skip to content

oauth/xai: Retry-After HTTP-date and fractional-second forms are ignored in postXaiToken #4046

Description

@lidge-jun

Where

src/oauth/xai.ts line 98 (retryDelay), on dev:

seconds=retryAfter!==null&&/^\d+$/.test(retryAfter)?Number(retryAfter):0

Problem

RFC 9110 §10.2.3 allows Retry-After as either delay-seconds or an HTTP-date. The regex accepts integer seconds only, so an HTTP-date (Retry-After: Sun, 06 Nov 1994 08:49:37 GMT) or a fractional value (1.5) becomes seconds = 0 and the server instruction is silently dropped; the client falls back to the 100/250ms jittered base delay.

Measured on Node 24:

retryDelay(1, "Sun, 06 Nov 1994 08:49:37 GMT", () => 0.5)  ->  100
retryDelay(1, "1.5", () => 0.5)                              ->  100

Fix

Parse as number first, then fall back to Date.parse:

function parseRetryAfterMs(raw: string | null): number | undefined {
  if (!raw) return undefined;
  const n = Number(raw);
  if (Number.isFinite(n)) return Math.max(0, n * 1000);
  const t = Date.parse(raw);
  return Number.isFinite(t) ? Math.max(0, t - Date.now()) : undefined;
}

Found while porting this module into ima2-gen (devlog 260909_grok_native_oauth/001_opencodex_port_spec.md D2). Independent of the 2000ms cap issue but the same function.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-poolOAuth, credentials, Codex pool, quota, failover, plansbugSomething isn't workingproviderProvider adapters, OpenAI-compat presets, upstream API quirks

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions