Skip to content

fix(api): reconnect OraclePriceBroadcaster on channel drop + surface its health [BUG-103] - #220

Open
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/oracle-broadcaster-reconnect-health
Open

fix(api): reconnect OraclePriceBroadcaster on channel drop + surface its health [BUG-103]#220
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/oracle-broadcaster-reconnect-health

Conversation

@Morenikeoa

Copy link
Copy Markdown

Problem

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, 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 local const in index.ts, never passed anywhere, and /health had no reference to it at all.

Impact

Live price broadcasts to WS clients can go dark indefinitely after a single transient Realtime hiccup, while /health continues reporting "ok", giving operators no signal that anything is wrong.

Fix

  • Added reconnect-with-backoff directly in the status callback (1s base delay, doubling each consecutive failure, capped at 30s, reset back to 1s once a SUBSCRIBED actually lands).
  • Added getStatus()/isHealthy() so the current connection state is queryable.
  • Converted the class to a singleton via getOraclePriceBroadcaster() so health.ts can reach the exact instance index.ts starts. This was necessary because index.ts registers routes (including healthRoutes()) 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.
  • 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".

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 /health check (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/getOraclePriceBroadcaster entirely; the health check defaulting to a different shape). Restored the fix and they pass.

  • All existing tests pass — output attached.
  • New/updated tests pass against the fix, fail against pre-fix code (verified locally).
  • tsc --noEmit clean (no separate lint script in this repo).

Test Output

✓ tests/services/oracle-price-broadcaster.test.ts (7 tests) 11ms
✓ tests/routes/health.test.ts (8 tests) 60ms

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/sdk error-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.

…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>
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Morenikeoa, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96009930-68f9-4a77-8aa0-7adb9293f62f

📥 Commits

Reviewing files that changed from the base of the PR and between b2751f4 and 3a817ab.

📒 Files selected for processing (5)
  • src/index.ts
  • src/routes/health.ts
  • src/services/OraclePriceBroadcaster.ts
  • tests/routes/health.test.ts
  • tests/services/oracle-price-broadcaster.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant