swarm: unguarded claude calls — triage and the healer must ride the limit guard, not redden or go blind on a limit window #253

Closed
opened 2026-08-01 00:48:06 +00:00 by ben · 1 comment
Owner

Parent

Swarm ops. Evidence from the 2026-07-31 19:50–21:50 limit window (140 weekly-limit + 18 org-spend-limit hits in worker logs). Sibling of #238 (its landed half made the limit marker matou-swarm-claude-limit deliberately HOST-GLOBAL — one host, one subscription); distinct from #250 (code sync).

What's true today

  • limit-lib.sh guards the swarm workers (the 2026-07-29 storm fix). Two callers never got it:
    1. run-triage.sh — a bare timeout 2700 claude -p "/triage …" under set -euo pipefail. Any limit refusal reddens the whole triage run; two blips within the watchdog window mint an always-red incident (exactly what happened on the matou-app side at 19:51/19:55 — healer escalation confirmed moot after recovery, but the mechanism stands for THIS repo too).
    2. heal.sh's healer agent call — during the same window the healer's own claude died silently (agent-out.log = 0 bytes in the 2026-08-01T00:01 incident dir): the healer goes blind precisely when the swarm most needs diagnosis, and burns healer-ledger attempts on non-incidents.

What to build

  • Both callers consult the global matou-swarm-claude-limit marker before invoking claude (marker fresh → yield cleanly: triage exits 0 with a "limit-parked" note, the healer defers the incident — ledger attempt NOT consumed), and classify a limit refusal after a failed call (recognize via limit-lib's signatures, write the global marker, exit clean) so the first hit parks the host for every caller, not just workers.
  • The guard logic lives in limit-lib.sh (already byte-identical across repos) or a small shared claude-guard.sh — either way inside the #250 manifest set, so the matou-app mirror arrives by whatever layout ruling #238 lands, not by hand.
  • A limit-parked triage/healer run must be distinguishable from success in the run list (honest no-op logging), so the watchdog never reads a parked window as green health.

Acceptance criteria

  • Given a fresh global limit marker, When triage cron fires, Then it yields 0 without calling claude and says so in its log
  • Given claude refuses mid-triage with a limit signature, Then the run writes the marker and exits clean — never red — and the next non-limit failure still reddens honestly
  • Given the healer wakes during a limit window, Then it defers without consuming the incident's ledger attempt and the evidence dir records "deferred: limit window"
  • Given a real (non-limit) claude failure, Then behavior is unchanged — loud red / real diagnosis

Task manifest

task: swarm:claude-call-guards
implements_seam: "limit-lib guard consulted by run-triage.sh + heal.sh (global marker semantics per #238)"
interface: "limit windows park triage/healer cleanly instead of reddening or blinding them"
seam: "offline tests: fake claude emitting limit signatures; marker fresh/stale/absent matrix"
acceptance:
  - given: fresh limit marker; when: triage fires; then: clean yield, no claude call
depends_on: []
out_of_scope: [raising the org spend limit (billing), matou-app mirror (rides #238's layout ruling + #250), workflow lock semantics (#238 landed half)]
## Parent Swarm ops. Evidence from the 2026-07-31 19:50–21:50 limit window (140 weekly-limit + 18 org-spend-limit hits in worker logs). Sibling of #238 (its landed half made the limit marker `matou-swarm-claude-limit` deliberately HOST-GLOBAL — one host, one subscription); distinct from #250 (code sync). ## What's true today - `limit-lib.sh` guards the **swarm workers** (the 2026-07-29 storm fix). Two callers never got it: 1. **`run-triage.sh`** — a bare `timeout 2700 claude -p "/triage …"` under `set -euo pipefail`. Any limit refusal reddens the whole triage run; two blips within the watchdog window mint an always-red incident (exactly what happened on the matou-app side at 19:51/19:55 — healer escalation confirmed moot after recovery, but the mechanism stands for THIS repo too). 2. **`heal.sh`'s healer agent call** — during the same window the healer's own claude died silently (`agent-out.log` = 0 bytes in the 2026-08-01T00:01 incident dir): the healer goes blind precisely when the swarm most needs diagnosis, and burns healer-ledger attempts on non-incidents. ## What to build - Both callers consult the global `matou-swarm-claude-limit` marker **before** invoking claude (marker fresh → yield cleanly: triage exits 0 with a "limit-parked" note, the healer defers the incident — ledger attempt NOT consumed), and **classify** a limit refusal after a failed call (recognize via limit-lib's signatures, write the global marker, exit clean) so the first hit parks the host for every caller, not just workers. - The guard logic lives in `limit-lib.sh` (already byte-identical across repos) or a small shared `claude-guard.sh` — either way inside the #250 manifest set, so the matou-app mirror arrives by whatever layout ruling #238 lands, not by hand. - A limit-parked triage/healer run must be distinguishable from success in the run list (honest no-op logging), so the watchdog never reads a parked window as green health. ## Acceptance criteria - [ ] Given a fresh global limit marker, When triage cron fires, Then it yields 0 without calling claude and says so in its log - [ ] Given claude refuses mid-triage with a limit signature, Then the run writes the marker and exits clean — never red — and the next non-limit failure still reddens honestly - [ ] Given the healer wakes during a limit window, Then it defers without consuming the incident's ledger attempt and the evidence dir records "deferred: limit window" - [ ] Given a real (non-limit) claude failure, Then behavior is unchanged — loud red / real diagnosis ## Task manifest ```yaml task: swarm:claude-call-guards implements_seam: "limit-lib guard consulted by run-triage.sh + heal.sh (global marker semantics per #238)" interface: "limit windows park triage/healer cleanly instead of reddening or blinding them" seam: "offline tests: fake claude emitting limit signatures; marker fresh/stale/absent matrix" acceptance: - given: fresh limit marker; when: triage fires; then: clean yield, no claude call depends_on: [] out_of_scope: [raising the org spend limit (billing), matou-app mirror (rides #238's layout ruling + #250), workflow lock semantics (#238 landed half)] ```
Author
Owner

Landed on origin/main as 76162f0.

Both unguarded claude callers now ride the host-global matou-swarm-claude-limit marker via two shared helpers in limit-lib.sh (claude_limit_parked / claude_limit_park, on the #250 harness-manifest so the matou-app mirror arrives by sync, not by hand):

  • run-triage.sh — sources the lib, consults the marker BEFORE the claude call (fresh → exit 0 with an honest limit-parked log line, no blind refusing call → no always-red incident), and CLASSIFIES a limit refusal after a failed call (capture via tee; claude_limit_hit → park + exit clean; any other failure still reddens through the verdict EXIT trap). AC1, AC2.
  • heal.sh — a pre-claude gate right after gather_evidence defers a fresh-marker window (writes deferred: limit window to the evidence dir, consumes NO ledger attempt — the ledger is only touched past the gate), and the existing post-call limit branch now parks the host + records the deferral (the 2026-08-01 0-byte agent-out.log blind-healer incident). AC3.
  • Real (non-limit) failures are unchanged — triage still reddens, the healer still investigates + ledgers. AC4.

Evidence: new offline seam tests/claude-call-guards-test.sh (7 groups) drives BOTH real scripts with a fake claude/agent emitting limit signatures across the marker fresh/stale/absent matrix; tests/limit-lib-test.sh gains the marker matrix. All existing .sandcastle tests (limit-lib, heal, heal-lib, swarm-lock-yield, preflight, sync-harness) stay green.

Out of scope as filed: raising the org spend limit (billing), the matou-app run-triage caller wiring (rides #238/#250), workflow lock semantics (#238 landed half).

Landed on `origin/main` as `76162f0`. Both unguarded claude callers now ride the host-global `matou-swarm-claude-limit` marker via two shared helpers in `limit-lib.sh` (`claude_limit_parked` / `claude_limit_park`, on the #250 harness-manifest so the matou-app mirror arrives by sync, not by hand): - **run-triage.sh** — sources the lib, consults the marker BEFORE the claude call (fresh → exit 0 with an honest `limit-parked` log line, no blind refusing call → no always-red incident), and CLASSIFIES a limit refusal after a failed call (capture via `tee`; `claude_limit_hit` → park + exit clean; any other failure still reddens through the verdict EXIT trap). **AC1, AC2.** - **heal.sh** — a pre-claude gate right after `gather_evidence` defers a fresh-marker window (writes `deferred: limit window` to the evidence dir, consumes NO ledger attempt — the ledger is only touched past the gate), and the existing post-call limit branch now parks the host + records the deferral (the 2026-08-01 0-byte `agent-out.log` blind-healer incident). **AC3.** - Real (non-limit) failures are unchanged — triage still reddens, the healer still investigates + ledgers. **AC4.** Evidence: new offline seam `tests/claude-call-guards-test.sh` (7 groups) drives BOTH real scripts with a fake claude/agent emitting limit signatures across the marker fresh/stale/absent matrix; `tests/limit-lib-test.sh` gains the marker matrix. All existing `.sandcastle` tests (limit-lib, heal, heal-lib, swarm-lock-yield, preflight, sync-harness) stay green. Out of scope as filed: raising the org spend limit (billing), the matou-app run-triage caller wiring (rides #238/#250), workflow lock semantics (#238 landed half).
ben closed this issue 2026-08-01 01:06:41 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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/idss#253
No description provided.