fix: recover from corrupt session when previous_message_id is invalid - #32
Open
a-whitmore-exec wants to merge 2 commits into
Open
fix: recover from corrupt session when previous_message_id is invalid#32a-whitmore-exec wants to merge 2 commits into
a-whitmore-exec wants to merge 2 commits into
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>
a-whitmore-exec
force-pushed
the
fix/claude-session-bad-previous-message-id
branch
from
June 8, 2026 03:23
d231998 to
7d21332
Compare
Contributor
|
Security/usefulness review: the recovery target is useful, but I’m holding merge until it has a regression test. Please cover the actual sequence: bad |
Contributor
|
Follow-up pushed in 44867b7: the completion-state transition is now directly testable, with regressions covering bad diagnostics.previous_message_id stderr clearing the stored session and remaining retryable, plus unrelated stderr preserving the session. Full go test ./..., go vet ./..., and ./build.sh pass. |
dorkitude
added a commit
to alan-botts/goated
that referenced
this pull request
Aug 23, 2026
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