* fix(brain): SSE connection limiter, pipeline rate limit, Firestore pagination fallback (ADR-130)
Three fixes for recurring pi.ruv.io outages:
1. SSE connection limiter (max 50) — prevents MCP reconnect storms from
exhausting Cloud Run concurrency slots. Tracks active count with
AtomicUsize, rejects excess with 429.
2. Pipeline optimize rate limiter — max 1 concurrent request with 30s
cooldown. Prevents scheduler thundering herd from CPU-saturating
the instance.
3. Firestore pagination offset fallback — when page tokens go stale
after OOM restart (400 Bad Request), switches to offset-based
pagination to load all documents instead of stopping at first batch.
Also adds /v1/ready lightweight probe (zero-cost, no state access)
for Cloud Run health checks.
ADR-130 documents the full decoupling architecture (SSE service split).
Co-Authored-By: claude-flow <ruv@ruv.net>
* feat(brain): ADR-130 service split — SSE proxy, worker binary, internal queue
Implements full MCP SSE decoupling to eliminate recurring outages:
1. ruvbrain-sse: Thin SSE proxy (308 lines) that manages MCP connections
independently from the API. Max 200 concurrent SSE, forwards JSON-RPC
to the API, polls /internal/queue/drain for responses. No business logic.
2. ruvbrain-worker: Batch worker binary (202 lines) for Cloud Run Jobs.
Runs scheduler actions (train, drift, transfer, graph, cleanup, attractor)
with direct Firestore access. Runs once and exits.
3. Internal queue endpoints on the API:
- POST /internal/queue/push (forward JSON-RPC to session)
- GET /internal/queue/drain (poll for responses)
- POST /internal/session/create (register session)
- DELETE /internal/session/:id (cleanup)
4. Deploy infrastructure:
- Dockerfile.sse, Dockerfile.worker
- cloudbuild-sse.yaml, cloudbuild-worker.yaml
- scripts/deploy_brain_services.sh [api|sse|worker|all]
Architecture: SSE (500 concurrency, 512MB) → API (80 concurrency, 4GB) ← Worker (Cloud Run Job, 4GB)
Co-Authored-By: claude-flow <ruv@ruv.net>