feat: Autopilot graceful degradation with job retry — pause on error instead of hard-fail
Description
When a merge conflict, test failure, or touchSet violation occurs during autopilot plan execution, the orchestrator immediately sets plan.status = 'failed', stops the reconciler, and tears down event subscriptions. The entire plan is dead with no recovery path.
This forces users to choose between:
- Autopilot (hands-off but fragile — one conflict kills everything)
- Supervisor (recoverable but requires babysitting every checkpoint)
There's no middle ground. And even supervisor mode can only pause — there's no mechanism to retry a failed job after fixing it.
Problem (Real-World)
Agents touch files they were told not to. Two parallel jobs edit overlapping files. A transitive dependency causes an unexpected change. In all these cases, autopilot dies and the user must mc_plan_cancel and start over, losing all previously merged work.
Even with the pause (#39 original scope), there's no path from "paused on error" to "fixed and retrying." The reconciler sees the job as failed and immediately fails the plan again on resume.
Proposed Solution
Two parts — both required for actual recovery:
Part 1: Pause on Error (any mode)
On conflict or test failure in autopilot mode, pause instead of fail — the same behavior supervisor mode uses for on_error checkpoints:
Current behavior (autopilot):
conflict → plan.status = 'failed' → reconciler stops → plan is dead
Proposed behavior (autopilot):
conflict → plan.status = 'paused' → checkpoint = 'on_error' → notify user → wait
In orchestrator.ts reconcile(), remove the isSupervisor() gate on conflict/test-failure handlers:
// Current (lines ~521-534):
if (mergeResult.type === 'conflict') {
await updatePlanJob(plan.id, nextJob.name, { status: 'conflict', ... });
if (this.isSupervisor(plan)) {
await this.setCheckpoint('on_error', plan);
return;
}
plan.status = 'failed'; // ← autopilot dies here
}
// Proposed:
if (mergeResult.type === 'conflict') {
await updatePlanJob(plan.id, nextJob.name, { status: 'conflict', ... });
await this.setCheckpoint('on_error', plan); // ← always pause, any mode
return;
}
Same change for the test failure branch (~535-554) and touchSet violations (#16 Phase 1.5).
Part 2: Job Retry on Approve (CRITICAL)
Without this, Part 1 is just a nicer error message. The plan pauses, but resuming immediately hits the same failed job and fails again.
Extend mc_plan_approve to accept a retry parameter:
mc_plan_approve(checkpoint: "on_error", retry: "job-name")
This would:
- Validate the named job exists and is in a retryable state (
failed,conflict) - Reset the job status:
failed/conflict→ready_to_merge - Clear the
errorfield on the job - Clear the checkpoint
- Resume the reconciler
- Merge train re-evaluates the job (re-runs touchSet gate if applicable, attempts merge)
Valid retry transitions:
failed → ready_to_merge (user fixed the branch, retry merge)
conflict → ready_to_merge (user resolved conflicts, retry merge)
Without retry parameter (existing behavior): clears the checkpoint and resumes. If the failed job isn't retried, the reconciler will see it and fail the plan. This preserves backward compatibility — supervisor users who want to acknowledge-and-fail can still do so.
Part 2b: Re-launch option (stretch)
For cases where the job's work is fundamentally wrong (not just out-of-scope files), the user may want to re-run the job entirely:
mc_plan_approve(checkpoint: "on_error", relaunch: "job-name")
This would:
- Kill the job's tmux session if still alive
- Reset job branch to integration HEAD
- Reset job status:
failed→queued - Clear checkpoint, resume reconciler
- Reconciler re-launches the job from scratch
This is a stretch goal — retry covers the common case where the agent did 90% right and just needs a branch fix.
Example Flow
mc_plan(name: "notifications", mode: "autopilot", jobs: [
{ name: "schema", touchSet: ["src/db/**"], ... },
{ name: "api", touchSet: ["src/api/notifications/**"], dependsOn: ["schema"], ... },
{ name: "ui", touchSet: ["src/components/notifications/**"], dependsOn: ["api"], ... }
])
schema → completes → merges ✅
api → completes → touchSet gate rejects (agent edited src/db/schema.ts)
plan pauses, user notified
User fixes api branch (reverts out-of-scope changes)
mc_plan_approve(checkpoint: "on_error", retry: "api")
api → touchSet gate ✅ → merges ✅
ui → launches → completes → merges ✅
PR created
Without retry:
User fixes api branch
mc_plan_approve(checkpoint: "on_error")
reconciler resumes → sees api: "failed" → plan.status = 'failed'
User must mc_plan_cancel and start over, losing schema's merged work
Implementation
Files
src/lib/orchestrator.ts- Remove
isSupervisor()gate onsetCheckpoint('on_error', ...)for conflict and test failure - Add
retryJob(planId, jobName)method that resets job status
- Remove
src/tools/plan-approve.ts- Add
retryparameter (optional string — job name) - Call
orchestrator.retryJob()before resuming
- Add
src/lib/plan-types.ts- Verify
failed → ready_to_mergeandconflict → ready_to_mergeare valid transitions (add if missing)
- Verify
- Tests — verify:
- Autopilot plans pause on conflict instead of failing
mc_plan_approvewithretryresets job and resumes successfullymc_plan_approvewithoutretrypreserves existing behavior
Schema change for plan-approve
args: {
checkpoint: tool.schema.enum(['pre_merge', 'on_error', 'pre_pr']).optional(),
retry: tool.schema.string().optional().describe('Job name to retry (resets failed/conflict → ready_to_merge)'),
}
Relationship to Other Issues
- #16 (touchSet enforcement) — defines the gate that rejects jobs. This issue defines what happens after rejection.
- #36 (needs_rebase) — early conflict detection. If rebase fails, the job hits this same pause → retry flow.
- #35 (pre-merge rebase on mc_merge) — standalone merge improvement, not plan-specific.
Together: #16 prevents → #36 detects early → #39 recovers.
Priority
P1 — Without retry, every other conflict-handling improvement (#16, #36) just produces better error messages before the plan dies anyway. This is the only issue that actually enables recovery.