fix(claude-code): recreate a persisted session the CLI no longer has - #5651
fix(claude-code): recreate a persisted session the CLI no longer has#5651nocstah wants to merge 1 commit into
Conversation
The claude-code driver mints a session UUID, persists it to claude-code-sessions.json before the creating turn runs, then uses --resume on every later turn. If that first create fails (a transient error, a cancelled turn, a cleared CLI store), the id is already persisted but the session was never created, so every later turn fails with "No conversation found with session ID: <uuid>" and there is no recovery. The thread is poisoned across app and model restarts. This checks whether the CLI still has the session on disk before choosing --resume. When the persisted id has no <config>/projects/*/<id>.jsonl, the turn is treated as new: it recreates the session (reusing the same id so the thread mapping stays stable) with --session-id and full context. Adds cc_session_exists / cc_session_exists_in plus a unit test. Closes tinyhumansai#5648 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Claude Code driver now verifies that persisted session UUIDs have matching on-disk session files. Missing sessions are recreated with the existing valid UUID. Tests cover absent, matching, and mismatched session files. ChangesClaude Code session recovery
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: 🔵 Low · up to The change recovers Claude Code conversations whose persisted session is missing by recreating the session with its prior context. It is mergeable with explicit owner awareness that concurrent turns for the same conversation could still overlap and cause duplicate or out-of-order transcript updates. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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. Comment |
How this change flows2 changed behaviours across 1 relationship. The code graph does not know these behaviours yet — normal for newly added code, and a cold index otherwise. 1 further behaviour left out to keep the diagram readable. flowchart LR
n0["append_system_prompt_args<br/>changed"]:::changed
n1["run_turn<br/>changed"]:::changed
n1 -->|calls| n0
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Green: changed behaviour. Grey: surrounding behaviour. Arrows name the call, use, implementation, or test relationship. Orange: has findings. Red: has a finding that blocks the merge. |
Summary
claude-code) chat thread breaks permanently withNo conversation found with session ID: <uuid>.--resumes it — so any first-turn failure poisons the thread with no recovery.--resume, and recreates a missing one with--session-id+ full context.Problem
run_turninclaude_code/driver.rsdecides new-vs-resume fromsession_storealone: a persisted UUID means--resume. But the id is written toclaude-code-sessions.jsonbefore the creating call runs, so if that call fails (transient error, cancelled turn, or the user's CLI session store is cleared), the id survives but the session was never created. Every later turn then--resumes a session the CLI does not have and exits non-zero withNo conversation found with session ID: <uuid>. Restarting the app or model does not help — the mapping is never invalidated.Reproduced against
claudeCLI 2.1.237 / modelclaude-opus-5. Confirmed a shim that rewrites--resume <id>→--session-id <id>when the session file is absent makes chat work immediately, i.e. the CLI and model are fine; the driver's create/resume bookkeeping is the bug.Solution
cc_session_exists(+ a pure, testablecc_session_exists_in) that scans<CLAUDE_CONFIG_DIR|~/.claude>/projects/*/<id>.jsonl.--session-id, and send full context (is_new = true) since the CLI holds no prior turns.--resumeas before).Submission Checklist
cc_session_exists_in_detects_present_and_absentcovers present, absent, and wrong-id cases.run_turn(the new/resume decision) are not directly covered becauserun_turnspawns a subprocess and has no unit harness.pnpm test:rustpasses locally. Happy to add an integration test if reviewers prefer.N/A: behaviour-only fix, no feature row change.## Related—N/A.N/A: does not touch release-cut surfaces.Closes #NNN.Impact
Related
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
fix/cc-session-recreateSummary by CodeRabbit