Dataface Tasks

Add startup and post-pull task-manager reconcile hooks

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

Problem

Add a second-stage reconciliation command/hook that runs at manager startup and after git pull to prune stale register entries, archive stale dispatch status files, and refresh root task metadata from durable PR/runtime state instead of relying only on the heartbeat loop.

Context

  • Heartbeat is currently the only regular cleanup trigger.
  • That means stale state can survive whenever:
  • a repo is pulled forward outside the manager loop
  • merged PR metadata lands after the last heartbeat cycle
  • register/dispatch residue accumulates while no ready task is being picked up
  • A separate reconcile command/hook would give the manager a second repair path on startup and after repo sync.
  • Relevant files likely include:
  • scripts/task-manager-start
  • scripts/task-manager-run
  • scripts/task-manager-heartbeat
  • a new scripts/task-manager-reconcile or scripts/task-system/reconcile
  • This task should build on the auto-reconcile logic, not duplicate it.

Possible Solutions

  • Option 1: Keep cleanup only inside heartbeat. Simplest, but it leaves startup/pull transitions fragile and allows stale state to persist longer than necessary. Rejected.
  • Option 2: Recommended Add a dedicated reconcile command and invoke it:
  • once on manager startup
  • once after a successful git pull/repo refresh path
  • optionally on demand for operators This keeps repair logic reusable and avoids duplicating cleanup behavior across shell scripts.
  • Option 3: Fold all reconcile work directly into task-manager-start and task-manager-run scripts. Less indirection, but harder to test and reuse.

Plan

  1. Add a dedicated reconcile entrypoint that reuses task-manager library cleanup logic.
  2. Call it from startup and post-pull manager paths.
  3. Ensure it is safe to run repeatedly and produces operator-readable output.
  4. Add tests around startup/post-pull invocation behavior.
  5. Document when operators should still run manual reconcile.

Implementation Progress

Files created

  • scripts/task-manager-reconcile — standalone Python script that runs all four reconcile steps (auto-complete merged PRs, auto-demote orphaned in_progress, prune stale register entries, clear stale dispatch state) in a single idempotent pass. Supports --owner, --idle-seconds, --format text|json.
  • scripts/task-system/reconcile — canonical namespace shim.

Files modified

  • scripts/task-manager-start — calls task-manager-reconcile synchronously before launching the heartbeat background process, so stale state from a previous session is cleaned up on startup.
  • scripts/task-manager-run — calls task-manager-reconcile once before entering the heartbeat loop, covering the case where the run script is invoked directly.
  • scripts/task-system/README.md — added reconcile to the canonical command list.
  • tests/scripts/test_task_manager_scripts.py — 6 new subprocess-level tests covering merged-PR completion, orphan demotion, register pruning, dispatch cleanup, text output, and idempotency. Added task-manager-reconcile to _make_repo copy list.

Key decisions

  • Reuses all existing auto_* and reconcile_register_orphans functions from task_manager_lib — no duplication.
  • The reconcile script is safe to run repeatedly (all operations are idempotent).
  • Startup integration uses check=False so a reconcile failure doesn't block the manager from starting.
  • Tests use a fake gh binary for PR-state tests and TASK_MANAGER_PR_CI_CHECK=0 for non-PR tests.

QA Exploration

  • [x] QA exploration completed (or N/A for non-UI tasks)
  • N/A: backend/orchestration task

Review Feedback

  • [x] Review cleared