Skip to content

refactor(config,cli): drive built-in HTTP providers from one table (ENG-1066) - #368

Merged
lg2m merged 21 commits into
mainfrom
refactor/eng-1066-ap7-provider-table
Oct 20, 2026
Merged

lg2m merged 21 commits into
mainfrom
refactor/eng-1066-ap7-provider-table

Conversation

@lg2m

@lg2m lg2m commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

AP7a: drive built-in HTTP providers from one table (ADR-0064)

Spec: docs/plans/auth-providers.md (AP7) ADR: docs/adr/0064-builtin-provider-table.md (Proposed) Linear: ENG-1066

There's no user-visible change: the same config syntax, trust digests, CLI messages, login flows and qq init output.

What changed

  • ADR-0064 (number reserved in progress/root.md) records the decision. The five built-in HTTP providers (openai, openai-codex, anthropic, google, xai) become rows in one qq-config table. The RON patch syntax, per-provider field rejection, trust digests and request-shape identity bytes stay unchanged.
  • The table, BUILTIN_HTTP_PROVIDERS (crates/qq-config/src/providers.rs): one row per provider, holding:
    • id, endpoint, endpoint mode, protocol, usage and model catalog;
    • the credential preset: an API key with stored name, variables and audience; or the Codex or xAI OAuth credential;
    • the login methods;
    • the model qq init proposes.
    • builtin(), provider_credential_variables(), the trust-declaration label and patch application all read it.
  • ProviderEntryPatch keeps its per-provider RON variants. That keeps deny_unknown_fields rejection and the serialization that trust digests hash. All five built-in variants now go through one BuiltinPatch view instead of five match arms.
  • Root code reads qq_config::builtin_providers():
    • the login provider list and its error;
    • the audience a login binds. API-key presets use the table's audience. Providers whose credential qq-auth owns map to qq-auth's constant through BuiltinAudience, so OAuth audiences are still written only in qq-auth, as AP3 established.
    • the login method: --oauth and --device-auth each select a method, and the row decides whether it's offered. With no flag, the row's first method applies.
    • qq init choices and the next-step hint.
  • Removed: LOGIN_PROVIDERS, the separate login-order list (each row now carries display_order), and the provider-name matches in validate_login_mode.
  • Scope split. AP7 is split, and the plan and ledger say so. The HttpCredential::Builtin collapse moves to AP7b, together with the stored-name and remedy literals in runtime/catalog/doctor/harness and the root.

How verified

cargo xtask check

Head dfe66c671aa3 vs origin/main; 12 changed file(s); scope: qq, qq-config, qq-harness, qq-tui, xtask.

Gate Result Tests Time Command
fmt pass 1.6s cargo fmt --all -- --check
lint pass 2.5s cargo xtask lint
clippy pass 14.2s cargo clippy --color never -p qq -p qq-config -p qq-harness -p qq-tui -p xtask --all-targets --all-features -- -D warnings
test pass 991/991 passed, 3 skipped 39.5s cargo nextest run --color never --profile default -p qq -p qq-config -p qq-harness -p qq-tui -p xtask

All gates passed in 57.8s.

  • Pinning tests committed before the refactor (157e5ed9). They pass unchanged after it:
    • builtin_provider_patches_keep_their_trust_digests: the sensitive-section digests of nine built-in patch shapes, recorded from the old per-variant code.
    • builtin_provider_patches_reject_fields_they_do_not_have
    • builtin_provider_patches_layer_over_their_presets: endpoint, protocol, credential and usage for each loaded preset.
  • Existing tests unchanged: provider_credential_variables_cover_every_api_key_preset (same variable order), every CLI, init, docs_truth and config test.
  • New tests:
    • login_methods_come_from_the_provider_table: every row's default, and every flag accepted or rejected exactly as the row lists.
    • login_audiences_match_the_table_and_qq_auth: the same five audiences as before; a non-built-in returns None.
    • every_table_row_is_listed_once_in_display_order: each row lists exactly once, in the order its display_order field gives, so there's no separate login-order registry to forget.

Compatibility

  • PROTOCOL, DESCRIPTOR, store schema, config syntax and trust digests are unchanged, and the digests are pinned by test.
  • New public API in qq-config: builtin_providers, BuiltinProvider, BuiltinAudience, LoginMethod. It is publish = false.

lg2m added 20 commits October 18, 2026 00:38
…ovider (ENG-1066)

Slice AP5. CodexRequestCredentials and XaiRequestCredentials each
implemented RequestCredentialProvider; only Codex cached, and it held its
cache mutex across the whole awaited load, so warm requests on one
compiled provider waited for each other. request::CachedRequestCredentials
now serves both through a small RequestCredentialSource trait:

- warm requests copy the cached value under a short lock and confirm it
  with one credential-epoch read, so they never wait behind a fill;
- a miss (no value, a newer epoch, a passed refresh deadline) takes a
  per-provider fill lock, so one request loads or refreshes and the rest
  reuse it;
- xAI OAuth gains the cache: it is reused until its epoch moves or
  expires_at passes, and the post-refresh value is re-read under the state
  lock so the cached epoch matches the durable one, as Codex already did;
- explicit references, stored xAI API keys and XAI_API_KEY are resolved
  on every request and never cached, since the epoch cannot see them.

Existing tests keep their scenarios and assertions (the Codex test helper
calls the renamed constructor). New xAI regressions cover rotation and
removal in the same and an independent store, the refresh-deadline
recheck, single-flight refresh under concurrency, uncached API keys, and
warm requests completing while the fill lock is held.
…s off the fill lock (ENG-1066)

Review of 40f5eb0 (#353):
- The cache holds Arc<Cached<_>>, so a warm request clones a handle
  instead of deep-copying the secret bytes under the cache lock.
- A request that queued on the fill lock rechecks whether the source was
  found uncacheable meanwhile and, if so, releases the lock and resolves
  on the bounded worker pool; only cacheable misses resolve under it.
- The rotation regressions assert the token the provider serves after a
  same-store and an independent-store rotation, not just a keyring read.
- The warm-path regression counts fill-lock attempts instead of relying
  on a 30-second wall-clock bound.
Each new assertion fails with its fix removed.
…fill lock (ENG-1066)

Review of 38c6903 (#353): a resolution that failed cached nothing and
left uncacheable unset, so concurrent first requests (a missing explicit
variable, an unavailable keyring) each took the fill lock in turn and
could each wait the load timeout serially. A failed resolution now marks
the source uncacheable, so waiters and later requests resolve on the
bounded worker pool until a cacheable resolution clears it; and a source
with an explicit reference is uncacheable from construction. Both new
regressions hang on the held fill lock with the fix removed.
…ENG-1066)

Review of 59c9179 (#353): a load that timed out, found no worker
capacity or lost its worker returned before the source was marked
uncacheable, so queued requests took the fill lock in turn and could each
wait the 65-second load timeout serially. Both failure layers now release
the lock and send later misses to the bounded worker pool. The new
regression closes the loader's permit pool and hangs on the held fill
lock with the fix removed.
…s (ENG-1066)

Slice AP6 (first part). RequestCredential was an enum of Bearer and Codex
whose fields the authorizer turned into headers on every attempt. It is
now a list of prebuilt, validated headers, each marked secret or
metadata:

- secret values (tokens, account IDs) are redacted from every diagnostic;
  metadata (originator: qq, x-openai-fedramp: true) is sent but never
  registered for redaction, so diagnostics containing  stay intact;
- each recipe intent declares the credential-owned names it allows and
  requires; a credential with a request-controlled name, a protocol
  constant, another intent's name, a duplicate, a missing required name,
  more than eight headers or more than 64 KiB of values is rejected before
  any header is applied;
- an intent's optional names are cleared before applying, so a Codex
  credential that is no longer FedRAMP does not inherit the header.

The public constructors (bearer, codex) are unchanged. Existing provider
tests pass unchanged (260 -> 264 with the new ones).
…a-header-credentials

# Conflicts:
#	docs/plans/progress/auth-providers.md
…field (ENG-1066)

Slice AP6 (second part). The Codex Responses body (no max_output_tokens,
SSE accepted without Content-Type) was implied by the Codex auth intents.
HttpProviderRecipe now carries a ResponsesBodyShape; new() keeps the
implied default so existing recipes are unchanged, and with_body_shape()
chooses it independently. A Codex shape on any protocol but Responses is
a configuration error. Google GenerateContent now accepts request-time
bearer credentials through the same authorizer the other adapters use.

Tests: both independent combinations (Codex body with bearer auth;
standard body with Codex credentials), Codex shape rejected outside
Responses, and a Google request-time bearer reaching the wire. Existing
provider tests are unchanged (264 -> 267).
…1066)

Slice AP6 (second part, root). The runtime derived both the recipe's
Codex body and the output_token_control capability from matching
HttpCredential::OpenAiCodex in two places. One responses_body_shape
function now feeds the recipe (with_body_shape) and the capability, so
they cannot disagree. The request-shape identity is unchanged: the shape
is a function of the credential variant it already digests, so version 1
digests and their fixtures stay valid. Design and ledger updated.
…1066)

Move responses_body_shape_follows_the_route_not_the_auth_scheme to the
end of the runtime test module, and point four legacy sleep entries at
the lines the body-shape helper moved them to. No sleep is added
(73/73).
…ls at construction (ENG-1066)

Review of 912a27e (#359):
- Request-time Codex construction passed NoAuth to the header builder,
  so a recipe could set chatgpt-account-id, originator or
  x-openai-fedramp as static headers and have them silently overwritten
  per attempt. Both Codex intents now protect those names; the duplicate
  is rejected at compile time. Regression covers each name.
- RequestCredential::bearer and ::codex reject a credential whose header
  values exceed 64 KiB before building any value, as
  RequestCredentialError::Invalid; application still bounds them.
- A compiled-provider regression serves a 401 that echoes the Codex token,
  the account ID and a non-secret 'true', and asserts on the error the
  caller sees: both secrets redacted, the metadata intact. It fails if the
  account ID is not registered for redaction.
…r/eng-1066-ap6b-body-shape

# Conflicts:
#	crates/qq-provider/src/compiler.rs
#	crates/qq-provider/src/providers/openai.rs
…gle API keys (ENG-1066)

Review of 2da6fea (#361):
- provider_request_shape_identity now digests the Responses body shape.
  The pairing each credential has always used (Codex body for the OpenAI
  Codex route, standard otherwise) adds no bytes, so every existing
  version-1 digest and fixture is unchanged; any other pairing is
  digested explicitly, so two routes with different bodies never share an
  identity.
- HttpAuth::RequestTimeGoogleApiKey with RequestCredential::google_api_key
  resolves a Google API key per request and sends it as x-goog-api-key.
  It is valid only for GenerateContent, and a static x-goog-api-key is
  rejected beside it.
Legacy sleep entries follow the lines the digest helper moved (73/73).
Review of 3243229 (#359): the Codex size check always added four bytes
for x-openai-fedramp: true, so a non-FedRAMP credential within the limit
by up to four bytes was rejected. The boundary test fails with the bytes
counted unconditionally.
…sts (ENG-1066)

Slice AP7, first step. ADR-0064 (reserved in root.md) records the
decision to drive the five built-in HTTP providers from one qq-config
table while keeping the RON patch syntax, per-variant field rejection,
trust digests and request-shape identity bytes unchanged.

Before any code moves, three tests pin what the table must preserve:
- builtin_provider_patches_keep_their_trust_digests: the sensitive-
  section digests of every built-in patch shape, recorded from the
  current per-variant representation;
- builtin_provider_patches_reject_fields_they_do_not_have;
- builtin_provider_patches_layer_over_their_presets: endpoint, protocol,
  credential and usage of each loaded preset.
…NG-1066)

Slice AP7 (ADR-0064). qq-config's BUILTIN_HTTP_PROVIDERS holds, per
provider, its id, endpoint, mode, protocol, usage, model catalog,
credential preset, login methods and init model. builtin(),
provider_credential_variables(), the trust-declaration label and patch
application read it; ProviderEntryPatch keeps its per-provider RON
variants (and so its field rejection and trust digests) and maps them to
one BuiltinPatch view instead of five match arms.

The root derives from builtin_providers(): the login provider list and
its error, the login audience (table audience for API-key presets,
qq-auth's constant for providers whose credential it owns, so OAuth
audiences still live only in qq-auth), the login method selected by
--oauth/--device-auth or the row's default, and qq init's choices and
next-step hint. LOGIN_PROVIDERS and validate_login_mode's string
matches are gone.

Behaviour is unchanged: the pinned trust digests, field-rejection and
preset-layering tests, the credential-variable list, login messages and
every existing CLI, init and config test pass. New tests check that
login methods and audiences come from the table.
…-provider-table

# Conflicts:
#	docs/plans/progress/auth-providers.md
#	docs/plans/progress/root.md
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T22:45:10.645517Z ad8d49d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfe66c671a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread crates/qq-config/src/providers.rs Resolved
Replace the separate LOGIN_ORDER registry with a display_order field on
each BUILTIN_HTTP_PROVIDERS row, so a new row reaches qq auth login and
qq init without a second list to keep in step. Addresses the #368 review
finding.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m

lg2m commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ad8d49dc70

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@lg2m
lg2m merged commit 88e0607 into main Oct 20, 2026
6 checks passed
@lg2m
lg2m deleted the refactor/eng-1066-ap7-provider-table branch October 20, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant