Skip to content

feat: Cooperative Rate Limiting & Predictive Circuit Breaker (#515)#518

Merged
bradygaster merged 4 commits intobradygaster:devfrom
tamirdresher:tamirdresher/515-cooperative-rate-limiting
Mar 23, 2026
Merged

feat: Cooperative Rate Limiting & Predictive Circuit Breaker (#515)#518
bradygaster merged 4 commits intobradygaster:devfrom
tamirdresher:tamirdresher/515-cooperative-rate-limiting

Conversation

@tamirdresher
Copy link
Copy Markdown
Collaborator

Closes #515

Adds cooperative rate limiting patterns for multi-agent Squad deployments.

Changes

  • New SDK module: packages/squad-sdk/src/ralph/rate-limiting.ts

    • PredictiveCircuitBreaker class: Opens circuit BEFORE 429 using linear regression
    • getTrafficLight(): GREEN/AMBER/RED throttling from API headers
    • shouldProceed(): Priority-based agent scheduling
    • getRetryDelay(): Non-overlapping jitter windows by agent priority
    • canUseQuota(): Cooperative token pool management
    • loadRatePool(): Shared rate-pool.json reader
  • New template: .squad-templates/cooperative-rate-limiting.md

    • 6-pattern architecture documentation (RAAS, CMARP, PCB, PWJG, RET, CDD)
    • TypeScript code examples for each pattern
    • Kubernetes integration guide with KEDA scaler reference
  • Tests: test/rate-limiting.test.ts (23 test cases)

  • Changeset included

Context

Builds on the existing circuit breaker template (#450) with patterns for multi-instance coordination. Based on production experience running 7+ concurrent agents on AKS.

…ygaster#515)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tamirdresher pushed a commit to tamirdresher/squad that referenced this pull request Mar 22, 2026
…aster#515)

Integrates PredictiveCircuitBreaker from squad-sdk into Ralph's watch loop:
- Pre-round rate limit check via gh api rate_limit
- Traffic light gating (GREEN/AMBER/RED)
- Predictive circuit opening before 429
- Exponential backoff on rate limit errors
- Half-open recovery with 2-success threshold
- State persistence to .squad/ralph-circuit-breaker.json
- Adds ghRateLimitCheck() and isRateLimitError() to gh-cli.ts

Depends on bradygaster#518 for the SDK module.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add non-null assertions for array indexing in PredictiveCircuitBreaker
- Add ./ralph/rate-limiting export entry to SDK package.json

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tamirdresher pushed a commit to tamirdresher/squad that referenced this pull request Mar 22, 2026
…aster#515)

Integrates PredictiveCircuitBreaker from squad-sdk into Ralph's watch loop:
- Pre-round rate limit check via gh api rate_limit
- Traffic light gating (GREEN/AMBER/RED)
- Predictive circuit opening before 429
- Exponential backoff on rate limit errors
- Half-open recovery with 2-success threshold
- State persistence to .squad/ralph-circuit-breaker.json
- Adds ghRateLimitCheck() and isRateLimitError() to gh-cli.ts

Depends on bradygaster#518 for the SDK module.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- canUseQuota() is now a pure read — returns boolean, no side effects
- consumeQuota() handles stale lease reclamation and usage tracking
- Correct JSDoc: prediction uses first-to-last delta rate, not linear regression
- Update tests: add consumeQuota test suite, fix canUseQuota purity assertions

Fixes Q review findings on PR bradygaster#518: side-effect bug in canUseQuota()
and inaccurate 'linear regression' JSDoc claim.
Copy link
Copy Markdown
Owner

@bradygaster bradygaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-designed rate limiting module — the traffic light pattern and priority-based retry windows are production-quality. Clean types, good test coverage (23 cases).\n\nMinor fix needed: test imports use relative paths (../packages/squad-sdk/src/ralph/rate-limiting.js) instead of package subpath imports (@bradygaster/squad-sdk/ralph/rate-limiting). The rest of our test suite uses subpath imports — please update for consistency.\n\nAlso: \writeFile\ is imported but never used in
ate-limiting.ts\ — small cleanup.\n\nOther than that, this is great work. Ready to merge after those tweaks. ✅

…ile import

- Changed test import from relative path to @bradygaster/squad-sdk/ralph/rate-limiting
- Removed unused writeFile import from rate-limiting.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bradygaster bradygaster merged commit 7f86e0e into bradygaster:dev Mar 23, 2026
chrislomonico pushed a commit to clomonico/squad that referenced this pull request Mar 26, 2026
…r#546)

Consolidated 15 remaining issues into a single PR. Redesigns help UX with grouped categories, surfaces all /help commands, aligns docs with actual CLI behavior, adds first-run welcome, standardizes naming.

Closes bradygaster#510, Closes bradygaster#513, Closes bradygaster#514, Closes bradygaster#515, Closes bradygaster#516, Closes bradygaster#517, Closes bradygaster#518, Closes bradygaster#521, Closes bradygaster#522, Closes bradygaster#523, Closes bradygaster#524, Closes bradygaster#525, Closes bradygaster#527, Closes bradygaster#528, Closes bradygaster#529

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