|
| 1 | +> **SUPERSEDED IN PART — read `000_research_inventory.md` amendments 1 and 2 first.** |
| 2 | +> |
| 3 | +> Two things in this document are wrong and were corrected after it was written: |
| 4 | +> |
| 5 | +> 1. **It is NOT a stack layer and does NOT root on #2134.** No dependency edge exists; |
| 6 | +> the shipped PR (#2137) is based on `dev` as a sibling. |
| 7 | +> 2. **The substitution predicate is NOT "native ChatGPT pool".** Pool-only would exclude |
| 8 | +> `codexAccountMode: "direct"` and re-break #1686, whose Direct admission is only safe |
| 9 | +> BECAUSE substitution still runs. The shipped predicate is |
| 10 | +> `route.codexAccountMode !== undefined`, covering pool AND direct. Do not "correct" it back. |
| 11 | +
|
| 12 | + |
| 13 | +# 010 — Layer 1 (stack bottom): fix issue #2132, bearer admission must not force a ChatGPT credential |
| 14 | + |
| 15 | +Work-phase: wp2. Branch: `codex/fix-bearer-admission-2132`. Base: `codex/fix-subagent-roster-truncation` (PR #2134). |
| 16 | +Absorbs: nothing (no PR exists). Closes: #2132. |
| 17 | + |
| 18 | +## Why this is the stack bottom |
| 19 | + |
| 20 | +It is the highest-scoring item in the backlog (96) and it shares `src/server/responses/core.ts` |
| 21 | +with layer 2 (#2131). Layer 2 must be based on this, or the two edits to that file collide. |
| 22 | + |
| 23 | +## Defect |
| 24 | + |
| 25 | +Reported in #2132: after v2.23.0, a key-auth provider (Cloudflare/etc.) returns 401 |
| 26 | +`No usable Codex main credential` when `~/.codex/auth.json` holds no ChatGPT token. Bearer |
| 27 | +admission sets `substituteMainCredential` unconditionally, so a route that needs no ChatGPT |
| 28 | +identity is still gated on one. |
| 29 | + |
| 30 | +## P-phase re-verification required (stale check) |
| 31 | + |
| 32 | +Before editing, confirm against the CURRENT tree — the lane read `dev`, not this branch: |
| 33 | +1. `rg -n "substituteMainCredential" src/` — enumerate every producer and consumer. |
| 34 | +2. Read `src/server/responses/core.ts`, `src/server/responses/compact.ts`, |
| 35 | + `src/codex/auth-context.ts` and establish where the flag is set and where it is read. |
| 36 | +3. Reproduce the admission decision in a unit context with a key-auth provider and an |
| 37 | + auth.json containing no ChatGPT token. If the current code does NOT reproduce, stop and |
| 38 | + amend this doc rather than writing a fix for a defect that is not there. |
| 39 | + |
| 40 | +## Intended change |
| 41 | + |
| 42 | +Make the substitution conditional on the resolved route actually requiring a native/ChatGPT |
| 43 | +credential. A key-auth routed provider carries its own credential and must be admitted |
| 44 | +without one. Exact call sites are fixed during the stale check above; the invariant is: |
| 45 | +`substituteMainCredential` is set only when the route's credential source is the native |
| 46 | +ChatGPT pool. |
| 47 | + |
| 48 | +Out of scope: changing what happens once a native route legitimately lacks a credential, |
| 49 | +and any change to the pool/account selection itself. |
| 50 | + |
| 51 | +## Test plan (must fail RED first) |
| 52 | + |
| 53 | +New `tests/bearer-admission-key-auth.test.ts`: |
| 54 | +1. key-auth routed provider + auth.json with NO ChatGPT token -> request is admitted (no 401). |
| 55 | +2. native gpt route + no ChatGPT token -> still fails closed with the existing error. |
| 56 | +3. key-auth provider + ChatGPT token present -> unchanged behavior (no regression). |
| 57 | + |
| 58 | +Drive the file against the unpatched tree first and record the failure output; a test that |
| 59 | +passes before the fix does not prove anything. |
| 60 | + |
| 61 | +## Verification |
| 62 | + |
| 63 | +`bun run typecheck`; `bun test --isolate` on the new file plus the existing responses/auth |
| 64 | +suites; full `bun test --isolate tests` before marking review-ready; `bun run privacy:scan`. |
| 65 | + |
| 66 | +## Standalone thesis (DEV-STACK-03) |
| 67 | + |
| 68 | +"A provider that carries its own key must not be gated on a ChatGPT credential." Builds and |
| 69 | +passes its own tests at its own tip, independent of layer 2. |
| 70 | + |
0 commit comments