Generalize same-agent repair for conflicted, CI-red, and unreconciled task PRs
Problem
Extend the agent-before-human escalation pattern from conflicted PRs to also cover CI-red and dispatch-completed-unreconciled states, so the task manager dispatches a targeted repair agent before escalating to a human.
Context
resume_conflicted_pr_via_agent()inscripts/task_manager_lib.pyalready implements the pattern for conflicted PRs: dispatch a targeted agent to the existing worktree, collect results (agent_resolved/agent_failed/agent_skipped), escalate to human on failure.- CI-red PRs are detected by
apply_pr_ci_attention()which adds aneeds_attentionline but no escalation code and no agent repair attempt. The task has a worktree and a PR — an agent can read CI failures and attempt fixes. - Unreconciled tasks are detected by
detect_dispatch_completed_unreconciled()with codedispatch_completed_unreconciled. The dispatch exited 0 but the task wasn't marked completed — an agent can review the worktree and reconcile. - The
scripts/dispatchscript supports--pathto reuse an existing worktree, so all three repair types use the same dispatch infrastructure. - Agent repair must remain opt-in (
--agent-resolveflag) — not every caller wants subprocess spawns. - Relevant files:
scripts/task_manager_lib.py— repair functions, prompts,_note_attention()scripts/task-manager-reconcile-pr-conflicts— CLI for conflict repair (already has--agent-resolve)scripts/task-manager-heartbeat— main loop (no agent repair yet)tests/scripts/test_task_manager_scripts.py— test suite
Possible Solutions
- Option 1: Keep current behavior — agent repair for conflicts only, passive monitoring for CI-red and unreconciled. Simple but leaves two common failure states requiring human intervention for issues agents can fix. Rejected.
- Option 2: Recommended Add
resume_ci_red_pr_via_agent()andresume_unreconciled_via_agent()following the same pattern asresume_conflicted_pr_via_agent(): - Each gets a narrow, targeted prompt
- Each dispatches to the existing worktree via
scripts/dispatch - On success → recorded as
agent_resolved, no human escalation - On failure/timeout → escalated with a distinct
_needs_humancode at tier1 - Wire into a new
scripts/task-manager-reconcile-ci-redscript and extendscripts/task-manager-reconcile-pr-conflictsoutput for the combined view - Controlled by
--agent-resolveflag (opt-in) - Option 3: Build a single generic
resume_via_agent()that takes a prompt and filter predicate. Elegant but premature — each failure type has different candidate selection, different prompts, and different escalation codes. Keep them separate for now. Rejected.
Plan
- Write failing tests for
resume_ci_red_pr_via_agent(): - Agent succeeds →agent_resolved, no escalation - Agent fails →ci_red_needs_humantier1 escalation - Agent times out → same escalation - No worktree → skipped - Write failing tests for
resume_unreconciled_via_agent(): - Agent succeeds →agent_resolved, no escalation - Agent fails →unreconciled_needs_humantier1 escalation - No worktree → skipped - Implement
resume_ci_red_pr_via_agent()with_CI_RED_RESOLVE_PROMPT. - Implement
resume_unreconciled_via_agent()with_UNRECONCILED_RESOLVE_PROMPT. - Add
ci_red_needs_humanandunreconciled_needs_humanto escalation code inapply_pr_ci_attention(). - Wire CI-red repair into
scripts/task-manager-reconcile-pr-conflictsbehind--agent-resolve. - Run focused tests and validate task file.
Implementation Progress
Files modified
scripts/task_manager_lib.py— Added two new agent-repair functions:resume_ci_red_pr_via_agent(tasks)— dispatches agent to fix CI failures with_CI_RED_RESOLVE_PROMPT. On failure/timeout escalates withci_red_needs_humantier1.resume_unreconciled_via_agent(tasks)— dispatches agent to reconcile tasks where dispatch exited 0 but task not completed, using_UNRECONCILED_RESOLVE_PROMPT. On failure/timeout escalates withunreconciled_needs_humantier1.scripts/task-manager-reconcile-pr-conflicts— Extended to call all three agent-repair functions (conflicts, CI-red, unreconciled) when--agent-resolveis passed. Added helper functions_empty_agent_results()and_merge_agent_results()to combine results.scripts/escalation_lib.py— AddedCI_RED_NEEDS_HUMANandUNRECONCILED_NEEDS_HUMANfailure modes, signal-to-mode mappings, classification priority entries, andESCALATE_HUMANaction recommendations.tests/scripts/test_task_manager_scripts.py— 9 new tests:- 5 for
resume_ci_red_pr_via_agent: success, failure escalation, timeout escalation, no worktree skip, non-failure skip - 4 for
resume_unreconciled_via_agent: success, failure escalation, no worktree skip, non-exited skip
Key decisions
- All agent repair remains opt-in (
--agent-resolveflag) — no change to default heartbeat behavior - Each failure type gets its own function with a narrow, targeted prompt rather than a generic dispatch
- New escalation codes (
ci_red_needs_human,unreconciled_needs_human) are distinct from existing codes so triage can differentiate "agent tried and failed" from "no agent attempt" - CI-red prompt includes the specific failing check names for agent context
- Unreconciled prompt instructs agent to either complete the task or create the PR
QA Exploration
- [x] QA exploration completed (or N/A for non-UI tasks)
- N/A: backend/orchestration task — no UI changes
Review Feedback
- [ ] Review cleared