Bound the swarm healer: throwaway clone, mechanical diff rails, shared ledger, escalation latch only on a delivered post #203

Closed
opened 2026-10-15 02:59:14 +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 (verified)

  • heal.sh:386-387 runs claude -p --dangerously-skip-permissions in $WORKDIR (the shared swarm checkout); .sandcastle/heal-prompt.md:44-60 tells it to push to main. Mechanical bounds are only the 900 s timeout, a per-repo flock (heal.sh:140), and the ledger's repaired=1 (heal.sh:515), which blocks a second repair only inside the 6 h cooldown (heal-lib.sh:9,141) and only on THIS host (ledger at $WORKDIR/.sandcastle/.state/healer, heal.sh:87). The law-grade rails in rehearsal-heal-lib.sh heal_rails (line cap, product-surface refusal, assertion-weakening check) are NOT applied to heal.sh's agent. ACTION-TAKEN classification is prose regex (heal-lib.sh:170-179). The #167 gate applies only when LANDING=pr.
  • heal.sh:447-448,461-462 set escalated=1 whether or not post succeeded; post swallows failure (heal.sh:324, notify-mattermost.sh exits 0). A Mattermost brownout during the one @ben ping silences that signature for the whole cooldown.
  • heal.sh:262 probes only slot 1 before the prompt permits reset --hard origin/main on the shared workdir (heal-prompt.md:54-55); slot 2 may be held.
  • The runtime kill switch is HEAL_DRY_RUN, which needs a workflow re-render; the host killswitch gates cron lines only.

Proposed change

  • Run the heal agent in a throwaway clone (not $WORKDIR); push via a heal_push that applies heal_rails + a path allowlist diff check (harness-infra paths only) before any push; in push-default repos route the repair to a PR when the diff exceeds the rails (ties to #168).
  • Ledger moves to swarm.db events so dedup spans hosts.
  • escalated=1 only when post returns a post id; otherwise retry next tick.
  • Probe every path in HOST_CAPACITY_SLOTS before permitting a workdir reset.
  • Runtime off-file ($HOME/swarm/state/heal.off) honoured like session-runner.off.

Acceptance

  • tests/heal-test.sh: rails refuse an over-cap diff; escalation not latched on a 5xx post; slot-2-held blocks the reset permission; off-file yields.

out_of_scope

The pr-mode healer design itself (#168).

_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 (verified) - `heal.sh:386-387` runs `claude -p --dangerously-skip-permissions` in `$WORKDIR` (the shared swarm checkout); `.sandcastle/heal-prompt.md:44-60` tells it to push to main. Mechanical bounds are only the 900 s timeout, a per-repo flock (`heal.sh:140`), and the ledger's `repaired=1` (`heal.sh:515`), which blocks a second repair only inside the 6 h cooldown (`heal-lib.sh:9,141`) and only on THIS host (ledger at `$WORKDIR/.sandcastle/.state/healer`, `heal.sh:87`). The law-grade rails in `rehearsal-heal-lib.sh heal_rails` (line cap, product-surface refusal, assertion-weakening check) are NOT applied to heal.sh's agent. ACTION-TAKEN classification is prose regex (`heal-lib.sh:170-179`). The #167 gate applies only when `LANDING=pr`. - `heal.sh:447-448,461-462` set `escalated=1` whether or not `post` succeeded; `post` swallows failure (`heal.sh:324`, `notify-mattermost.sh` exits 0). A Mattermost brownout during the one @ben ping silences that signature for the whole cooldown. - `heal.sh:262` probes only slot 1 before the prompt permits `reset --hard origin/main` on the shared workdir (`heal-prompt.md:54-55`); slot 2 may be held. - The runtime kill switch is `HEAL_DRY_RUN`, which needs a workflow re-render; the host killswitch gates cron lines only. ## Proposed change - Run the heal agent in a throwaway clone (not `$WORKDIR`); push via a `heal_push` that applies `heal_rails` + a path allowlist diff check (harness-infra paths only) before any push; in push-default repos route the repair to a PR when the diff exceeds the rails (ties to #168). - Ledger moves to swarm.db `events` so dedup spans hosts. - `escalated=1` only when `post` returns a post id; otherwise retry next tick. - Probe every path in `HOST_CAPACITY_SLOTS` before permitting a workdir reset. - Runtime off-file (`$HOME/swarm/state/heal.off`) honoured like `session-runner.off`. ## Acceptance - `tests/heal-test.sh`: rails refuse an over-cap diff; escalation not latched on a 5xx post; slot-2-held blocks the reset permission; off-file yields. ## out_of_scope The pr-mode healer design itself (#168).

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: isolating the heal agent to a throwaway clone, applying the existing heal_rails + a path allowlist before push, latching escalation only on a delivered post, and adding a runtime off-file are all tightenings/correctness fixes; revertible by a commit, nothing provisioned. The pr-mode healer design is explicitly carved out to #168.
  • What proves it: tests/heal-test.sh — rails refuse an over-cap diff, escalation is not latched on a 5xx post, a slot-2-held state blocks the reset permission, and the off-file yields.

Agent Brief

Category: bug

Summary: The swarm healer runs an unbounded claude -p --dangerously-skip-permissions agent in the shared swarm checkout with push-to-main permission, no law-grade diff rails, a per-host ledger, a slot-1-only lock probe before it permits reset --hard origin/main, and an escalation latch that sets escalated=1 even when the one ping was swallowed by a Mattermost brownout. Bound it.

Current behavior: Agent runs in $WORKDIR; mechanical bounds are only a 900 s timeout, a per-repo flock, and repaired=1 (per-host, 6 h cooldown). rehearsal-heal-lib.sh's heal_rails (line cap, product-surface refusal, assertion-weakening check) is never applied. escalated=1 latches regardless of whether post delivered. The lock probe checks only slot 1 while the prompt permits a shared-workdir reset. The kill switch (HEAL_DRY_RUN) needs a workflow re-render.

Desired behavior:

  • Run the heal agent in a throwaway clone, not $WORKDIR.
  • Push via a heal_push that applies heal_rails + a path-allowlist diff check (harness-infra paths only) before any push.
  • Move the ledger to swarm.db events so dedup spans hosts.
  • Set escalated=1 only when post returns a post id; otherwise retry next tick.
  • Probe EVERY path in HOST_CAPACITY_SLOTS before permitting a workdir reset.
  • Honour a runtime off-file ($HOME/swarm/state/heal.off) like session-runner.off.

Key interfaces: A heal agent confined to a disposable clone; a push helper that refuses a diff exceeding the rails or touching non-harness-infra paths; a cross-host dedup ledger backed by the events table; an escalation latch keyed on a confirmed delivered post id; a slot probe covering all configured capacity slots; a runtime off-file honoured without re-render.

Acceptance criteria:

  • tests/heal-test.sh: rails refuse an over-cap diff; escalation is NOT latched when the post returns 5xx; a slot-2-held state blocks the reset permission; the off-file yields.
  • The heal agent operates in a throwaway clone, not the shared $WORKDIR.
  • Dedup is observable across hosts via the events ledger.
  • Offline suite green.

Out of scope: The pr-mode healer design that opens a PR for its fix in push-default repos (#168) — this ticket may route an over-rails diff toward that path but does not design it.

> *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:** isolating the heal agent to a throwaway clone, applying the existing `heal_rails` + a path allowlist before push, latching escalation only on a delivered post, and adding a runtime off-file are all tightenings/correctness fixes; revertible by a commit, nothing provisioned. The pr-mode healer *design* is explicitly carved out to #168. - **What proves it:** `tests/heal-test.sh` — rails refuse an over-cap diff, escalation is not latched on a 5xx post, a slot-2-held state blocks the reset permission, and the off-file yields. ## Agent Brief **Category:** bug **Summary:** The swarm healer runs an unbounded `claude -p --dangerously-skip-permissions` agent in the shared swarm checkout with push-to-main permission, no law-grade diff rails, a per-host ledger, a slot-1-only lock probe before it permits `reset --hard origin/main`, and an escalation latch that sets `escalated=1` even when the one ping was swallowed by a Mattermost brownout. Bound it. **Current behavior:** Agent runs in `$WORKDIR`; mechanical bounds are only a 900 s timeout, a per-repo flock, and `repaired=1` (per-host, 6 h cooldown). `rehearsal-heal-lib.sh`'s `heal_rails` (line cap, product-surface refusal, assertion-weakening check) is never applied. `escalated=1` latches regardless of whether `post` delivered. The lock probe checks only slot 1 while the prompt permits a shared-workdir reset. The kill switch (`HEAL_DRY_RUN`) needs a workflow re-render. **Desired behavior:** - Run the heal agent in a throwaway clone, not `$WORKDIR`. - Push via a `heal_push` that applies `heal_rails` + a path-allowlist diff check (harness-infra paths only) before any push. - Move the ledger to swarm.db `events` so dedup spans hosts. - Set `escalated=1` only when `post` returns a post id; otherwise retry next tick. - Probe EVERY path in `HOST_CAPACITY_SLOTS` before permitting a workdir reset. - Honour a runtime off-file (`$HOME/swarm/state/heal.off`) like `session-runner.off`. **Key interfaces:** A heal agent confined to a disposable clone; a push helper that refuses a diff exceeding the rails or touching non-harness-infra paths; a cross-host dedup ledger backed by the events table; an escalation latch keyed on a confirmed delivered post id; a slot probe covering all configured capacity slots; a runtime off-file honoured without re-render. **Acceptance criteria:** - [ ] `tests/heal-test.sh`: rails refuse an over-cap diff; escalation is NOT latched when the post returns 5xx; a slot-2-held state blocks the reset permission; the off-file yields. - [ ] The heal agent operates in a throwaway clone, not the shared `$WORKDIR`. - [ ] Dedup is observable across hosts via the events ledger. - [ ] Offline suite green. **Out of scope:** The pr-mode healer design that opens a PR for its fix in push-default repos (#168) — this ticket may route an over-rails diff toward that path but does not design it.

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

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

close-report for #203 — status success

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

envelope
{
  "issue": 203,
  "status": "success",
  "commits": [
    "3912924c678bf157462352fcb9018926c960f629"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "heal.sh",
    "tests/heal-test.sh",
    "tests/test-env.sh"
  ],
  "tests": [
    {
      "command": "bash tests/heal-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/heal-test.sh: rails refuse an over-cap diff; escalation NOT latched on a 5xx post; a slot-2-held state blocks the reset permission; the off-file yields": "tests/heal-test.sh +6 #203 scenarios (30 total): over-cap committing agent → 'refused by the rails' + remote main unchanged + repaired stays 0; the 5xx HEAL_NOTIFY_CMD stub leaves escalated unset and the signature retries (then a delivered post latches); slot-2-held → swarm-lock.txt reports held; the off-file / HEAL=0 yields before the agent, no ledger touched",
    "The heal agent operates in a throwaway clone, not the shared $WORKDIR": "heal.sh run_agent clones $WORKDIR into /tmp/matou-heal-clone-<tag>.* and cd's the agent (stub AND real claude) there; the agent-in-a-clone scenario asserts the captured cwd is the clone (not $WORKDIR), the incident prompt names the repair checkout + 'do not push yourself', and the clone is cleaned on exit",
    "Dedup is observable across hosts via the events ledger": "handle_incident mirrors every decision into swarm.db events as a heal-dedup row (sig, wf, decision, host); the python3-gated scenario asserts >=2 heal-dedup rows and the detail carries host=box7 and decision=",
    "Offline suite green": "the full tests/*.sh + onboarding/tests/*.sh loop exits with no FAIL lines on the merged tree"
  },
  "summary": "Bounded the swarm healer: throwaway repair clone, reused heal_rails+heal_push gating every landed repair, all-slot workdir-reset probe, delivery-gated escalation latch, a runtime off-file, and cross-host dedup events.",
  "blockers": []
}
**close-report** for #203 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 203, "status": "success", "commits": [ "3912924c678bf157462352fcb9018926c960f629" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "heal.sh", "tests/heal-test.sh", "tests/test-env.sh" ], "tests": [ { "command": "bash tests/heal-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/heal-test.sh: rails refuse an over-cap diff; escalation NOT latched on a 5xx post; a slot-2-held state blocks the reset permission; the off-file yields": "tests/heal-test.sh +6 #203 scenarios (30 total): over-cap committing agent → 'refused by the rails' + remote main unchanged + repaired stays 0; the 5xx HEAL_NOTIFY_CMD stub leaves escalated unset and the signature retries (then a delivered post latches); slot-2-held → swarm-lock.txt reports held; the off-file / HEAL=0 yields before the agent, no ledger touched", "The heal agent operates in a throwaway clone, not the shared $WORKDIR": "heal.sh run_agent clones $WORKDIR into /tmp/matou-heal-clone-<tag>.* and cd's the agent (stub AND real claude) there; the agent-in-a-clone scenario asserts the captured cwd is the clone (not $WORKDIR), the incident prompt names the repair checkout + 'do not push yourself', and the clone is cleaned on exit", "Dedup is observable across hosts via the events ledger": "handle_incident mirrors every decision into swarm.db events as a heal-dedup row (sig, wf, decision, host); the python3-gated scenario asserts >=2 heal-dedup rows and the detail carries host=box7 and decision=", "Offline suite green": "the full tests/*.sh + onboarding/tests/*.sh loop exits with no FAIL lines on the merged tree" }, "summary": "Bounded the swarm healer: throwaway repair clone, reused heal_rails+heal_push gating every landed repair, all-slot workdir-reset probe, delivery-gated escalation latch, a runtime off-file, and cross-host dedup events.", "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#203
No description provided.