Skip to content

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

Closed
chrisdeeming wants to merge 1 commit into
pingdotgg:mainfrom
chrisdeeming:fix/provider-session-recovery
Closed

chrisdeeming wants to merge 1 commit into
pingdotgg:mainfrom
chrisdeeming:fix/provider-session-recovery

Conversation

@chrisdeeming

@chrisdeeming chrisdeeming commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

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 for commit a905f33. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 5, 2026
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
@macroscopeapp

macroscopeapp Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

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.

@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from c06135c to 60a70c3 Compare August 5, 2026 17:14
Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts Outdated
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch 2 times, most recently from 7929c7f to 031d5ad Compare August 5, 2026 19:02
Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts Outdated
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from 031d5ad to 063bdc0 Compare August 5, 2026 19:17
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from 063bdc0 to 00bcdcd Compare August 5, 2026 19:33
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from 00bcdcd to d1e07ac Compare August 5, 2026 20:03
Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from d1e07ac to 324c388 Compare August 5, 2026 21:12
Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts Outdated
@chrisdeeming
chrisdeeming force-pushed the fix/provider-session-recovery branch from 324c388 to 3a428e3 Compare August 5, 2026 21:22
Comment thread apps/server/src/provider/acp/AcpSessionRuntime.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Reviewed by Cursor Bugbot for commit 3a428e31114d09e9c12460d0c2d66d8801a6d98a. Configure here.

Comment thread apps/server/src/provider/Drivers/ClaudeSessionRecovery.ts
@juliusmarminge

Copy link
Copy Markdown
Member

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.

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants