feat: Activate needs_rebase job status for early conflict detection in plans
Description
plan-types.ts defines a needs_rebase job status with the transition merged → needs_rebase, but the orchestrator never uses it. This status was scaffolded for early conflict detection but never implemented.
Current State
// src/lib/plan-types.ts
export type JobStatus = ... | 'needs_rebase' | ...;
export const VALID_JOB_TRANSITIONS: Record<JobStatus, JobStatus[]> = {
merged: ['needs_rebase'], // defined
needs_rebase: ['ready_to_merge', ...], // defined
};
The orchestrator goes directly from completed → ready_to_merge → merging → merged without any pre-merge conflict check.
Proposed Design
Before enqueueing a ready_to_merge job into the merge train, attempt a trial rebase:
-
In the reconciler, when a job reaches
ready_to_merge:- Attempt
git rebase <integrationBranch>in the job's worktree (dry-run or real) - If conflicts → set status to
needs_rebase, emit notification with conflict details - If clean → proceed to
mergingas normal
- Attempt
-
needs_rebasejobs can be resolved by:- Running
mc_sync(targeting the integration branch) to resolve conflicts - Then transitioning back to
ready_to_merge
- Running
-
In supervisor mode,
needs_rebasecould trigger a checkpoint for manual review.
Benefits
- Catches conflicts before the merge train, not during it
- Gives clearer error messages (conflict in job X vs. merge train failure)
- Makes the existing type system actually functional
Files
src/lib/orchestrator.ts— add pre-merge rebase check in reconcilersrc/tools/sync.ts— extend to accept explicitbaseReffor syncing against integration branchsrc/lib/plan-types.ts— already has the types, no changes needed
Depends On
- mc_sync fix (targeting correct base ref) — needed so
mc_synccan target the integration branch - Plan jobs from integration HEAD — reduces the likelihood of needing rebase in the first place
Dependency note: If the trial rebase fails and the job is marked needs_rebase, the user currently has no way to fix the branch and retry within the plan. #39 adds the retry mechanism (mc_plan_approve(retry: "job-name")) that makes this status actionable. Without #39, needs_rebase is a dead-end — the plan fails with a better error message but still dies.