Repository navigation
Description
Summary
BB's Codex AI service can report Codex as unavailable, with the message Run `codex login` on the primary machine to sign in, even though native Codex has a working configured model provider. The Codex AI service reads credentials only from auth.json. It then calls ChatGPT/OpenAI endpoints directly and does not honor Codex's configured custom model provider or its command-backed auth. The login prompt is misleading, because signing in to ChatGPT/OpenAI would not make BB use the configured custom provider/auth.
Versions and environment
- bb: desktop 0.44.0 (
desktop-v0.44.0at0baa605b32a00619c1d7e3f32be6553ebcf8244a); source checked on currentmainat66bbc1a2d80bdaba936d9df6cd583953a5f23937. - OS: macOS 26.7 (build 25G229), from
sw_verson the machine used for this investigation. - Codex CLI:
codex-cli 0.158.0. - Codex setup: a custom model provider (Vercel AI Gateway) with command-backed auth that retrieves a credential from macOS Keychain. No effective
auth.jsonis present in$CODEX_HOMEor~/.codex. Provider settings, command arguments, and credential values are intentionally omitted.
Steps to reproduce
- On the primary BB machine, set Codex's selected model provider to a custom provider whose auth is supplied by a command instead of
auth.json. - Make sure no
auth.jsonis present in the effective Codex home ($CODEX_HOMEor~/.codex). Do not runcodex login. - Confirm that native Codex can authenticate through the configured provider, with any provider API-key environment variable removed.
- In BB desktop, open Settings → AI services.
- Select Codex as the AI service for a text task, then inspect its status and click Test.
Expected vs actual
Expected: BB either uses the Codex provider/auth configuration that native Codex uses, or clearly states that the Codex AI service supports only auth.json ChatGPT/OpenAI credentials and does not support configured custom providers.
Actual (reported): Codex is unavailable in AI services, and the test fails with this status:
Codex: Run `codex login` on the primary machine to sign in
The code path explains the status message: a missing auth.json maps to that exact prompt. Running codex login is not the right fix for this configuration, because BB's inference path would call ChatGPT/OpenAI directly instead of using the configured Vercel AI Gateway provider.
Evidence
- Reported evidence: in
@thread:thr_ydmrr3g5fb(parent@thread:thr_qpxr5nxadb), a Codex invocation withAI_GATEWAY_API_KEYremoved returnedKEYCHAIN_AUTH_OK. That validates the native Codex/Keychain path only. The BB UI test was not independently run during this investigation. - Prior Keychain/native Codex finding:
@thread:thr_43m7rxspsv. - On the primary machine, we checked configuration safely without printing values. It selects the Vercel AI Gateway provider/model and a command-based auth section, and has no effective
auth.json. - The AI-services test runs the selected service through
runTextAiTask; it does not check Codex OAuth directly:bb/apps/app/src/components/settings/AiServicesSettingsSection.tsx
Lines 184 to 198 in 66bbc1a
const test = useMutation({ meta: { showErrorToast: false }, mutationFn: (task: AiTextTask) => sdk.system.testAiService({ task }), onSuccess: (result, task) => { setTestResults((current) => ({ ...current, [task]: result })); }, onError: (error, task) => { const message = error instanceof Error && error.message.trim().length > 0 ? error.message : "The request failed"; setTestResults((current) => ({ ...current, [task]: { ok: false, message }, })); bb/apps/server/src/services/ai/ai-services-view.ts
Lines 122 to 155 in 66bbc1a
export async function testAiService( deps: AiServicesViewDeps, args: { task: AiTextTask; signal: AbortSignal }, ): Promise<TestAiServiceResponse> { const sample = sampleFor(args.task); const outcome = await runTextAiTask(deps, { task: args.task, label: "AI service test", prompt: sample.prompt, signal: args.signal, }); if (!outcome.ok) { return { ok: false, message: outcome.message, durationMs: outcome.durationMs, }; } const text = sample.sanitize(outcome.value); if (text === null) { return { ok: false, message: `${outcome.service.displayName} returned an empty reply`, durationMs: outcome.durationMs, }; } return { ok: true, pluginId: outcome.service.pluginId, serviceId: outcome.service.id, displayName: outcome.service.displayName, text, durationMs: outcome.durationMs, }; bb/apps/server/src/services/ai/ai-tasks.ts
Lines 168 to 217 in 66bbc1a
function skipMessage( service: AiServiceRegistration, status: AiServiceStatus, ): string | null { return status.ready ? null : `${service.displayName}: ${status.message}`; } export async function runAiTask<T>( deps: AiTaskDeps, args: RunAiTaskArgs<T>, ): Promise<AiTaskOutcome<T>> { const startedAt = Date.now(); const selection = getAiServiceSelections(deps.db)[args.task]; const fail = ( reason: AiTaskFailureReason, message: string, ): AiTaskOutcome<T> => ({ ok: false, reason, message, durationMs: Date.now() - startedAt, }); if (selection.mode === "off") { return fail("off", "Turned off in Settings → AI services"); } if (args.signal?.aborted) { return fail("cancelled", REQUEST_CANCELLED_MESSAGE); } const services = aiTaskServices(deps, args.task, selection); if (services.length === 0) { return fail( "unavailable", selection.mode === "service" ? `The selected AI service "${selection.serviceId}" is not loaded` : "No AI service is available", ); } const timeoutMs = args.timeoutMs ?? AI_TASK_TIMEOUT_MS[args.task]; let last: { reason: AiTaskFailureReason; message: string } = { reason: "unavailable", message: "No AI service is ready", }; for (const service of services) { const skipped = skipMessage( service, await deps.aiServices.status(aiServiceKey(service)), ); if (skipped !== null) { last = { reason: "unavailable", message: skipped }; continue;
- The Codex AI service delegates status and completion to the primary host:
bb/plugins/provider-codex/src/ai-service.ts
Lines 21 to 97 in 66bbc1a
export function registerCodexAiService(bb: BbPluginApi): void { const host = bb.hosts.experimental_client({ contract: codexAiHostContract }); async function primaryHostId(): Promise<string | null> { return (await bb.sdk.system.config()).primaryHostId; } async function requirePrimaryHostId(): Promise<string> { const hostId = await primaryHostId(); if (hostId === null) { throw new Error("No primary machine is connected"); } return hostId; } function textOrThrow(result: CodexAiTextResult): string { if (result.ok) return result.text; throw new Error(result.message); } bb.experimental_aiServices.register({ id: "codex", displayName: "Codex", async complete(prompt, { signal }) { const hostId = await requirePrimaryHostId(); let last: CodexAiTextResult | null = null; for (const model of CODEX_TEXT_MODELS) { last = await host.call( "codex.ai.complete", { model, prompt, timeoutMs: COMPLETE_TIMEOUT_MS }, { hostId, signal, timeoutMs: COMPLETE_TIMEOUT_MS + HOST_CALL_GRACE_MS, }, ); if (last.ok || !RETRY_WITH_NEXT_MODEL.has(last.code)) break; if (signal.aborted) break; } if (last === null) throw new Error("Codex did not answer"); return textOrThrow(last); }, async transcribe(audio, { signal, hint }) { if (audio.size > TRANSCRIBE_MAX_BYTES) { throw new Error( `Recordings over ${TRANSCRIBE_MAX_BYTES / (1024 * 1024)} MB are too large to transcribe`, ); } const hostId = await requirePrimaryHostId(); return textOrThrow( await host.call( "codex.ai.transcribe", { model: CODEX_TRANSCRIPTION_MODEL, audioBase64: Buffer.from(await audio.arrayBuffer()).toString( "base64", ), mimeType: audio.type || "application/octet-stream", filename: audio.name || "voice-input", hint, timeoutMs: TRANSCRIBE_TIMEOUT_MS, }, { hostId, signal, timeoutMs: TRANSCRIBE_TIMEOUT_MS + HOST_CALL_GRACE_MS, }, ), ); }, async status(): Promise<PluginAiServiceStatus> { const hostId = await primaryHostId(); if (hostId === null) { return { ready: false, message: "No primary machine is connected" }; } return host.call("codex.ai.status", {}, { hostId, timeoutMs: 5_000 }); },
- Host status calls
readCodexAuthCredentials()and maps missing auth to thecodex loginprompt:bb/plugins/provider-codex/src/host.ts
Lines 45 to 57 in 66bbc1a
"codex.ai.status": async (): Promise<CodexAiStatus> => { try { await readCodexAuthCredentials(); return { ready: true }; } catch (error) { return { ready: false, message: error instanceof AiServiceFailure && error.detailCode !== "codex_auth_missing" ? error.message : "Run `codex login` on the primary machine to sign in", };
- Credential reading and classification support only
auth.jsonAPI-key and ChatGPT-token forms:bb/plugins/provider-codex/src/ai/codex-auth.ts
Lines 118 to 164 in 66bbc1a
function classifyAuthJson(value: JsonValue): ClassifiedAuthJson { const parsed = toJsonObject(value); if (parsed === null) { return { state: "unusable", reason: "not_object" }; } const authMode = nonEmptyString(parsed.auth_mode); const apiKey = nonEmptyString(parsed.OPENAI_API_KEY); if ( authMode === "apikey" || authMode === "apiKey" || (authMode === null && apiKey !== null) ) { return apiKey === null ? { state: "unusable", reason: "api_key" } : { state: "ok", credentials: { type: "apiKey", apiKey } }; } const tokens = toJsonObject(parsed.tokens); const accessToken = nonEmptyString(tokens?.access_token); if (tokens === null || accessToken === null) { return { state: "unusable", reason: "access_token" }; } const claims = chatGptClaims(accessToken); const idToken = nonEmptyString(tokens.id_token); const idTokenClaims = idToken === null ? toJsonObject(tokens.id_token) : chatGptClaims(idToken); const accountId = nonEmptyString(tokens.account_id) ?? nonEmptyString(claims?.chatgpt_account_id) ?? nonEmptyString(idTokenClaims?.chatgpt_account_id); if (accountId === null) { return { state: "unusable", reason: "account_id" }; } return { state: "ok", credentials: { type: "chatgpt", accessToken, accountId, accountEmail: accountEmail(accessToken) ?? (idToken === null ? null : accountEmail(idToken)), expired: tokenExpired(accessToken), isFedrampAccount: claims?.chatgpt_account_is_fedramp === true || idTokenClaims?.chatgpt_account_is_fedramp === true, }, }; bb/plugins/provider-codex/src/ai/codex-auth.ts
Lines 167 to 224 in 66bbc1a
export async function readCodexAuthFile(): Promise<CodexAuthFile> { const authPath = codexAuthPath(); let raw: string; try { raw = await fs.readFile(authPath, "utf8"); } catch (error) { return errnoCode(error) === "ENOENT" ? { state: "missing", authPath } : { state: "unreadable", authPath, error: toError(error) }; } let value: JsonValue; try { value = parseJsonValue(raw); } catch (error) { return { state: "malformed", authPath, error: toError(error) }; } return { ...classifyAuthJson(value), authPath }; } const UNUSABLE_AUTH_MESSAGES: Record< CodexAuthUnusableReason, (authPath: string) => string > = { not_object: (authPath) => `Codex auth file at ${authPath} is not valid JSON. Run codex login on this host.`, api_key: (authPath) => `Codex auth file at ${authPath} does not contain a usable API key. Run codex login on this host.`, access_token: (authPath) => `Codex auth file at ${authPath} does not contain a usable access token. Run codex login on this host.`, account_id: () => "Codex auth tokens do not include a ChatGPT account id. Run codex login on this host.", }; export async function readCodexAuthCredentials(): Promise<CodexAuthCredentials> { const auth = await readCodexAuthFile(); switch (auth.state) { case "ok": return auth.credentials; case "missing": case "unreadable": throw new AiServiceFailure( "auth_required", "codex_auth_missing", `Codex auth file not found at ${auth.authPath}. Run codex login on this host.`, ); case "malformed": throw new AiServiceFailure( "auth_required", "codex_auth_invalid", UNUSABLE_AUTH_MESSAGES.not_object(auth.authPath), ); case "unusable": throw new AiServiceFailure( "auth_required", "codex_auth_invalid", UNUSABLE_AUTH_MESSAGES[auth.reason](auth.authPath), ); }
- Inference loads the same auth file and calls either the ChatGPT or the OpenAI Responses endpoint:
bb/plugins/provider-codex/src/ai/chatgpt-client.ts
Lines 709 to 765 in 66bbc1a
async function fetchChatGptResponses( args: ChatGptResponsesFetchArgs, ): Promise<Response> { return runWithTimeout({ deadline: args.deadline, work: (signal) => fetchChatGpt({ url: CODEX_RESPONSES_URL, init: (headers) => ({ method: "POST", headers: createChatGptResponsesHeaders(args.auth, headers), body: JSON.stringify(args.request), signal, }), }), }); } async function fetchOpenAiResponses( args: OpenAiResponsesFetchArgs, ): Promise<Response> { return runWithTimeout({ deadline: args.deadline, work: (signal) => fetch(OPENAI_RESPONSES_URL, { method: "POST", headers: createOpenAiResponsesHeaders(args.auth), body: JSON.stringify(args.request), signal, }), }); } async function fetchResponses(args: ResponsesFetchArgs): Promise<Response> { return args.auth.type === "chatgpt" ? fetchChatGptResponses({ auth: args.auth, command: args.command, deadline: args.deadline, request: args.request, }) : fetchOpenAiResponses({ auth: args.auth, command: args.command, deadline: args.deadline, request: args.request, }); } export async function completeCodexInference( command: InferenceCompleteCommand, signal: AbortSignal, ): Promise<string> { const deadline = createCodexRequestDeadline(command.timeoutMs, signal); const auth = await readCodexAuthCredentials(); const request = buildCodexResponsesRequest(command); const response = await fetchResponses({ auth, command, deadline, request });
What you ruled out
- Not a duplicate of Codex thread titles: fallback model gpt-5.4-mini always 400s on ChatGPT-account logins, so rate-limited titles are lost #4318 or Helper inference (titles): let the user pick the Fast service tier; the default fallback model fails on ChatGPT accounts #4262: those cover fallback-model/service-tier behavior for ChatGPT logins, not auth or provider resolution.
- Not a duplicate of bb settings for model account usage don't respect CODEX_HOME #1324: that issue covered
CODEX_HOMEhandling for account usage. This path honorsCODEX_HOME, but only for locatingauth.json. - Not a duplicate of Account Pooler: show and spend Claude and Codex usage-limit resets per account #4157 (usage limits).
- Duplicate searches covered open and closed issues for Codex
auth.json, AI services, custom model providers,model_provider, Vercel AI Gateway, Keychain, command auth,readCodexAuthCredentials, andcodex loginAI services. - We did not run
codex loginor create anauth.json, because either could change the credential state being reported.
AGENT GENERATED
Activity
SawyerHood commentedon Sep 30, 2026
Verified scoped report: https://get-bb.github.io/reports/issues/4484.html
PARTIALLY REPRODUCED in two clean checkouts: the real status handler returns the login prompt and completion fails at missing auth.json for two synthetic custom-provider selections and the no-config control. Only auth.json is read, with zero network calls and no credentials created. Native Codex, command-backed authentication, successful routing and desktop UI remain unverified; both-run evidence and limits are included.