host-capacity-lib: drive holders must label the slots the drive ACTUALLY holds (not a mode prediction), and carry repo separately from target #118

Closed
opened 2026-08-31 06:08:25 +00:00 by ben · 2 comments
Owner

Symptom

A rehearsal drive on a drive-exclusive slot host (the consumer's DRIVE_EXCLUSIVE=slot branch, which acquires via host_capacity_acquire_heavy) can hold slot 2 while slot 1 runs a ticket. host_capacity_drive_log_start would then write kind=drive holders on both pooled slots (or slot 1 only), and host_capacity_drive_log_end would clear both — wiping the ticket worker's holder on the slot the drive never held. The fleet monitor's slot rows (spec 2026-08-28) would mislabel the host for the whole drive.

Observed 2026-08-31 while investigating why the fleet TUI shows no drives: no host and no consumer sets HOST_CAPACITY_DRIVE_MODE, so _host_capacity_drive_slots always resolves to exclusive = every pooled slot, regardless of what the drive actually holds. (Today no consumer calls the primitive at all — that wiring is the consumer's ticket — so this is latent, but it must be right before the wiring lands.)

Cause

host-capacity-lib.sh — host_capacity_drive_log_start (≈L456) and host_capacity_drive_log_end (≈L479) place/clear holders by _host_capacity_drive_slots "$mode" (a prediction from HOST_CAPACITY_DRIVE_MODE) instead of by what the acquire actually won. The acquire already records that: HOST_CAPACITY_EXCLUSIVE_SLOTS (pooled slots won by acquire_exclusive) and HOST_CAPACITY_HELD_SLOT (the one slot won by acquire_heavy). Flock is truth, the sidecar is a label (GOTCHAS 42); the label must follow the flock.

A second accuracy defect in the same primitive: its third argument is named target but lands in the holder's repo field (host_capacity_holder_write "$slot" drive "$id" "$target" executor …; the test asserts repo == Acme/widget). For the consumer that drives, "target" is the drive shape (droplet|device|idip) and the repo is owner/slug — two different things. The fleet monitor renders holder repo as REPO and drive-status target as TARGET, so wiring against today's signature would render them swapped, and the durable drive-log's target field would carry a repo slug.

Fix

  1. host_capacity_drive_log_start: write the drive holder on HOST_CAPACITY_EXCLUSIVE_SLOTS when set, else on HOST_CAPACITY_HELD_SLOT when set; fall back to _host_capacity_drive_slots "$mode" only when neither is set (a caller that acquired some other way). host_capacity_drive_log_end clears exactly the slots _start labelled — remember them in a lib variable (e.g. HOST_CAPACITY_DRIVE_HOLDER_SLOTS) rather than re-predicting.
  2. Give the primitive an explicit repo: host_capacity_drive_log_start <id> <box> <target> [repo] [mode] [window] is a signature change, so prefer an additive env (HOST_CAPACITY_DRIVE_REPO, mirroring HOST_CAPACITY_DRIVE_RUN_DIR) that fills the holder's repo; target stays the drive shape in both the holder (add a target key or reuse mode-adjacent field) and the drive-log start line. Keep the existing positional args working (GOTCHAS 20: additive, never a flag day).
  3. Update the header comment block for the drive log (≈L399-420) — it still says "the drive-side wiring is a one-liner"; document the two env knobs the consumer should export before calling.

Tests (same commit)

tests/host-capacity-lib-test.sh drive-holder group (≈L416-430): add (a) acquire_heavy lands on slot 2 (slot 1 pre-held by a ticket holder) → _start labels slot 2 only, slot 1's ticket holder untouched; _end clears slot 2 only. (b) acquire_exclusive under single-slot → labels exactly HOST_CAPACITY_EXCLUSIVE_SLOTS. (c) HOST_CAPACITY_DRIVE_REPO rides into repo, target no longer does. Existing exclusive-mode assertions keep passing. Run the full offline sweep before proposing close.

Blast radius

Vendored byte-identical into every consumer; reaches hosts at the next pin bump. No prompt skeletons touched. Add a GOTCHAS entry (label follows the flock, not the mode) and a STATUS.md follow-ups line; the consumer wiring ticket in the driving product repo depends on this landing + a pin bump.

## Symptom A rehearsal drive on a `drive-exclusive slot` host (the consumer's `DRIVE_EXCLUSIVE=slot` branch, which acquires via `host_capacity_acquire_heavy`) can hold **slot 2** while slot 1 runs a ticket. `host_capacity_drive_log_start` would then write `kind=drive` holders on **both** pooled slots (or slot 1 only), and `host_capacity_drive_log_end` would clear both — wiping the ticket worker's holder on the slot the drive never held. The fleet monitor's slot rows (spec 2026-08-28) would mislabel the host for the whole drive. Observed 2026-08-31 while investigating why the fleet TUI shows no drives: no host and no consumer sets `HOST_CAPACITY_DRIVE_MODE`, so `_host_capacity_drive_slots` always resolves to `exclusive` = every pooled slot, regardless of what the drive actually holds. (Today no consumer calls the primitive at all — that wiring is the consumer's ticket — so this is latent, but it must be right before the wiring lands.) ## Cause `host-capacity-lib.sh` — `host_capacity_drive_log_start` (≈L456) and `host_capacity_drive_log_end` (≈L479) place/clear holders by `_host_capacity_drive_slots "$mode"` (a **prediction** from `HOST_CAPACITY_DRIVE_MODE`) instead of by what the acquire actually won. The acquire already records that: `HOST_CAPACITY_EXCLUSIVE_SLOTS` (pooled slots won by `acquire_exclusive`) and `HOST_CAPACITY_HELD_SLOT` (the one slot won by `acquire_heavy`). Flock is truth, the sidecar is a label (GOTCHAS 42); the label must follow the flock. A second accuracy defect in the same primitive: its third argument is named `target` but lands in the holder's **`repo`** field (`host_capacity_holder_write "$slot" drive "$id" "$target" executor …`; the test asserts `repo == Acme/widget`). For the consumer that drives, "target" is the drive shape (`droplet|device|idip`) and the repo is `owner/slug` — two different things. The fleet monitor renders holder `repo` as REPO and drive-status `target` as TARGET, so wiring against today's signature would render them swapped, and the durable drive-log's `target` field would carry a repo slug. ## Fix 1. `host_capacity_drive_log_start`: write the drive holder on `HOST_CAPACITY_EXCLUSIVE_SLOTS` when set, else on `HOST_CAPACITY_HELD_SLOT` when set; fall back to `_host_capacity_drive_slots "$mode"` only when neither is set (a caller that acquired some other way). `host_capacity_drive_log_end` clears exactly the slots `_start` labelled — remember them in a lib variable (e.g. `HOST_CAPACITY_DRIVE_HOLDER_SLOTS`) rather than re-predicting. 2. Give the primitive an explicit repo: `host_capacity_drive_log_start <id> <box> <target> [repo] [mode] [window]` is a signature change, so prefer an additive env (`HOST_CAPACITY_DRIVE_REPO`, mirroring `HOST_CAPACITY_DRIVE_RUN_DIR`) that fills the holder's `repo`; `target` stays the drive shape in both the holder (add a `target` key or reuse `mode`-adjacent field) and the drive-log start line. Keep the existing positional args working (GOTCHAS 20: additive, never a flag day). 3. Update the header comment block for the drive log (≈L399-420) — it still says "the drive-side wiring is a one-liner"; document the two env knobs the consumer should export before calling. ## Tests (same commit) `tests/host-capacity-lib-test.sh` drive-holder group (≈L416-430): add (a) `acquire_heavy` lands on slot 2 (slot 1 pre-held by a ticket holder) → `_start` labels slot 2 only, slot 1's ticket holder untouched; `_end` clears slot 2 only. (b) `acquire_exclusive` under `single-slot` → labels exactly `HOST_CAPACITY_EXCLUSIVE_SLOTS`. (c) `HOST_CAPACITY_DRIVE_REPO` rides into `repo`, `target` no longer does. Existing exclusive-mode assertions keep passing. Run the full offline sweep before proposing close. ## Blast radius Vendored byte-identical into every consumer; reaches hosts at the next pin bump. No prompt skeletons touched. Add a GOTCHAS entry (label follows the flock, not the mode) and a STATUS.md follow-ups line; the consumer wiring ticket in the driving product repo depends on this landing + a pin bump.

swarm-claim host=matou-dev-server-01 run=4290
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=4290 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #118 — status success

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

envelope
{
  "issue": 118,
  "status": "success",
  "commits": [
    "52d50b3"
  ],
  "changed_files": [
    "host-capacity-lib.sh",
    "tests/host-capacity-lib-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/host-capacity-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\"; done  (only pre-existing tests/fleet-tui-test.sh env failure: fleet-tui/.venv has no pytest module; fails identically on a clean tree, unrelated to this diff)",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Fix 1: _start labels HOST_CAPACITY_EXCLUSIVE_SLOTS when set, else HOST_CAPACITY_HELD_SLOT, else _host_capacity_drive_slots mode fallback; _end clears exactly the slots remembered in HOST_CAPACITY_DRIVE_HOLDER_SLOTS": "host-capacity-lib.sh host_capacity_drive_log_start slot-selection if/elif/else + HOST_CAPACITY_DRIVE_HOLDER_SLOTS; host_capacity_drive_log_end reads that var with the _host_capacity_drive_slots fallback (commit 52d50b3)",
    "Fix 2: explicit repo via additive HOST_CAPACITY_DRIVE_REPO env fills holder repo; target stays the drive shape in the holder (new target key) and the drive-log start line; existing positional args still work": "HOST_CAPACITY_DRIVE_REPO read into repo; host_capacity_holder_write gains additive 9th positional [target]; holder JSON gains target key; drive-log start line keeps target and gains repo. Positional signature host_capacity_drive_log_start <id> <box> <target> [mode] [window] unchanged (commit 52d50b3)",
    "Fix 3: drive-log header comment (~L399-420) documents the two env knobs (HOST_CAPACITY_DRIVE_REPO, HOST_CAPACITY_DRIVE_RUN_DIR) the consumer exports; 'drive-side wiring is a one-liner' removed": "host-capacity-lib.sh drive-log header block rewritten with the two-knob documentation (commit 52d50b3)",
    "Tests (same commit): (a) acquire_heavy lands on slot 2 with slot 1 pre-held by a ticket -> _start labels slot 2 only, ticket holder untouched, _end clears slot 2 only": "tests/host-capacity-lib-test.sh case (a) d6 block: holds slot1 flock + ticket holder, acquire_heavy wins slot2, asserts drive on slot2/ticket intact on slot1 through _start and _end (commit 52d50b3)",
    "Tests (b) acquire_exclusive under single-slot labels exactly HOST_CAPACITY_EXCLUSIVE_SLOTS": "tests/host-capacity-lib-test.sh case (b) d7 block: single-slot acquire_exclusive, asserts EXCLUSIVE_SLOTS==slot1, drive label on slot1 only (commit 52d50b3)",
    "Tests (c) HOST_CAPACITY_DRIVE_REPO rides into repo, target no longer does; existing exclusive-mode assertions keep passing": "tests/host-capacity-lib-test.sh d4 block sets HOST_CAPACITY_DRIVE_REPO=Acme/widget, target=vm; asserts .repo=Acme/widget, .target=vm on holder and drive-log start line; full suite green (commit 52d50b3)",
    "Blast radius: GOTCHAS entry (label follows the flock, not the mode) + STATUS.md follow-ups line": "docs/GOTCHAS.md entry 45; STATUS.md header + Host capacity row + milestone log (commit 52d50b3)"
  },
  "summary": "host_capacity_drive_log_start/_end now label the pooled slots the drive actually holds (flock, not a mode prediction) and carry repo via HOST_CAPACITY_DRIVE_REPO separately from the target drive shape.",
  "blockers": []
}
**close-report** for #118 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 118, "status": "success", "commits": [ "52d50b3" ], "changed_files": [ "host-capacity-lib.sh", "tests/host-capacity-lib-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/host-capacity-lib-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\"; done (only pre-existing tests/fleet-tui-test.sh env failure: fleet-tui/.venv has no pytest module; fails identically on a clean tree, unrelated to this diff)", "exit_code": 0 } ], "criteria": { "Fix 1: _start labels HOST_CAPACITY_EXCLUSIVE_SLOTS when set, else HOST_CAPACITY_HELD_SLOT, else _host_capacity_drive_slots mode fallback; _end clears exactly the slots remembered in HOST_CAPACITY_DRIVE_HOLDER_SLOTS": "host-capacity-lib.sh host_capacity_drive_log_start slot-selection if/elif/else + HOST_CAPACITY_DRIVE_HOLDER_SLOTS; host_capacity_drive_log_end reads that var with the _host_capacity_drive_slots fallback (commit 52d50b3)", "Fix 2: explicit repo via additive HOST_CAPACITY_DRIVE_REPO env fills holder repo; target stays the drive shape in the holder (new target key) and the drive-log start line; existing positional args still work": "HOST_CAPACITY_DRIVE_REPO read into repo; host_capacity_holder_write gains additive 9th positional [target]; holder JSON gains target key; drive-log start line keeps target and gains repo. Positional signature host_capacity_drive_log_start <id> <box> <target> [mode] [window] unchanged (commit 52d50b3)", "Fix 3: drive-log header comment (~L399-420) documents the two env knobs (HOST_CAPACITY_DRIVE_REPO, HOST_CAPACITY_DRIVE_RUN_DIR) the consumer exports; 'drive-side wiring is a one-liner' removed": "host-capacity-lib.sh drive-log header block rewritten with the two-knob documentation (commit 52d50b3)", "Tests (same commit): (a) acquire_heavy lands on slot 2 with slot 1 pre-held by a ticket -> _start labels slot 2 only, ticket holder untouched, _end clears slot 2 only": "tests/host-capacity-lib-test.sh case (a) d6 block: holds slot1 flock + ticket holder, acquire_heavy wins slot2, asserts drive on slot2/ticket intact on slot1 through _start and _end (commit 52d50b3)", "Tests (b) acquire_exclusive under single-slot labels exactly HOST_CAPACITY_EXCLUSIVE_SLOTS": "tests/host-capacity-lib-test.sh case (b) d7 block: single-slot acquire_exclusive, asserts EXCLUSIVE_SLOTS==slot1, drive label on slot1 only (commit 52d50b3)", "Tests (c) HOST_CAPACITY_DRIVE_REPO rides into repo, target no longer does; existing exclusive-mode assertions keep passing": "tests/host-capacity-lib-test.sh d4 block sets HOST_CAPACITY_DRIVE_REPO=Acme/widget, target=vm; asserts .repo=Acme/widget, .target=vm on holder and drive-log start line; full suite green (commit 52d50b3)", "Blast radius: GOTCHAS entry (label follows the flock, not the mode) + STATUS.md follow-ups line": "docs/GOTCHAS.md entry 45; STATUS.md header + Host capacity row + milestone log (commit 52d50b3)" }, "summary": "host_capacity_drive_log_start/_end now label the pooled slots the drive actually holds (flock, not a mode prediction) and carry repo via HOST_CAPACITY_DRIVE_REPO separately from the target drive shape.", "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.

Reference
Matou/dev-factory#118
No description provided.