Tasks: xAI Grok OAuth provider tier¶
Tasks¶
- T-001 —
core/xai_oauth.py: constants (auth base, client id, scope, device/authorize/token URLs, loopback host:port), PKCE S256 helpers,CredentialStorewith atomic0600write + env seeding. (FR-3, FR-4, NFR-SEC-1) - T-002 — Device-code grant:
request_device_code()+poll_device_token()withauthorization_pending/slow_down/access_denied/expired_tokenhandling, injectablesleep/now, deadline fromexpires_in. (FR-2, AC-2) - T-003 — Loopback PKCE grant: authorize-URL builder with
state/nonce/plan=generic, a one-shothttp.serveron127.0.0.1:56121/callback, state verification, code exchange. (FR-3) - T-004 — Refresh:
refresh_tokens()+access_token()with 120s skew, unsigned JWTexpdecode, and cross-process single-flight underfcntl.flock. (FR-5, FR-6, AC-3) - T-005 —
core/xai.py:generate()against/v1/chat/completionswithresponse_format.json_schemamapping, temperature pass-through, 429/5xx backoff honouringretry-after, and one 401→refresh→retry. Plusprobe(). (FR-7, FR-8, AC-4, NFR-COMPAT-1) - T-006 —
XaiProviderincore/llm/providers.py, registered asxaiinPROVIDER_REGISTRYwithconfigured()/unconfigured_reason()/model_for()/agenerate()/probe(). (FR-1, FR-10, NFR-AUDIT-1) - T-007 — Settings +
.env.example:XAI_*block, defaultLLM_PROVIDER_CHAIN=claude_code,anthropic_api,xai,ollama;settings/test.pyblanks credentials and points the store at a non-existent path;.gitignorethe credentials file. (FR-1, FR-11, NFR-PRIV-1, AC-5) - T-008 —
xai_login(device-code default,--loopback,--status) andvalidate_xaimanagement commands +make xai-login/make validate-xai. (FR-9) - T-009 — Tests under
backend/tests/core/: polling branches, credential store round-trip + rotation, 401 retry, chain skip when unconfigured, and a guard that the test settings leave the tier unreachable. (AC-1, AC-2, AC-3, AC-4, AC-5) - T-011 —
XaiExecutorfor the LSAT content factory, routed through the chain pinned toxai, registered as--executor xai; tests inbackend/tests/lsat/test_factory_executors.py. (FR-12) - T-010 — Docs: flip ADR 0007 status to accepted/implemented, drop the "authorised, not yet implemented" language from constitution §1, refresh the chain listings in
AGENTS.md,CLAUDE.md,AO-SDLC_Outline_Guide.md(nowdocs/ao-sdlc-guide.md) §4.1,README.md,PRD.md. (FR-1)
Follow-ups Discovered¶
- BL-20260904-04 — test-gap, high — The cross-process refresh lock is only proven in-process:
test_second_refresh_reuses_the_first_resultexercises the freshness shortcut, not two OS processes contending onfcntl.flock. A real daphne/Celery race replaying a rotated refresh token would still slip through. - BL-20260904-05 — tech-debt, med —
XAI_MODELdefaults togrok-4.6with no discovery: an operator on a subscription that does not expose that id gets a 404 per request until they set the var. Probe/v1/modelsinvalidate_xaiand name the reachable ids. - BL-20260904-06 — test-gap, med — Nothing asserts the loopback PKCE path end-to-end;
_serve_one_callbackand the state-mismatch rejection are untested because they need a real socket. Only the authorize-URL builder is covered. - BL-20260904-07 — doc-gap, low —
docs/claude-code-dev-llm.mdis now a misnomer: it documents the whole chain including a non-Claude tier. Rename todocs/llm-provider-chain.mdand fix the inbound links. - BL-20260904-08 — feature, low — The xAI tier has no streaming path, same gap as the Claude tiers (
BL-20260811-20). The WebSocket consumer still cannot stream from any hosted provider. - BL-20260905-11 — tech-debt, med — Live-measured xAI latency is 5-10x the Claude tiers (IRAC 56-103s), which forced
XAI_REQUEST_TIMEOUT_S=240. Fine for a fallback, slow for interactive paths; evaluate a faster Grok model or ship streaming. - BL-20260905-12 — test-gap, med —
core.llm.__init__re-exported every provider constant exceptXAI/XaiProvider; no test asserts the package surface matchesPROVIDER_REGISTRY.
Mirrored into BACKLOG.md. Live end-to-end verification against a real SuperGrok subscription ran 2026-09-05; two defects it caught (the 60s timeout and the read-timeout retry) are fixed in this spec.