Skip to content

fix(agent): fallback to fresh start when resume args fail#180

Merged
johannesjo merged 2 commits into
johannesjo:mainfrom
FourWindff:fix/resume-args-fallback
Jun 17, 2026
Merged

fix(agent): fallback to fresh start when resume args fail#180
johannesjo merged 2 commits into
johannesjo:mainfrom
FourWindff:fix/resume-args-fallback

Conversation

@FourWindff

@FourWindff FourWindff commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

When using Claude Code (which supports session resumption via --continue ) to create a task, if the user closes and restarts the app before any conversation has taken place, the system relaunches the agent using the resume_args defined in AgentDef. Because no session exists to continue, the process exits immediately with No conversation found to continue, forcing the user to manually click the restart button to recover the task.

1. Root Cause

  • After the app restarts, agents in the resumed state are launched with AgentDef.resume_args (for Claude Code this is typically --continue ).
  • If no conversation took place before the restart, Claude Code cannot find a session to resume and exits with an error.
  • The previous implementation had no automatic fallback when an agent exited due to failed resume arguments, leaving the user to manually restart.

2. Solution

This PR adds resume-failure detection in the onExit callback of TaskAITerminal:

  • If the agent is in resumed state, exits with a non-zero code, and its final output matches a known resume-failure signature (e.g. Claude's No conversation found to continue), it automatically calls restartAgent(id, false).
  • Passing false skips resume_args and falls back to AgentDef.args, starting a fresh session without requiring manual intervention.

It also introduces isResumeArgsFailure in src/lib/agent-args.ts to centralize the resume-failure signatures for each CLI, making future extensions easier.

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 <[email protected]>
@johannesjo

Copy link
Copy Markdown
Owner

Review

Nice, focused fix — I traced the full flow and the core logic is correct and, importantly, loop-safe: restartAgent(id, false) sets resumed = false, so if the fresh start also exits non-zero the a().resumed guard is false and it falls through to markAgentExited rather than restarting again. Going straight from running → running (skipping the "exited" state) is the right call for a seamless recovery, and centralizing the signatures in RESUME_FAILURE_PATTERNS is a clean, extensible approach.

A few things worth addressing:

Important

  • Add a unit test for isResumeArgsFailure. It's a pure function and src/lib/agent-args.test.ts already exists right beside it. Suggested cases: claude match, claude no-match, non-claude command (→ false), empty lastOutput (→ false), and a multi-line lastOutput where the pattern is on one of several lines.

Minor

  • Manual "Resume" button now silently falls back too. The new onExit logic also fires when the user explicitly clicks Resume and it fails — the agent restarts fresh with no indication the resume failed. For the app-restart auto-resume case that silence is fine; just worth a conscious decision on whether an explicit Resume click should surface a brief notice.
  • English-string matching is inherently fragile. No conversation found to continue will break if Claude rewrites/localizes the message, and the raw last_output carries ANSI escapes (only \r is stripped in pty.ts). The substring match still works as long as the codes bracket the phrase rather than split it — low risk for a short non-wrapping string — but it's a signature that'll need maintenance. Centralizing it makes that easy, so this is just a flag.
  • code.exit_code !== 0 also matches null (signal kill). Harmless because isResumeArgsFailure must also match, but noting it.

Verdict: Ready to merge once the isResumeArgsFailure test is added.

@johannesjo

Copy link
Copy Markdown
Owner

Thank you very much!

@johannesjo johannesjo merged commit 4e7fb77 into johannesjo:main Jun 17, 2026
2 checks passed
@FourWindff FourWindff deleted the fix/resume-args-fallback branch June 17, 2026 14:16
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