rehearsal-cycle.sh keeps the #663 capacity reservation up for the whole drive — release it on acquire so one-slot work can use the free slot (ADR 0003 slot host) #1652

Closed
opened 2026-09-20 04:55:40 +00:00 by ben · 3 comments
Owner

Symptom

On elitebook-03 (a DRIVE_EXCLUSIVE=slot host) a rehearsal drive keeps /tmp/matou-drive-wanted (the #663 capacity reservation) standing for its whole run, not just while it is waiting for a slot. While the file is fresh every heavy consumer on the host — swarm/triage/healer/session-runner for every repo — yields its tick (reason=yielded-to-drive, exit 0) even though the drive holds only slot 1 and slot 2 is free.

Observed 2026-09-19 ~04:20Z: drive 20260919T035808Z on #1277 (target local-guest) in flight since 03:58Z holding /tmp/matou-swarm.lock only (/proc/locks confirms slot 2 unheld); healer defer-count 3, dev-factory/idss/matou-website session-runner defer-counts 2 each; session-runner-*.log show hundreds of deferring to a ready drive lines. The #1277 standing drive is re-firing every ~1.5 h (RED → blocker → swarm fix → refire: 19:32, 21:14, 00:44, 03:58), so the host is under a drive ~60% of the time — which is intended and stays — but each run should not fence off the free slot.

The drive alone would let the reservation age out after HOST_CAPACITY_DRIVE_WANTED_TTL (900 s), so on its own it over-fences for 15 min per drive. Combined with a Matou/matou-app pr-e2e job camping on the same host and re-touching the same file every 20 s (matou-app ticket linked below) the fence stays up for the entire drive.

Cause

scripts/rehearsal-cycle.sh: host_capacity_drive_reserve (line ~74) runs before the DRIVE_EXCLUSIVE acquire branch, and host_capacity_drive_release is only ever called from the EXIT traps (lines ~170, ~287). The reservation exists to stop NEW heavy work grabbing the slot a waiting drive needs (#663/#664). Once the acquire has succeeded the drive holds a real flock, and the lib's own comment says the reservation "costs nothing" lapsing mid-drive — but nothing lets it lapse, and other reservers keep it fresh.

Ruling (Ben, 2026-09-19)

I want the refire instantly. I don't want the drive to wait for other work. But I do want other jobs that only need one slot to be able to fire while one slot is free.

So: the drive keeps its instant refire (executor self-nudge untouched) and keeps reserving while it is genuinely waiting; it must release the reservation the moment it has won capacity (both slot and all branches — under all there are no free slots anyway, so releasing is harmless). This is exactly what .sandcastle/host-slot-wait.sh --exclusive already does: reserve while polling, release right after acquiring, then run holding the flocks.

Change

  • scripts/rehearsal-cycle.sh: immediately after the capacity_busy check passes (just before/at host_capacity_drive_skip_reset), call host_capacity_drive_release. Keep the existing EXIT-trap releases (idempotent, belt-and-braces for the wait-then-crash path).
  • scripts/tests/rehearsal-drive-exclusive-test.sh (offline): in both the slot and unset/all cases assert /tmp/matou-drive-wanted (re-pointed via HOST_CAPACITY_DRIVE_WANTED) is absent once the acquire has succeeded and the drive body is running, and still present on the busy/yield path.
  • GOTCHAS entry: a reservation is for waiting, not for running — a job that holds it after it has acquired fences off capacity it does not use.

Acceptance

Offline: the test above green. Live: on elitebook-03, with a drive in flight, stat /tmp/matou-drive-wanted is absent (or older than 900 s) and a session-runner/swarm tick takes slot 2 instead of logging deferring to a ready drive — provided the matou-app camping job is also fixed (linked below); until then matou-app's 20 s re-touch will still keep the file fresh.

  • dev-factory ADR 0003 (drive exclusivity is a per-host knob), idss #706 (the DRIVE_EXCLUSIVE branch), #663/#664 (the reservation), #657 (the starvation it solved — the other direction).
  • Sibling: the matou-app pr-e2e two-slot camp on elitebook-03 (link in first comment).
  • Note for whoever picks this up: ADR 0003's RAM reasoning for slot on elitebook-03 says a drive is "Playwright + SSH to a droplet, no local build"; a local-guest drive boots a KVM guest locally. free showed ~12 GB available mid-drive on 2026-09-19 so slot still looks safe, but the reasoning in the ADR is stale and worth a one-line amendment.
## Symptom On `elitebook-03` (a `DRIVE_EXCLUSIVE=slot` host) a rehearsal drive keeps `/tmp/matou-drive-wanted` (the #663 capacity reservation) standing for its **whole run**, not just while it is waiting for a slot. While the file is fresh every heavy consumer on the host — swarm/triage/healer/session-runner for every repo — yields its tick (`reason=yielded-to-drive`, exit 0) even though the drive holds only slot 1 and slot 2 is free. Observed 2026-09-19 ~04:20Z: drive `20260919T035808Z` on #1277 (target `local-guest`) in flight since 03:58Z holding `/tmp/matou-swarm.lock` only (`/proc/locks` confirms slot 2 unheld); healer defer-count 3, dev-factory/idss/matou-website session-runner defer-counts 2 each; `session-runner-*.log` show hundreds of `deferring to a ready drive` lines. The #1277 standing drive is re-firing every ~1.5 h (RED → blocker → swarm fix → refire: 19:32, 21:14, 00:44, 03:58), so the host is under a drive ~60% of the time — which is intended and stays — but each run should not fence off the free slot. The drive alone would let the reservation age out after `HOST_CAPACITY_DRIVE_WANTED_TTL` (900 s), so on its own it over-fences for 15 min per drive. Combined with a `Matou/matou-app` `pr-e2e` job camping on the same host and re-touching the same file every 20 s (matou-app ticket linked below) the fence stays up for the entire drive. ## Cause `scripts/rehearsal-cycle.sh`: `host_capacity_drive_reserve` (line ~74) runs before the `DRIVE_EXCLUSIVE` acquire branch, and `host_capacity_drive_release` is only ever called from the EXIT traps (lines ~170, ~287). The reservation exists to stop NEW heavy work grabbing the slot a *waiting* drive needs (#663/#664). Once the acquire has succeeded the drive holds a real flock, and the lib's own comment says the reservation "costs nothing" lapsing mid-drive — but nothing lets it lapse, and other reservers keep it fresh. ## Ruling (Ben, 2026-09-19) > I want the refire instantly. I don't want the drive to wait for other work. But I do want other jobs that only need one slot to be able to fire while one slot is free. So: the drive keeps its instant refire (executor self-nudge untouched) and keeps reserving while it is genuinely waiting; it must **release the reservation the moment it has won capacity** (both `slot` and `all` branches — under `all` there are no free slots anyway, so releasing is harmless). This is exactly what `.sandcastle/host-slot-wait.sh --exclusive` already does: reserve while polling, release right after acquiring, then run holding the flocks. ## Change - `scripts/rehearsal-cycle.sh`: immediately after the `capacity_busy` check passes (just before/at `host_capacity_drive_skip_reset`), call `host_capacity_drive_release`. Keep the existing EXIT-trap releases (idempotent, belt-and-braces for the wait-then-crash path). - `scripts/tests/rehearsal-drive-exclusive-test.sh` (offline): in both the `slot` and unset/`all` cases assert `/tmp/matou-drive-wanted` (re-pointed via `HOST_CAPACITY_DRIVE_WANTED`) is **absent** once the acquire has succeeded and the drive body is running, and still **present** on the busy/yield path. - GOTCHAS entry: a reservation is for waiting, not for running — a job that holds it after it has acquired fences off capacity it does not use. ## Acceptance Offline: the test above green. Live: on elitebook-03, with a drive in flight, `stat /tmp/matou-drive-wanted` is absent (or older than 900 s) and a session-runner/swarm tick takes slot 2 instead of logging `deferring to a ready drive` — provided the matou-app camping job is also fixed (linked below); until then matou-app's 20 s re-touch will still keep the file fresh. ## Related - dev-factory ADR 0003 (drive exclusivity is a per-host knob), idss #706 (the `DRIVE_EXCLUSIVE` branch), #663/#664 (the reservation), #657 (the starvation it solved — the other direction). - Sibling: the matou-app `pr-e2e` two-slot camp on `elitebook-03` (link in first comment). - Note for whoever picks this up: ADR 0003's RAM reasoning for `slot` on elitebook-03 says a drive is "Playwright + SSH to a droplet, no local build"; a `local-guest` drive boots a KVM guest locally. `free` showed ~12 GB available mid-drive on 2026-09-19 so `slot` still looks safe, but the reasoning in the ADR is stale and worth a one-line amendment.
Author
Owner

Sibling (matou-app side, the 20 s re-touch that keeps this reservation fresh): Matou/matou-app#572

Sibling (matou-app side, the 20 s re-touch that keeps this reservation fresh): https://git.matou.nz/Matou/matou-app/issues/572

swarm-claim host=bens-mac-04 run=28113
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=28113 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1652 — status success

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

envelope
{
  "issue": 1652,
  "status": "success",
  "commits": [
    "92376303"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "scripts/rehearsal-cycle.sh",
    "scripts/tests/rehearsal-drive-exclusive-test.sh"
  ],
  "tests": [
    {
      "command": "bash scripts/tests/rehearsal-drive-exclusive-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash -n scripts/rehearsal-cycle.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Offline: the drive-exclusive test asserts /tmp/matou-drive-wanted is absent once the acquire succeeds and the drive body runs (both slot and all cases), and present on the busy/yield path": "scripts/tests/rehearsal-drive-exclusive-test.sh checks 7-10 (reservation_after helper sources the real host-capacity-lib, re-points HOST_CAPACITY_DRIVE_WANTED); 6->10 checks green; red-green confirmed by removing the release line",
    "rehearsal-cycle.sh releases the reservation the moment it wins capacity (both slot and all branches), keeping the EXIT-trap releases": "scripts/rehearsal-cycle.sh:122 host_capacity_drive_release inside the DRIVE_EXCLUSIVE-branch sentinels after the capacity_busy check; EXIT-trap releases preserved at lines 184 and 301",
    "GOTCHAS entry: a reservation is for waiting, not for running": "docs/GOTCHAS.md #285"
  },
  "summary": "The rehearsal drive releases the #663 capacity reservation the instant it wins a slot instead of holding it for the whole run, so one-slot work can use the free slot on a DRIVE_EXCLUSIVE=slot host.",
  "blockers": []
}
**close-report** for #1652 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1652, "status": "success", "commits": [ "92376303" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "scripts/rehearsal-cycle.sh", "scripts/tests/rehearsal-drive-exclusive-test.sh" ], "tests": [ { "command": "bash scripts/tests/rehearsal-drive-exclusive-test.sh", "exit_code": 0 }, { "command": "bash -n scripts/rehearsal-cycle.sh", "exit_code": 0 } ], "criteria": { "Offline: the drive-exclusive test asserts /tmp/matou-drive-wanted is absent once the acquire succeeds and the drive body runs (both slot and all cases), and present on the busy/yield path": "scripts/tests/rehearsal-drive-exclusive-test.sh checks 7-10 (reservation_after helper sources the real host-capacity-lib, re-points HOST_CAPACITY_DRIVE_WANTED); 6->10 checks green; red-green confirmed by removing the release line", "rehearsal-cycle.sh releases the reservation the moment it wins capacity (both slot and all branches), keeping the EXIT-trap releases": "scripts/rehearsal-cycle.sh:122 host_capacity_drive_release inside the DRIVE_EXCLUSIVE-branch sentinels after the capacity_busy check; EXIT-trap releases preserved at lines 184 and 301", "GOTCHAS entry: a reservation is for waiting, not for running": "docs/GOTCHAS.md #285" }, "summary": "The rehearsal drive releases the #663 capacity reservation the instant it wins a slot instead of holding it for the whole run, so one-slot work can use the free slot on a DRIVE_EXCLUSIVE=slot host.", "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#1652
No description provided.