fix: recover from corrupt session when previous_message_id is invalid#32
Open
a-whitmore-exec wants to merge 1 commit into
Open
Conversation
When a claude -p run is interrupted before an assistant response is written, the stored session JSONL ends on a user-turn entry (UUID format). On the next --resume, Claude Code passes that UUID as diagnostics.previous_message_id, which the API rejects with a 400 because it must start with msg_. Detect this specific error in the background goroutine, drop the stored session_id so the retry runs without --resume, and register the pattern in DetectRetryableError so the message is automatically retried. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
claude -prun is interrupted before an assistant response is written, the session JSONL ends on a user-turn entry (UUID format likead38b534-...)--resume, Claude Code passes that UUID asdiagnostics.previous_message_id, which the API rejects with400: must be the 'id' from a prior /v1/messages response (starts with 'msg_')session_idfile, and log a warning — so the next retry runs without--resumeand creates a fresh sessiondiagnostics.previous_message_idinDetectRetryableErrorso the message is automatically retriedTest plan
claude -pprocess mid-response, then verify the next message starts a fresh session (no--resume) rather than failing again🤖 Generated with Claude Code