Move host-state ownership (crontab, /tmp/matou-swarm.lock, swarm.db) to this repo #3

Closed
opened 2026-08-19 22:05:57 +00:00 by ben · 2 comments
Owner

Follow-up from #571 (Matou/ourcloud) — the factory-core extraction

ADR 0180 point 4: "Host state is factory-owned. Crontab entries, /tmp/matou-swarm.lock, swarm.db, and host scheduling belong to the factory, not to any product repo." #571 extracted the factory's CODE (libs, orchestrators, forgejo-lib.sh) but did not move host state ownership — the workstation's crontab, the lock file, and swarm.db still live/are installed per the old ourcloud-centric assumptions.

Distinct from #577 (Matou/ourcloud) — host scheduling POLICY (capacity semaphore, per-repo fairness, drive-vs-worker serialization) — this ticket is about WHERE that state and its installers live, which #577's design needs settled first (an arbiter needs a home before it can arbitrate). Likely session-shaped (host crontab is live infrastructure), not swarm-workable.

What's needed

  • Decide (or confirm ADR 0180's point 4 stands as-is) whether crontab entries get installed FROM this repo (a setup script here that a product repo's onboarding runs) vs. staying hand-maintained per host.
  • swarm.db's location/ownership once multiple product repos share one workstation — does each repo get its own db, or one shared db this repo owns the schema/migrations for?
  • Coordinate with #577's design once it lands.
## Follow-up from #571 (Matou/ourcloud) — the factory-core extraction ADR 0180 point 4: "Host state is factory-owned. Crontab entries, /tmp/matou-swarm.lock, swarm.db, and host scheduling belong to the factory, not to any product repo." #571 extracted the factory's CODE (libs, orchestrators, forgejo-lib.sh) but did not move host state ownership — the workstation's crontab, the lock file, and swarm.db still live/are installed per the old ourcloud-centric assumptions. Distinct from #577 (Matou/ourcloud) — host scheduling POLICY (capacity semaphore, per-repo fairness, drive-vs-worker serialization) — this ticket is about WHERE that state and its installers live, which #577's design needs settled first (an arbiter needs a home before it can arbitrate). Likely session-shaped (host crontab is live infrastructure), not swarm-workable. ## What's needed - Decide (or confirm ADR 0180's point 4 stands as-is) whether crontab entries get installed FROM this repo (a setup script here that a product repo's onboarding runs) vs. staying hand-maintained per host. - swarm.db's location/ownership once multiple product repos share one workstation — does each repo get its own db, or one shared db this repo owns the schema/migrations for? - Coordinate with #577's design once it lands.
Author
Owner

Observed 2026-08-23 (session-runner fairness): with two repos' runners on matou-workstation, /tmp/matou-session-runner.lock is host-global, so while idss's session is in flight every dev-factory tick logs session in flight — tick absorbed — one repo can starve the other for a whole SESSION_RUNNER_TIMEOUT (2 h) with no rotation. Same shape as the swarm's host-capacity question (idss #577 / ADR 0184): the lock is a host resource and should be owned by the host layer this ticket moves here — either a pooled slot count for session-runners or a round-robin pick across enrolled repos, with the per-repo SESSION_RUNNER=on|off policy (#6 ruling) deciding who is in the rotation.

**Observed 2026-08-23 (session-runner fairness):** with two repos' runners on matou-workstation, `/tmp/matou-session-runner.lock` is host-global, so while idss's session is in flight every dev-factory tick logs `session in flight — tick absorbed` — one repo can starve the other for a whole `SESSION_RUNNER_TIMEOUT` (2 h) with no rotation. Same shape as the swarm's host-capacity question (idss #577 / ADR 0184): the lock is a host resource and should be owned by the host layer this ticket moves here — either a pooled slot count for session-runners or a round-robin pick across enrolled repos, with the per-repo `SESSION_RUNNER=on|off` policy (#6 ruling) deciding who is in the rotation.

Close report — host state is factory-owned, and installs from here

Ruled by agent under ADR 0174 — veto anytime. Every part of this is a two-way door: a commit, plus a crontab change made from a backup that undoes with one crontab <backup>, proven by an offline test suite and a live cron-like run.

What the ticket asked, and how each part was answered

1. "Decide (or confirm ADR 0180 point 4 stands) whether crontab entries get installed FROM this repo." — Installed from here. New docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md; the mechanism is onboarding/onboard.sh host-cron {render,diff,install} over onboarding/host-state-lib.sh.

Hand-maintained lost on evidence found while looking: ~/swarm/backstop-tick.sh still described the product repo the core was extracted from as "the canonical harness home", read THAT repo's secrets/forgejo_token, and dispatched every other repo's workflows with it — and nobody had hand-edited it for this repo, so Matou/dev-factory had run since onboarding with no schedule backstop at all, depending solely on the Forgejo scheduler that #238 proved dies silently. A host with no declared state cannot be drift-checked.

2. "swarm.db's location/ownership once multiple repos share one workstation." — ONE shared db per host (<home>/state/swarm.db), schema owned here. This CONFIRMS the shipped default rather than changing it. Reasons in ADR 0004 point 5: runs.repo already exists; the questions actually asked of the db (open-processes — the #435 wedge surface — and spend-weekly) are HOST questions; WAL + busy_timeout=5000 already handles several writers and the write path is best-effort because the db is a MIRROR; and one db is safer across the pin lag than N, since the newest pin's migrate() covers the shared file while N dbs would each be migrated by whichever pin wrote last. That binds one rule: schema changes must be additive — a mixed-pin host has writers at several FACTORY_REFs, so never rename or drop a column a shipped pin still writes.

3. /tmp/matou-swarm.lock — recorded (point 6), nothing moves. It is the host's lock namespace, already owned by factory code (host-capacity-lib.sh), and host-global by construction: that is what makes the pooled slots genuinely shared between repos rather than per-repo. The ticket listed it as unmoved because the ownership had never been written down.

4. "Coordinate with #577's design once it lands." — #577 is policy (how a host arbitrates); this was ownership (where the state and its installers live). ADR 0004 gives the policy a home — the registry declares the enrolled set, the pooled locks are named as host state — and deliberately renders today's cadences UNCHANGED so the ownership move is behaviour-preserving and the policy can be judged on its own evidence. Your #3 comment (session-runner starvation) is filed as #35 with your observation quoted.

What landed

Commit 94ab290 on main (root + onboarding/ only — nothing vendored changed, so no consumer re-vendor is needed):

  • docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md
  • onboarding/host-state-lib.sh — registry parse/validate, both renders, the crontab splice, diff/install/conflicts
  • onboarding/onboard.sh host-cron {render,diff,install} [registry] [--allow-conflicts]
  • onboarding/templates/host-registry.conf.example — the schema
  • onboarding/tests/host-state-lib-test.sh — 53 cases
  • onboarding/README.md (new "Host state" section), STATUS.md

Design choices worth the veto's attention:

  • Factory-only, not vendored. onboarding/** is vendor-excluded, so no consumer ships a tool that edits a host's crontab. Host enrolment runs from a dev-factory checkout. When a vendored consumer genuinely needs to READ the registry (the fairness arbiter in #35 is the likely first), the reader lifts to a root lib then.
  • The registry lives on the host, never here. Which repos a host carries is an operational fact — the same rule that keeps the consumer list in STATUS.md and not in a harness file. This repo owns the schema; a test ratchets that the lib names no product repo, host or path.
  • The splice is additive. Only lines between # BEGIN/END factory-managed are owned; everything else — MAILTO, a product's rehearsal executor, its lab reaper — passes through byte-identical. Promoting product loops into the block would mean the factory rendering product-shaped cron, which ADR 0001 and CLAUDE.md both forbid.
  • Three guards make it two-way: backup before any write; an unbalanced marker pair REFUSES to splice (an orphaned BEGIN would otherwise swallow the tail of someone's crontab); and install fails CLOSED (exit 3, offending lines named) when an unmanaged line still runs an entry point the block owns — because additive splicing means a superseded hand line keeps firing beside the managed one and DOUBLES the host's heavy jobs, on hosts whose whole capacity subsystem exists because they are memory-tight (GOTCHAS 14's OOM family). --allow-conflicts is the operator's explicit override.

Proof

  • Offline: onboarding/tests/host-state-lib-test.sh — 53 passed, 0 failed. Red before the lib existed; the conflict-guard cases were red before that guard. Full suite green: 63 files (60 vendored tests/ + 3 onboarding/tests/). Writing the test caught a real bug: word-splitting a registry line let the SHELL glob a cron expression's * against the working directory, so a declared */15 * * * * rendered whatever files sat beside the caller.
  • Live on matou-workstation (all of it revertible; the pre-change crontab is ~/swarm/cron-backups/crontab-pre-3-manual-20260823T152342Z.txt):
    • ~/swarm/host-registry.conf written from observed reality (3 repos, 2 session-runners, 13 backstop ticks).
    • host-cron install REFUSED first, naming the 3 superseded hand lines — the guard firing on the real host, not just in a test.
    • Those 3 lines pruned by hand (backed up), block installed; host-cron diff now reports no change — the host matches.
    • The unmanaged product lines (rehearsal executor, lab reaper, MAILTO) are byte-identical.
    • The generated tick script run once under a cron-like env -i: all three repos ticked from their own checkouts with their own tokens, in-window workflows skipped, and dev-factory's overdue healer/triage/resume-asks dispatched on their first-ever backstop run — the gap this move closes, demonstrated.
    • Retired wrapper renamed ~/swarm/backstop-tick.sh.retired-20260823 (bytes kept). Session-runner logs now land in ~/swarm/logs/session-runner-<repo>.log.

Residue, all ticketed — nothing silently dropped

  • #35 — session-runner fairness: /tmp/matou-session-runner.lock is host-global, so one repo's in-flight session absorbs another's ticks for up to a whole SESSION_RUNNER_TIMEOUT. Your comment quoted in full; pairs with Matou/idss#577 and #6.
  • #36 — swarm.db's reader queries are not repo-scoped although the db is shared: q_issue filters on issue=? alone, and issue numbers are per-repo. Latent today (live db: Matou/ourcloud 665 runs, Matou/idss 362, Matou/matou-app 75, Matou/dev-factory 11; no issue number has collided yet) — it will not stay latent.
  • #37 — the host env file is still product-flavoured (one product's drive variables beside the shared tokens). The registry names it as a path, so renaming it is host-side work, not a harness change.
  • Other hosts are not enrolled by this ticket: elitebook-03 has no registry yet. It is one file plus host-cron install when someone is at that host — natural work for #6 (host enrolment).
## Close report — host state is factory-owned, and installs from here **Ruled by agent under ADR 0174 — veto anytime.** Every part of this is a two-way door: a commit, plus a crontab change made from a backup that undoes with one `crontab <backup>`, proven by an offline test suite and a live cron-like run. ### What the ticket asked, and how each part was answered **1. "Decide (or confirm ADR 0180 point 4 stands) whether crontab entries get installed FROM this repo."** — Installed from here. New `docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md`; the mechanism is `onboarding/onboard.sh host-cron {render,diff,install}` over `onboarding/host-state-lib.sh`. Hand-maintained lost on evidence found while looking: `~/swarm/backstop-tick.sh` still described the product repo the core was extracted from as "the canonical harness home", read THAT repo's `secrets/forgejo_token`, and dispatched every other repo's workflows with it — and nobody had hand-edited it for **this** repo, so `Matou/dev-factory` had run since onboarding with **no schedule backstop at all**, depending solely on the Forgejo scheduler that #238 proved dies silently. A host with no declared state cannot be drift-checked. **2. "swarm.db's location/ownership once multiple repos share one workstation."** — ONE shared db per host (`<home>/state/swarm.db`), schema owned here. This CONFIRMS the shipped default rather than changing it. Reasons in ADR 0004 point 5: `runs.repo` already exists; the questions actually asked of the db (`open-processes` — the #435 wedge surface — and `spend-weekly`) are HOST questions; WAL + `busy_timeout=5000` already handles several writers and the write path is best-effort because the db is a MIRROR; and one db is *safer* across the pin lag than N, since the newest pin's `migrate()` covers the shared file while N dbs would each be migrated by whichever pin wrote last. That binds one rule: **schema changes must be additive** — a mixed-pin host has writers at several `FACTORY_REF`s, so never rename or drop a column a shipped pin still writes. **3. `/tmp/matou-swarm.lock`** — recorded (point 6), nothing moves. It is the host's lock namespace, already owned by factory code (`host-capacity-lib.sh`), and host-global *by construction*: that is what makes the pooled slots genuinely shared between repos rather than per-repo. The ticket listed it as unmoved because the ownership had never been written down. **4. "Coordinate with #577's design once it lands."** — #577 is policy (how a host arbitrates); this was ownership (where the state and its installers live). ADR 0004 gives the policy a home — the registry declares the enrolled set, the pooled locks are named as host state — and deliberately renders today's cadences UNCHANGED so the ownership move is behaviour-preserving and the policy can be judged on its own evidence. Your #3 comment (session-runner starvation) is filed as **#35** with your observation quoted. ### What landed Commit `94ab290` on `main` (root + `onboarding/` only — **nothing vendored changed, so no consumer re-vendor is needed**): - `docs/adr/0004-host-state-is-factory-owned-and-installed-from-a-host-registry.md` - `onboarding/host-state-lib.sh` — registry parse/validate, both renders, the crontab splice, `diff`/`install`/`conflicts` - `onboarding/onboard.sh host-cron {render,diff,install} [registry] [--allow-conflicts]` - `onboarding/templates/host-registry.conf.example` — the schema - `onboarding/tests/host-state-lib-test.sh` — 53 cases - `onboarding/README.md` (new "Host state" section), `STATUS.md` **Design choices worth the veto's attention:** - **Factory-only, not vendored.** `onboarding/**` is vendor-excluded, so no consumer ships a tool that edits a host's crontab. Host enrolment runs from a dev-factory checkout. When a *vendored* consumer genuinely needs to READ the registry (the fairness arbiter in #35 is the likely first), the reader lifts to a root lib then. - **The registry lives on the host, never here.** Which repos a host carries is an operational fact — the same rule that keeps the consumer list in `STATUS.md` and not in a harness file. This repo owns the schema; a test ratchets that the lib names no product repo, host or path. - **The splice is additive.** Only lines between `# BEGIN/END factory-managed` are owned; everything else — `MAILTO`, a product's rehearsal executor, its lab reaper — passes through byte-identical. Promoting product loops into the block would mean the factory rendering product-shaped cron, which ADR 0001 and CLAUDE.md both forbid. - **Three guards make it two-way:** backup before any write; an unbalanced marker pair REFUSES to splice (an orphaned BEGIN would otherwise swallow the tail of someone's crontab); and `install` fails CLOSED (exit 3, offending lines named) when an unmanaged line still runs an entry point the block owns — because additive splicing means a superseded hand line keeps firing beside the managed one and DOUBLES the host's heavy jobs, on hosts whose whole capacity subsystem exists because they are memory-tight (GOTCHAS 14's OOM family). `--allow-conflicts` is the operator's explicit override. ### Proof - **Offline:** `onboarding/tests/host-state-lib-test.sh` — 53 passed, 0 failed. Red before the lib existed; the conflict-guard cases were red before that guard. Full suite green: 63 files (60 vendored `tests/` + 3 `onboarding/tests/`). Writing the test caught a real bug: word-splitting a registry line let the SHELL glob a cron expression's `*` against the working directory, so a declared `*/15 * * * *` rendered whatever files sat beside the caller. - **Live on `matou-workstation`** (all of it revertible; the pre-change crontab is `~/swarm/cron-backups/crontab-pre-3-manual-20260823T152342Z.txt`): - `~/swarm/host-registry.conf` written from observed reality (3 repos, 2 session-runners, 13 backstop ticks). - `host-cron install` REFUSED first, naming the 3 superseded hand lines — the guard firing on the real host, not just in a test. - Those 3 lines pruned by hand (backed up), block installed; `host-cron diff` now reports **`no change — the host matches`**. - The unmanaged product lines (rehearsal executor, lab reaper, `MAILTO`) are byte-identical. - The generated tick script run once under a cron-like `env -i`: all three repos ticked from their own checkouts with their own tokens, in-window workflows skipped, and **dev-factory's overdue `healer`/`triage`/`resume-asks` dispatched on their first-ever backstop run** — the gap this move closes, demonstrated. - Retired wrapper renamed `~/swarm/backstop-tick.sh.retired-20260823` (bytes kept). Session-runner logs now land in `~/swarm/logs/session-runner-<repo>.log`. ### Residue, all ticketed — nothing silently dropped - **#35** — session-runner fairness: `/tmp/matou-session-runner.lock` is host-global, so one repo's in-flight session absorbs another's ticks for up to a whole `SESSION_RUNNER_TIMEOUT`. Your comment quoted in full; pairs with `Matou/idss#577` and #6. - **#36** — `swarm.db`'s reader queries are not repo-scoped although the db is shared: `q_issue` filters on `issue=?` alone, and issue numbers are per-repo. Latent today (live db: `Matou/ourcloud` 665 runs, `Matou/idss` 362, `Matou/matou-app` 75, `Matou/dev-factory` 11; no issue number has collided yet) — it will not stay latent. - **#37** — the host env file is still product-flavoured (one product's drive variables beside the shared tokens). The registry names it as a path, so renaming it is host-side work, not a harness change. - **Other hosts** are not enrolled by this ticket: `elitebook-03` has no registry yet. It is one file plus `host-cron install` when someone is at that host — natural work for #6 (host enrolment).
matou-build-agent 2026-08-23 15:29:33 +00:00
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#3
No description provided.