sweep: reap orphaned factory containers by label+age, not only sandcastle-* names (matou-app-ci leak, 5 orphans / 3 cores / 10 days) #122

Closed
opened 2026-09-03 15:27:15 +00:00 by ben · 2 comments
Owner

Symptom

sweep-lib.sh reaps only containers named sandcastle-* (docker ps -a --filter 'name=^/?sandcastle-'). Every other factory docker run — matou-app ci.yml's checks container, the healer agent's ad-hoc /tmp/heal-fix bisect runs — is invisible to it. Five such containers accumulated on elitebook-03 (2026-08-24 → 09-03), burned ~3 of 8 cores and ~700 MB swap for up to 11 days, and caused the idss ci 16970 red (idss #1182). Full trace and the workflow-side half of the fix: Matou/matou-app#331.

Mechanism

Forgejo cancels the run (auto-cancel on newer push) or the runner loses the task (Forgejo outage); the runner kills the step's process tree = the docker run client only. --rm never fires, sig-proxy has no client, bash -lc as PID 1 ignores SIGTERM, the act workspace is deleted from under the process, and the container spins forever. Same for heal.sh's timeout 900 killing the agent mid-docker run.

Fix

  1. Reap by label + age, not by name: in sweep-lib.sh, also reap any container carrying --label matou.factory=<kind> whose CreatedAt is older than a per-kind ceiling (ci: the workflow's timeout-minutes + slack; heal: 900 s + slack). Keep the sandcastle-* name path.
  2. Belt for containers nobody labelled: reap any container whose image is a factory sandbox image (*-ci, the sandcastle image tag) and is older than 3 h — no legitimate factory container lives that long.
  3. heal.sh / the healer prompt: every docker run the agent issues carries --label matou.factory=heal --label matou.run=$RUN_ID (or run under --cidfile and docker rm -f in a trap); timeout should use --kill-after and the trap must run before the kill.
  4. Log each reap to the swarm db / Mattermost sweep line so a recurrence is visible instead of silent.

Acceptance

  • heal-lib-test.sh / sweep tests: a labelled container older than its ceiling is reaped; a fresh one is not; an unlabelled matou-app-ci container older than 3 h is reaped.
  • After the next cancelled matou-app ci run, docker ps --filter ancestor=matou-app-ci is empty on the runner within one sweep tick.
## Symptom `sweep-lib.sh` reaps only containers named `sandcastle-*` (`docker ps -a --filter 'name=^/?sandcastle-'`). Every other factory `docker run` — matou-app `ci.yml`'s checks container, the healer agent's ad-hoc `/tmp/heal-fix` bisect runs — is invisible to it. Five such containers accumulated on elitebook-03 (2026-08-24 → 09-03), burned ~3 of 8 cores and ~700 MB swap for up to 11 days, and caused the idss ci 16970 red (idss #1182). Full trace and the workflow-side half of the fix: Matou/matou-app#331. ## Mechanism Forgejo cancels the run (auto-cancel on newer push) or the runner loses the task (Forgejo outage); the runner kills the step's process tree = the `docker run` client only. `--rm` never fires, sig-proxy has no client, `bash -lc` as PID 1 ignores SIGTERM, the act workspace is deleted from under the process, and the container spins forever. Same for `heal.sh`'s `timeout 900` killing the agent mid-`docker run`. ## Fix 1. Reap by **label + age**, not by name: in `sweep-lib.sh`, also reap any container carrying `--label matou.factory=<kind>` whose `CreatedAt` is older than a per-kind ceiling (ci: the workflow's `timeout-minutes` + slack; heal: 900 s + slack). Keep the `sandcastle-*` name path. 2. Belt for containers nobody labelled: reap any container whose image is a factory sandbox image (`*-ci`, the sandcastle image tag) and is older than 3 h — no legitimate factory container lives that long. 3. `heal.sh` / the healer prompt: every `docker run` the agent issues carries `--label matou.factory=heal --label matou.run=$RUN_ID` (or run under `--cidfile` and `docker rm -f` in a trap); `timeout` should use `--kill-after` and the trap must run before the kill. 4. Log each reap to the swarm db / Mattermost sweep line so a recurrence is visible instead of silent. ## Acceptance - `heal-lib-test.sh` / `sweep` tests: a labelled container older than its ceiling is reaped; a fresh one is not; an unlabelled `matou-app-ci` container older than 3 h is reaped. - After the next cancelled matou-app ci run, `docker ps --filter ancestor=matou-app-ci` is empty on the runner within one sweep tick.

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

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

close-report for #122 — status success

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

envelope
{
  "issue": 122,
  "status": "success",
  "commits": [
    "3a107e672ebae7f874dccedaff90f36266da01d6"
  ],
  "changed_files": [
    "sweep-lib.sh",
    "report-lib.sh",
    "tests/sweep-lib-test.sh",
    "tests/report-lib-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/sweep-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash \"$t\"; done (all green except pre-existing fleet-tui no-pytest env failure)",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Fix 1 — reap by label + age (matou.factory=<kind>, per-kind ceiling), keep sandcastle-* name path": "sweep-lib.sh reap_containers: one pass classifies name `sandcastle-*` (floor), label `matou.factory=heal` (HEAL_REAP_CEILING) / `ci` (CI_REAP_CEILING) / other (floor); name path preserved",
    "Fix 2 — belt: reap factory sandbox image (*-ci, sandcastle image tag) older than 3h": "sweep-lib.sh: image case `sandcastle:*|*-ci|*-ci:*` reaped past the floor when name+label absent",
    "Fix 4 — log each reap to swarm db / Mattermost sweep line": "reap_containers echoes `reaped <id> (<reason>, created …)` to stderr → report_sweep's sweep line; notice reworded to 'factory container(s)' (report-lib.sh)",
    "Acceptance — a labelled container older than its ceiling is reaped; a fresh one is not": "tests/sweep-lib-test.sh reap group: heal_stale (1h > 1800s ceiling) reaped, heal_fresh (20m) spared; CI_REAP_CEILING tighten group proves per-kind ceiling",
    "Acceptance — an unlabelled *-ci container older than 3h is reaped": "tests/sweep-lib-test.sh: belt_ci (widget-ci, unlabelled, 4h) reaped; foreign (postgres:16) never touched",
    "Acceptance — docker ps --filter ancestor=<product>-ci empty within one sweep tick after a cancelled ci run": "the IMAGE belt reaps any `*-ci` container past the floor on the next run-swarm exit-trap sweep, regardless of name/label",
    "Fix 3 — healer/ci docker runs carry matou.factory labels + timeout --kill-after": "label-stamping half is prompt/consumer design work: matou-app#331 (ci.yml, pull-only) + #123 filed ready-for-session (heal-prompt + heal.sh --kill-after); the belt reaps them meanwhile"
  },
  "summary": "reap_containers now reaps leaked factory containers by matou.factory label (per-kind ceiling) and by factory image (*-ci / sandcastle: belt), not only by sandcastle-* name, so cancelled ci/heal docker runs no longer leak for days.",
  "blockers": []
}
**close-report** for #122 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 122, "status": "success", "commits": [ "3a107e672ebae7f874dccedaff90f36266da01d6" ], "changed_files": [ "sweep-lib.sh", "report-lib.sh", "tests/sweep-lib-test.sh", "tests/report-lib-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/sweep-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/report-lib-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash \"$t\"; done (all green except pre-existing fleet-tui no-pytest env failure)", "exit_code": 0 } ], "criteria": { "Fix 1 — reap by label + age (matou.factory=<kind>, per-kind ceiling), keep sandcastle-* name path": "sweep-lib.sh reap_containers: one pass classifies name `sandcastle-*` (floor), label `matou.factory=heal` (HEAL_REAP_CEILING) / `ci` (CI_REAP_CEILING) / other (floor); name path preserved", "Fix 2 — belt: reap factory sandbox image (*-ci, sandcastle image tag) older than 3h": "sweep-lib.sh: image case `sandcastle:*|*-ci|*-ci:*` reaped past the floor when name+label absent", "Fix 4 — log each reap to swarm db / Mattermost sweep line": "reap_containers echoes `reaped <id> (<reason>, created …)` to stderr → report_sweep's sweep line; notice reworded to 'factory container(s)' (report-lib.sh)", "Acceptance — a labelled container older than its ceiling is reaped; a fresh one is not": "tests/sweep-lib-test.sh reap group: heal_stale (1h > 1800s ceiling) reaped, heal_fresh (20m) spared; CI_REAP_CEILING tighten group proves per-kind ceiling", "Acceptance — an unlabelled *-ci container older than 3h is reaped": "tests/sweep-lib-test.sh: belt_ci (widget-ci, unlabelled, 4h) reaped; foreign (postgres:16) never touched", "Acceptance — docker ps --filter ancestor=<product>-ci empty within one sweep tick after a cancelled ci run": "the IMAGE belt reaps any `*-ci` container past the floor on the next run-swarm exit-trap sweep, regardless of name/label", "Fix 3 — healer/ci docker runs carry matou.factory labels + timeout --kill-after": "label-stamping half is prompt/consumer design work: matou-app#331 (ci.yml, pull-only) + #123 filed ready-for-session (heal-prompt + heal.sh --kill-after); the belt reaps them meanwhile" }, "summary": "reap_containers now reaps leaked factory containers by matou.factory label (per-kind ceiling) and by factory image (*-ci / sandcastle: belt), not only by sandcastle-* name, so cancelled ci/heal docker runs no longer leak for days.", "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#122
No description provided.