Move host-global factory state out of /tmp into $HOME/swarm/state #205

Closed
opened 2026-10-15 02:59:18 +00:00 by ben · 3 comments
Owner

Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against main at 3e50274.

Symptom

Locks, debounce stamps, defer counters, the limit marker, the active-token marker and holder sidecars all live under /tmp (host-capacity-lib.sh:37,227,232; limit-lib.sh:73,212; schedule-lib.sh:575; execute-lib.sh:42). A tmp cleaner (systemd-tmpfiles) unlinking a held lock leaves the holder on an unlinked inode; the next acquirer creates a fresh file and wins — capacity silently doubles. Reboot wipes the active-token marker (falls back to account A, possibly the exhausted one) and the limit marker, so limit-lost never sees the unpark edge (swarm-db.py:606-636 under-reports). Sticky /tmp means a second OS user cannot exec 9> another user's lock file (set -e exit). ADR 0004 point 6 records the namespace as owned but keeps it in /tmp.

Proposed change

  • HOST_CAPACITY_STATE_DIR default $HOME/swarm/state (where swarm.db and cancel markers already live, cancel-lib.sh:170); every default path above derives from it. Slot 1 keeps a compatibility symlink /tmp/matou-swarm.lock → new path for one pin cycle (an unmodified older pin on the same host must still exclude; GOTCHAS 11 shape).
  • The fleet sampler verifies the lock's inode still matches its path (/proc/locks already used, #138).
  • The inline workflow guards (swarm.yml/triage.yml flock blocks) source host-capacity.env for the paths rather than hardcoding /tmp/....
  • ADR 0004 amendment + GOTCHAS entry.

Acceptance

  • tests/host-capacity-lib-test.sh and tests/limit-lib-test.sh run against a redirected state dir; a scenario deletes a held lock file and asserts the next acquire is refused (inode check).
_Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against `main` at 3e50274._ ## Symptom Locks, debounce stamps, defer counters, the limit marker, the active-token marker and holder sidecars all live under `/tmp` (`host-capacity-lib.sh:37,227,232`; `limit-lib.sh:73,212`; `schedule-lib.sh:575`; `execute-lib.sh:42`). A tmp cleaner (systemd-tmpfiles) unlinking a held lock leaves the holder on an unlinked inode; the next acquirer creates a fresh file and wins — capacity silently doubles. Reboot wipes the active-token marker (falls back to account A, possibly the exhausted one) and the limit marker, so `limit-lost` never sees the unpark edge (`swarm-db.py:606-636` under-reports). Sticky `/tmp` means a second OS user cannot `exec 9>` another user's lock file (set -e exit). ADR 0004 point 6 records the namespace as owned but keeps it in /tmp. ## Proposed change - `HOST_CAPACITY_STATE_DIR` default `$HOME/swarm/state` (where swarm.db and cancel markers already live, `cancel-lib.sh:170`); every default path above derives from it. Slot 1 keeps a compatibility symlink `/tmp/matou-swarm.lock` → new path for one pin cycle (an unmodified older pin on the same host must still exclude; GOTCHAS 11 shape). - The fleet sampler verifies the lock's inode still matches its path (`/proc/locks` already used, #138). - The inline workflow guards (`swarm.yml`/`triage.yml` flock blocks) source `host-capacity.env` for the paths rather than hardcoding `/tmp/...`. - ADR 0004 amendment + GOTCHAS entry. ## Acceptance - `tests/host-capacity-lib-test.sh` and `tests/limit-lib-test.sh` run against a redirected state dir; a scenario deletes a held lock file and asserts the next acquire is refused (inode check).

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

  • Ruling: ready-for-agent.
  • Why this is a two-way door: relocating host-global state paths behind a defaulted env var is a mechanical change, not a security-posture move; revertible by restoring the default, and the one-pin-cycle compatibility symlink preserves cross-pin lock exclusion. $HOME/swarm/state already exists — nothing is provisioned.
  • What proves it: tests/host-capacity-lib-test.sh and tests/limit-lib-test.sh run against a redirected state dir, plus a scenario deleting a held lock out from under its holder and asserting the next acquire is refused (inode check).

Agent Brief

Category: bug

Summary: Host-global factory state (slot locks, drive reservation, defer/skip counters, the Claude limit + active-token + auth-dead markers, debounce stamps) lives under /tmp. A tmp-cleaner unlinking a held lock silently doubles capacity (the next acquirer makes a fresh inode and wins); a reboot wipes the active-token and limit markers (falling back to the possibly-exhausted account A and losing the limit-lost unpark edge); sticky /tmp blocks a second OS user from exec 9>-ing another user's lock. Move the namespace under $HOME/swarm/state.

Current behavior: Every host-global path defaults to /tmp/matou-*. ADR 0004 point 6 records the namespace as owned but keeps it in /tmp.

Desired behavior: A HOST_CAPACITY_STATE_DIR defaulting to $HOME/swarm/state (where swarm.db and cancel markers already live); every host-global default path derives from it. Slot 1 keeps a one-pin-cycle compatibility symlink from the old /tmp/matou-swarm.lock to the new path so an unmodified older pin on the same host still excludes correctly (GOTCHAS 11 shape). The fleet sampler verifies the lock's inode still matches its path. The inline swarm.yml/triage.yml flock guards source a shared host-capacity.env for the paths instead of hardcoding /tmp/.... ADR 0004 amendment + a GOTCHAS entry land in the same commit.

Key interfaces: A single state-dir root var from which all host-global lock/marker/counter defaults derive, backward-compatible for one pin cycle via a slot-1 symlink; a sampler check that a held lock's inode matches its declared path; workflow flock guards reading their paths from a sourced env file rather than literals.

Acceptance criteria:

  • tests/host-capacity-lib-test.sh and tests/limit-lib-test.sh run against a redirected state dir.
  • A scenario deletes a held lock file out from under the holder and asserts the next acquire is refused (inode check).
  • The old /tmp/matou-swarm.lock path still excludes via the compatibility symlink for one pin cycle.
  • ADR 0004 amendment + GOTCHAS entry present; offline suite green.

Out of scope: Changing the lock/reservation semantics themselves; retiring the compatibility symlink (a later pin-cycle follow-up).

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** - **Ruling:** `ready-for-agent`. - **Why this is a two-way door:** relocating host-global state paths behind a defaulted env var is a mechanical change, not a security-posture move; revertible by restoring the default, and the one-pin-cycle compatibility symlink preserves cross-pin lock exclusion. `$HOME/swarm/state` already exists — nothing is provisioned. - **What proves it:** `tests/host-capacity-lib-test.sh` and `tests/limit-lib-test.sh` run against a redirected state dir, plus a scenario deleting a held lock out from under its holder and asserting the next acquire is refused (inode check). ## Agent Brief **Category:** bug **Summary:** Host-global factory state (slot locks, drive reservation, defer/skip counters, the Claude limit + active-token + auth-dead markers, debounce stamps) lives under `/tmp`. A tmp-cleaner unlinking a held lock silently doubles capacity (the next acquirer makes a fresh inode and wins); a reboot wipes the active-token and limit markers (falling back to the possibly-exhausted account A and losing the `limit-lost` unpark edge); sticky `/tmp` blocks a second OS user from `exec 9>`-ing another user's lock. Move the namespace under `$HOME/swarm/state`. **Current behavior:** Every host-global path defaults to `/tmp/matou-*`. ADR 0004 point 6 records the namespace as owned but keeps it in `/tmp`. **Desired behavior:** A `HOST_CAPACITY_STATE_DIR` defaulting to `$HOME/swarm/state` (where swarm.db and cancel markers already live); every host-global default path derives from it. Slot 1 keeps a one-pin-cycle compatibility symlink from the old `/tmp/matou-swarm.lock` to the new path so an unmodified older pin on the same host still excludes correctly (GOTCHAS 11 shape). The fleet sampler verifies the lock's inode still matches its path. The inline `swarm.yml`/`triage.yml` flock guards source a shared `host-capacity.env` for the paths instead of hardcoding `/tmp/...`. ADR 0004 amendment + a GOTCHAS entry land in the same commit. **Key interfaces:** A single state-dir root var from which all host-global lock/marker/counter defaults derive, backward-compatible for one pin cycle via a slot-1 symlink; a sampler check that a held lock's inode matches its declared path; workflow flock guards reading their paths from a sourced env file rather than literals. **Acceptance criteria:** - [ ] `tests/host-capacity-lib-test.sh` and `tests/limit-lib-test.sh` run against a redirected state dir. - [ ] A scenario deletes a held lock file out from under the holder and asserts the next acquire is refused (inode check). - [ ] The old `/tmp/matou-swarm.lock` path still excludes via the compatibility symlink for one pin cycle. - [ ] ADR 0004 amendment + GOTCHAS entry present; offline suite green. **Out of scope:** Changing the lock/reservation semantics themselves; retiring the compatibility symlink (a later pin-cycle follow-up).

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

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

close-report for #205 — status success

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

envelope
{
  "issue": 205,
  "status": "success",
  "commits": [
    "2f5b27557e5ef1de209cef55adcdf845227aa75e"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md",
    "execute-lib.sh",
    "host-capacity-lib.sh",
    "limit-lib.sh",
    "tests/host-capacity-lib-test.sh",
    "tests/limit-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/host-capacity-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/limit-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/execute-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\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "tests/host-capacity-lib-test.sh and tests/limit-lib-test.sh run against a redirected state dir": "host-capacity-lib-test.sh gains a 'state-dir redirect (#205)' group setting HOST_CAPACITY_STATE_DIR and asserting the slots/drive-wanted/skips/drive-log all derive from it; the whole suite now runs off a throwaway HOST_CAPACITY_STATE_DIR/HOST_CAPACITY_SLOT1_COMPAT so it never touches real host state. limit-lib-test.sh gains a 'state-dir redirect (#205)' group asserting the limit + active-token markers derive from HOST_CAPACITY_STATE_DIR and park() creates the dir. Both green (27 and 21 groups).",
    "A scenario deletes a held lock file out from under the holder and asserts the next acquire is refused (inode check)": "host-capacity-lib-test.sh 'inode check (#205)' group: acquire_heavy holds slot 1 (HOST_CAPACITY_HELD_INO recorded), host_capacity_held_live reads live; `rm` the held lock out from under the holder; host_capacity_held_live then returns non-zero (refused) — the holder's inode re-check (its next trust in the slot) fails so it stands down instead of acting on doubled capacity. Implemented by the post-flock inode guard in host_capacity_acquire_heavy/_exclusive (refuses an orphan) plus host_capacity_held_live in host-capacity-lib.sh.",
    "The old /tmp/matou-swarm.lock path still excludes via the compatibility symlink for one pin cycle": "host-capacity-lib-test.sh 'compat symlink (#205)' group: a background holder wins the new state-dir slot 1 via the lib, which creates the non-clobbering /tmp compat symlink (host_capacity_compat_link) pointing at the real slot 1; an opener of the old path (the symlink) is flock-EXCLUDED while slot 1 is held. HOST_CAPACITY_SLOT1_COMPAT (default /tmp/matou-swarm.lock) in host-capacity-lib.sh.",
    "ADR 0004 amendment + GOTCHAS entry present; offline suite green": "docs/adr/0004-*.md point 6 amended (namespace moved to $HOME/swarm/state, inode guard + compat symlink + lockstep-cutover note); docs/GOTCHAS.md gains entry 67 (renumbered from 66 at rebase after #207 took 66); STATUS.md header updated. Full offline suite green post-rebase."
  },
  "summary": "Moved the host-global factory-state DEFAULTS (slot locks, holder sidecars, drive reservation/skip counter, limit/active-token/auth-dead markers) off /tmp into HOST_CAPACITY_STATE_DIR with an inode-orphan guard and a slot-1 compat symlink; the enrolled-host cutover (protected workflow guards + host-capacity.env) is filed ready-for-session #218.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #205 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 205, "status": "success", "commits": [ "2f5b27557e5ef1de209cef55adcdf845227aa75e" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md", "execute-lib.sh", "host-capacity-lib.sh", "limit-lib.sh", "tests/host-capacity-lib-test.sh", "tests/limit-lib-test.sh" ], "tests": [ { "command": "bash tests/host-capacity-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/limit-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/execute-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\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "tests/host-capacity-lib-test.sh and tests/limit-lib-test.sh run against a redirected state dir": "host-capacity-lib-test.sh gains a 'state-dir redirect (#205)' group setting HOST_CAPACITY_STATE_DIR and asserting the slots/drive-wanted/skips/drive-log all derive from it; the whole suite now runs off a throwaway HOST_CAPACITY_STATE_DIR/HOST_CAPACITY_SLOT1_COMPAT so it never touches real host state. limit-lib-test.sh gains a 'state-dir redirect (#205)' group asserting the limit + active-token markers derive from HOST_CAPACITY_STATE_DIR and park() creates the dir. Both green (27 and 21 groups).", "A scenario deletes a held lock file out from under the holder and asserts the next acquire is refused (inode check)": "host-capacity-lib-test.sh 'inode check (#205)' group: acquire_heavy holds slot 1 (HOST_CAPACITY_HELD_INO recorded), host_capacity_held_live reads live; `rm` the held lock out from under the holder; host_capacity_held_live then returns non-zero (refused) — the holder's inode re-check (its next trust in the slot) fails so it stands down instead of acting on doubled capacity. Implemented by the post-flock inode guard in host_capacity_acquire_heavy/_exclusive (refuses an orphan) plus host_capacity_held_live in host-capacity-lib.sh.", "The old /tmp/matou-swarm.lock path still excludes via the compatibility symlink for one pin cycle": "host-capacity-lib-test.sh 'compat symlink (#205)' group: a background holder wins the new state-dir slot 1 via the lib, which creates the non-clobbering /tmp compat symlink (host_capacity_compat_link) pointing at the real slot 1; an opener of the old path (the symlink) is flock-EXCLUDED while slot 1 is held. HOST_CAPACITY_SLOT1_COMPAT (default /tmp/matou-swarm.lock) in host-capacity-lib.sh.", "ADR 0004 amendment + GOTCHAS entry present; offline suite green": "docs/adr/0004-*.md point 6 amended (namespace moved to $HOME/swarm/state, inode guard + compat symlink + lockstep-cutover note); docs/GOTCHAS.md gains entry 67 (renumbered from 66 at rebase after #207 took 66); STATUS.md header updated. Full offline suite green post-rebase." }, "summary": "Moved the host-global factory-state DEFAULTS (slot locks, holder sidecars, drive reservation/skip counter, limit/active-token/auth-dead markers) off /tmp into HOST_CAPACITY_STATE_DIR with an inode-orphan guard and a slot-1 compat symlink; the enrolled-host cutover (protected workflow guards + host-capacity.env) is filed ready-for-session #218.", "reason": "", "blockers": [], "no_code_change": "" } ``` </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/dev-factory#205
No description provided.