Skip to content
Source
Sign inSign up
pingdotgg/t3code

[codex] Fix Claude auth probe fallback #3559

Closedjuliusmarmingewants to merge 1 commit intomain fromt3code/fix-claude-oauth-authenticationopened View on GitHub

juliusmarmingecommented

What Changed

  • Fall back to claude auth status when the Claude Agent SDK initialization probe is unavailable.
  • Preserve explicit logged-out detection and existing version advisories in the fallback path.
  • Add regression coverage for authenticated third-party/Bedrock sessions and logged-out sessions.

Why

The SDK initialization probe supplies optional account and slash-command metadata, but its failure was also being treated as an authentication failure. That put otherwise working OAuth/Max and third-party Claude installations into the non-selectable “Limited” state.

The CLI auth status is an independent, authoritative fallback, so a missing initialization result no longer disables an authenticated provider.

Fixes #2653.

Validation

  • vp test apps/server/src/provider/Layers/ProviderRegistry.test.ts
  • vp check
  • vp run typecheck

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes

Note

Fix Claude auth probe fallback to parse claude auth status CLI output

  • Previously, ClaudeProvider.checkClaudeProviderStatus returned a generic warning with unknown auth when capabilities were unavailable. Now it runs claude auth status as a fallback and parses the result.
  • Adds parseClaudeAuthStatusFromOutput in ClaudeProvider.ts to normalize CLI stdout/stderr/exit-code into ready/authenticated, error/unauthenticated, or warning/unknown states with context-specific messages.
  • Auth probe is bounded by AUTH_PROBE_TIMEOUT_MS; timeouts produce a warning with an explicit timeout message rather than a generic failure.
Macroscope summarized b1a7386.

Note

Medium Risk Changes how Claude provider selectability is determined from auth probes; incorrect parsing could mislabel working sessions as limited, but scope is limited to status checking with new regression tests.

Overview When the Claude Agent SDK initialization probe does not return capabilities, provider status no longer treats that as an auth failure. checkClaudeProviderStatus now runs claude auth status (with AUTH_PROBE_TIMEOUT_MS) and maps the result to ready/authenticated, error/unauthenticated, or warning/unknown.

Adds parseClaudeAuthStatusFromOutput to interpret CLI stdout/stderr (unknown command, login prompts, JSON via extractAuthBoolean, exit code). Timeouts get an explicit timeout message instead of a generic warning.

Tests cover authenticated third-party/Bedrock JSON and logged-out CLI responses when capabilities are unavailable.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b1a7386972f78d0a49df1fab4a8abc3a30f1c0fc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 8af67dd6-8669-4a8f-9a2a-b2c1516ec4b3

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/fix-claude-oauth-authentication`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. @@ -444,3 +449,4 @@
      444449 return undefined;
      445450 }
      446451
      452+function parseClaudeAuthStatusFromOutput(result: CommandResult): {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/ClaudeProvider.ts:452

      parseClaudeAuthStatusFromOutput() parses JSON from claude auth status but only extracts the boolean loggedIn field, discarding authMethod, apiProvider, and email. When the SDK probe is unavailable and this fallback path is used, checkClaudeProviderStatus returns authenticated snapshots without auth.type, auth.label, or auth.email, so the settings UI shows a generic "Authenticated" headline instead of identifying API key / Bedrock / Max sessions. Consider propagating the parsed metadata through claudeAuthMetadata() to preserve the auth details.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/provider/Layers/ClaudeProvider.ts around line 452:
      
      `parseClaudeAuthStatusFromOutput()` parses JSON from `claude auth status` but only extracts the boolean `loggedIn` field, discarding `authMethod`, `apiProvider`, and `email`. When the SDK probe is unavailable and this fallback path is used, `checkClaudeProviderStatus` returns authenticated snapshots without `auth.type`, `auth.label`, or `auth.email`, so the settings UI shows a generic "Authenticated" headline instead of identifying API key / Bedrock / Max sessions. Consider propagating the parsed metadata through `claudeAuthMetadata()` to preserve the auth details.
      @@ -743 +823,21 @@
      743823 if (!capabilities) {
      824+ const authProbe = yield* runClaudeCommand(
      825+ claudeSettings,
      826+ ["auth", "status"],
      827+ resolvedEnvironment,
      828+ ).pipe(Effect.timeoutOption(AUTH_PROBE_TIMEOUT_MS), Effect.result);
      829+
      830+ if (Result.isSuccess(authProbe) && Option.isSome(authProbe.success)) {
      831+ const parsedAuth = parseClaudeAuthStatusFromOutput(authProbe.success.value);
      832+ return buildServerProvider({
      833+ presentation: CLAUDE_PRESENTATION,
      834+ enabled: claudeSettings.enabled,
      835+ checkedAt,
      836+ models,
      837+ slashCommands: dedupedSlashCommands,
      838+ probe: {
      839+ installed: true,
      840+ version: parsedVersion,
      841+ status: parsedAuth.status,
      842+ auth: parsedAuth.auth,
      843+ ...(parsedAuth.message
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/ClaudeProvider.ts:843

      When parseClaudeAuthStatusFromOutput() returns a message (e.g., "authentication status command is unavailable" on older Claude versions), the existing versionUpgradeMessage is dropped even when present. This means old installations that need the upgrade advisory for claude-fable-5 or claude-opus-4-8 only see the auth message, hiding the model availability warning. Consider concatenating both messages or prioritizing the upgrade message when both apply.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/provider/Layers/ClaudeProvider.ts around line 843:
      
      When `parseClaudeAuthStatusFromOutput()` returns a message (e.g., "authentication status command is unavailable" on older Claude versions), the existing `versionUpgradeMessage` is dropped even when present. This means old installations that need the upgrade advisory for `claude-fable-5` or `claude-opus-4-8` only see the auth message, hiding the model availability warning. Consider concatenating both messages or prioritizing the upgrade message when both apply.
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Auth heuristics precede JSON parsing
        • Reordered parseClaudeAuthStatusFromOutput to attempt structured JSON parsing of stdout first and only fall back to keyword heuristics on combined stdout/stderr when the output is not valid JSON, preventing false-negative auth detection from substring matches in JSON fields or stderr.

      Create PR

      Or push these changes by commenting:

      @cursor push d6571156ac
      Preview (pingdotgg/t3code@d6571156ac)
      diff --git a/apps/server/src/provider/Layers/ClaudeProvider.ts b/apps/server/src/provider/Layers/ClaudeProvider.ts
      --- a/apps/server/src/provider/Layers/ClaudeProvider.ts
      +++ b/apps/server/src/provider/Layers/ClaudeProvider.ts
      @@ -454,6 +454,41 @@
         readonly auth: Pick<ServerProviderAuth, "status">;
         readonly message?: string;
       } {
      +  // Attempt structured JSON parsing first so that keyword heuristics on
      +  // combined stdout/stderr don't accidentally match JSON field names or
      +  // values (e.g. "loggedIn") or unrelated CLI hints in stderr.
      +  const trimmedStdout = result.stdout.trim();
      +  let parsedAuth: boolean | undefined;
      +  let parsedJson = false;
      +  if (trimmedStdout.startsWith("{") || trimmedStdout.startsWith("[")) {
      +    try {
      +      parsedAuth = extractAuthBoolean(JSON.parse(trimmedStdout) as unknown);
      +      parsedJson = true;
      +    } catch {
      +      // Fall through to heuristics for non-JSON output.
      +    }
      +  }
      +
      +  if (parsedAuth === true) {
      +    return { status: "ready", auth: { status: "authenticated" } };
      +  }
      +  if (parsedAuth === false) {
      +    return {
      +      status: "error",
      +      auth: { status: "unauthenticated" },
      +      message: "Claude is not authenticated. Run `claude auth login` and try again.",
      +    };
      +  }
      +  if (parsedJson) {
      +    return {
      +      status: "warning",
      +      auth: { status: "unknown" },
      +      message:
      +        "Could not verify Claude authentication status from JSON output (missing auth marker).",
      +    };
      +  }
      +
      +  // Fallback: plain-text heuristics for non-JSON CLI output.
         const lowerOutput = `${result.stdout}\n${result.stderr}`.toLowerCase();
       
         if (
      @@ -483,36 +518,6 @@
           };
         }
       
      -  const trimmedStdout = result.stdout.trim();
      -  let parsedAuth: boolean | undefined;
      -  let parsedJson = false;
      -  if (trimmedStdout.startsWith("{") || trimmedStdout.startsWith("[")) {
      -    try {
      -      parsedAuth = extractAuthBoolean(JSON.parse(trimmedStdout) as unknown);
      -      parsedJson = true;
      -    } catch {
      -      // Fall through to the command exit status for non-JSON output.
      -    }
      -  }
      -
      -  if (parsedAuth === true) {
      -    return { status: "ready", auth: { status: "authenticated" } };
      -  }
      -  if (parsedAuth === false) {
      -    return {
      -      status: "error",
      -      auth: { status: "unauthenticated" },
      -      message: "Claude is not authenticated. Run `claude auth login` and try again.",
      -    };
      -  }
      -  if (parsedJson) {
      -    return {
      -      status: "warning",
      -      auth: { status: "unknown" },
      -      message:
      -        "Could not verify Claude authentication status from JSON output (missing auth marker).",
      -    };
      -  }
         if (result.code === 0) {
           return { status: "ready", auth: { status: "authenticated" } };
         }
      You can send follow-ups to the cloud agent here. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b1a7386972f78d0a49df1fab4a8abc3a30f1c0fc. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -446,0 +476,21 @@
      476+ lowerOutput.includes("run `claude login`") ||
      477+ lowerOutput.includes("run claude login")
      478+ ) {
      479+ return {
      480+ status: "error",
      481+ auth: { status: "unauthenticated" },
      482+ message: "Claude is not authenticated. Run `claude auth login` and try again.",
      483+ };
      484+ }
      485+
      486+ const trimmedStdout = result.stdout.trim();
      487+ let parsedAuth: boolean | undefined;
      488+ let parsedJson = false;
      489+ if (trimmedStdout.startsWith("{") || trimmedStdout.startsWith("[")) {
      490+ try {
      491+ parsedAuth = extractAuthBoolean(JSON.parse(trimmedStdout) as unknown);
      492+ parsedJson = true;
      493+ } catch {
      494+ // Fall through to the command exit status for non-JSON output.
      495+ }
      496+ }

      Auth heuristics precede JSON parsing

      Medium Severity

      In parseClaudeAuthStatusFromOutput, keyword checks on combined stdout/stderr run before stdout JSON parsing. This can incorrectly mark an authenticated session as unauthenticated if "logged out" or "unknown command" phrases appear in stderr or JSON string fields.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b1a7386972f78d0a49df1fab4a8abc3a30f1c0fc. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Approvability

      Verdict: Needs human review

      2 blocking correctness issues found. This PR introduces new authentication fallback logic with ~75 lines of parsing heuristics. Open review comments identify potential bugs including false authentication failures from heuristic ordering. Authentication flow changes with unresolved bug reports warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. juliusmarminge closed this

Sign in to join this conversation.