Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): log why a saved session could not be resumed
AdityaUmalea31d97108acf
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex ea3101070a..9989af12b7 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -4280,6 +4280,31 @@ describe("ClaudeDriver resume recovery (fake CLI)", () => {expect(text).toBe(REBUILD);});+ it("logs why the saved session could not be resumed before starting a new one", async () => {+ const logged = vi.spyOn(console, "error").mockImplementation(() => {});+ try {+ await instance.adapter.sendTurn({ threadId: "t-logged", text: "what now?", resumeCursor: "an-outside-session", recoveryText: REBUILD });+ await recorder.until((e) => e.type === "turn.completed");+ const lines = logged.mock.calls.map((call) => String(call[0]));+ expect(lines.find((line) => line.includes("could not resume session an-outside-session"))).toMatch(/^claude \(claude-test\): could not resume session an-outside-session for thread t-logged, starting a new one: claude exited \d+ before result/u);+ } finally {+ logged.mockRestore();+ }+ });++ it("logs the CLI's own reason when it refuses --resume with an error result", async () => {+ process.env.FAKE_CLAUDE_MODE = "stale-session";+ const logged = vi.spyOn(console, "error").mockImplementation(() => {});+ try {+ await instance.adapter.sendTurn({ threadId: "t-logged-stale", text: "what now?", resumeCursor: "an-outside-session", recoveryText: REBUILD });+ await recorder.until((e) => e.type === "turn.completed");+ const lines = logged.mock.calls.map((call) => String(call[0]));+ expect(lines).toContain("claude (claude-test): could not resume session an-outside-session for thread t-logged-stale, starting a new one: No conversation found with session ID: an-outside-session");+ } finally {+ logged.mockRestore();+ }+ });+it("does not announce a replacement as rebuilt when there was nothing to replay", async () => {const dump = join(scratch, "no-replay.json");process.env.FAKE_CLAUDE_DUMP = dump;diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex e39ae60688..767892c025 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -843,6 +843,8 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {sessionId: string | null;/** `init` arrived; before it the CLI took nothing, so a resume retry is safe */sawInit: boolean;+ /** why the CLI refused `--resume` with an error result instead of exiting, for the log line */+ resumeRefusal?: string;/** the mode `init` reports: the CLI accepts `--permission-mode auto` for any model but runs* "default" silently where auto is unavailable (Haiku 4.5, Sonnet 4.5, an org that disabled it) */nativePermissionMode: string | null;@@ -1589,6 +1591,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {// After a long idle 2.1.295 answers a --resume it no longer has with an error result ("No// conversation found with session ID …") and stays up; end it so its close rebuilds once.if (o.is_error === true && sessionId && !session.sawInit && session.turn && !session.turn.settled) {+ session.resumeRefusal = claudeResultError(o);closeSession(threadId, "resume refused");break;}@@ -1801,6 +1804,8 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {producedOutput: session.turn.sawStreamDelta,});if (mayReplay(resumeFailure) && !retry.cancelled) {+ // Without this line a refused --resume looks like an ordinary new session in the logs.+ console.error(`claude (${instanceId}): could not resume session ${sessionId} for thread ${threadId}, starting a new one: ${session.resumeRefusal ?? message}`);const recovery = recoveryPromptFor({recoveryText: turn.recoveryText,currentText: turn.text,