parallel-code
parallel-code copied to clipboard
fix(agent): fallback to fresh start when resume args fail
Summary
When using an Agent CLI that supports session resumption (like Claude Code) to create a Task, if the user closes and restarts the app without having any conversation first, the system relaunches the Agent using the resume_args defined in AgentDef. Since there is no existing session 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
resumedstate are launched withAgentDef.resume_args(for Claude Code this is typically--continueor equivalent). - If no actual conversation happened before the restart, the CLI 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
resumedstate, exits with a non-zero code, and its final output matches a known resume-failure signature (e.g. Claude'sNo conversation found to continue), it automatically callsrestartAgent(id, false). - Passing
falseskipsresume_argsand falls back toAgentDef.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.