Skip to content

refactor(provider): make the Responses body shape an explicit recipe field (ENG-1066) - #361

Merged
lg2m merged 6 commits into
refactor/eng-1066-ap6a-header-credentialsfrom
refactor/eng-1066-ap6b-body-shape
Oct 19, 2026
Merged

lg2m merged 6 commits into
refactor/eng-1066-ap6a-header-credentialsfrom
refactor/eng-1066-ap6b-body-shape

Conversation

@lg2m

@lg2m lg2m commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

AP6 (part 2): make the Responses body shape an explicit recipe field

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

There's no user-visible change: every configured route sends the same body and headers as before. The one new capability is that Google can now use request-time bearer credentials.

What changed

  • ResponsesBodyShape (Standard or Codex) is a new field on HttpProviderRecipe. Before this change, the Codex body (no max_output_tokens, and SSE accepted without a Content-Type) was implied by the Codex auth intents.
    • new() picks the shape the intent used to imply, so existing recipes behave the same.
    • with_body_shape() sets it independently.
    • Asking for the Codex shape on any protocol other than Responses is a configuration error.
  • Google GenerateContent accepts HttpAuth::RequestTimeBearer, through the same authorizer the other adapters use. It used to reject request-time credentials.
  • Root: one responses_body_shape(access) function now drives both the recipe and the output_token_control capability. Before, each matched HttpCredential::OpenAiCodex separately.
  • The request-shape identity is unchanged. The shape is a function of the credential variant, which the identity already digests (request-time-codex), so existing version-1 digests and their fixtures stay valid. The function's doc comment says that a configurable shape would have to be digested in its own right.
  • docs/design/providers.md describes the body-shape contract. Four legacy sleep baselines are updated to the lines they moved to (still 73/73).

How verified

  • qq-provider tests go from 264 to 267, and none of the existing tests changed. The new ones:
    • responses_body_shape_is_independent_of_the_auth_intent: a Codex body with bearer auth omits max_output_tokens, and a standard body with Codex credentials includes it while still sending chatgpt-account-id.
    • the_codex_body_shape_is_rejected_outside_openai_responses
    • google_accepts_request_time_bearer_credentials
  • qq: responses_body_shape_follows_the_route_not_the_auth_scheme. The request-shape identity and Codex-capability tests pass unchanged.
  • Gate: fmt, lint and clippy pass. The test gate run had one failure that exists on main (headless::tests::closing_goal_host_drains_accepted_work_without_admitting_successors, from feat(cli)!: expose durable goals in TUI and headless commands #331). It also had six qq-core session failures. This PR doesn't touch qq-core, the host load average was about 21 at the time, and the same tests pass when re-run on their own (7/7).

Compatibility

  • PROTOCOL, DESCRIPTOR, store schema and ProviderRequestShapeVersion are unchanged.
  • New public API: ResponsesBodyShape and HttpProviderRecipe::with_body_shape. All crates are publish = false.

lg2m added 3 commits October 18, 2026 22:04
…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).
@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-19T17:05:33.256975Z 000f54b 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

@lg2m
lg2m added this pull request to stack #362 October 19, 2026 05:24

@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: 2da6fea03c

ℹ️ 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 src/runtime.rs Resolved
Comment thread crates/qq-provider/src/construction.rs Resolved
lg2m added 3 commits October 18, 2026 22:58
…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).
@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
03b7fc9 fixes both findings, and the head merges #359's latest. All threads are replied to and resolved. The full affected gate passes; qq-provider 272/272.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 000f54b74a

ℹ️ 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 5f7d611 into main Oct 19, 2026
6 checks passed
@lg2m
lg2m deleted the refactor/eng-1066-ap6b-body-shape 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.
lg2m added a commit that referenced this pull request Oct 22, 2026
Remove the static Codex and request-time Google API-key intents, which no runtime or xtask code constructs; drop refresh error arms for login-only errors; stop redacting anthropic-version; narrow crate-internal qq-auth items to pub(crate); fix provider/auth docs; add the auth/provider consolidation plan.

The request-time Google API-key intent added in #361 had no caller; Google
keys still resolve to a static x-goog-api-key header.

QQ-Allow-Revert: crates/qq-provider/src/request_auth.rs
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