Skip to content

fix(api): surface shared-store (Redis/Upstash) liveness in /health [BUG-111] - #226

Open
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/shared-store-health-ping
Open

fix(api): surface shared-store (Redis/Upstash) liveness in /health [BUG-111]#226
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/shared-store-health-ping

Conversation

@Morenikeoa

@Morenikeoa Morenikeoa commented Jun 26, 2026

Copy link
Copy Markdown

Bug

UpstashStore is designed to fall back to an in-memory store on any Redis error, which is the right call-site behavior (a Redis outage shouldn't take the API down). But every fallback decision today is only visible via a scattered logger.warn() inside whichever method happened to fail. There's no operator-facing signal that the multi-replica abuse-control guarantee (rate limits, WS connection caps, auth bans — all documented at the top of shared-store.ts) has silently degraded to per-replica enforcement across the whole deployment. /health has no idea this subsystem exists.

Fix

Add ping(): Promise<boolean> to the SharedStore interface:

  • InMemoryStore.ping() is trivially always true — it's the deliberately chosen single-replica backend, not a degraded state.
  • UpstashStore.ping() issues a real Redis PING and returns false on any failure — deliberately not routed through the fallback-to-memory path the other methods use, since the whole point here is to report the real backend's reachability rather than mask it.

health.ts now calls getSharedStore().ping() and reports it as a new checks.sharedStore field, following the same pattern as the existing db/rpc/ws checks.

Test plan

  • Added ping() liveness probe (BUG-111) block to tests/middleware/shared-store.test.ts: InMemoryStore always true; UpstashStore true on PONG, false on network failure, false on a non-PONG response.
  • Added shared store health check (BUG-111) block to tests/routes/health.test.ts: checks.sharedStore flips false when ping() resolves false or throws, true when it resolves true; updated the existing "all checks fail" test to also mock ping() failing so it still exercises the true all-down case.
  • Verified both are genuine regressions: reverted src/middleware/shared-store.ts + src/routes/health.ts via git stash, confirmed all 8 new/updated tests fail against the unfixed code (missing ping on the interface/check), restored the fix.
  • Full suite passes (301/302 — the 1 pre-existing failure is unrelated to this change, in adl.test.ts).
  • tsc --noEmit clean.

Summary by CodeRabbit

  • New Features

    • Added a shared-store connectivity check to the health endpoint, improving visibility into service health.
    • Health responses now include shared-store status alongside existing checks.
  • Bug Fixes

    • Health status now reflects shared-store failures as degraded or down instead of appearing fully healthy.
    • Redis-backed shared-store checks now fail safely when connectivity is lost or responses are unexpected.
  • Tests

    • Expanded coverage for shared-store liveness and health endpoint behavior.

…UG-111)

When Upstash Redis becomes unreachable, UpstashStore silently falls back
to per-replica in-memory enforcement for rate limits, WS connection caps,
and auth bans — the only signal is a scattered logger.warn() per failed
call. Operators had no way to see this degradation from /health.

Add ping() to the SharedStore interface: InMemoryStore is trivially
always healthy (it's the deliberately chosen backend), UpstashStore
issues a real Redis PING without the fallback masking applied to its
other methods. health.ts now reports this as a new `sharedStore` check.
@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

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 638e5f77-7734-4160-b71c-4c234bb7a291

📥 Commits

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

📒 Files selected for processing (4)
  • src/middleware/shared-store.ts
  • src/routes/health.ts
  • tests/middleware/shared-store.test.ts
  • tests/routes/health.test.ts

📝 Walkthrough

Walkthrough

SharedStore now exposes a ping() liveness probe. /health calls that probe and includes shared-store health in its overall status. Tests cover in-memory and Upstash ping behavior plus the updated health-route outcomes.

Changes

Shared store ping contract

Layer / File(s) Summary
Shared store ping contract
src/middleware/shared-store.ts, tests/middleware/shared-store.test.ts
SharedStore adds ping(), InMemoryStore returns true, UpstashStore issues Redis PING, and tests cover success, non-PONG, and failure cases.
Health route shared-store check
src/routes/health.ts, tests/routes/health.test.ts
/health calls getSharedStore().ping(), adds checks.sharedStore, and the route tests assert the new healthy and unhealthy outcomes.

Sequence Diagram

sequenceDiagram
  participant Client
  participant HealthRoute
  participant SharedStore
  Client->>HealthRoute: GET /health
  HealthRoute->>SharedStore: ping()
  alt ping succeeds
    SharedStore-->>HealthRoute: true
  else ping throws or fails
    SharedStore-->>HealthRoute: false
  end
  HealthRoute-->>Client: status with checks.sharedStore
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A tiny bunny hopped in light,
To ping the store by moonlit night.
If Redis snoozed, I’d still know true,
And /health would tell the view.
Thump thump — the checks are neat and bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding shared-store liveness reporting to /health.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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