Skip to content

refactor(provider): carry request credentials as validated header sets (ENG-1066) - #359

Merged
lg2m merged 10 commits into
mainfrom
refactor/eng-1066-ap6a-header-credentials
Oct 19, 2026
Merged

lg2m merged 10 commits into
mainfrom
refactor/eng-1066-ap6a-header-credentials

Conversation

@lg2m

@lg2m lg2m commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

AP6 (part 1): carry request credentials as validated header sets

Spec: docs/plans/auth-providers.md (AP6) Linear: ENG-1066 Stacked on: #353

There's no user-visible change: bearer and Codex requests send the same headers as before.

What changed

  • RequestCredential is now a list of headers. It used to be an enum of Bearer and Codex, turned into headers on every attempt. Now each credential is a list of prebuilt headers, each marked either secret or metadata. The public constructors bearer and codex are unchanged.
  • Only secrets are redacted. Secret values (tokens, account IDs) are redacted from every diagnostic. Metadata (originator: qq, x-openai-fedramp: true) is sent but never registered for redaction. Redacting true would rewrite every matching substring of a diagnostic.
  • Each intent lists the headers a credential may set. Bearer may set Authorization. Codex must set Authorization, chatgpt-account-id and originator, and may set x-openai-fedramp.
  • Invalid credentials are rejected before any header is applied. That covers:
    • a request-controlled or protocol-constant name;
    • another intent's name;
    • a duplicate;
    • a missing required name;
    • more than 8 headers, or more than 64 KiB of values.
  • Optional headers are cleared first. A Codex credential that is no longer FedRAMP doesn't inherit x-openai-fedramp from an earlier attempt.
  • docs/design/providers.md describes the header-set contract.

How verified

cargo xtask check

Head 912a27eacdcd vs origin/main; 10 changed file(s); scope: qq, qq-auth, qq-client, qq-config, qq-core, qq-harness, qq-mcp, qq-provider, qq-server, qq-tui, xtask.

Gate Result Tests Time Command
fmt pass 2.1s cargo fmt --all -- --check
lint pass 2.1s cargo xtask lint
clippy pass 26.9s cargo clippy ... --all-targets --all-features -- -D warnings
test fail 2723/2724 passed, 15 skipped 569.9s cargo nextest run ...
  • qq-provider tests go from 260 to 264, and none of the existing tests changed. The new tests cover:
    • codex_credentials_redact_secrets_but_not_metadata: the FedRAMP header is set and cleared for both flag values, and only secrets are redacted.
    • credential_headers_outside_the_recipe_intent_are_rejected_before_any_is_applied: one case per class, and in each the request is left untouched.
    • credential_header_bytes_are_bounded.
    • rejections_redact_every_secret_of_a_multi_header_credential: a Codex rejection redacts both the token and the account ID.

Compatibility

  • PROTOCOL, DESCRIPTOR, store schema and public constructors are unchanged.

lg2m added 7 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).
@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-19T06:26:25.642158Z 629d6e1 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

Base automatically changed from refactor/eng-1066-ap5-request-credentials to main October 19, 2026 04:59
…a-header-credentials

# Conflicts:
#	docs/plans/progress/auth-providers.md

@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: 912a27eacd

ℹ️ 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-provider/src/request_auth.rs Resolved
Comment thread crates/qq-provider/src/http.rs Resolved
Comment thread crates/qq-provider/src/request_auth.rs Resolved
@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.

…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.
@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
3243229 fixes all three findings; all threads are replied to and resolved. qq-provider 267/267.

@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: 3243229ea3

ℹ️ 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-provider/src/request_auth.rs Resolved
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.
@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
629d6e1 fixes the FedRAMP size off-by-four; all threads are replied to and resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 629d6e132b

ℹ️ 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 a1c972f into main Oct 19, 2026
5 of 6 checks passed
@lg2m
lg2m deleted the refactor/eng-1066-ap6a-header-credentials branch October 19, 2026 17:44
lg2m added a commit that referenced this pull request Oct 20, 2026
…NG-1066) (#368)

* refactor(auth): serve OAuth request credentials through one cached provider (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.

* docs(plans): record the AP5 perf receipt (ENG-1066)

* fix(auth): share cached request credentials and keep uncacheable loads 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.

* fix(auth): keep failed and explicit request-credential loads off the 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.

* fix(auth): treat worker-level load failures like failed resolutions (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.

* refactor(provider): carry request credentials as validated header sets (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).

* docs(provider): describe request-credential header sets (ENG-1066)

* refactor(provider): make the Responses body shape an explicit recipe 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).

* refactor(runtime): read the Responses body shape from the route (ENG-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.

* test(runtime): keep the body-shape test after the legacy sleeps (ENG-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).

* fix(provider): protect request-time Codex headers and bound credentials 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.

* fix(provider,runtime): digest the body shape and add request-time Google 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).

* fix(provider): count the FedRAMP header only when it is sent (ENG-1066)

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.

* docs(adr): ADR-0064 built-in providers as table rows, with pinning tests (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.

* refactor(config,cli): drive built-in HTTP providers from one table (ENG-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.

* docs(plans): split AP7 into the table slice and the credential collapse (ENG-1066)

* fix(config): list every provider table row in display order (ENG-1066)

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