Skip to content

feat(watch): circuit breaker integration — additive patch (#515)#552

Merged
bradygaster merged 2 commits intobradygaster:devfrom
tamirdresher:tamirdresher/515-rate-limit-watch-v2
Mar 23, 2026
Merged

feat(watch): circuit breaker integration — additive patch (#515)#552
bradygaster merged 2 commits intobradygaster:devfrom
tamirdresher:tamirdresher/515-rate-limit-watch-v2

Conversation

@tamirdresher
Copy link
Copy Markdown
Collaborator

Summary

Adds rate limit protection to Ralph's watch command as a surgical additive patch on the existing flow. Reworked from #522 per Brady's feedback — no full rewrite, no existing functions modified.

Closes #515

What changed

File Lines Change
gh-cli.ts +34 ghRateLimitCheck(), isRateLimitError() helpers
watch.ts +148/-23 Circuit breaker state type, executeRound() wrapper, roundInProgress guard
watch-circuit-breaker.test.ts +320 16 tests covering all state transitions

Architecture: Additive wrapper

Existing functions are completely untouched: runCheck, checkPRs, reportBoard, emptyBoardState.

The only change is in runWatch():

  1. Initialize PredictiveCircuitBreaker + load persisted state
  2. executeRound() gates existing call: pre-flight quota check -> delegate to runCheck() -> post-round update
  3. roundInProgress flag + try/finally prevents overlapping rounds

State machine

CLOSED -> OPEN (red/predicted) -> HALF-OPEN (cooldown expires) -> CLOSED (2 successes) or back to OPEN (429 during probe)

Cooldown: 2m -> 4m -> 8m -> ... -> 30m cap. Persists to .squad/ralph-circuit-breaker.json.

Addressed feedback from #522

  • Additive patch (not a full rewrite)
  • saveCBState is sync (writeFileSync, no await)
  • Internal exports (gh-cli helpers NOT exposed in package.json)
  • 16 state machine tests (all transitions covered)
  • Race condition guard (roundInProgress with try/finally)

Test results

  • 22/22 watch tests pass (6 existing + 16 new)
  • 21/27 rate-limiting tests pass (6 failures are pre-existing on dev)
  • 0 new TypeScript errors

Copilot and others added 2 commits March 23, 2026 09:45
…radygaster#515)

Adds rate limit protection to Ralph's watch command as an additive patch
on top of the existing watch flow. No existing functions are modified.

Changes:
- gh-cli.ts: +ghRateLimitCheck(), +isRateLimitError() helpers
- watch.ts: +CircuitBreakerState type, persistence helpers
- watch.ts: +executeRound() wrapper gates existing runCheck through
  pre-flight quota checks (traffic light + predictive CB)
- watch.ts: +roundInProgress flag prevents overlapping setInterval rounds
- 16 new tests: state machine transitions, race guard, isRateLimitError

State machine: closed → open (quota critical) → half-open (cooldown expires)
→ closed (2 consecutive successes) or re-open (429 during probe).
Cooldown doubles on each failure (2m → 4m → ... → 30m cap).
State persists to .squad/ralph-circuit-breaker.json.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Linux chmod 444 returns EACCES, not EPERM. Handle both codes
for cross-platform compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bradygaster bradygaster merged commit 76974e8 into bradygaster:dev Mar 23, 2026
2 checks passed
chrislomonico pushed a commit to clomonico/squad that referenced this pull request Mar 26, 2026
Session: 2026-02-27T23-18-55Z-repo-assessment
Requested by: Scribe

Changes:
- Logged orchestration for Kobayashi (branch cleanup, 57 refs pruned)
- Logged orchestration for Keaton (full repo assessment, replatform readiness)
- Logged session: full repo assessment with concrete timeline
- Merged 5 decisions from inbox to decisions.md (deduplicated)
- Cleared decisions/inbox/ directory

**Merged decisions:**
- Fenster: Ghost command aliasing strategy
- Fenster: Per-command --help/-h intercept-before-dispatch pattern
- Keaton: Replatform readiness assessment (APPROVE launch, contingent on bradygaster#532)
- Kovash: REPL cancellation and configurable timeout
- Saul: Shell observability metrics design

**Deduplication:** No exact duplicates found. All decisions preserved.

**Cross-agent impact:**
- Keaton's replatform decision affects all agents: v1 public alpha approved for Feb 28-Mar 1 launch
- Timeline: Close bradygaster#532 (dogfood), merge bradygaster#552 (Ralph triage), ship v0.8.5.1 public alpha
- Wave E queued: bradygaster#553 (personal consult), bradygaster#547 (remote control), bradygaster#542 (board automation)
chrislomonico pushed a commit to clomonico/squad that referenced this pull request Mar 26, 2026
bradygaster#552)

* feat(ralph): routing-aware triage, PR monitoring, board state tracking

- Add packages/squad-sdk/src/ralph/triage.ts with parseRoutingRules(),
  parseModuleOwnership(), parseRoster(), and triageIssue() that reads
  routing.md for smart work assignment (module path > routing keyword >
  role keyword > Lead fallback)
- Add templates/ralph-triage.js standalone CJS script for heartbeat
  workflow (zero deps, reads .squad/ files, outputs triage-results.json)
- Update squad-heartbeat.yml to use ralph-triage.js instead of inline
  keyword matching
- Update watch.ts to use SDK triage module instead of hardcoded keywords
- Add PR/CI monitoring to watch: drafts, review feedback, CI failures,
  merge-ready PRs
- Add BoardState tracking, board-clear detection, round counting
- Wire RalphMonitor into watch for health checks and state persistence
- Add body field to GhIssue, add GhPullRequest/ghPrList to gh-cli.ts
- Fix Ralph charter: "Persistent Memory Agent" -> "Work Monitor"
- Create ralph-reference.md template (was referenced but missing)
- Add SDK subpath export for ralph/triage
- Update docs/features/ralph.md with routing-aware triage, WIP
  monitoring, board state, and wake-up event documentation
- 57 tests across 3 test files (ralph-triage, ralph-monitor, ralph-board)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(ai-team): Ralph smart triage session — merge inbox, log, dedupe

Session: 2026-02-27T03-25-00Z-ralph-smart-triage
Requested by: Copilot CLI

Changes:
- Logged session: triage engine build (Fenster), 57 passing tests (Hockney), architecture review approved (Keaton), docs updated (McManus)
- Merged 6 inbox decisions: shell metrics, REPL improvements, triage review, watch integration, CLI help, ghost commands
- Deduplicated 0 exact duplicates; consolidated 0 overlapping decisions
- Deleted 6 inbox files after merge

* fix(ralph): address PR bradygaster#552 review feedback

- Fix assigned issue count: use raw count instead of PR-derived subtraction
- Change squad-sdk dependency to workspace:* for monorepo correctness
- Fix ralph-reference.md: replace non-existent label refs with actual API fields
- Add sync headers to ralph-triage.js (3 copies) and squad-heartbeat.yml (4 copies)
- Add triage parity tests: syntax validation + routing priority verification

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Cooperative Rate Limiting & Predictive Circuit Breaker for Multi-Agent Deployments

2 participants