Dataface Tasks

Detect open PR conflicts after reconcile and auto-rebase safe task branches

IDINFRA_TOOLING-DETECT_OPEN_PR_CONFLICTS_AFTER_RECONCILE_AND_AUTO_REBASE_SAFE_TASK_BRANCHES
Statuscompleted
Priorityp1
Milestonem1-ft-analytics-analyst-pilot
Ownersr-engineer-architect
Completed bydave
Completed2026-03-27

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/mergeability
  • apply_pr_ci_attention() emits pr_conflict when pr_mergeable == CONFLICTING
  • The recent failure on PR #835 showed 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-heartbeat
  • scripts/task_manager_lib.py
  • scripts/task-manager-start
  • tests/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-lease only 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

  1. Extend task-manager PR discovery so reconcile can locate open PR-backed tasks even when root frontmatter is missing or stale.
  2. Add a conflict-check phase after reconcile/startup refresh that probes mergeable/mergeStateStatus for open PRs.
  3. 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
  4. Surface results in snapshot/history: - auto-rebased PRs - escalated conflicted PRs - skipped unsafe branches
  5. Add focused tests for: - stale root metadata but discoverable PR-backed branch - clean stale-branch auto-rebase - rebase failure escalation - dirty worktree skip
  6. 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 carries branch
  • TaskInfo now tracks branch_name
  • discover_pr_backed_tasks() fills pr_number, pr_url, and pr_state from gh 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, and git 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-conflicts
  • scripts/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 13 with 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