Skip to content

Fix stale resume (#10) + add CLAUDE_MODEL env var (#11)#12

Merged
chadingTV merged 2 commits intomainfrom
claude/hardcore-noether-21a1aa
Apr 21, 2026
Merged

Fix stale resume (#10) + add CLAUDE_MODEL env var (#11)#12
chadingTV merged 2 commits intomainfrom
claude/hardcore-noether-21a1aa

Conversation

@chadingTV
Copy link
Copy Markdown
Owner

Closes #10, Closes #11.

Summary

Changes

src/claude/session-manager.ts

  • Extract query() creation into runQuery(useResume: boolean) closure.
  • Wrap the for-await message loop in retry: while (true) with an inner try/catch.
  • On inner error, if attemptedResume && !hasTextOutput && !hasResult and the error message matches resume-stale patterns ("process exited with code", "No conversation found", "session not found", /resume/i), clear the DB session_id, re-run query() without resume, and continue retry. Only retries once (attemptedResume = false).
  • Genuine mid-stream failures (after any output/result) still surface to the user as before.
  • Inject model: CLAUDE_MODEL into query() options when set.

src/utils/config.ts

  • Add CLAUDE_MODEL: z.string().optional().transform(...) — empty string normalized to undefined.

.env.example

  • Add CLAUDE_MODEL= entry with examples in comment.

Test plan

🤖 Generated with Claude Code

nats1412019@gmail.com and others added 2 commits April 20, 2026 16:40
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>
@chadingTV chadingTV merged commit 6c93cad into main Apr 21, 2026
2 checks passed
@chadingTV chadingTV deleted the claude/hardcore-noether-21a1aa branch April 21, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant