Repository navigation
fix(pusher): circuit breaker + reconnect state machine + graceful degradation - #6025
Conversation
|
Required fixes from review cycle 1 — all 6 issues addressed:
Re-running reviewer. by AI for @beastoin |
|
Required fixes from review cycle 2 — all 3 issues addressed:
Re-running reviewer. by AI for @beastoin |
CP8.1 Test Detail Table
CP8.2 Sequence Catalog
by AI for @beastoin |
CP9 Changed-Path Coverage ChecklistAll changed executable code paths from PR diff, mapped to flow diagram sequences (S1–S7).
by AI for @beastoin |
CP9A: Level 1 Live Test — Backend StandaloneBuild evidenceBackend started successfully on port 10240 with circuit breaker code on branch Unit tests (32/32 pass)Metrics registration (P11)All 3 new Prometheus metrics registered with correct initial values: Live integration test results
Backend log evidence (degraded mode + reconnect state machine)With L1 SynthesisAll changed paths P1–P11 (circuit breaker layer) were proven via 32 unit tests + live integration tests showing correct state transitions (CLOSED→OPEN→HALF_OPEN→CLOSED), metric updates (0→1→2→0), and fail-fast behavior. Paths P12, P14, P16, P17, P18 (reconnect state machine + graceful degradation) were proven via backend logs from a live WS session showing degraded mode entry (no 1011 close), reconnect loop activation, and probe cycling. Sequences S1 (normal), S3 (backoff), S4 (breaker trip), S5 (degraded), S6 (probe), S7 (initial failure) all have live evidence. No paths remain UNTESTED at L1. by AI for @beastoin |
CP9B: Level 2 Live Test — Backend + App IntegratedBuild evidenceBackend: Started on port 10240 with circuit breaker code (branch App: Built and installed on Android emulator (sdk gphone64 x86 64): App wired to local backend via Integrated flow evidenceBackend received multiple WS connections from app: Graceful degradation verified across both service + app (P17, P18, P22): App-side verification (P18 — no 1011 from new backend):
Correlated timestamps: Backend WS accept → app GET /v1/conversations → all within same session window, confirming end-to-end integration. Updated CP9 Checklist Results (L2 column)
L2 SynthesisPaths P12, P14–P18, P21–P23 were proven via integrated backend+app testing with 5 WS sessions showing degraded mode entry (no 1011 close), reconnect loop activation and cleanup, and zero 1011 errors on the new app. Sequences S2 (disconnect), S5 (degraded mode), S7 (initial connect failure) have end-to-end evidence across both backend logs and app behavior. Paths P1, P13, P19–P20 remain UNTESTED at L2 because they require a live pusher service or active conversation processing during degraded mode — these are covered by L1 unit tests (32 pass). Circuit breaker internals (P2–P11) are fully proven at L1 with unit tests + live integration. by AI for @beastoin |
|
All checkpoints passed (CP0–CP9B). PR is ready for merge. Checkpoint summary:
Level 3 not required (no cluster config/Helm changes, no remote-only infra deps). Awaiting explicit merge approval. by AI for @beastoin |
…trics (#6022) Co-Authored-By: Claude Opus 4.6 <[email protected]>
) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…dation (#6022) Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
36d3cb3 to
8592879
Compare
|
Rebased onto latest
All 32 tests pass. PR is mergeable. by AI for @beastoin |
|
lgtm |
Fixes #6022
Adds a 3-layer defense against pusher retry exhaustion cascades that caused a 3.5h production outage on 2026-03-24:
Layer 1 — Pod-level circuit breaker (
utils/pusher.py): Tracks failures across all sessions. Trips OPEN after ≥20 failures in 30s, rejects all connect attempts for 60s cooldown, allows a single HALF_OPEN probe to recover. PusherCircuitBreakerOpen exception enables callers to distinguish breaker-open from normal failures.Layer 2 — Per-session reconnect state machine (
routers/transcribe.py): Replaces 3 scattered auto-reconnect calls with a single_pusher_reconnect_loop()per session. States: CONNECTED → RECONNECT_BACKOFF (6 attempts, exp backoff 1s→60s) → DEGRADED (60s cooldown) → HALF_OPEN_PROBE → CONNECTED. Centralized_mark_disconnected()ensures consistent state transitions from all disconnect paths.Layer 3 — Graceful degradation (
routers/transcribe.py): When pusher is unavailable, DG streaming continues normally. Conversations route to_create_conversation_fallback()with dedup guard. Initial connect failure enters degraded mode instead of closing client WS with 1011. Thestart_degraded()function bootstraps the reconnect loop on initial failure.Observability (
utils/metrics.py): Three new Prometheus metrics —pusher_circuit_breaker_state(gauge: 0=closed, 1=open, 2=half_open),pusher_circuit_breaker_rejections_total(counter),pusher_sessions_degraded(gauge).Testing
API_BASE_URL=http://10.0.2.2:10240/, 5 WS sessions showed graceful degradation (no 1011), zero 1011 errors from new app instanceReview history
by AI for @beastoin