swarm: two-account Claude token failover — ride over an exhausted weekly window instead of parking #510

Closed
opened 2026-08-14 05:14:38 +00:00 by ben · 4 comments
Owner

Why

2026-08-13/14: the primary Claude account hit its weekly limit (resets Aug 15, 8am UTC) and the whole loop parked — swarm runs on both repos paused on the limit guard, the rehearsal reporter's diagnosis leg failed to the generic ready-for-human path, and the healer went dark. The fix was a hand-swap to a second account's token (org secret + rehearsal-env.sh), ~a day of degraded reds later than it needed to be.

We now hold two accounts. The machinery should ride over an exhausted window by itself.

Design sketch

  • Second org secret CLAUDE_CODE_OAUTH_TOKEN_B (the standby account). The org level is now the ONE source of truth — the diverged ourcloud repo-level override was deleted 2026-08-14; never reintroduce it.
  • Detection is already centralized in .sandcastle/limit-lib.sh (shared by run-swarm and the healer so they can't drift — the 2026-07-29 "weekly" phrasing lesson). Failover keys off the same predicate.
  • run-swarm.sh: on claude_limit_hit with the active token, re-try the sandcastle run ONCE on the other token, and stamp a host-global active-token marker (sibling of the existing /tmp/matou-swarm-claude-limit notice marker — repo-agnostic by design, one subscription window per account) so subsequent runs on this host start on the live token without paying a failed attempt first.
  • Healer: same swap via limit-lib before declining on a limit.
  • Workstation rehearsal machinery: rehearsal-env.sh carries both tokens; the reporter/healer wrapper tries active-then-standby with the same marker discipline. (Host-only file — the tokens must never enter .sandcastle/.env, which forwards into worker containers; 2026-07-11 lesson.)
  • Notices: the hourly-deduped Mattermost limit notice names WHICH account parked ("account A limited — failed over to B" / "BOTH accounts limited — parked until "). Both limited → exactly today's quiet park.

Acceptance criteria

  1. With token A scripted to answer the limit line and B healthy, a run completes on B and the marker leaves the host starting on B; one Mattermost notice names the failover.
  2. With both tokens limited, the run parks quietly green exactly as today (no red storm), notice names both.
  3. The healer path swaps identically (limit-lib is the only detection point — no second grep anywhere).
  4. Marker expiry/reset: a stale marker never pins the host to the standby forever (e.g. re-probe A after its reset hint, or hourly TTL).
  5. Offline tests alongside the existing limit-guard cases; no live-token test in the gate.

Notes

  • Account 1 resets Aug 15 08:00 UTC and becomes the natural standby (_B).
  • This is .sandcastle/ machinery: prompt rule 9 / #445 route — human-gated landing, hence ready-for-human.
## Why 2026-08-13/14: the primary Claude account hit its weekly limit (resets Aug 15, 8am UTC) and the whole loop parked — swarm runs on both repos paused on the limit guard, the rehearsal reporter's diagnosis leg failed to the generic ready-for-human path, and the healer went dark. The fix was a hand-swap to a second account's token (org secret + `rehearsal-env.sh`), ~a day of degraded reds later than it needed to be. We now hold **two** accounts. The machinery should ride over an exhausted window by itself. ## Design sketch - **Second org secret** `CLAUDE_CODE_OAUTH_TOKEN_B` (the standby account). The org level is now the ONE source of truth — the diverged ourcloud repo-level override was deleted 2026-08-14; never reintroduce it. - **Detection is already centralized** in `.sandcastle/limit-lib.sh` (shared by run-swarm and the healer so they can't drift — the 2026-07-29 "weekly" phrasing lesson). Failover keys off the same predicate. - **run-swarm.sh:** on `claude_limit_hit` with the active token, re-try the sandcastle run ONCE on the other token, and stamp a host-global active-token marker (sibling of the existing `/tmp/matou-swarm-claude-limit` notice marker — repo-agnostic by design, one subscription window per account) so subsequent runs on this host start on the live token without paying a failed attempt first. - **Healer:** same swap via limit-lib before declining on a limit. - **Workstation rehearsal machinery:** `rehearsal-env.sh` carries both tokens; the reporter/healer wrapper tries active-then-standby with the same marker discipline. (Host-only file — the tokens must never enter `.sandcastle/.env`, which forwards into worker containers; 2026-07-11 lesson.) - **Notices:** the hourly-deduped Mattermost limit notice names WHICH account parked ("account A limited — failed over to B" / "BOTH accounts limited — parked until <reset hint>"). Both limited → exactly today's quiet park. ## Acceptance criteria 1. With token A scripted to answer the limit line and B healthy, a run completes on B and the marker leaves the host starting on B; one Mattermost notice names the failover. 2. With both tokens limited, the run parks quietly green exactly as today (no red storm), notice names both. 3. The healer path swaps identically (limit-lib is the only detection point — no second grep anywhere). 4. Marker expiry/reset: a stale marker never pins the host to the standby forever (e.g. re-probe A after its reset hint, or hourly TTL). 5. Offline tests alongside the existing limit-guard cases; no live-token test in the gate. ## Notes - Account 1 resets Aug 15 08:00 UTC and becomes the natural standby (`_B`). - This is `.sandcastle/` machinery: prompt rule 9 / #445 route — human-gated landing, hence ready-for-human.
Author
Owner

Ruled by agent under ADR 0174 — veto anytime. Ruling: build as sketched — the design + acceptance criteria in the body are complete, offline-tested, marker-TTL-bounded, and degrade to exactly today's quiet park when both accounts are limited. Two-way door. It sits ready-for-session (not ready-for-agent) only because .sandcastle/ is a protected path (#445) — an interactive session lands it.

**Ruled by agent under ADR 0174 — veto anytime.** Ruling: build as sketched — the design + acceptance criteria in the body are complete, offline-tested, marker-TTL-bounded, and degrade to exactly today's quiet park when both accounts are limited. Two-way door. It sits `ready-for-session` (not `ready-for-agent`) only because `.sandcastle/` is a protected path (#445) — an interactive session lands it.
Author
Owner

Machinery LANDED: 4ed8d44 (ruled build-as-sketched under ADR 0174, landed by session — protected path #445).

  • Failover primitives beside the limit predicate in limit-lib.sh (ONE detection point — AC-3): claude_select_token / claude_failover / host-global active-account marker, 1h TTL (stale never pins the standby — AC-4).
  • Wired: run-swarm.sh (retry once + account-named notices: "account A limited — failed over to B" / "BOTH accounts limited" — AC-1/AC-2 shape), heal.sh, and both rehearsal-report.sh call sites.
  • Bonus defect fixed (GOTCHAS #33): limit refusals arriving on stdout (exactly how the reporter misfiled #530 today) are now caught — both streams checked.
  • Offline proof (AC-5): limit-lib-test.sh 11 groups (marker matrix, flip/flip-back, fresh-B steering, stale-fallback) + heal-test.sh ride-over and no-standby-defers scenarios. No live-token test in the gate.

Why human (the remaining tail)

The machinery is INERT until the standby credential exists — personal-credential work (ADR 0174 one-way door):

  1. Mint the org Actions secret CLAUDE_CODE_OAUTH_TOKEN_B (the standby account's token — org level only, the repo-level override stays dead).
  2. Add the CLAUDE_CODE_OAUTH_TOKEN_B export to the workstation's rehearsal-env.sh (host-only file — never .sandcastle/.env).

Relabelled ready-for-human for that two-line tail; it rides the next digest.

**Machinery LANDED: `4ed8d44`** (ruled build-as-sketched under ADR 0174, landed by session — protected path #445). - Failover primitives beside the limit predicate in `limit-lib.sh` (ONE detection point — AC-3): `claude_select_token` / `claude_failover` / host-global active-account marker, 1h TTL (stale never pins the standby — AC-4). - Wired: `run-swarm.sh` (retry once + account-named notices: "account A limited — failed over to B" / "BOTH accounts limited" — AC-1/AC-2 shape), `heal.sh`, and both `rehearsal-report.sh` call sites. - Bonus defect fixed (GOTCHAS #33): limit refusals arriving on **stdout** (exactly how the reporter misfiled #530 today) are now caught — both streams checked. - Offline proof (AC-5): `limit-lib-test.sh` 11 groups (marker matrix, flip/flip-back, fresh-B steering, stale-fallback) + `heal-test.sh` ride-over and no-standby-defers scenarios. No live-token test in the gate. ## Why human (the remaining tail) The machinery is INERT until the standby credential exists — personal-credential work (ADR 0174 one-way door): 1. Mint the **org** Actions secret `CLAUDE_CODE_OAUTH_TOKEN_B` (the standby account's token — org level only, the repo-level override stays dead). 2. Add the `CLAUDE_CODE_OAUTH_TOKEN_B` export to the workstation's `rehearsal-env.sh` (host-only file — never `.sandcastle/.env`). Relabelled `ready-for-human` for that two-line tail; it rides the next digest.
Author
Owner

COMPLETE — tokens wired, primary probed live, failover armed (Ben's hands + session, 2026-08-14 evening).

  • rehearsal-env.sh carries both accounts: primary answers a live ok probe; standby is a distinct 108-char token (fresh mint, back in window at its 8am UTC reset). Host-only file, as designed — nothing entered .sandcastle/.env.
  • Org secret CLAUDE_CODE_OAUTH_TOKEN_B exists (set via UI — the API PUT 403s on a repo-scoped PAT); the swarm + healer workflows pass it through since db928ad.
  • Machinery landed earlier as 4ed8d44 (limit-lib primitives, run-swarm/healer/reporter wiring, both-streams detection, offline suites green).
  • Live proof in flight: a session-runner tick is running a REAL unattended session on #425 on the primary token right now — its Mattermost notice is the drain's first heartbeat.
  • Open residue (minor, non-blocking): the org B secret currently holds the same token as the workstation primary — if those are one account, swap the org B value to the standby's token so the SWARM pair spans two accounts too. One UI paste, whenever convenient.

Closing: the loop now rides over an exhausted window on the workstation paths, and the CI paths are one secret-value swap from the same. AC-2 (both-limited quiet park) was proven live earlier today — twice, unintentionally.

**COMPLETE — tokens wired, primary probed live, failover armed** (Ben's hands + session, 2026-08-14 evening). - `rehearsal-env.sh` carries both accounts: primary answers a live `ok` probe; standby is a distinct 108-char token (fresh mint, back in window at its 8am UTC reset). Host-only file, as designed — nothing entered `.sandcastle/.env`. - Org secret `CLAUDE_CODE_OAUTH_TOKEN_B` exists (set via UI — the API PUT 403s on a repo-scoped PAT); the swarm + healer workflows pass it through since `db928ad`. - Machinery landed earlier as `4ed8d44` (limit-lib primitives, run-swarm/healer/reporter wiring, both-streams detection, offline suites green). - Live proof in flight: a session-runner tick is running a REAL unattended session on #425 on the primary token right now — its Mattermost notice is the drain's first heartbeat. - Open residue (minor, non-blocking): the org B secret currently holds the same token as the workstation primary — if those are one account, swap the org B value to the standby's token so the SWARM pair spans two accounts too. One UI paste, whenever convenient. Closing: the loop now rides over an exhausted window on the workstation paths, and the CI paths are one secret-value swap from the same. AC-2 (both-limited quiet park) was proven live earlier today — twice, unintentionally.
ben closed this issue 2026-08-14 22:25:06 +00:00
Author
Owner

Residue resolved: org CLAUDE_CODE_OAUTH_TOKEN_B swapped to the standby account's token (PUT 204 — the earlier 403 was the workstation's scoped-down token, not the local PAT). Both pairs (org + rehearsal-env.sh) now span the two accounts: primary = live account, standby = the 8am-reset account. Org secrets verified as two independent slots (list API), values write-only.

Residue resolved: org `CLAUDE_CODE_OAUTH_TOKEN_B` swapped to the standby account's token (PUT 204 — the earlier 403 was the workstation's scoped-down token, not the local PAT). Both pairs (org + rehearsal-env.sh) now span the two accounts: primary = live account, standby = the 8am-reset account. Org secrets verified as two independent slots (list API), values write-only.
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#510
No description provided.