test suites leak into the REAL swarm.db — fixture x/y runs and phantom limit-pause park edges (tmp-path evidence) pollute the Loss/limit telemetry #116

Closed
opened 2026-08-30 04:27:27 +00:00 by ben · 3 comments
Owner

Symptom

The REAL ~/swarm/state/swarm.db on matou-workstation carries fixture rows and phantom limit telemetry written by test suites:

  • events: limit-pause | park account=B ids 3566/3571 (2026-08-30 00:24:34/36, evidence /tmp/tmp.qGJTToRVsZ/limit-marker), ids 3554/3559 (2026-08-29 ~20:08, evidence /tmp/tmp.GN0J7vGt19/limit-marker), ids 3446/3451 (park account=A, evidence /tmp/tmp.G0hFzwrfN1/limit-marker) — all with run_id=limit-park (the no-SWARM_RUN_ID default) and a mktemp marker path as evidence: the unmistakable shape of a test that overrode CLAUDE_LIMIT_MARKER into its tmpdir but left the swarm-db mirror wired at the real database.
  • runs: fixture rows triage-x-y-1788049474-*, heal-x-y-1788049476-* (repo x/y / Matou/dev-factory, 2026-08-30 00:24:34-37) — the heal-test / run-triage-test fixture repo landing in the live run ledger.
  • The fixture park events also read the REAL host CLAUDE_ACTIVE_MARKER (they stamped the live account letter B), so the tests are not just leaking writes — they read live host state too.

Why it matters

The limit-pause edges exist precisely to measure real lost capacity per account per week (#100 — the Loss tab's calibration input, the budget/second-account decision). Phantom park/unpark pairs from every CI run of the test suite make that measurement lie. It also cost real diagnosis time: during the 2026-08-30 false-park investigation (idss #1015 / GOTCHAS #131), the fake park account=B edges initially read as evidence account B had hit real limits, when B was healthy throughout.

Ask

  1. The test harness isolates the swarm-db mirror exactly as it isolates the markers: point the db at a tmp path (or leave swarmdb_event undefined) in every suite that sources limit-lib/heal/run-triage — heal-test.sh, run-triage-test.sh, claude-call-guards-test.sh, execute-lib-test.sh and siblings, wherever they run host-mode.
  2. A guard with teeth: a test-suite run that writes a row into a db outside its own tmpdir should FAIL the suite (e.g. assert the real db's max(id) unchanged across the run, or an env tripwire in swarmdb_event).
  3. Sweep the existing fixture rows (the x/y runs and the limit-pause events whose evidence is a /tmp/tmp.* path) so the Loss telemetry is honest again.

Found during the idss 2026-08-30 false-park investigation; the marker-side hardening (empty marker distrusted) landed as dev-factory a7509a4 / idss e7dc9eb0.

## Symptom The REAL `~/swarm/state/swarm.db` on matou-workstation carries fixture rows and phantom limit telemetry written by test suites: - `events`: `limit-pause | park account=B` ids **3566/3571** (2026-08-30 00:24:34/36, evidence `/tmp/tmp.qGJTToRVsZ/limit-marker`), ids **3554/3559** (2026-08-29 ~20:08, evidence `/tmp/tmp.GN0J7vGt19/limit-marker`), ids **3446/3451** (`park account=A`, evidence `/tmp/tmp.G0hFzwrfN1/limit-marker`) — all with `run_id=limit-park` (the no-SWARM_RUN_ID default) and a **mktemp marker path as evidence**: the unmistakable shape of a test that overrode `CLAUDE_LIMIT_MARKER` into its tmpdir but left the swarm-db mirror wired at the real database. - `runs`: fixture rows `triage-x-y-1788049474-*`, `heal-x-y-1788049476-*` (repo `x/y` / `Matou/dev-factory`, 2026-08-30 00:24:34-37) — the heal-test / run-triage-test fixture repo landing in the live run ledger. - The fixture park events also read the REAL host `CLAUDE_ACTIVE_MARKER` (they stamped the live account letter `B`), so the tests are not just leaking writes — they read live host state too. ## Why it matters The `limit-pause` edges exist precisely to measure real lost capacity per account per week (#100 — the Loss tab's calibration input, the budget/second-account decision). Phantom park/unpark pairs from every CI run of the test suite make that measurement lie. It also cost real diagnosis time: during the 2026-08-30 false-park investigation (idss #1015 / GOTCHAS #131), the fake `park account=B` edges initially read as evidence account B had hit real limits, when B was healthy throughout. ## Ask 1. The test harness isolates the swarm-db mirror exactly as it isolates the markers: point the db at a tmp path (or leave `swarmdb_event` undefined) in every suite that sources limit-lib/heal/run-triage — `heal-test.sh`, `run-triage-test.sh`, `claude-call-guards-test.sh`, `execute-lib-test.sh` and siblings, wherever they run host-mode. 2. A guard with teeth: a test-suite run that writes a row into a db outside its own tmpdir should FAIL the suite (e.g. assert the real db's max(id) unchanged across the run, or an env tripwire in swarmdb_event). 3. Sweep the existing fixture rows (the `x/y` runs and the `limit-pause` events whose evidence is a `/tmp/tmp.*` path) so the Loss telemetry is honest again. Found during the idss 2026-08-30 false-park investigation; the marker-side hardening (empty marker distrusted) landed as dev-factory `a7509a4` / idss `e7dc9eb0`.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: category bug; state ready-for-agent, scoped to asks 1 & 2 (prevent future leaks + a guard with teeth). Ask 3 (sweeping the already-leaked rows from the live host db) is carved out to #117 and labelled ready-for-human.

Why this is a two-way door: asks 1 & 2 touch only test scaffolding and a defensive guard — no .sandcastle/, no prompt skeleton, no .forgejo/, no host credentials, no live door. Every change is revertible by a later commit and provable by the existing offline test suite (a suite that writes outside its own tmpdir fails the guard). That is squarely inside the ADR 0174 bar, so the swarm may claim it.

Why ask 3 is split out: deleting rows from the live ~/swarm/state/swarm.db on matou-workstation is data destruction against live telemetry — a one-way door — and needs the host's own state, not a swarm container. It also has no code path today (swarm-db.py exposes no prune/delete subcommand). It is sequenced after this fix (else the suite re-dirties the db) and tracked in #117.

Verification done during triage: the leak mechanism is confirmed. SWARM_DB defaults to $HOME/swarm/state/swarm.db (swarm-db-lib.sh:13) and CLAUDE_LIMIT_MARKER to a fixed host path (limit-lib.sh:52); swarmdb_event writes to $SWARM_DB (swarm-db-lib.sh:57-78). Any suite that sources the mirror in host-mode without overriding both writes real rows and reads live host state — exactly the reported shape (run_id=limit-park, /tmp/tmp.* evidence, x/y fixture runs).


Agent brief — asks 1 & 2 only

Goal: no test suite can ever again write a row into a db (or read/stamp a marker) outside its own tmpdir; a suite that tries fails loud.

Context / where it breaks

  • swarmdb_event (swarm-db-lib.sh:57) writes to $SWARM_DB, defaulting to $HOME/swarm/state/swarm.db (:13). claude_limit_parked (limit-lib.sh:100-101) mirrors a limit-pause edge through it, defaulting run_id to limit-park and evidence to $CLAUDE_LIMIT_MARKER (:113). CLAUDE_LIMIT_MARKER defaults to /tmp/matou-swarm-claude-limit (:52) and the live host marker carries the active account letter.
  • Good examples already in-tree: tests/run-triage-test.sh:136 (db="$tmp/swarm.db" … "never the real host one"), tests/heal-test.sh:46 (SWARM_DB="$work/swarm.db"), tests/execute-lib-test.sh:46 (stubs swarmdb_event entirely). The leak is a suite/codepath that sources limit-lib/heal/run-triage in host-mode and calls a park/unpark or run path without SWARM_DB (and/or CLAUDE_LIMIT_MARKER) pointed at its tmpdir.

Ask 1 — isolate the mirror in every host-mode suite

  • Audit every suite that sources limit-lib.sh / heal / run-triage / execute-lib (tests/heal-test.sh, tests/run-triage-test.sh, tests/claude-call-guards-test.sh, tests/execute-lib-test.sh, and siblings) and ensure each invocation that can reach swarmdb_event exports SWARM_DB="$tmp/…" and CLAUDE_LIMIT_MARKER="$tmp/…" (and CLAUDE_ACTIVE_MARKER where a park reads the active letter). Find the specific invocation(s) that produced ids 3566/3571 etc. — the triage-x-y-*/heal-x-y-* run-ids point at run-triage-test/heal-test paths that leaked.
  • Prefer isolating at the seam (export the tmp defaults once near each suite's mktemp -d setup) over per-line patches, so a future test can't forget.

Ask 2 — a guard with teeth

  • Add a tripwire so a suite that writes outside its own tmpdir fails. Options, pick the robust one: (a) an env tripwire honoured inside swarmdb_event (e.g. when a test-only SWARMDB_ASSERT_UNDER=$tmp is set, refuse/abort a write whose $SWARM_DB is not under it), and/or (b) a suite-level assertion that the real ~/swarm/state/swarm.db max(id) is unchanged across the run (skip cleanly when python3/db absent, like heal-test.sh:432).
  • The guard itself needs a test that proves it fires (red without the fix, green with it).

Constraints

  • CLAUDE.md: every lib change updates its test in the same commit; run the offline suite before proposing a close:
    for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done
  • No repo names/hosts/product paths in harness files.
  • Do NOT touch the live ~/swarm/state/swarm.db — the cleanup of already-leaked rows is #117 (ready-for-human), sequenced after this.

Done when: the audited suites provably write only under their tmpdir; the new guard fails a deliberately-leaking test and passes the fixed suites; the full offline suite is green.

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** category `bug`; state `ready-for-agent`, **scoped to asks 1 & 2** (prevent future leaks + a guard with teeth). Ask 3 (sweeping the already-leaked rows from the live host db) is carved out to #117 and labelled `ready-for-human`. **Why this is a two-way door:** asks 1 & 2 touch only test scaffolding and a defensive guard — no `.sandcastle/`, no prompt skeleton, no `.forgejo/`, no host credentials, no live door. Every change is revertible by a later commit and **provable by the existing offline test suite** (a suite that writes outside its own tmpdir fails the guard). That is squarely inside the ADR 0174 bar, so the swarm may claim it. **Why ask 3 is split out:** deleting rows from the **live** `~/swarm/state/swarm.db` on matou-workstation is data destruction against live telemetry — a one-way door — and needs the host's own state, not a swarm container. It also has **no** code path today (`swarm-db.py` exposes no prune/delete subcommand). It is sequenced *after* this fix (else the suite re-dirties the db) and tracked in #117. **Verification done during triage:** the leak mechanism is confirmed. `SWARM_DB` defaults to `$HOME/swarm/state/swarm.db` (`swarm-db-lib.sh:13`) and `CLAUDE_LIMIT_MARKER` to a fixed host path (`limit-lib.sh:52`); `swarmdb_event` writes to `$SWARM_DB` (`swarm-db-lib.sh:57-78`). Any suite that sources the mirror in host-mode without overriding **both** writes real rows and reads live host state — exactly the reported shape (`run_id=limit-park`, `/tmp/tmp.*` evidence, `x/y` fixture runs). --- ## Agent brief — asks 1 & 2 only **Goal:** no test suite can ever again write a row into a db (or read/stamp a marker) outside its own tmpdir; a suite that tries **fails loud**. **Context / where it breaks** - `swarmdb_event` (`swarm-db-lib.sh:57`) writes to `$SWARM_DB`, defaulting to `$HOME/swarm/state/swarm.db` (`:13`). `claude_limit_parked` (`limit-lib.sh:100-101`) mirrors a `limit-pause` edge through it, defaulting `run_id` to `limit-park` and `evidence` to `$CLAUDE_LIMIT_MARKER` (`:113`). `CLAUDE_LIMIT_MARKER` defaults to `/tmp/matou-swarm-claude-limit` (`:52`) and the live host marker carries the active account letter. - Good examples already in-tree: `tests/run-triage-test.sh:136` (`db="$tmp/swarm.db"` … "never the real host one"), `tests/heal-test.sh:46` (`SWARM_DB="$work/swarm.db"`), `tests/execute-lib-test.sh:46` (stubs `swarmdb_event` entirely). The leak is a suite/codepath that sources limit-lib/heal/run-triage in host-mode and calls a park/unpark or run path **without** `SWARM_DB` (and/or `CLAUDE_LIMIT_MARKER`) pointed at its tmpdir. **Ask 1 — isolate the mirror in every host-mode suite** - Audit every suite that sources `limit-lib.sh` / heal / run-triage / execute-lib (`tests/heal-test.sh`, `tests/run-triage-test.sh`, `tests/claude-call-guards-test.sh`, `tests/execute-lib-test.sh`, and siblings) and ensure **each invocation that can reach `swarmdb_event`** exports `SWARM_DB="$tmp/…"` and `CLAUDE_LIMIT_MARKER="$tmp/…"` (and `CLAUDE_ACTIVE_MARKER` where a park reads the active letter). Find the specific invocation(s) that produced ids 3566/3571 etc. — the `triage-x-y-*`/`heal-x-y-*` run-ids point at run-triage-test/heal-test paths that leaked. - Prefer isolating at the seam (export the tmp defaults once near each suite's `mktemp -d` setup) over per-line patches, so a future test can't forget. **Ask 2 — a guard with teeth** - Add a tripwire so a suite that writes outside its own tmpdir **fails**. Options, pick the robust one: (a) an env tripwire honoured inside `swarmdb_event` (e.g. when a test-only `SWARMDB_ASSERT_UNDER=$tmp` is set, refuse/abort a write whose `$SWARM_DB` is not under it), and/or (b) a suite-level assertion that the real `~/swarm/state/swarm.db` `max(id)` is unchanged across the run (skip cleanly when python3/db absent, like `heal-test.sh:432`). - The guard itself needs a test that proves it fires (red without the fix, green with it). **Constraints** - CLAUDE.md: every lib change updates its test in the **same commit**; run the offline suite before proposing a close: `for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done` - No repo names/hosts/product paths in harness files. - **Do NOT touch the live `~/swarm/state/swarm.db`** — the cleanup of already-leaked rows is #117 (`ready-for-human`), sequenced after this. **Done when:** the audited suites provably write only under their tmpdir; the new guard fails a deliberately-leaking test and passes the fixed suites; the full offline suite is green.

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

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

close-report for #116 — status success

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

envelope
{
  "issue": 116,
  "status": "success",
  "commits": [
    "1598be15496988e3665bb7356ede876d31dc93f7"
  ],
  "changed_files": [
    "swarm-db-lib.sh",
    "tests/swarm-db-test.sh",
    "tests/test-env.sh",
    "tests/claude-call-guards-test.sh",
    "tests/run-triage-test.sh",
    "tests/heal-test.sh",
    "tests/session-runner-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/swarm-db-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/test-env.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/claude-call-guards-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/run-triage-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/heal-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/session-runner-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/limit-lib-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Ask 1 — isolate the mirror in every host-mode suite": "claude-call-guards-test.sh (the confirmed leaker: run_id=limit-park + /tmp/tmp.*/limit-marker + x/y run rows) now sources test-env.sh and calls test_env_hermetic (redirecting SWARM_DB) and pins CLAUDE_ACTIVE_MARKER; test_env_hermetic also redirects CLAUDE_LIMIT_MARKER/CLAUDE_ACTIVE_MARKER for every sourcer (tests/test-env.sh). run-triage-test.sh and heal-test.sh now source it too.",
    "Ask 1 — prefer isolating at the seam so a future test can't forget": "The redirect lives in test_env_hermetic (one place), and test-env.sh's self-guard LINT now fails the suite for any test that execs run-swarm|session-runner|run-triage|heal by path without sourcing the helper (previously only run-swarm/session-runner).",
    "Ask 2 — a guard with teeth that FAILS a suite writing outside its tmpdir": "swarm-db-lib.sh honours SWARMDB_ASSERT_UNDER (armed by test_env_hermetic): swarmdb/swarmdb_sweep_orphans/swarmdb_ingest/swarmdb_spend_from_result REFUSE any write whose SWARM_DB escapes the sandbox, print a loud LEAK TRIPWIRE line, and record a .swarmdb-leak-attempts breadcrumb a suite asserts on (claude-call-guards asserts it stays absent).",
    "Ask 2 — the guard has its own test proving it fires (red without, green with)": "tests/swarm-db-test.sh #116 block: control write with no tripwire lands (proves path live); armed+outside is refused (db untouched, stderr announces, breadcrumb written, named path); armed+inside proceeds normally; swarmdb_ingest honours it too.",
    "Full offline suite green before close": "for t in tests/*.sh onboarding/tests/*.sh loop: all green except tests/fleet-tui-test.sh, a pre-existing pytest-env red on clean HEAD (git stash confirmed) unrelated to this change.",
    "Ask 3 (sweep already-leaked live rows) NOT done here": "Carved out to #117 (ready-for-human) by the triage ADR-0174 ruling — one-way-door data destruction against live telemetry; out of scope for this ticket."
  },
  "summary": "Host-mode test suites no longer mirror phantom park/run rows into the live swarm.db: the test-env seam redirects SWARM_DB + the limit markers and its lint now covers run-triage/heal, backed by a SWARMDB_ASSERT_UNDER tripwire in swarm-db-lib.sh that refuses and records any out-of-sandbox write.",
  "blockers": []
}
**close-report** for #116 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 116, "status": "success", "commits": [ "1598be15496988e3665bb7356ede876d31dc93f7" ], "changed_files": [ "swarm-db-lib.sh", "tests/swarm-db-test.sh", "tests/test-env.sh", "tests/claude-call-guards-test.sh", "tests/run-triage-test.sh", "tests/heal-test.sh", "tests/session-runner-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/swarm-db-test.sh", "exit_code": 0 }, { "command": "bash tests/test-env.sh", "exit_code": 0 }, { "command": "bash tests/claude-call-guards-test.sh", "exit_code": 0 }, { "command": "bash tests/run-triage-test.sh", "exit_code": 0 }, { "command": "bash tests/heal-test.sh", "exit_code": 0 }, { "command": "bash tests/session-runner-test.sh", "exit_code": 0 }, { "command": "bash tests/limit-lib-test.sh", "exit_code": 0 } ], "criteria": { "Ask 1 — isolate the mirror in every host-mode suite": "claude-call-guards-test.sh (the confirmed leaker: run_id=limit-park + /tmp/tmp.*/limit-marker + x/y run rows) now sources test-env.sh and calls test_env_hermetic (redirecting SWARM_DB) and pins CLAUDE_ACTIVE_MARKER; test_env_hermetic also redirects CLAUDE_LIMIT_MARKER/CLAUDE_ACTIVE_MARKER for every sourcer (tests/test-env.sh). run-triage-test.sh and heal-test.sh now source it too.", "Ask 1 — prefer isolating at the seam so a future test can't forget": "The redirect lives in test_env_hermetic (one place), and test-env.sh's self-guard LINT now fails the suite for any test that execs run-swarm|session-runner|run-triage|heal by path without sourcing the helper (previously only run-swarm/session-runner).", "Ask 2 — a guard with teeth that FAILS a suite writing outside its tmpdir": "swarm-db-lib.sh honours SWARMDB_ASSERT_UNDER (armed by test_env_hermetic): swarmdb/swarmdb_sweep_orphans/swarmdb_ingest/swarmdb_spend_from_result REFUSE any write whose SWARM_DB escapes the sandbox, print a loud LEAK TRIPWIRE line, and record a .swarmdb-leak-attempts breadcrumb a suite asserts on (claude-call-guards asserts it stays absent).", "Ask 2 — the guard has its own test proving it fires (red without, green with)": "tests/swarm-db-test.sh #116 block: control write with no tripwire lands (proves path live); armed+outside is refused (db untouched, stderr announces, breadcrumb written, named path); armed+inside proceeds normally; swarmdb_ingest honours it too.", "Full offline suite green before close": "for t in tests/*.sh onboarding/tests/*.sh loop: all green except tests/fleet-tui-test.sh, a pre-existing pytest-env red on clean HEAD (git stash confirmed) unrelated to this change.", "Ask 3 (sweep already-leaked live rows) NOT done here": "Carved out to #117 (ready-for-human) by the triage ADR-0174 ruling — one-way-door data destruction against live telemetry; out of scope for this ticket." }, "summary": "Host-mode test suites no longer mirror phantom park/run rows into the live swarm.db: the test-env seam redirects SWARM_DB + the limit markers and its lint now covers run-triage/heal, backed by a SWARMDB_ASSERT_UNDER tripwire in swarm-db-lib.sh that refuses and records any out-of-sandbox write.", "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/dev-factory#116
No description provided.