Multi-Loop Coordination

July 27, 2026 · View on GitHub

Running more than one loop in a repo is normal. Running them without boundaries is how loops fight each other.

Principles

  1. One owner per branch — at most one loop may mutate a branch per hour.
  2. Separate state filesSTATE.md for triage; pattern-specific files for action loops.
  3. Triage reports, action loops execute — Daily Triage at L1 never competes with CI Sweeper fixes.
  4. Shared denylist — copy the same path denylist into every LOOP.md.
  5. Aggregate token budget — see templates/loop-budget.md.template.
STATE.md                    # Daily Triage (priorities, human inbox)
pr-babysitter-state.md      # PR watcher
ci-sweeper-state.md         # Active CI failures + attempt counts
dependency-sweeper-state.md # In-flight package updates
post-merge-state.md         # Cleanup backlog
loop-run-log.md             # Append-only observability

Priority when loops conflict

PriorityLoopReason
1CI SweeperRed main blocks everything
2PR BabysitterActive PRs are time-sensitive
3Dependency SweeperPause while CI red
4Post-Merge CleanupOff-peak, lowest urgency
5Daily TriageReports only at L1; schedules others

Scheduler coordination

Document in root LOOP.md:

## Multi-loop schedule
- CI Sweeper: /loop 15m (active hours)
- PR Babysitter: /loop 10m (active hours, skip if CI Sweeper acting on same PR)
- Daily Triage: /loop 1d 08:00
- Dependency Sweeper: /loop 6h (skip if main CI red)
- Post-Merge: /loop 1d 22:00

Collision detection

Each action loop should write acting_on: branch-or-pr-id in its state file. Before spawning a fix:

  1. Read all other pattern state files
  2. If another loop acting_on matches → skip and log to loop-run-log.md

loop-worktree codifies this as an advisory lock instead of a hand-checked convention: a loop's control script runs loop-worktree lock --paths <globs> --owner <pattern> before spawning a worktree, and loop-worktree unlock --owner <pattern> once done. loop-worktree create does not check locks itself — the two stay paired by convention in the control script, the same way loop-context --check and loop-worktree mark --status escalated are paired.

loop-sandbox follows the same convention through its own --lock-paths option, since a one-shot sandboxed agent run is just another kind of control script that can collide with a scheduled loop's files. It is opt-in — an unadorned loop-sandbox run is not lock-protected.

Human inbox

Use a shared section in STATE.md:

## Human Inbox (ambiguous / cross-loop)
- [ ] PR #42: CI Sweeper and PR Babysitter both flagged — human pick owner

Example: safe three-loop setup

LoopLevelCadence
Daily TriageL11d
PR BabysitterL210m
Post-Merge CleanupL1 → L21d off-peak

Add CI Sweeper only after PR Babysitter attempt limits and verifier are proven for two weeks.

See stories/multi-loop-collision.md and stories/dependency-vs-ci-sweeper-collision.md for real-world collision stories.