fix(api): reconnect OraclePriceBroadcaster on channel drop + surface its health [BUG-103] - #220
Conversation
…its health [BUG-103] OraclePriceBroadcaster's Supabase Realtime .subscribe() status callback logged CHANNEL_ERROR/TIMED_OUT/CLOSED but never re-subscribed — Realtime does not retry on its own once it reports one of these terminal statuses. Once the channel dropped for any of these reasons, live WS price broadcasts went silently and permanently dead until a process restart, with zero visibility: the instance was a local const in index.ts, never passed anywhere, and /health had no reference to it at all. Added reconnect-with-backoff (1s base, doubling, capped at 30s, reset on a successful SUBSCRIBED) directly in the status callback, and getStatus()/ isHealthy() so the current connection state is queryable. Converted the class to a singleton-via-getter (getOraclePriceBroadcaster()) so health.ts can reach the exact instance index.ts starts — index.ts currently registers routes (including healthRoutes()) before it creates the broadcaster, so a direct reference couldn't have been threaded through without reordering index.ts's whole startup sequence. Wired a new `priceBroadcaster` check into /health's checks object, alongside the existing rpc/db/ws checks — a dead channel now makes /health report "degraded" instead of silently "ok" while no live prices flow. Added tests covering: backoff scheduling and reset, stop() cancelling any pending reconnect, the singleton returning the same instance, and the new /health check (including a thrown error from the broadcaster not crashing the health endpoint). Verified all new assertions fail against the pre-fix code (missing getStatus/isHealthy/getOraclePriceBroadcaster entirely, and the health check defaulting to a different shape) and pass against the fix. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@Princessdada is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 27 minutes and 7 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
OraclePriceBroadcaster's Supabase Realtime.subscribe()status callback loggedCHANNEL_ERROR/TIMED_OUT/CLOSEDbut never re-subscribed — Realtime does not retry on its own once it reports one of these terminal statuses. Once the channel dropped, live WS price broadcasts went silently and permanently dead until a process restart. There was also zero visibility into this: the broadcaster instance was a localconstinindex.ts, never passed anywhere, and/healthhad no reference to it at all.Impact
Live price broadcasts to WS clients can go dark indefinitely after a single transient Realtime hiccup, while
/healthcontinues reporting"ok", giving operators no signal that anything is wrong.Fix
SUBSCRIBEDactually lands).getStatus()/isHealthy()so the current connection state is queryable.getOraclePriceBroadcaster()sohealth.tscan reach the exact instanceindex.tsstarts. This was necessary becauseindex.tsregisters routes (includinghealthRoutes()) before it creates the broadcaster — a direct reference couldn't have been threaded through without reordering the whole startup sequence, so a singleton accessor was the minimal change.priceBroadcastercheck into/health'schecksobject, alongside the existingrpc/db/wschecks — a dead channel now makes/healthreport"degraded"instead of silently"ok".Proof of Fix
New tests cover: backoff scheduling and its reset on success,
stop()cancelling any pending reconnect, the singleton returning the same instance across calls, and the new/healthcheck (including a thrown error from the broadcaster not crashing the health endpoint — caught and treated as unhealthy).Verified these are genuine regression tests: reverted the 3 source files and reran — all 8 new/updated assertions failed (missing
getStatus/isHealthy/getOraclePriceBroadcasterentirely; the health check defaulting to a different shape). Restored the fix and they pass.tsc --noEmitclean (no separate lint script in this repo).Test Output
Full suite: 303/304 passed (294 baseline + 9 new). The 1 failure (
tests/sdk-smoke.test.ts) is pre-existing and unrelated — it asserts on an exact@percolatorct/sdkerror-message string that has drifted from the locally-resolved SDK version in this environment.Related
Found during a broader API audit; no existing open issue/PR covers this.