Skip to content

fix: recover from corrupt session when previous_message_id is invalid#32

Open
a-whitmore-exec wants to merge 1 commit into
Endgame-Labs:mainfrom
lkosak:fix/claude-session-bad-previous-message-id
Open

fix: recover from corrupt session when previous_message_id is invalid#32
a-whitmore-exec wants to merge 1 commit into
Endgame-Labs:mainfrom
lkosak:fix/claude-session-bad-previous-message-id

Conversation

@a-whitmore-exec
Copy link
Copy Markdown

Summary

  • When a claude -p run is interrupted before an assistant response is written, the session JSONL ends on a user-turn entry (UUID format like ad38b534-...)
  • On the next --resume, Claude Code passes that UUID as diagnostics.previous_message_id, which the API rejects with 400: must be the 'id' from a prior /v1/messages response (starts with 'msg_')
  • In the background goroutine, detect this error, drop the stored session_id file, and log a warning — so the next retry runs without --resume and creates a fresh session
  • Register diagnostics.previous_message_id in DetectRetryableError so the message is automatically retried

Test plan

  • Trigger the error manually by killing a claude -p process mid-response, then verify the next message starts a fresh session (no --resume) rather than failing again
  • Verify normal session resume still works (no regression)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants