#5689 · Expired Codex credentials bypass AI readiness checks
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
The Codex helper service says it is ready even when its saved ChatGPT access token is known to have expired. Its credential parser computes expiration, but neither the credential reader nor the readiness handler rejects that state. The same credential reader supplies transcription and text-completion requests, so these helpers can send the expired credential and then surface an authentication failure. Two clean checkouts reproduce this behavior with entirely synthetic credentials and intercepted HTTP, without Account Pooler or a live BB instance. Real OAuth refresh, user audio, and end-to-end title and commit generation were not exercised.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Known-expired credentials can still report ready. | Verified | The real host handler returns {"ready":true} with JWT expiration set to epoch second 1; the readiness regression fails. |
| Both transcription and text completion use the expired credential without recovery. | Verified at the host boundary | Each real handler makes one intercepted request, returns auth_required for a synthetic HTTP 401, and leaves the fixture unchanged. |
| The defect needs Account Pooler. | Not required | The harness loads the Codex host entry only; no pool is configured or queried. |
| Missing and unexpired credentials behave differently. | Verified | Missing auth is unavailable without HTTP; unexpired auth is ready and transcription succeeds against a synthetic response. |
| A real refresh grant would succeed; complete UI/CLI/title/commit flows fail in exactly the reported form. | Unverified | No real credentials, auth service, user recording, server transport, or live end-to-end helper flow was used. The synthetic refresh string is not a valid grant. |
3. Environment
- Trusted source:
get-bb/bb,origin/mainexplicitly fetched from the target repository, commit6a639cfc0d66e0c789a1bd7309266973228d1a80. - Linux x86_64; Node
22.19.0; pnpm9.15.0; Vitest4.1.1; sourcebb-plugin-provider-codex0.1.0. - Both worktrees start at this exact commit with a clean tracked tree. Each gets its own frozen dependency install and Turbo build. No production files are edited.
- No server or daemon instance, ports, persistent BB database, real Codex CLI login, or user runtime data. Each test creates a fresh temporary home and
CODEX_HOME, replaces global fetch, restores globals/environment, and removes its fixture.
4. Minimal reproduction
- Use a fresh checkout of the trusted base and install/build its existing dependencies:
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout 6a639cfc0d66e0c789a1bd7309266973228d1a80 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
- Save the complete inline test below as
plugins/provider-codex/src/issue-5689.test.ts. It is authored from trusted repository evidence, not copied from the issue. - Run from the repository root. Expected exit status is 1 while the bug remains:
pnpm exec turbo run test --filter=bb-plugin-provider-codex --force -- src/issue-5689.test.ts --silent=false
Expected: the known-expired fixture must not be reported ready. A credential-owner refresh may restore availability, otherwise status should return unavailable with recovery guidance. No real refresh is possible or attempted by this fixture.
Actual, both runs (verbatim salient output):
expired readiness: {"ready":true}
missing readiness: {"ready":false,"message":"Run `codex login` on the primary machine to sign in"}
transcribe {"ok":false,"code":"auth_required","message":"Codex transcription request failed with HTTP 401: Synthetic expired access"} requests=1 authUnchanged=true
complete {"ok":false,"code":"auth_required","message":"Codex inference request failed with HTTP 401: Synthetic expired access"} requests=1 authUnchanged=true
AssertionError: expected true to be false // Object.is equality
Test Files 1 failed (1)
Tests 1 failed | 4 passed (5)
The first case is the intended regression. The other cases are baseline controls and characterization evidence; the expired-request cases explicitly characterize today's false-ready behavior and are not proposed post-fix expectations. Only the expected availability invariant is needed for a permanent readiness regression.
Complete reproduction test (copy into the path above)
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { experimental_createHostEntryHarness } from "@get-bb/plugin-sdk/testing/host";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import hostEntry from "./host.js";
let temporaryHome: string;
let authPath: string;
const fetchMock = vi.fn<typeof fetch>();
const harness = experimental_createHostEntryHarness(hostEntry);
beforeEach(async () => {
temporaryHome = await fs.mkdtemp(path.join(os.tmpdir(), "bb-5689-"));
const codexHome = path.join(temporaryHome, "codex");
await fs.mkdir(codexHome);
authPath = path.join(codexHome, "auth.json");
vi.stubEnv("HOME", temporaryHome);
vi.stubEnv("USERPROFILE", temporaryHome);
vi.stubEnv("CODEX_HOME", codexHome);
fetchMock.mockReset();
fetchMock.mockImplementation(async () => {
throw new Error("Unexpected network request blocked by reproduction");
});
vi.stubGlobal("fetch", fetchMock);
});
afterEach(async () => {
vi.unstubAllGlobals();
vi.unstubAllEnvs();
await fs.rm(temporaryHome, { recursive: true, force: true });
});
async function writeAuth(expiration: number): Promise<string> {
const encode = (value: object) =>
Buffer.from(JSON.stringify(value)).toString("base64url");
const accessToken = `${encode({ alg: "none" })}.${encode({ exp: expiration })}.synthetic`;
const contents = JSON.stringify({
auth_mode: "chatgpt",
tokens: {
access_token: accessToken,
refresh_token: "synthetic-refresh",
account_id: "synthetic-account",
},
});
await fs.writeFile(authPath, contents, { mode: 0o600 });
return contents;
}
it("does not report a known-expired credential as ready", async () => {
await writeAuth(1);
const status = await harness.experimental_call("codex.ai.status", {});
console.log("expired readiness:", JSON.stringify(status));
expect(status.ready).toBe(false);
});
it("reports missing auth unavailable without requesting the network", async () => {
const status = await harness.experimental_call("codex.ai.status", {});
expect(status.ready).toBe(false);
expect(fetchMock).not.toHaveBeenCalled();
console.log("missing readiness:", JSON.stringify(status));
});
it("keeps valid auth usable for readiness and transcription", async () => {
await writeAuth(Math.floor(Date.now() / 1000) + 3600);
fetchMock.mockResolvedValueOnce(
Response.json({ text: "synthetic transcript" }),
);
expect(await harness.experimental_call("codex.ai.status", {})).toEqual({
ready: true,
});
expect(
await harness.experimental_call("codex.ai.transcribe", {
model: "gpt-transcribe",
audioBase64: Buffer.from("synthetic audio").toString("base64"),
mimeType: "audio/webm",
filename: "synthetic.webm",
hint: null,
timeoutMs: 1000,
}),
).toEqual({ ok: true, text: "synthetic transcript" });
expect(fetchMock).toHaveBeenCalledTimes(1);
});
it.each(["transcribe", "complete"] as const)(
"observes an expired %s request with no recovery",
async (operation) => {
const original = await writeAuth(1);
fetchMock.mockResolvedValueOnce(
Response.json(
{ error: { message: "Synthetic expired access" } },
{ status: 401 },
),
);
expect(await harness.experimental_call("codex.ai.status", {})).toEqual({
ready: true,
});
const result =
operation === "transcribe"
? await harness.experimental_call("codex.ai.transcribe", {
model: "gpt-transcribe",
audioBase64: Buffer.from("synthetic audio").toString("base64"),
mimeType: "audio/webm",
filename: "synthetic.webm",
hint: null,
timeoutMs: 1000,
})
: await harness.experimental_call("codex.ai.complete", {
model: "gpt-4.1",
prompt: "Synthetic request",
timeoutMs: 1000,
});
expect(result).toMatchObject({ ok: false, code: "auth_required" });
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(await fs.readFile(authPath, "utf8")).toBe(original);
console.log(
operation,
JSON.stringify(result),
"requests=1 authUnchanged=true",
);
},
);
This is nonvisual. No screenshots are applicable. Raw evidence and the separate test artifact are retained locally, not published as extra files, in accordance with the reports repository's publication policy.
5. Root cause
Expiration decoder compares the JWT exp against the current time. Classification still returns state: "ok" and stores that result as credentials.expired:
state: "ok",
credentials: {
type: "chatgpt",
...
expired: tokenExpired(accessToken),
}
The shared credential reader treats this as usable without checking expiry:
case "ok": return auth.credentials;
The host readiness handler only tests whether this reader throws:
await readCodexAuthCredentials();
return { ready: true };
Text completion and transcription obtain credentials from that same reader and issue their requests directly. HTTP 401 maps to auth_required. The server-side registration sends helper calls and service status to the configured primary host, sharing one availability status for the helper service.
Underlying lifecycle constraint: the existing read-only-auth test deliberately preserves direct use of an expired-looking access token and an unchanged auth file. Adding a second refresh writer without coordinating the credential owner could race token rotation. A missing expiry check is directly demonstrated; successful real refresh is not.
6. Proposed fix and safety gate
Make known-expired OAuth credentials unavailable through the shared helper credential boundary, with primary-host recovery guidance. If automatic recovery is supported, perform serialized refresh through the actual credential owner and retry only within the existing request deadline; do not introduce an independent writer of the auth file. Preserve API-key behavior and test valid, missing, expired, and unsuccessful-refresh paths.
No autopilot pull request: the verified defect lies in authentication semantics and credential ownership, explicitly excluded by the simple-fix gate. Selecting refresh ownership versus a read-only rejection also needs a lifecycle/product decision. Work stops before production edits, a branch, or a push. No linked open PR was found in issue timeline metadata or an open-PR body search for the trusted issue number.
7. Verification
The same investigator repeated the test in a second fresh detached worktree at 6a639cfc0d66e0c789a1bd7309266973228d1a80, confirmed clean before adding only the authored test. Dependencies were installed with the frozen lockfile and the normal Turbo build completed. The second run used --force so it could not replay a cached test result. Each case created new temporary auth data; no ports were needed. Both runs exit 1 with exactly the same readiness assertion failure and four passing controls. This is a second clean run, not independent verification.
No report correction was necessary: the second run supports every verified claim. Existing adjacent auth and client tests also pass:
pnpm exec turbo run test --filter=bb-plugin-provider-codex -- src/ai/chatgpt-client.test.ts src/ai/codex-auth.test.ts Test Files 2 passed (2) Tests 26 passed (26)
The full initial Turbo build completed 67 tasks successfully. The relevant existing tests intentionally do not reject expired-looking credentials, explaining why they do not detect the readiness regression.
8. Related issues and limits
No other issue or linked branch is needed to establish this root cause. Pool-owned routing, real OAuth validity, cross-device recovery guidance, server HTTP status wrapping, and real title/commit orchestration remain outside the demonstrated runtime scope. No external issue links, issue-supplied commands, scripts, patches, or branches were executed. Issue content was treated only as untrusted claims.
9. Appendix
Source inspection covered the host entry, auth parser, HTTP client and error classification, service registration, SDK host test harness, neighboring tests, and credential-parser history. Both clean worktrees use the same explicitly fetched target main commit. Reproduction commands and complete test are inline above; exact local install, build, test, and triage logs are retained privately. The report contains only synthetic account, audio, refresh, and response values. No actual credential, private recording, transcript, machine identity, or environment dump is included.
Classification: Bug (false availability and rejected helper requests); Medium priority (limited helper scope with a login workaround, no demonstrated loss); Medium effort (credential lifecycle and readiness share several modules). All values were missing and filled; no existing classification was replaced.