Detect open PR conflicts after reconcile and auto-rebase safe task branches
Problem
Extend task-manager reconcile so it discovers open PR-backed tasks even when root frontmatter is stale, probes mergeability after cleanup/startup checks, auto-rebases clean stale-branch conflicts onto main when safe, and escalates true semantic conflicts that need manual resolution.
Context
- Current conflict detection already exists in
scripts/task_manager_lib.py: refresh_pr_ci_for_tasks()probes GitHub PR state/CI/mergeabilityapply_pr_ci_attention()emitspr_conflictwhenpr_mergeable == CONFLICTING- The recent failure on PR
#835showed the actual gap: - the worktree task file had PR metadata and GitHub reported a conflicted PR
- the root task file still had no
pr_number - heartbeat therefore never probed mergeability for that task at all
- The new auto-reconcile and startup/post-pull reconcile work should reduce stale root metadata, but open PR conflict handling still needs a dedicated pass.
- Relevant files likely include:
scripts/task-manager-heartbeatscripts/task_manager_lib.pyscripts/task-manager-starttests/scripts/test_task_manager_scripts.py- Constraint: automatic repair must be narrow and safe. It should auto-rebase only when the branch is clean and the conflict is clearly a stale-base problem. True semantic conflicts should become explicit attention/escalation, not silent rewrite attempts.
Possible Solutions
- Option 1: Detect conflicts only and leave rebases fully manual. Low risk, but it preserves operator toil and leaves easy stale-base conflicts sitting around. Rejected.
- Option 2: Recommended Add a post-reconcile PR-conflict pass that:
- discovers open PR-backed tasks from root metadata, register/worktree state, and dispatch artifacts
- probes mergeability for open PRs after reconcile/startup checks
- attempts an automatic
git fetch && git rebase origin/main && push --force-with-leaseonly when the task branch/worktree is clean and the rebase applies without manual conflict resolution - emits explicit escalation when rebase fails or the branch has local drift This addresses the common stale-branch case while keeping real conflicts visible.
- Option 3: Attempt full automatic conflict resolution for all task PRs. Too risky for hot task-manager files and active task worksheets; likely to create silent bad merges. Rejected.
Plan
- Extend task-manager PR discovery so reconcile can locate open PR-backed tasks even when root frontmatter is missing or stale.
- Add a conflict-check phase after reconcile/startup refresh that probes
mergeable/mergeStateStatusfor open PRs. - Implement a narrow auto-rebase helper for safe cases only:
- clean branch/worktree
- open PR against
main- no uncommitted changes - rebase succeeds without manual conflict resolution - Surface results in snapshot/history: - auto-rebased PRs - escalated conflicted PRs - skipped unsafe branches
- Add focused tests for: - stale root metadata but discoverable PR-backed branch - clean stale-branch auto-rebase - rebase failure escalation - dirty worktree skip
- Document operator expectations so people know which conflicts will self-heal and which still require manual takeover.
Implementation Progress
- Added PR discovery by branch/worktree state when root frontmatter is stale:
inspect_dispatch()now carriesbranchTaskInfonow tracksbranch_namediscover_pr_backed_tasks()fillspr_number,pr_url, andpr_statefromgh pr list --head <branch>- Added narrow safe auto-rebase helper:
auto_rebase_conflicted_pr_tasks()only acts on open conflicted PRs- requires an existing clean task worktree
- runs
git fetch origin main,git rebase origin/main, andgit push --force-with-lease - skips dirty or missing worktrees and records attention instead of guessing
- Added a standalone operator command:
scripts/task-manager-reconcile-pr-conflictsscripts/task-system/reconcile-pr-conflicts- Added focused tests for:
- stale-root PR discovery from dispatch branch metadata
- clean auto-rebase path
- dirty-worktree skip path
- Trialed the command against task
auto-reconcile-merged-prs-and-orphaned-in-progress-tasks-in-task-manager/ PR#835: - PR discovery succeeded
- safe auto-rebase did not run because the task worktree is dirty (
ahead 19, behind 13with tracked deletions) - this is the intended first-pass safety behavior; the tool currently avoids discarding uncommitted task work
QA Exploration
- [x] QA exploration completed (or N/A for non-UI tasks)
- N/A: backend/orchestration task
Review Feedback
- [ ] Review cleared