fleet-tui: dead-pid open runs counted as occupancy — matou-workstation showed 6/2 @ 100% while idle; orphan rows need a sweeper #113

Closed
opened 2026-08-28 18:50:52 +00:00 by ben · 2 comments
Owner

Symptom

Fleet TUI showed matou-workstation at 6/2 slots, UTIL 100 % (2026-08-28 18:30) while the host had ONE healer running, both pooled slot locks free, load avg 0.57, and a true 24 h utilisation of ~12 % (138 closed runs, 5.7 slot-hours / 48).

Cause

fleet-tui/snapshot.py defines slots_used = len(runs where ended_at IS NULL) and util() bills every open row as busy from started_at to now. swarm.db on the host had six open runs rows; five belonged to dead pids:

run_id trigger started pid
heal-Matou-idss-1787815827-2192488 heal 08-27 07:30 dead
heal-Matou-idss-1787843929-3248477 heal 08-27 15:18 dead
heal-Matou-coa-1787927029-3060038 heal 08-28 14:23 dead
heal-Matou-idss-1787929661-3193849 heal 08-28 15:07 dead
Matou-coa-66-3862391 issues 08-28 17:38 dead

Four heal rows × ~24 h busy each ≫ the 48 slot-hour budget → clamped to 100 %; five phantoms + one real = 6/2.

Why they never closed: the Forgejo runner cancelled the jobs (RESULT_CANCELLED … beginning local task termination in the runner journal at 15:07:42 and 15:18:48, matching the row start times; 31 cancellations in 48 h — the queued-run mass-cancel of the #26 backlog). Cancellation terminates the process tree with SIGKILL, so heal.sh's EXIT trap (swarmdb_run_end) never fires — precisely the case heal.sh already documents (“an untrappable SIGKILL/OOM cannot run the trap: its open process row is the wedge marker”). The processes rows for those pids were also still open (they surface as the wedges count on the same row, so the TUI was double-reporting one fact as both occupancy and wedge).

Housekeeping done

The five rows were closed by hand on the host on 2026-08-28 with the harness's own tooling, exactly as the trap would have: swarm-db.py run-end --verdict died-in:<trigger> --source "orphan-sweep:runner-cancel-sigkill" --exit 137 + proc-close for each pid (after a kill -0 guard). The row now reads 1/2.

What should change

  1. Occupancy must be process-truth, not row-truth. The probe (fleet-tui/probe.py) already returns the processes rows; on the host it should kill -0 each open ref and the snapshot should count a run as live only when it has a living process. Dead-pid open rows are orphans: show them distinctly (or fold into wedges), never as slots_used, and exclude them from util_24h past their last evidence of life.
  2. A sweeper closes orphans durably. A SIGKILLed run is not recoverable by its own trap, so something else must finalise it — the natural home is the next tick of the same orchestrator on that host (or the backstop): for every open runs row whose processes.ref pids are all dead and whose started_at is older than the job timeout, run-end --verdict died-in:<trigger> + proc-close. Fail-safe like sweep-lib.sh's age floor: never reap something younger than a full run-lifetime.
  3. Tests: fleet-tui/tests/test_app.py / a snapshot test with an open row + dead pid → slots_used 0, orphan surfaced; a swarm-db-lib/sweeper test with a fixture db.

Fits the slot-aware fleet monitor arc (a480fcb plan, spec a649810) — the per-slot Fleet rows should be driven by the slot-holder sidecar + live pids, not by ended_at IS NULL.

Related: GOTCHAS on runner cancellation being SIGKILL; #26 (queued no-op runs whose mass-cancel produced these orphans); #103 (no cancel API).

## Symptom Fleet TUI showed `matou-workstation` at **6/2 slots, UTIL 100 %** (2026-08-28 18:30) while the host had ONE healer running, both pooled slot locks free, load avg 0.57, and a true 24 h utilisation of ~12 % (138 closed runs, 5.7 slot-hours / 48). ## Cause `fleet-tui/snapshot.py` defines `slots_used = len(runs where ended_at IS NULL)` and `util()` bills every open row as busy from `started_at` to now. `swarm.db` on the host had six open `runs` rows; five belonged to **dead pids**: | run_id | trigger | started | pid | |---|---|---|---| | heal-Matou-idss-1787815827-2192488 | heal | 08-27 07:30 | dead | | heal-Matou-idss-1787843929-3248477 | heal | 08-27 15:18 | dead | | heal-Matou-coa-1787927029-3060038 | heal | 08-28 14:23 | dead | | heal-Matou-idss-1787929661-3193849 | heal | 08-28 15:07 | dead | | Matou-coa-66-3862391 | issues | 08-28 17:38 | dead | Four heal rows × ~24 h busy each ≫ the 48 slot-hour budget → clamped to 100 %; five phantoms + one real = 6/2. Why they never closed: the Forgejo runner **cancelled** the jobs (`RESULT_CANCELLED … beginning local task termination` in the runner journal at 15:07:42 and 15:18:48, matching the row start times; 31 cancellations in 48 h — the queued-run mass-cancel of the #26 backlog). Cancellation terminates the process tree with SIGKILL, so `heal.sh`'s EXIT trap (`swarmdb_run_end`) never fires — precisely the case `heal.sh` already documents (“an untrappable SIGKILL/OOM cannot run the trap: its open process row is the wedge marker”). The `processes` rows for those pids were also still open (they surface as the `wedges` count on the same row, so the TUI was double-reporting one fact as both occupancy and wedge). ## Housekeeping done The five rows were closed by hand on the host on 2026-08-28 with the harness's own tooling, exactly as the trap would have: `swarm-db.py run-end --verdict died-in:<trigger> --source "orphan-sweep:runner-cancel-sigkill" --exit 137` + `proc-close` for each pid (after a `kill -0` guard). The row now reads 1/2. ## What should change 1. **Occupancy must be process-truth, not row-truth.** The probe (`fleet-tui/probe.py`) already returns the `processes` rows; on the host it should `kill -0` each open `ref` and the snapshot should count a run as *live* only when it has a living process. Dead-pid open rows are **orphans**: show them distinctly (or fold into `wedges`), never as slots_used, and exclude them from `util_24h` past their last evidence of life. 2. **A sweeper closes orphans durably.** A SIGKILLed run is not recoverable by its own trap, so something else must finalise it — the natural home is the next tick of the same orchestrator on that host (or the backstop): for every open `runs` row whose `processes.ref` pids are all dead and whose `started_at` is older than the job timeout, `run-end --verdict died-in:<trigger>` + `proc-close`. Fail-safe like `sweep-lib.sh`'s age floor: never reap something younger than a full run-lifetime. 3. Tests: `fleet-tui/tests/test_app.py` / a snapshot test with an open row + dead pid → `slots_used` 0, orphan surfaced; a swarm-db-lib/sweeper test with a fixture db. Fits the slot-aware fleet monitor arc (a480fcb plan, spec a649810) — the per-slot Fleet rows should be driven by the slot-holder sidecar + live pids, not by `ended_at IS NULL`. Related: GOTCHAS on runner cancellation being SIGKILL; #26 (queued no-op runs whose mass-cancel produced these orphans); #103 (no cancel API).

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

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

close-report for #113 — status success

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

envelope
{
  "issue": 113,
  "status": "success",
  "commits": [
    "465e82c"
  ],
  "changed_files": [
    "fleet-tui/probe.py",
    "fleet-tui/snapshot.py",
    "fleet-tui/tests/test_probe.py",
    "fleet-tui/tests/test_snapshot.py",
    "swarm-db.py",
    "swarm-db-lib.sh",
    "report-lib.sh",
    "tests/swarm-db-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/swarm-db-test.sh",
      "exit_code": 0
    },
    {
      "command": "PYTHONPATH=fleet-tui/.venv/lib/python3.12/site-packages python3 -m pytest fleet-tui/tests/test_snapshot.py fleet-tui/tests/test_probe.py fleet-tui/tests/test_app.py -q",
      "exit_code": 0
    },
    {
      "command": "bash tests/report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/run-swarm-landing-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Occupancy is process-truth: probe kill -0 each open ref; snapshot counts a run live only with a living process": "probe.py _pid_alive stamps each open processes row with live (True/False/None); snapshot.py demotes open runs whose every open ref is live is False out of slots_used (commit 465e82c)",
    "Dead-pid open rows shown distinctly (orphans), never as slots_used, excluded from util past last evidence of life": "snapshot.py adds orphans field, slots_used excludes orphans, util_runs caps orphan ended_at at newest process start (_life_end); test_snapshot.py test_dead_pid_open_run_is_an_orphan_not_a_slot asserts slots_used 0, orphans 1, running None, util_24h < 0.01",
    "A sweeper closes orphans durably: for every open run whose processes.ref pids are all dead and older than the job timeout, run-end died-in:<trigger> + proc-close": "swarm-db.py cmd_sweep_orphans (verdict died-in:<trigger>, source orphan-sweep, exit 137, closes attempts + processes) wired into report_sweep via swarmdb_sweep_orphans; tests/swarm-db-test.sh sweep-orphans group",
    "Fail-safe age floor: never reap something younger than a full run-lifetime": "ORPHAN_MAX_AGE=10800 (sweep-lib.sh floor); started_at > floor spared; test asserts YOUNG run spared; live pid / un-ageable wedge ref / no-proc runs also spared",
    "Tests: snapshot test (open row + dead pid) and a swarm-db-lib/sweeper test with a fixture db": "fleet-tui/tests/test_snapshot.py + test_probe.py (pid liveness) and tests/swarm-db-test.sh sweep-orphans group (22 groups pass)"
  },
  "summary": "Fleet occupancy now reads process-truth (pid liveness) so SIGKILLed orphan runs stop billing as busy slots, plus a durable swarm-db sweep-orphans finaliser wired into the post-run backstop.",
  "blockers": []
}
**close-report** for #113 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 113, "status": "success", "commits": [ "465e82c" ], "changed_files": [ "fleet-tui/probe.py", "fleet-tui/snapshot.py", "fleet-tui/tests/test_probe.py", "fleet-tui/tests/test_snapshot.py", "swarm-db.py", "swarm-db-lib.sh", "report-lib.sh", "tests/swarm-db-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/swarm-db-test.sh", "exit_code": 0 }, { "command": "PYTHONPATH=fleet-tui/.venv/lib/python3.12/site-packages python3 -m pytest fleet-tui/tests/test_snapshot.py fleet-tui/tests/test_probe.py fleet-tui/tests/test_app.py -q", "exit_code": 0 }, { "command": "bash tests/report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/run-swarm-landing-test.sh", "exit_code": 0 } ], "criteria": { "Occupancy is process-truth: probe kill -0 each open ref; snapshot counts a run live only with a living process": "probe.py _pid_alive stamps each open processes row with live (True/False/None); snapshot.py demotes open runs whose every open ref is live is False out of slots_used (commit 465e82c)", "Dead-pid open rows shown distinctly (orphans), never as slots_used, excluded from util past last evidence of life": "snapshot.py adds orphans field, slots_used excludes orphans, util_runs caps orphan ended_at at newest process start (_life_end); test_snapshot.py test_dead_pid_open_run_is_an_orphan_not_a_slot asserts slots_used 0, orphans 1, running None, util_24h < 0.01", "A sweeper closes orphans durably: for every open run whose processes.ref pids are all dead and older than the job timeout, run-end died-in:<trigger> + proc-close": "swarm-db.py cmd_sweep_orphans (verdict died-in:<trigger>, source orphan-sweep, exit 137, closes attempts + processes) wired into report_sweep via swarmdb_sweep_orphans; tests/swarm-db-test.sh sweep-orphans group", "Fail-safe age floor: never reap something younger than a full run-lifetime": "ORPHAN_MAX_AGE=10800 (sweep-lib.sh floor); started_at > floor spared; test asserts YOUNG run spared; live pid / un-ageable wedge ref / no-proc runs also spared", "Tests: snapshot test (open row + dead pid) and a swarm-db-lib/sweeper test with a fixture db": "fleet-tui/tests/test_snapshot.py + test_probe.py (pid liveness) and tests/swarm-db-test.sh sweep-orphans group (22 groups pass)" }, "summary": "Fleet occupancy now reads process-truth (pid liveness) so SIGKILLed orphan runs stop billing as busy slots, plus a durable swarm-db sweep-orphans finaliser wired into the post-run backstop.", "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#113
No description provided.