Skip to content

Codex AI service ignores configured custom provider auth and falsely asks for codex login #4484

Open

Description

@tomdale

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.0 at 0baa605b32a00619c1d7e3f32be6553ebcf8244a); source checked on current main at 66bbc1a2d80bdaba936d9df6cd583953a5f23937.
  • OS: macOS 26.7 (build 25G229), from sw_vers on 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.json is present in $CODEX_HOME or ~/.codex. Provider settings, command arguments, and credential values are intentionally omitted.

Steps to reproduce

  1. 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.
  2. Make sure no auth.json is present in the effective Codex home ($CODEX_HOME or ~/.codex). Do not run codex login.
  3. Confirm that native Codex can authenticate through the configured provider, with any provider API-key environment variable removed.
  4. In BB desktop, open Settings → AI services.
  5. 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 with AI_GATEWAY_API_KEY removed returned KEYCHAIN_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:
    • 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 },
      }));
    • 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,
      };
    • 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:
    • 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 the codex login prompt:
    • "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.json API-key and ChatGPT-token forms:
    • 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,
      },
      };
    • 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:
    • 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

AGENT GENERATED

Activity

  1. added theissue type on Sep 30, 2026
  2. added
    providers
    provider-codex
    partial-repro
    on Sep 30, 2026
  3. SawyerHood commented on Sep 30, 2026

    @SawyerHood
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    partial-reproprovider-codexproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions