Skip to content

Commit 60d76cb

Browse files
FourWindffclaude
authored andcommitted
fix(agent): fallback to fresh start when resume args fail
When a resumed agent exits with a non-zero code and the output indicates a resume-args failure (e.g. Claude's \"No conversation found to continue\"), automatically restart the agent without resume args instead of leaving it in an exited state. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f8db98a commit 60d76cb

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/components/TaskAITerminal.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { createHighlightedMarkdown } from '../lib/marked-shiki';
3030
import type { Task } from '../store/types';
3131
import type { AgentDef } from '../ipc/types';
3232
import type { PromptInputHandle } from './PromptInput';
33-
import { buildTaskAgentArgs } from '../lib/agent-args';
33+
import { buildTaskAgentArgs, isResumeArgsFailure } from '../lib/agent-args';
3434

3535
function aiTerminalPanelId(agentId: string): string {
3636
return `ai-terminal:${agentId}`;
@@ -614,7 +614,19 @@ function AgentTerminalPane(props: {
614614
}
615615
attachExisting={a().attachExisting}
616616
preserveSessionOnCleanup
617-
onExit={(code) => markAgentExited(a().id, code)}
617+
onExit={(code) => {
618+
if (
619+
a().resumed &&
620+
code.exit_code !== 0 &&
621+
isResumeArgsFailure(a().def.command, code.last_output)
622+
) {
623+
// Resume args failed (e.g. Claude's "No conversation to continue");
624+
// fall back to a fresh start with normal args.
625+
restartAgent(a().id, false);
626+
return;
627+
}
628+
markAgentExited(a().id, code);
629+
}}
618630
onData={(data) => markAgentOutput(a().id, data, props.task.id)}
619631
onFileLink={props.onFileLink}
620632
onPromptDetected={(text) => setLastPrompt(props.task.id, text)}

src/lib/agent-args.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ function isAntigravityCommand(command: string): boolean {
99
return command.split('/').pop() === 'agy';
1010
}
1111

12+
const RESUME_FAILURE_PATTERNS: Record<string, string[]> = {
13+
claude: ['No conversation found to continue'],
14+
};
15+
16+
export function isResumeArgsFailure(command: string, lastOutput: string[]): boolean {
17+
const base = command.split('/').pop() ?? command;
18+
const patterns = RESUME_FAILURE_PATTERNS[base];
19+
if (!patterns || lastOutput.length === 0) return false;
20+
const text = lastOutput.join('\n');
21+
return patterns.some((pattern) => text.includes(pattern));
22+
}
23+
1224
function legacyMcpConfigArgs(command: string, mcpConfigPath: string | undefined): string[] {
1325
// Codex and Antigravity have no `--mcp-config` flag; passing it would break launch.
1426
if (!mcpConfigPath || isCodexCommand(command) || isAntigravityCommand(command)) return [];

0 commit comments

Comments
 (0)