Fix stale resume (#10) + add CLAUDE_MODEL env var (#11)#12
Merged
Conversation
When the bot restarts and the saved session_id in data.db is stale (CC CLI rotated the id, JSONL file deleted, bot killed mid-stream), the SDK child process crashed with "process exited with code 1" before emitting any messages. The outer catch surfaced that as a ❌ error embed, then the caller retried and a fresh session succeeded — users saw a confusing double-card UX of ⏳ → ❌ → ⏳ → ✅. Extract the query() creation into a runQuery(useResume) closure and wrap the for-await loop in a retry-capable while block. On error, if attemptedResume && no user-visible output has been produced yet and the error looks resume-related, clear the stale session_id in DB and re-run query() without resume. Only retries once; genuine mid-stream crashes still surface to the user as before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Expose the SDK's `model` option via an optional CLAUDE_MODEL env var so users can pin a specific Claude model (e.g., claude-opus-4-7 for hard coding, claude-haiku-4-5-20251001 for cheap throughput). When unset, the SDK default is used — zero breaking change for existing users. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 21, 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.
Closes #10, Closes #11.
Summary
resumewhen the savedsession_idis stale, eliminating the⏳ → ❌ → ⏳ → ✅double-card UX that users saw after bot restart.CLAUDE_MODELenv var to pin a specific Claude model variant. Unset = SDK default (no breaking change).Changes
src/claude/session-manager.tsquery()creation intorunQuery(useResume: boolean)closure.retry: while (true)with an inner try/catch.attemptedResume && !hasTextOutput && !hasResultand the error message matches resume-stale patterns ("process exited with code","No conversation found","session not found",/resume/i), clear the DBsession_id, re-runquery()without resume, andcontinue retry. Only retries once (attemptedResume = false).model: CLAUDE_MODELintoquery()options when set.src/utils/config.tsCLAUDE_MODEL: z.string().optional().transform(...)— empty string normalized toundefined..env.exampleCLAUDE_MODEL=entry with examples in comment.Test plan
npx tsc --noEmit— passesnpm run build— passesnpm test— 93/93 passing~/.claude/projects/<slug>/*.jsonl→ restart bot → send message → should see⏳ Thinking...→✅ Task Completewith no ❌ card!hasTextOutput && !hasResult)CLAUDE_MODEL=claude-haiku-4-5-20251001→ verify model pinned🤖 Generated with Claude Code