ADR 0184's all-or-nothing capacity acquire starves the rehearsal drive — the executor needs a RESERVATION, not a retry #663

Closed
opened 2026-08-22 12:38:33 +00:00 by ben · 4 comments
Owner

Recurrence (the trigger to ticket this)

Observed again 2026-08-22 on the widened phase-3 drive #657: three consecutive */2 ticks fired and immediately withdrew —

executor: #657 is ready and unblocked — firing the drive
rehearsal: host capacity busy (a swarm/triage/session-runner/healer run holds a slot) — skipping this firing

No drive directory was created; the drive simply did not run. Prior occurrence measured ~100 minutes of starvation across ~50 skipped ticks under a busier queue. Two occurrences is the bar this was left at ("no reservation exists; ticket it if it recurs").

Mechanism

host_capacity_acquire_exclusive (#577 / ADR 0184) needs all of /tmp/matou-swarm.lock, /tmp/matou-host-slot-2.lock and /tmp/matou-session-runner.lock free, and never camps — it yields immediately. The swarm, by contrast, takes its lock and holds it for a whole worker run. So the contest is not fair: the swarm always wins a lock it already holds, and the drive re-loses every 2 minutes for as long as the swarm has any workable ticket. There is no queue, no ageing, and no reservation — only an unbounded retry.

The drive is also the expensive, long-latency side of the contest (a paid droplet, tens of minutes), and it is the only actor that can prove a phase. Starving it in favour of short worker runs inverts the intended priority.

Why priority does NOT solve this (ruled out during triage)

Worth recording so the obvious fix is not re-attempted: the priority label orders the swarm's ticket claim (claim-next-task.sh, priority-first). It has no bearing on the host-capacity lock. And a standing drive is structurally invisible to the swarm anyway — .sandcastle/list-ready-tasks.sh:80 excludes the standing-drive label by construction (GOTCHAS #23). Labelling the drive ticket cannot influence which process holds the lock.

What plugging it needs

A reservation, so a ready drive stops losing to work that starts after it declared. Sketch, cheapest first:

  1. Intent file. The executor writes /tmp/matou-drive-wanted when it fires and unlinks it on completion/abandon. run-swarm.sh / triage / session-runner check it before claiming a NEW task and decline to start (in-flight runs finish untouched — no work is killed). The drive then wins as soon as the current worker drains, bounded by one worker run instead of unbounded.
  2. Bounded camp. The executor waits up to N minutes for the slot rather than yielding instantly — simpler, but it holds an executor process and still loses to a swarm that re-claims quickly.
  3. Ageing. Track consecutive skipped ticks; after K skips the drive takes precedence. Most faithful to "the drive is the expensive side", most code.

(1) is preferred: it is a single file, it never interrupts running work, and it makes the starvation bound explicit and observable.

Whatever lands must emit the skip reason with a COUNT — skipped N consecutive ticks — because the current log line is indistinguishable at tick 3 and tick 50, which is exactly why this went unnoticed for ~100 minutes the first time.

## Recurrence (the trigger to ticket this) Observed again 2026-08-22 on the widened phase-3 drive #657: three consecutive `*/2` ticks fired and immediately withdrew — ``` executor: #657 is ready and unblocked — firing the drive rehearsal: host capacity busy (a swarm/triage/session-runner/healer run holds a slot) — skipping this firing ``` No drive directory was created; the drive simply did not run. Prior occurrence measured **~100 minutes of starvation across ~50 skipped ticks** under a busier queue. Two occurrences is the bar this was left at ("no reservation exists; ticket it if it recurs"). ## Mechanism `host_capacity_acquire_exclusive` (#577 / ADR 0184) needs **all** of `/tmp/matou-swarm.lock`, `/tmp/matou-host-slot-2.lock` and `/tmp/matou-session-runner.lock` free, and **never camps** — it yields immediately. The swarm, by contrast, takes its lock and holds it for a whole worker run. So the contest is not fair: the swarm always wins a lock it already holds, and the drive re-loses every 2 minutes for as long as the swarm has *any* workable ticket. There is no queue, no ageing, and no reservation — only an unbounded retry. The drive is also the expensive, long-latency side of the contest (a paid droplet, tens of minutes), and it is the only actor that can prove a phase. Starving it in favour of short worker runs inverts the intended priority. ## Why `priority` does NOT solve this (ruled out during triage) Worth recording so the obvious fix is not re-attempted: the `priority` label orders the **swarm's ticket claim** (`claim-next-task.sh`, priority-first). It has no bearing on the host-capacity lock. And a standing drive is *structurally invisible* to the swarm anyway — `.sandcastle/list-ready-tasks.sh:80` excludes the `standing-drive` label by construction (GOTCHAS #23). Labelling the drive ticket cannot influence which process holds the lock. ## What plugging it needs A reservation, so a ready drive stops losing to work that starts *after* it declared. Sketch, cheapest first: 1. **Intent file.** The executor writes `/tmp/matou-drive-wanted` when it fires and unlinks it on completion/abandon. `run-swarm.sh` / triage / session-runner check it before claiming a NEW task and decline to start (in-flight runs finish untouched — no work is killed). The drive then wins as soon as the current worker drains, bounded by one worker run instead of unbounded. 2. **Bounded camp.** The executor waits up to N minutes for the slot rather than yielding instantly — simpler, but it holds an executor process and still loses to a swarm that re-claims quickly. 3. **Ageing.** Track consecutive skipped ticks; after K skips the drive takes precedence. Most faithful to "the drive is the expensive side", most code. (1) is preferred: it is a single file, it never interrupts running work, and it makes the starvation bound explicit and observable. **Whatever lands must emit the skip reason with a COUNT** — `skipped N consecutive ticks` — because the current log line is indistinguishable at tick 3 and tick 50, which is exactly why this went unnoticed for ~100 minutes the first time.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: adopt option 1 from the ticket's own sketch — an intent-file reservation — as the fix.

  • scripts/rehearsal-executor.sh (or scripts/rehearsal-cycle.sh itself, right where it currently calls host_capacity_acquire_exclusive) writes /tmp/matou-drive-wanted the moment a drive is ready-and-unblocked and about to attempt the acquire, and removes it on completion or abandonment — mirroring the existing release discipline in scripts/lib/host-capacity-lib.sh (a trap ... EXIT, not a bare rm that a crash could skip).
  • The swarm's task-claim path (.sandcastle/claim-next-task.sh / run-swarm.sh) and triage/session-runner's own heavy-job entry points check for /tmp/matou-drive-wanted before claiming a new task, and decline (yield, exit 0) if present. In-flight work is never interrupted — only new starts are held back, bounding the starvation to one worker run instead of the unbounded retry the ticket documents.
  • The skip-reason log line grows a count ("skipped N consecutive ticks"), both for the drive's own skip message and the swarm/triage/session-runner message on the other side of the new check — closing the observability gap the ticket names (tick 3 is indistinguishable from tick 50 today).

Why this is a two-way door: it's a lock/scheduling change confined to scripts/lib/host-capacity-lib.sh, scripts/rehearsal-cycle.sh/rehearsal-executor.sh, and the swarm/triage/session-runner claim entry points — none of it under a protected .sandcastle/ path per #445's boundary (claim-next-task.sh and run-swarm.sh are inside .sandcastle/ but this is an ordinary logic change to an unprotected file within it, not one of the #445-protected paths). It's revertible by a follow-up commit, and provable the same way ADR 0184 itself was proved: extend the existing offline seam tests (scripts/tests/host-capacity-lib-test.sh) with a reservation-respected case, plus the next live standing-drive tick (#652/#657) as the real-world probe. No personal credential, security-posture widening, member-facing trust surface, data destruction, or spend involved.

Rejected, per the ticket's own reasoning (adopted as-is): bounded camping (still loses to a swarm that reclaims its slot quickly) and an ageing/skip-counter override (materially more code for a similar outcome to a single flag file).

Labelling bug (an unbounded-starvation defect in the exclusive-acquire contract, not a new capability) + ready-for-agent, and rehearsal-183 to match this cluster's convention.

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** adopt option 1 from the ticket's own sketch — an **intent-file reservation** — as the fix. - `scripts/rehearsal-executor.sh` (or `scripts/rehearsal-cycle.sh` itself, right where it currently calls `host_capacity_acquire_exclusive`) writes `/tmp/matou-drive-wanted` the moment a drive is ready-and-unblocked and about to attempt the acquire, and removes it on completion or abandonment — mirroring the existing release discipline in `scripts/lib/host-capacity-lib.sh` (a `trap ... EXIT`, not a bare `rm` that a crash could skip). - The swarm's task-claim path (`.sandcastle/claim-next-task.sh` / `run-swarm.sh`) and triage/session-runner's own heavy-job entry points check for `/tmp/matou-drive-wanted` before claiming a **new** task, and decline (yield, exit 0) if present. In-flight work is never interrupted — only new starts are held back, bounding the starvation to one worker run instead of the unbounded retry the ticket documents. - The skip-reason log line grows a **count** ("skipped N consecutive ticks"), both for the drive's own skip message and the swarm/triage/session-runner message on the other side of the new check — closing the observability gap the ticket names (tick 3 is indistinguishable from tick 50 today). **Why this is a two-way door:** it's a lock/scheduling change confined to `scripts/lib/host-capacity-lib.sh`, `scripts/rehearsal-cycle.sh`/`rehearsal-executor.sh`, and the swarm/triage/session-runner claim entry points — none of it under a protected `.sandcastle/` path per #445's boundary (`claim-next-task.sh` and `run-swarm.sh` are inside `.sandcastle/` but this is an ordinary logic change to an unprotected file within it, not one of the #445-protected paths). It's revertible by a follow-up commit, and provable the same way ADR 0184 itself was proved: extend the existing offline seam tests (`scripts/tests/host-capacity-lib-test.sh`) with a reservation-respected case, plus the next live standing-drive tick (#652/#657) as the real-world probe. No personal credential, security-posture widening, member-facing trust surface, data destruction, or spend involved. **Rejected**, per the ticket's own reasoning (adopted as-is): bounded camping (still loses to a swarm that reclaims its slot quickly) and an ageing/skip-counter override (materially more code for a similar outcome to a single flag file). Labelling `bug` (an unbounded-starvation defect in the exclusive-acquire contract, not a new capability) + `ready-for-agent`, and `rehearsal-183` to match this cluster's convention.

swarm-claim host=elitebook-distributed-server-03 run=8794
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=8794 (automated multi-host claim — lowest live claim id works this ticket)

Producer half shipped; consumer half split to #664 (a protected-path correction to the ruling).

Implemented the intent-file reservation exactly as ruled — but the ruling's claim that the consumer edits land on "an ordinary logic change to an unprotected file within" .sandcastle/ is wrong about the #445 boundary. .sandcastle/protected-paths-lib.sh fingerprints the entire .sandcastle/ and .forgejo/ trees (PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"), not a named subset — so claim-next-task.sh, run-swarm.sh, run-triage.sh, session-runner.sh, the vendored host-capacity-lib.sh, and the swarm.yml/triage.yml workflows are all protected machinery a swarm worker is rolled back for touching. The consumer half needs an interactive session's standing (ADR 0174/#445), and the vendored lib copy needs an upstream Matou/dev-factory change + re-vendor (ADR 0184 point 6). Filed as #664 (ready-for-session).

Shipped here on unprotected scripts/ (the whole producer half + the observability fix this recurrence was actually ticketed for):

  • scripts/rehearsal-cycle.sh: writes /tmp/matou-drive-wanted before the exclusive acquire, persists it across skipped */2 ticks, releases it on completion/abandonment via an EXIT trap (merged with the existing drive-status trap).
  • Reservation helpers in scripts/lib/host-capacity-lib.sh: host_capacity_drive_reserve / _release / _wanted (the predicate consumers will call) / _skip_bump / _skip_reset.
  • The drive's skip line now carries a consecutive-tick count — skipped N consecutive tick(s) — so tick 3 is distinguishable from tick 50 (the exact gap that let the first occurrence starve ~100 min unnoticed).
  • Offline tests: scripts/tests/host-capacity-lib-test.sh (8 groups; +2 for the reservation).

Until #664 lands, the reservation is written correctly but not yet honoured — so the behaviour fix (bounding starvation to one worker run) arrives with #664, while the observability fix (the count) is live now.

**Producer half shipped; consumer half split to #664 (a protected-path correction to the ruling).** Implemented the intent-file reservation exactly as ruled — but the ruling's claim that the consumer edits land on "an ordinary logic change to an unprotected file within" `.sandcastle/` is **wrong about the #445 boundary**. `.sandcastle/protected-paths-lib.sh` fingerprints the **entire** `.sandcastle/` and `.forgejo/` trees (`PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"`), not a named subset — so `claim-next-task.sh`, `run-swarm.sh`, `run-triage.sh`, `session-runner.sh`, the vendored `host-capacity-lib.sh`, and the `swarm.yml`/`triage.yml` workflows are all protected machinery a swarm worker is rolled back for touching. The consumer half needs an interactive session's standing (ADR 0174/#445), and the vendored lib copy needs an upstream `Matou/dev-factory` change + re-vendor (ADR 0184 point 6). Filed as **#664** (`ready-for-session`). Shipped here on unprotected `scripts/` (the whole producer half + the observability fix this recurrence was actually ticketed for): - `scripts/rehearsal-cycle.sh`: writes `/tmp/matou-drive-wanted` before the exclusive acquire, persists it across skipped `*/2` ticks, releases it on completion/abandonment via an EXIT trap (merged with the existing drive-status trap). - Reservation helpers in `scripts/lib/host-capacity-lib.sh`: `host_capacity_drive_reserve` / `_release` / `_wanted` (the predicate consumers will call) / `_skip_bump` / `_skip_reset`. - The drive's skip line now carries a **consecutive-tick count** — `skipped N consecutive tick(s)` — so tick 3 is distinguishable from tick 50 (the exact gap that let the first occurrence starve ~100 min unnoticed). - Offline tests: `scripts/tests/host-capacity-lib-test.sh` (8 groups; +2 for the reservation). Until #664 lands, the reservation is written correctly but not yet honoured — so the **behaviour** fix (bounding starvation to one worker run) arrives with #664, while the **observability** fix (the count) is live now.

close-report for #663 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 663,
  "status": "success",
  "commits": [
    "726507c"
  ],
  "changed_files": [
    "STATUS.md",
    "scripts/lib/host-capacity-lib.sh",
    "scripts/rehearsal-cycle.sh",
    "scripts/tests/host-capacity-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash scripts/tests/host-capacity-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash -n scripts/rehearsal-cycle.sh scripts/lib/host-capacity-lib.sh scripts/tests/host-capacity-lib-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Reservation intent file exists (option 1): drive declares /tmp/matou-drive-wanted when ready and about to acquire": "scripts/rehearsal-cycle.sh calls host_capacity_drive_reserve immediately before host_capacity_acquire_exclusive; helper in scripts/lib/host-capacity-lib.sh",
    "Reservation persists across skipped ticks and is removed only on completion/abandonment via a trap (not a bare rm)": "reservation written before acquire; release trap armed only after a successful acquire and extended into the drive-status EXIT trap (scripts/rehearsal-cycle.sh); skip path exits 0 WITHOUT removing it — offline-tested reserve/release in scripts/tests/host-capacity-lib-test.sh",
    "Skip reason emits a COUNT (skipped N consecutive ticks) so tick 3 is distinguishable from tick 50": "scripts/rehearsal-cycle.sh skip line now prints 'skipped $n consecutive tick(s)' via host_capacity_drive_skip_bump (persistent /tmp/matou-drive-skip-count); counter climb/reset/wipe covered by scripts/tests/host-capacity-lib-test.sh",
    "Consumer side (swarm/triage/session-runner decline to start a NEW task when the reservation is present) — the behaviour half": "NOT shipped here: the call sites live in the fully #445-protected .sandcastle/ + .forgejo/ trees (protected-paths-lib.sh PP_PROTECTED_DIRS_DEFAULT). Filed as #664 (ready-for-session) with the predicate host_capacity_drive_wanted already defined in scripts/lib/host-capacity-lib.sh for that follow-up to call",
    "priority label ruled out; standing-drive structurally invisible to the swarm — no regression": "no swarm claim path touched; scripts/-only change; documented on #663 comment and in STATUS.md"
  },
  "summary": "Rehearsal drive now writes an intent-file reservation before acquiring host capacity and its skip line carries a consecutive-tick count; the reservation-honouring consumer half is a protected .sandcastle/+.forgejo/ change filed as #664.",
  "reason": "The intent-file reservation's consumer half lands only on #445-protected paths (.sandcastle/, .forgejo/), which a swarm agent cannot edit — filed #664 (ready-for-session). The producer half + the observability count this recurrence was ticketed for are fully shipped on unprotected scripts/.",
  "blockers": []
}
**close-report** for #663 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 663, "status": "success", "commits": [ "726507c" ], "changed_files": [ "STATUS.md", "scripts/lib/host-capacity-lib.sh", "scripts/rehearsal-cycle.sh", "scripts/tests/host-capacity-lib-test.sh" ], "tests": [ { "command": "bash scripts/tests/host-capacity-lib-test.sh", "exit_code": 0 }, { "command": "bash -n scripts/rehearsal-cycle.sh scripts/lib/host-capacity-lib.sh scripts/tests/host-capacity-lib-test.sh", "exit_code": 0 } ], "criteria": { "Reservation intent file exists (option 1): drive declares /tmp/matou-drive-wanted when ready and about to acquire": "scripts/rehearsal-cycle.sh calls host_capacity_drive_reserve immediately before host_capacity_acquire_exclusive; helper in scripts/lib/host-capacity-lib.sh", "Reservation persists across skipped ticks and is removed only on completion/abandonment via a trap (not a bare rm)": "reservation written before acquire; release trap armed only after a successful acquire and extended into the drive-status EXIT trap (scripts/rehearsal-cycle.sh); skip path exits 0 WITHOUT removing it — offline-tested reserve/release in scripts/tests/host-capacity-lib-test.sh", "Skip reason emits a COUNT (skipped N consecutive ticks) so tick 3 is distinguishable from tick 50": "scripts/rehearsal-cycle.sh skip line now prints 'skipped $n consecutive tick(s)' via host_capacity_drive_skip_bump (persistent /tmp/matou-drive-skip-count); counter climb/reset/wipe covered by scripts/tests/host-capacity-lib-test.sh", "Consumer side (swarm/triage/session-runner decline to start a NEW task when the reservation is present) — the behaviour half": "NOT shipped here: the call sites live in the fully #445-protected .sandcastle/ + .forgejo/ trees (protected-paths-lib.sh PP_PROTECTED_DIRS_DEFAULT). Filed as #664 (ready-for-session) with the predicate host_capacity_drive_wanted already defined in scripts/lib/host-capacity-lib.sh for that follow-up to call", "priority label ruled out; standing-drive structurally invisible to the swarm — no regression": "no swarm claim path touched; scripts/-only change; documented on #663 comment and in STATUS.md" }, "summary": "Rehearsal drive now writes an intent-file reservation before acquiring host capacity and its skip line carries a consecutive-tick count; the reservation-honouring consumer half is a protected .sandcastle/+.forgejo/ change filed as #664.", "reason": "The intent-file reservation's consumer half lands only on #445-protected paths (.sandcastle/, .forgejo/), which a swarm agent cannot edit — filed #664 (ready-for-session). The producer half + the observability count this recurrence was ticketed for are fully shipped on unprotected scripts/.", "blockers": [] } ``` </details>
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#663
No description provided.