Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): respawn Claude after an expired login #9468

Closedrobertnisipeanu(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/9468/headopened View on GitHub

Fixes #9607

Problem

Claude Code loads its OAuth credentials once per process. T3 Code keeps one long-lived CLI per thread, so after the credentials expire that thread keeps answering "Not logged in · Please run /login" even after the user logs in again from a terminal. New threads work because they spawn a fresh CLI. The stuck thread only recovers once the idle reaper kills its process, up to 30 minutes later, or after a manual Stop.

Fix

When the CLI reports an assistant message with error: "authentication_failed", the Claude adapter:

  • fails the turn with the CLI's own message (a message without text gets a runtime error with a fixed fallback instead), and
  • stops the session at the end of that turn, so the next send recovers the thread from its persisted resume cursor and spawns a fresh CLI with the current credentials.

The stop runs on the stream fiber itself, so stopSessionInternal skips interrupting that fiber and lets the stream end through its own stopped check. The first auth-failure message in a turn wins, so a repeated failure does not duplicate the runtime error or replace the CLI's message with the fallback.

Testing

  • vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts (81 passed, two new tests: auth failure with text, and repeated auth failure without text)
  • server typecheck, lint, and format on the touched files

Built with Claude Fable 5.1 in Claude Code.

🤖 Generated with Claude Code


Note

Medium Risk Changes Claude session lifecycle and turn completion on auth errors; incorrect handling could drop sessions prematurely or leave stale CLI processes, but behavior is scoped to authentication_failed and covered by new tests.

Overview Fixes threads stuck on “Not logged in” after the user re-authenticates by treating Claude CLI authentication_failed assistant messages as a hard session failure and tearing down the long-lived process so the next message spawns a fresh CLI with current credentials.

The Claude adapter records the first auth failure per turn in authenticationError, fails the turn with the CLI’s text (or a runtime.error plus fallback when there is no text), skips duplicating that message as a generic runtime error, and calls stopSessionInternal after turn.completed. stopSessionInternal no longer interrupts the stream fiber when stop is invoked from that same fiber, avoiding a self-deadlock while the session exits.

Tests cover auth failure with CLI text (failed turn, session.exited, no session, one close) and repeated empty auth messages (single runtime error, first message wins).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5222edfe8f1f0f1f59da2e45887ff98b555140db. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Stop and respawn Claude session after expired login authentication failure

  • Adds an authentication-error field to ClaudeSessionContext that captures the first authentication-failure message from a Claude CLI assistant message; textless failures emit a fallback runtime error.
  • The result handler in makeClaudeAdapter now checks for a captured authentication error: if present, it completes the turn as failed with that message and stops the session, suppressing a duplicate runtime error. Normal failed results keep existing behavior.
  • Fixes stopSessionInternal so that shutdown invoked from the stream fiber does not wait to interrupt that same fiber; distinct live stream fibers are still interrupted.
  • Risk: any code relying on a second runtime error after an authentication-failed result message will no longer receive it, since makeClaudeAdapter.handleResultMessage suppresses the duplicate when the assistant message already supplied the error text.
Macroscope summarized 619ddee.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The production adapter changes authentication-failure handling and terminates long-lived Claude sessions so later requests can respawn with refreshed credentials. Although the change is narrowly scoped and tested, its credential and session-lifecycle implications require focused review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. juliusmarminge closed this

    4. Closing as part of the open-PR backlog sweep (wave 2).

      Reason: Duplicate of newer #9628 for the same #9607 Claude auth-respawn fix Related: #9628

      Reopen if this is still wanted and you’re willing to rebase onto current main.

    5. @juliusmarminge this is still wanted and is rebased onto current main, but GitHub will not reopen a PR after its branch was force-pushed, so the rebased version is at #11048.

      Two notes on the close reason:

      • #9628 was opened after this PR and the issue that links it, for the same fix. Newer does not mean better here: it substring-matches error text, hand-sets the session status to closed and widens hasSession instead of using the existing stop path, has an open Macroscope finding where the auth flag survives an interrupted turn and tears down a later healthy session, and is currently conflicting with main. Details in https://github.com/pingdotgg/t3code/pull/9628#issuecomment-5557638882.
      • #10321 landed in the meantime and names the expired login in the turn error, but it explicitly does not restart the CLI process and tells the user to start a new thread. #11048 builds on its per-turn latch and makes the same thread recover.

Sign in to join this conversation.