run-swarm.sh: classify Claude auth refusals (mirror rehearsal-report CLAUDE_AUTH_RE) — a dead token must fail over/name, not red the swarm #632

Closed
opened 2026-08-21 04:42:53 +00:00 by matou-build-agent · 2 comments

Class: harness-infra (swarm executor gap). Filed by the swarm healer for run https://git.matou.nz/Matou/idss/actions/runs/8307 (signature 096ffba7729c).

Symptom

The swarm job went red and paged the healer with a degraded signature (seam-degraded marker set, trigger error line unknown, no fresh verdict artifact). The worker log (.sandcastle/logs/main-sandcastle-worker-20260821-043605-d7cda4-worker.log) shows the real fault:

Agent started
Not logged in · Please run /login
Agent invocation failed: claude-code exited with code 1:
Not logged in · Please run /login

Root cause

.sandcastle/run-swarm.sh's while ! pnpm run sandcastle loop classifies only two refusal shapes: swarm_cancel_hit (operator cancel) and claude_limit_hit (subscription-limit → #510 two-account failover). A Claude auth refusal ("Not logged in · Please run /login" / "failed to authenticate" / "oauth session expired") matches neither, so it falls straight through to SWARM_EXIT_REASON="sandcastle-run-failed"; exit 1 — a hard red that pages the healer with a signature that degrades to the workflow name (the near-unparseable anti-pattern commit 2f0d3a65 warned against).

.sandcastle/rehearsal-report.sh already solves this for the cron reporter/healer path: claude_auth_failed / CLAUDE_AUTH_RE="failed to authenticate|oauth session expired|not logged in|invalid api key|authentication_error" with a fail-over-once-then-name pattern. The swarm executor never got the mirror.

What good looks like

In run-swarm.sh, add an auth-refusal branch alongside the limit branch (reuse a shared CLAUDE_AUTH_RE/claude_auth_failed from limit-lib.sh, don't re-declare): on a Claude auth refusal, fail over once to the standby account (like the limit path), and if the retry also auth-fails (both accounts dead), exit cleanly with a LOUD, named Mattermost alarm ("BOTH Claude accounts auth-dead — re-login required") + a swarm.db event — never a degraded red that keys the healer on unknown. Keep it loud, keep it named (commit 2f0d3a65's ruling).

Acceptance

  • A worker log containing only the "Not logged in · Please run /login" auth refusal is classified as auth (not limit, not generic fail) — covered by a test over the classifier, using that exact log shape.
  • Single-account auth refusal fails over to the standby and retries once (mirrors the #510 limit path).
  • Both-accounts auth-dead exits 0 with a named alarm naming both accounts, not a red job.
  • claim-lib/limit-lib seam tests stay green.

Note (not part of this ticket)

The concrete outage that surfaced this — both org OAuth tokens (CLAUDE_CODE_OAUTH_TOKEN [A] and CLAUDE_CODE_OAUTH_TOKEN_B [B]) auth-dead at ~04:31–04:36 UTC 2026-08-21 — is a credential re-login the operator must do by hand (org secrets); it is escalated separately on Mattermost and is out of scope for this code change.

**Class:** harness-infra (swarm executor gap). Filed by the swarm healer for run https://git.matou.nz/Matou/idss/actions/runs/8307 (signature `096ffba7729c`). ## Symptom The `swarm` job went **red** and paged the healer with a *degraded* signature (`seam-degraded` marker set, trigger error line `unknown`, no fresh verdict artifact). The worker log (`.sandcastle/logs/main-sandcastle-worker-20260821-043605-d7cda4-worker.log`) shows the real fault: ``` Agent started Not logged in · Please run /login Agent invocation failed: claude-code exited with code 1: Not logged in · Please run /login ``` ## Root cause `.sandcastle/run-swarm.sh`'s `while ! pnpm run sandcastle` loop classifies only two refusal shapes: `swarm_cancel_hit` (operator cancel) and `claude_limit_hit` (subscription-limit → `#510` two-account failover). A **Claude auth refusal** ("Not logged in · Please run /login" / "failed to authenticate" / "oauth session expired") matches neither, so it falls straight through to `SWARM_EXIT_REASON="sandcastle-run-failed"; exit 1` — a hard red that pages the healer with a signature that degrades to the workflow name (the near-`unparseable` anti-pattern commit `2f0d3a65` warned against). `.sandcastle/rehearsal-report.sh` **already** solves this for the cron reporter/healer path: `claude_auth_failed` / `CLAUDE_AUTH_RE="failed to authenticate|oauth session expired|not logged in|invalid api key|authentication_error"` with a fail-over-once-then-name pattern. The swarm executor never got the mirror. ## What good looks like In `run-swarm.sh`, add an auth-refusal branch alongside the limit branch (reuse a shared `CLAUDE_AUTH_RE`/`claude_auth_failed` from `limit-lib.sh`, don't re-declare): on a Claude auth refusal, **fail over once** to the standby account (like the limit path), and if the retry also auth-fails (both accounts dead), exit **cleanly** with a LOUD, *named* Mattermost alarm ("BOTH Claude accounts auth-dead — re-login required") + a swarm.db event — never a degraded red that keys the healer on `unknown`. Keep it loud, keep it named (commit `2f0d3a65`'s ruling). ## Acceptance - A worker log containing only the "Not logged in · Please run /login" auth refusal is classified as auth (not limit, not generic fail) — covered by a test over the classifier, using that exact log shape. - Single-account auth refusal fails over to the standby and retries once (mirrors the `#510` limit path). - Both-accounts auth-dead exits 0 with a named alarm naming both accounts, not a red job. - `claim-lib`/`limit-lib` seam tests stay green. ## Note (not part of this ticket) The concrete outage that surfaced this — **both** org OAuth tokens (`CLAUDE_CODE_OAUTH_TOKEN` [A] and `CLAUDE_CODE_OAUTH_TOKEN_B` [B]) auth-dead at ~04:31–04:36 UTC 2026-08-21 — is a credential re-login the operator must do by hand (org secrets); it is escalated separately on Mattermost and is out of scope for this code change.
Author
Member

Blocked — protected-path machinery change, needs a session (not a swarm agent)

This ticket is out of a swarm worker's reach: its entire deliverable is editing .sandcastle/run-swarm.sh and (per the ticket) .sandcastle/limit-lib.sh — both under .sandcastle/, a fingerprinted protected directory (PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo" in .sandcastle/protected-paths-lib.sh, #445). The protected-paths boundary snapshots that tree before/after every worker run, rolls back any protected path a worker creates/changes/deletes, and fails the run loud. So a swarm agent physically cannot land this change — there is no non-protected surface here (the classifier, the failover branch, and the classifier test all live under .sandcastle/).

Per CLAUDE.md rule 9 and the escape path spelled out in protected-paths-lib.sh (PP_ESCAPE_PATH): a protected .sandcastle/ change needs an interactive session's standing, not a swarm agent (ADR 0174 / #445). This is not a side-improvement I discovered while doing other work — the ticket is the machinery change — so the right move is to re-route this same issue rather than file a new one.

Why session

The work modifies the machinery that judges swarm work (run-swarm.sh classifier + limit-lib.sh). ADR 0174 / #445 reserve that to a session; a session rules on the machinery change itself and escalates to ready-for-human only if it finds a genuine one-way door. Nothing here looks one-way (mirrors the already-shipped rehearsal-report.sh CLAUDE_AUTH_RE pattern), so ready-for-session — not ready-for-human.

What a session must do (scope unchanged from the ticket)

  • Factor a shared CLAUDE_AUTH_RE / claude_auth_failed into limit-lib.sh (don't re-declare it in run-swarm.sh), mirroring rehearsal-report.sh.
  • Add an auth-refusal branch in run-swarm.sh's while ! pnpm run sandcastle loop, alongside claude_limit_hit: fail over once to the standby account (like the #510 limit path); if the retry also auth-fails, exit 0 with a LOUD, named Mattermost alarm ("BOTH Claude accounts auth-dead — re-login required") + a swarm.db event — never a degraded red keyed on unknown.
  • Cover the classifier with a test over the exact "Not logged in · Please run /login" worker-log shape; keep claim-lib/limit-lib seam tests green.

Re-arm by resolving in a session and (if needed) re-labelling. Releasing the swarm claim now.

## Blocked — protected-path machinery change, needs a session (not a swarm agent) This ticket is out of a swarm worker's reach: its **entire deliverable** is editing `.sandcastle/run-swarm.sh` and (per the ticket) `.sandcastle/limit-lib.sh` — both under `.sandcastle/`, a **fingerprinted protected directory** (`PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"` in `.sandcastle/protected-paths-lib.sh`, #445). The protected-paths boundary snapshots that tree before/after every worker run, **rolls back** any protected path a worker creates/changes/deletes, and **fails the run loud**. So a swarm agent physically cannot land this change — there is no non-protected surface here (the classifier, the failover branch, and the classifier test all live under `.sandcastle/`). Per CLAUDE.md rule 9 and the escape path spelled out in `protected-paths-lib.sh` (`PP_ESCAPE_PATH`): a protected `.sandcastle/` change **needs an interactive session's standing, not a swarm agent** (ADR 0174 / #445). This is not a side-improvement I discovered while doing other work — the ticket *is* the machinery change — so the right move is to re-route this same issue rather than file a new one. ## Why session The work modifies the machinery that judges swarm work (`run-swarm.sh` classifier + `limit-lib.sh`). ADR 0174 / #445 reserve that to a session; a session rules on the machinery change itself and escalates to `ready-for-human` only if it finds a genuine one-way door. Nothing here looks one-way (mirrors the already-shipped `rehearsal-report.sh` `CLAUDE_AUTH_RE` pattern), so `ready-for-session` — not `ready-for-human`. ## What a session must do (scope unchanged from the ticket) - Factor a shared `CLAUDE_AUTH_RE` / `claude_auth_failed` into `limit-lib.sh` (don't re-declare it in `run-swarm.sh`), mirroring `rehearsal-report.sh`. - Add an auth-refusal branch in `run-swarm.sh`'s `while ! pnpm run sandcastle` loop, alongside `claude_limit_hit`: fail over once to the standby account (like the #510 limit path); if the retry also auth-fails, exit **0** with a LOUD, *named* Mattermost alarm ("BOTH Claude accounts auth-dead — re-login required") + a swarm.db event — never a degraded red keyed on `unknown`. - Cover the classifier with a test over the exact "Not logged in · Please run /login" worker-log shape; keep `claim-lib`/`limit-lib` seam tests green. Re-arm by resolving in a session and (if needed) re-labelling. Releasing the swarm claim now.
Author
Member

Ruled by agent under ADR 0174 — veto anytime.

Two-way door: a code/config change to .sandcastle/, revertible with git revert 7d836350, provable by tests. Not on the one-way-door list (no credentials, no security-posture widening, no member-facing trust surface, no data destruction, no physical hardware).

Landed: 7d836350 (7d836350e8)

  • CLAUDE_AUTH_RE/claude_auth_failed moved from rehearsal-report.sh into limit-lib.sh — one shared definition, consumed by both scripts (rehearsal-report.sh's own copy deleted, now sources the lib's).
  • run-swarm.sh's retry loop gets a new branch, checked before the limit guard: a Claude auth refusal (claude_auth_failed) fails over to the standby account and retries once (mirrors the #510 limit path); if the retry also auth-fails, exits 0 with a loud, named BOTH Claude accounts auth-dead — re-login required Mattermost alarm (single-account hosts name that one account instead) + a swarm.db event — never a red job. An hourly marker dedupes repeat alarms from a queued-trigger burst, mirroring the existing limit-pause notice.
  • preflight-swarm.sh gets a new guard_auth_detection (mirrors guard_limit_detection): a wording drift in CLAUDE_AUTH_RE reds preflight, named, before any worker spawns — plus a cross-classification check (an auth refusal must never also read as a limit hit, and vice versa).
  • New fixture tests/fixtures/claude-auth-refusal.txt, captured from the run 8307 worker log (main-sandcastle-worker-20260821-043605-d7cda4-worker.log) that surfaced this gap.

Proof:

  • tests/run-swarm-auth-guard-test.sh (new, 5 scenarios): the exact #632 worker-log shape classifies as auth and not limit; a two-account host's first refusal fails over and retries; the second refusal halts naming BOTH accounts; a repeat halt inside the TTL re-logs to swarm.db but does not re-post to Mattermost; a single-account host's refusal halts naming that one account only.
  • tests/preflight-swarm-test.sh updated (7→8 guards) and passing.
  • Full .sandcastle/tests/*.sh suite green, including claim-lib-test.sh and limit-lib-test.sh (seam tests unaffected).

The concrete outage that filed this ticket (both org OAuth tokens auth-dead ~04:31–04:36 UTC) is a human re-login, out of scope here per the ticket's own note — tracked separately.

**Ruled by agent under ADR 0174 — veto anytime.** Two-way door: a code/config change to `.sandcastle/`, revertible with `git revert 7d836350`, provable by tests. Not on the one-way-door list (no credentials, no security-posture widening, no member-facing trust surface, no data destruction, no physical hardware). **Landed:** `7d836350` (7d836350e8c01da7e8be073b326831767f66b4ee) - `CLAUDE_AUTH_RE`/`claude_auth_failed` moved from `rehearsal-report.sh` into `limit-lib.sh` — one shared definition, consumed by both scripts (rehearsal-report.sh's own copy deleted, now sources the lib's). - `run-swarm.sh`'s retry loop gets a new branch, checked before the limit guard: a Claude auth refusal (`claude_auth_failed`) fails over to the standby account and retries once (mirrors the #510 limit path); if the retry also auth-fails, exits **0** with a loud, named `BOTH Claude accounts auth-dead — re-login required` Mattermost alarm (single-account hosts name that one account instead) + a `swarm.db` event — never a red job. An hourly marker dedupes repeat alarms from a queued-trigger burst, mirroring the existing limit-pause notice. - `preflight-swarm.sh` gets a new `guard_auth_detection` (mirrors `guard_limit_detection`): a wording drift in `CLAUDE_AUTH_RE` reds preflight, named, before any worker spawns — plus a cross-classification check (an auth refusal must never also read as a limit hit, and vice versa). - New fixture `tests/fixtures/claude-auth-refusal.txt`, captured from the run 8307 worker log (`main-sandcastle-worker-20260821-043605-d7cda4-worker.log`) that surfaced this gap. **Proof:** - `tests/run-swarm-auth-guard-test.sh` (new, 5 scenarios): the exact #632 worker-log shape classifies as auth and not limit; a two-account host's first refusal fails over and retries; the second refusal halts naming BOTH accounts; a repeat halt inside the TTL re-logs to swarm.db but does not re-post to Mattermost; a single-account host's refusal halts naming that one account only. - `tests/preflight-swarm-test.sh` updated (7→8 guards) and passing. - Full `.sandcastle/tests/*.sh` suite green, including `claim-lib-test.sh` and `limit-lib-test.sh` (seam tests unaffected). The concrete outage that filed this ticket (both org OAuth tokens auth-dead ~04:31–04:36 UTC) is a human re-login, out of scope here per the ticket's own note — tracked separately.
matou-build-agent 2026-08-21 04:58: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#632
No description provided.