factory design: host scheduling — capacity semaphore, per-repo fairness, drive-vs-worker serialization #577

Closed
opened 2026-08-15 06:01:34 +00:00 by ben · 2 comments
Owner

Problem — the host lock is the multi-project wall

/tmp/matou-swarm.lock admits one heavy worker per host across ALL repos. Two repos already produced documented hour-class starvation (the yield-don't-camp fix in swarm.yml:46-59 mitigates, doesn't remove); project #3 triples the queue behind one mutex.

Separately, nothing serializes a 1–3 h rehearsal drive against the other workstation workers: rehearsal-cycle.sh:12-13's comment claims "never beside a swarm run", but the code only takes /tmp/matou-rehearsal-drive.lock — the hourly healer and the */10 session-runner can land mid-drive on the same host, sharing nothing but the Claude-limit marker.

Design to rule on

  • replace the single flock with a host capacity semaphore (N slots, declared weight classes: swarm worker = heavy, drive = heavy + long, healer/session-runner = light?)
  • per-repo fairness so one project's deep queue can't starve another's hour-class work
  • decide what a drive excludes (everything heavy? everything Claude-consuming? nothing, given the limit marker?)
  • keep the property the flock bought: fail-closed, yield-don't-camp, zero lock server

Needs Ben: the concurrency policy is a genuine ruling (capacity per host, what coexists with a drive), and it interacts with the two-account token reality. Survey: docs/research/2026-08-15-factory-reengineering-survey.md §scheduling.

## Problem — the host lock is the multi-project wall `/tmp/matou-swarm.lock` admits **one heavy worker per host across ALL repos**. Two repos already produced documented hour-class starvation (the yield-don't-camp fix in `swarm.yml:46-59` mitigates, doesn't remove); project #3 triples the queue behind one mutex. Separately, **nothing serializes a 1–3 h rehearsal drive against the other workstation workers**: `rehearsal-cycle.sh:12-13`'s comment claims "never beside a swarm run", but the code only takes `/tmp/matou-rehearsal-drive.lock` — the hourly healer and the */10 session-runner can land mid-drive on the same host, sharing nothing but the Claude-limit marker. ## Design to rule on - replace the single flock with a **host capacity semaphore** (N slots, declared weight classes: swarm worker = heavy, drive = heavy + long, healer/session-runner = light?) - **per-repo fairness** so one project's deep queue can't starve another's hour-class work - decide what a drive excludes (everything heavy? everything Claude-consuming? nothing, given the limit marker?) - keep the property the flock bought: fail-closed, yield-don't-camp, zero lock server **Needs Ben:** the concurrency policy is a genuine ruling (capacity per host, what coexists with a drive), and it interacts with the two-account token reality. Survey: `docs/research/2026-08-15-factory-reengineering-survey.md` §scheduling.
Author
Owner

Ben ruled (2026-08-19, live session): the factory block is delegated under ADR 0174 — dispatched to the agent/session lanes with dependency edges wired; veto via the tracker anytime.

Ben ruled (2026-08-19, live session): the factory block is delegated under ADR 0174 — dispatched to the agent/session lanes with dependency edges wired; veto via the tracker anytime.

Ruled by agent under ADR 0174 — veto anytime.

Ben's delegation on this ticket ("the factory block is delegated under ADR
0174 — dispatched to the agent/session lanes with dependency edges wired;
veto via the tracker anytime") made the concurrency policy itself a two-way
door: revertible by commit/config, provable by offline tests plus a live
probe. Full reasoning: docs/adr/0184-host-capacity-is-a-two-slot-pool-not-a-single-lock.md.

Capacity semaphore: 2 pooled heavy slots (/tmp/matou-swarm.lock kept as
slot 1 for cross-repo backward compatibility, new /tmp/matou-host-slot-2.lock
as slot 2), first-fit non-blocking, still yield-don't-camp (#238). Sized to
the #510 two-account reality — never more concurrent heavy Claude-burners than
accounts — not to RAM headroom alone.

Per-repo fairness: rides the pool itself. The documented starvation
pattern was sequential re-triggering of one slot (a deep queue's cron ticks +
label/close events out-racing a sibling repo's tick), which 1→2 pooled slots
fixes directly with no repo-affinity logic. A dedicated-lane-per-repo registry
was considered and rejected — no existing home (workflow YAML is copy-per-repo,
.sandcastle/ vendoring is deliberately repo-agnostic per ADR 0180) and more
complexity than the evidence calls for. Named fallback if this proves
insufficient: cap swarm.yml's matrix width to structurally limit one repo to
1 held slot.

Drive-vs-worker serialization: a drive now excludes EVERYTHING heavy,
host-wide, for its whole run — scripts/lib/host-capacity-lib.sh's
host_capacity_acquire_exclusive grabs both pooled slots plus
session-runner's and the ourcloud healer's own existing locks, all-or-nothing,
non-blocking. This closes the exact gap named in the ticket (drive shared
nothing with the healer/session-runner but the Claude-limit marker) without
touching either vendored file — it grabs their existing lock files from the
outside.

Proof: scripts/tests/host-capacity-lib-test.sh (6 offline groups: first-fit,
fallthrough, pool-exhausted yield, release-and-reacquire, exclusive-acquire-
all-free, exclusive-acquire-partial-failure-releases-everything — all green),
.sandcastle/tests/host-capacity-yield-test.sh (4 groups mirroring the
workflow-embedded snippet, all green), plus two live probes this session on
matou-workstation: a real flock -n on both real slot paths, and
rehearsal-cycle.sh's exclusive-acquire correctly detecting THIS session's
own live /tmp/matou-session-runner.lock and yielding in <1s with zero
residue.

Deferred, filed as #605: session-runner and the healer formally joining
the pool as participants (not just exclusion targets) against swarm/triage —
needs editing .sandcastle/session-runner.sh/heal.sh, both vendored
byte-identical from Matou/dev-factory (ADR 0180), a separate cross-repo
two-way door out of this ticket's safe blast radius.

Close-report

Landed (9c235a0, pushed to main): scripts/lib/host-capacity-lib.sh
(new), scripts/tests/host-capacity-lib-test.sh (new, 6 groups green),
.sandcastle/tests/host-capacity-yield-test.sh (new, 4 groups green),
.forgejo/workflows/swarm.yml + triage.yml (2-slot lock block),
scripts/rehearsal-cycle.sh (exclusive-acquire wired in), docs/adr/0184-*.md
(this ruling), docs/GOTCHAS.md #44 (new — the #469 restart procedure only
held slot 1, silently stopped proving quiescence once slot 2 exists; fixed in
the same commit, .forgejo/runner/README.md's restart command now nests both
flocks), docs/agents/swarm-atlas.md + .sandcastle/README.md updated,
STATUS.md updated. No vendored .sandcastle/ files touched (ADR 0180
respected). git pull --rebase was clean, pushed to main directly (no
conflicts).

Not done, tracked as #605: session-runner/healer pool participation
(needs Matou/dev-factory).

Closing #577 — the three items in "Design to rule on" are addressed (capacity
semaphore, per-repo fairness, drive-vs-worker serialization); the remaining
residue is scoped, tested-as-far-as-possible, and tracked separately.

Ruled by agent under ADR 0174 — veto anytime. Ben's delegation on this ticket ("the factory block is delegated under ADR 0174 — dispatched to the agent/session lanes with dependency edges wired; veto via the tracker anytime") made the concurrency policy itself a two-way door: revertible by commit/config, provable by offline tests plus a live probe. Full reasoning: `docs/adr/0184-host-capacity-is-a-two-slot-pool-not-a-single-lock.md`. **Capacity semaphore:** 2 pooled heavy slots (`/tmp/matou-swarm.lock` kept as slot 1 for cross-repo backward compatibility, new `/tmp/matou-host-slot-2.lock` as slot 2), first-fit non-blocking, still yield-don't-camp (#238). Sized to the #510 two-account reality — never more concurrent heavy Claude-burners than accounts — not to RAM headroom alone. **Per-repo fairness:** rides the pool itself. The documented starvation pattern was sequential re-triggering of one slot (a deep queue's cron ticks + label/close events out-racing a sibling repo's tick), which 1→2 pooled slots fixes directly with no repo-affinity logic. A dedicated-lane-per-repo registry was considered and rejected — no existing home (workflow YAML is copy-per-repo, `.sandcastle/` vendoring is deliberately repo-agnostic per ADR 0180) and more complexity than the evidence calls for. Named fallback if this proves insufficient: cap `swarm.yml`'s matrix width to structurally limit one repo to 1 held slot. **Drive-vs-worker serialization:** a drive now excludes EVERYTHING heavy, host-wide, for its whole run — `scripts/lib/host-capacity-lib.sh`'s `host_capacity_acquire_exclusive` grabs both pooled slots plus session-runner's and the ourcloud healer's own existing locks, all-or-nothing, non-blocking. This closes the exact gap named in the ticket (drive shared nothing with the healer/session-runner but the Claude-limit marker) without touching either vendored file — it grabs their existing lock files from the outside. **Proof:** `scripts/tests/host-capacity-lib-test.sh` (6 offline groups: first-fit, fallthrough, pool-exhausted yield, release-and-reacquire, exclusive-acquire- all-free, exclusive-acquire-partial-failure-releases-everything — all green), `.sandcastle/tests/host-capacity-yield-test.sh` (4 groups mirroring the workflow-embedded snippet, all green), plus two live probes this session on matou-workstation: a real `flock -n` on both real slot paths, and `rehearsal-cycle.sh`'s exclusive-acquire correctly detecting THIS session's own live `/tmp/matou-session-runner.lock` and yielding in <1s with zero residue. **Deferred, filed as #605:** session-runner and the healer formally joining the pool as participants (not just exclusion targets) against swarm/triage — needs editing `.sandcastle/session-runner.sh`/`heal.sh`, both vendored byte-identical from `Matou/dev-factory` (ADR 0180), a separate cross-repo two-way door out of this ticket's safe blast radius. ## Close-report **Landed** (`9c235a0`, pushed to main): `scripts/lib/host-capacity-lib.sh` (new), `scripts/tests/host-capacity-lib-test.sh` (new, 6 groups green), `.sandcastle/tests/host-capacity-yield-test.sh` (new, 4 groups green), `.forgejo/workflows/swarm.yml` + `triage.yml` (2-slot lock block), `scripts/rehearsal-cycle.sh` (exclusive-acquire wired in), `docs/adr/0184-*.md` (this ruling), `docs/GOTCHAS.md` #44 (new — the #469 restart procedure only held slot 1, silently stopped proving quiescence once slot 2 exists; fixed in the same commit, `.forgejo/runner/README.md`'s restart command now nests both flocks), `docs/agents/swarm-atlas.md` + `.sandcastle/README.md` updated, `STATUS.md` updated. No vendored `.sandcastle/` files touched (ADR 0180 respected). `git pull --rebase` was clean, pushed to `main` directly (no conflicts). **Not done**, tracked as #605: session-runner/healer pool participation (needs `Matou/dev-factory`). Closing #577 — the three items in "Design to rule on" are addressed (capacity semaphore, per-repo fairness, drive-vs-worker serialization); the remaining residue is scoped, tested-as-far-as-possible, and tracked separately.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#577
No description provided.