Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): recover provider sessions when resume history is missing #5433

Closedchrisdeeming(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5433/headopened View on GitHub

What Changed

Every provider adapter now recovers when a thread's resume target no longer exists, instead of failing identically on every subsequent message.

  • Claude — locates an orphaned session transcript under the Claude projects directory and copies it into the current project before start, but only when the directory it was recorded against is gone; a transcript with a live home is left untouched. When the CLI then rejects a directory recorded inside the session (Path "..." does not exist), the adapter restarts once and replays the pending prompt, keeping the resume cursor so conversation history survives. One retry only, guarded by a flag.
  • Cursor / Grok — a failed session/load in the shared ACP runtime falls back to session/new and rewrites the resume cursor. Timeouts are excluded: a hung agent surfaces as an error rather than silently discarding history.
  • Codex / OpenCode — both already fell back to a fresh session but only wrote a server-side logWarning; they now tell the user.

Transcript inspection is best-effort throughout — if it fails for any reason, the session starts as though nothing was found.

Why

A thread can be pinned to a git worktree that something else later deletes — another agent, another thread, or the user. The consequences were provider-specific and mostly bad:

  • Claude derives transcript storage from the working directory and re-homes transcripts itself on EnterWorktree. Delete that worktree and the transcript is stranded: resume fails with No conversation found with session ID: <id> even though the file still exists. The cursor was never cleared, so every later message retried the same doomed resume and the thread stayed permanently wedged.
  • Cursor and Grok share one session/load call that had no fallback and never rewrote the cursor, so an unloadable session id wedged the thread the same way. Their failures also arrive as defects rather than typed errors, so recovery handles the cause rather than the error channel while still re-raising transport timeouts.
  • Codex and OpenCode degraded gracefully but silently, leaving users with an agent that had no memory of the conversation and no explanation.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes — no UI changes; the only user-visible addition is a standard warning row
  • I included a video for animation/interaction changes — no animation or interaction changes

Note

Medium Risk Touches session start, resume cursors, and mid-turn restart across all provider adapters; mistakes could drop history or double-run turns, though behavior is heavily covered by new tests.

Overview Provider adapters no longer stay wedged when a thread’s resume target is gone (e.g. deleted git worktree). Users get runtime.warning when history can’t be resumed instead of silent fresh sessions or repeated failures.

Claude adds recoverClaudeSession, which finds orphaned .jsonl transcripts under Claude’s projects/ tree (when the recorded cwd is missing) and copies the newest match into the current workspace before start. If recovery is missing, start drops the resume cursor and warns. On CLI Path "..." does not exist, the adapter restarts once, keeps the resume id, replays the last prompt, and injects a workspace-moved notice.

Cursor / Grok (ACP) treat recoverable session/load failures as session/new with resumeFallback; transport/timeouts still fail. Codex and OpenCode already fell back but now emit the same user-visible warning pattern.

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

Note

Recover provider sessions when resume history is missing by rehoming orphaned transcripts

  • Adds recoverClaudeSession in ClaudeSessionRecovery.ts that scans Claude's projects directory for orphaned transcripts matching the session ID, copies the most recently modified one into the current workspace, and returns 'available' | 'rehomed' | 'missing'.
  • Updates makeClaudeAdapter in ClaudeAdapter.ts to call session recovery on start, suppress resume when history is missing, and automatically restart and replay the last prompt when the CLI reports a missing resume path.
  • ACP session runtime (AcpSessionRuntime.ts) now falls back to a fresh session when session/load fails recoverably, returning a resumeFallback flag to callers.
  • Cursor, Grok, OpenCode, and Codex adapters each emit a runtime.warning event when they start a fresh session due to an unresumable prior session.
  • Risk: the automatic restart-and-replay path in ClaudeAdapter silently retries once; if the restarted session also fails, the turn completes as failed and a session.exited with exitKind: 'error' is emitted.
Macroscope summarized a905f33.
    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 Plus

      Run ID: 47c6a9f5-fb2c-41b7-ab5e-0faba206c469

      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

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

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

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

      Approvability

      Verdict: Needs human review

      This PR introduces new session recovery capabilities across 6 provider adapters, including automatic session restart and prompt replay logic. The significant runtime behavior changes and an unresolved review comment about potential incorrect transcript handling warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3a428e31114d09e9c12460d0c2d66d8801a6d98a. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Closing as part of the open-PR backlog sweep (wave 1).

      Reason: Aug conflicted resume-history recovery; provider adapters have moved a long way.

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

    6. juliusmarminge closed this

Sign in to join this conversation.