You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(sdk): upstream rate limiting behind the SSR proxy does not open its breaker - #2147
The SSR proxy (vapi) now answers upstream throttling as 503 with X-Ssr-Cache: RATELIMITED (ecency/vision-api#124). The SDK reads that as its own miss reason, ratelimited:
It is outside the breaker and resets the miss streak, like rpcerror. The proxy answered correctly; opening the breaker sent every following read straight to the same throttling nodes, per process and without the proxy's coalescing.
This read still falls back to the node pool. The SDK pool is not the proxy's pool, so a fallback can still succeed.
A 503 without the tag, or the tag on any other status, is still a status miss and still counts.
The [rpc-proxy] line reports ratelimited=.
Known trade-off (measure after deploy)
Under a sustained throttle of the whole pool, the breaker no longer opens. A throttled read then costs one proxy call plus the SDK's own node attempts, against node attempts only while the breaker was open. The gain is that every other read keeps the proxy's cache and coalescing. Whether to also skip the direct fallback on ratelimited, or honour Retry-After, will be decided from the [rpc-proxy] counters and the proxy's rate_limited stats after both ship.
Rollout
Either order is safe. An old proxy never sends the tag. An old SDK reads the new 503 as status, the same as today's 502.
Tests (written first, seen failing)
pnpm --filter @ecency/sdk test src/hive-tx/helpers/server-rpc-proxy.spec.ts
Before: an upstream-throttled answer falls back but neither opens nor advances the breaker failed with expected [ …(2) ] to have a length of 4 but got 2 (the breaker opened after two throttled answers).
After: 25/25 passed.
Mutation checks: dropping ratelimited from the breaker exemption fails the spec, and so does accepting the tag on any status (pinned after a first mutant survived).
Full runs:
pnpm --filter @ecency/sdk test: 1548 passed.
pnpm test (web): 7172 passed.
apps/web/src/specs/core/sdk-init-proxy.spec.ts: 9 passed, covering the report line.
SDK typecheck and lint, and web lint: clean.
Ships in the SDK dist, so it needs a version label to take effect.
Summary by CodeRabbit
Bug Fixes
Rate-limited proxy responses now fall back to node RPC instead of being counted as ordinary status misses.
These responses are tracked separately in proxy statistics, including periodic reports.
Rate limiting no longer advances the proxy breaker; it resets any existing miss count. Other proxy errors and untagged status responses retain their existing handling.
…ts breaker
The proxy answers 503 X-Ssr-Cache: RATELIMITED when every node behind it is
throttling the host. Treat that as its own miss reason, outside the breaker like
rpcerror: opening it sent every following read straight to the same throttling
nodes, per process and without the proxy's coalescing. The read itself still
falls back. The [rpc-proxy] line reports ratelimited=.
Closes#2146
Keep the SSR proxy breaker closed on upstream rate limiting
🐞 Bug fix🧪 Tests🕐 10-20 Minutes
AI Description
• Recognize tagged upstream throttling as a healthy proxy response, preventing it from opening the
breaker.
• Continue falling back to SDK nodes for throttled reads and report them separately.
• Test breaker resets, tag and status boundaries, and diagnostic output.
Merge Risk 🟡 Medium
Blast radius 🔴 High💥 2 capabilities
2 affected capabilities span independent functional scopes: SSR RPC proxy observability, SSR RPC read-through integration.
The changed proxy classification, breaker state, proxy fallback, and node-pool read all participate in one end-to-end behavior: obtaining allowlisted Hive read data for SSR.
The proxy and node pool are implementation hops of that same read capability, not independent capabilities.
The source call loop explicitly falls through to the existing node loop after a proxy miss, so no separate capability is established by the shared runtime boundary.
This is a distinct output behavior: emitting a periodic proxy health summary for operators/log consumers.
It is not a technical hop of the SSR content-read capability because it has a separate consumer outcome—diagnostic parsing and monitoring—and the changed line only formats that output.
Before: non-200 proxy responses were classified as rpcerror only for 502/RPCERROR; other statuses counted as ordinary breaker misses.
After: a specific 503/header combination becomes ratelimited, still falls back, but clears the consecutive-miss breaker state.
New correctness condition: the response status and header contract must be interpreted consistently with the proxy's upstream throttling semantics, and the breaker state transition must preserve the intended distinction between a healthy proxy relaying an upstream condition and an unavailable proxy.
This interacts with consecutive misses, cooldown skipping, fallback ordering, and shared per-process breaker state; it is more than a direct field mapping.
Potential damage 🟡 Medium🩹 Recoverable
The most supported consequence is temporary latency/resource degradation in SSR reads: each affected read still falls back to the existing node pool, so a normal node response remains available.
If throttling or resource exhaustion also affects the node pool, SSR reads could become temporarily unavailable, but that wider failure is not established by this change alone.
Reverting code stops the repeated breaker-reset behavior; any accumulated upstream throttling or resource pressure must clear operationally and is not repaired by rollback.
Usually recoverable by proxy recovery, throttling expiry, configuration disablement, or code rollback.
Code rollback does not undo requests already sent or immediately restore exhausted upstream quotas.
graph TD
R["SDK read"] --> P["SSR proxy"] --> D{"Proxy response"}
D -->|200| S["Return result"]
D -->|tagged throttle| H["Reset miss streak"] --> N["SDK node pool"]
D -->|other miss| B["Advance breaker"] --> N
Loading
High-Level Assessment
The following are alternative approaches to this PR:
1. Skip direct fallback on throttling
➕ Avoids SDK node attempts when the proxy reports upstream throttling.
➖ Removes the chance of success from the SDK's distinct node pool and changes the caller's fallback behavior.
2. Honor Retry-After before retrying
➕ Could reduce requests during sustained upstream throttling.
➖ Introduces retry timing and latency policy beyond this breaker fix.
Recommendation: Keep the PR's narrow classification change and existing per-read fallback. Use the new counter and proxy-side rate-limit statistics after deployment to decide whether sustained throttling warrants a separate fallback or retry policy.
call.tsExclude tagged upstream throttling from proxy breaker misses+15/-6
Exclude tagged upstream throttling from proxy breaker misses
• Classifies only 503 responses tagged X-Ssr-Cache: RATELIMITED as ratelimited. These reads retain node-pool fallback and their own counter, but reset rather than advance the proxy breaker miss streak.
server-rpc-proxy.spec.tsCover throttling fallback and breaker boundaries+55/-0
Cover throttling fallback and breaker boundaries
• Verifies repeated tagged 503 responses keep reaching the proxy while falling back, and reset an existing miss streak. Also confirms untagged 503 and incorrectly tagged 502 responses remain breaker-counting status misses.
[Medium impact] This PR appears safe to merge; no blocking issues were found.
Summary
The SDK now treats tagged upstream throttling as a separate fallback reason without opening the proxy breaker. This update ships the fix in rebuilt browser and Node packages as version 2.9.5.
Tagged upstream throttling still falls back without opening the proxy breaker.
The proxy report shows rate-limited fallbacks as their own count.
feruzm accepts the extra proxy call plus direct node attempts during sustained throttling and plans to measure the cost after deployment.
This repository does not receive automatic reviews because it has fewer than 10 stars.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 53191c74-4252-4ccf-abe4-9114da65603f
No actionable comments were generated in the recent review.
Walkthrough
The SDK now classifies tagged 503 RATELIMITED proxy responses separately from status misses. These responses fall back to node RPC and reset the breaker miss streak. The RPC proxy report includes a ratelimited fallback counter.
Tagged 503 RATELIMITED responses use the ratelimited miss reason, fall back to nodes, and reset the breaker miss streak. Tests check that untagged 503 responses and tagged 502 responses remain status misses.
sequenceDiagram
participant RPCProxy
participant SDKCall
participant Breaker
participant NodePool
RPCProxy->>SDKCall: Return tagged 503 RATELIMITED
SDKCall->>Breaker: Reset consecutive miss count
SDKCall->>NodePool: Fall back to node RPC
NodePool-->>SDKCall: Return node response
Loading
Suggested labels:patch:sdk
Merge Risk: Minimal · previous review 89a12
This change treats upstream throttling from the RPC proxy as a distinct, non-breaker-counting miss while still falling back to nodes, and adds a ratelimited counter to the proxy report. No concrete merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the fix (upstream rate limiting behind the SSR proxy no longer opens the breaker) and the sdk scope. The changeset matches: a tagged 503 RATELIMITED response now resets the miss streak…
Linked Issues check
Issue #2146 is the only directly linked target. Its coding requirements are: (1) a 503 with X-Ssr-Cache: RATELIMITED is classified as a new ratelimited miss; (2) that miss does not count toward the br…
Out of Scope Changes check
All changed areas connect to #2146. call.ts holds the new classification, breaker exemption, and counters. server-rpc-proxy.spec.ts holds the acceptance tests. sdk-init.ts and sdk-init-proxy.spec.ts a…
Full details: Title check
Explanation
The title names the fix (upstream rate limiting behind the SSR proxy no longer opens the breaker) and the sdk scope. The changeset matches: a tagged 503 RATELIMITED response now resets the miss streak, does not count toward the breaker, still falls back to node RPC, and has its own ratelimited counter. The title states the problem rather than the new behavior, but it is specific and on topic.
Full details: Linked Issues check
Explanation
Issue #2146 is the only directly linked target. Its coding requirements are: (1) a 503 with X-Ssr-Cache: RATELIMITED is classified as a new ratelimited miss; (2) that miss does not count toward the breaker and resets the miss streak; (3) the read still falls back to the node pool and returns the node's result; (4) repeated tagged throttles leave the next eligible read going to the proxy and increment fallbackByReason.ratelimited; (5) an untagged 503 still counts as status and can open the breaker; (6) the [rpc-proxy] line reports ratelimited=. The whole-PR summary maps each requirement to changes in packages/sdk/src/hive-tx/helpers/call.ts (ProxyMissReason and per-reason counters, breaker exemption, fallback preserved). The spec server-rpc-proxy.spec.ts adds a test for throttled fallback, breaker non-advance, streak reset, and the untagged 503 and tagged-502 status cases. apps/web/src/core/sdk-init.ts and sdk-init-proxy.spec.ts add the ratelimited counter to the report line. Limitation: I did not read the call.ts hunks directly. The verdict relies on the summary and the author's reported test runs (25/25 spec, 1548 SDK tests, 7172 web tests), which I did not re-run. The implementation matches the requirements as described.
Full details: Out of Scope Changes check
Explanation
All changed areas connect to #2146. call.ts holds the new classification, breaker exemption, and counters. server-rpc-proxy.spec.ts holds the acceptance tests. sdk-init.ts and sdk-init-proxy.spec.ts add the ratelimited= field to the [rpc-proxy] report, which #2146 requires. The call.ts documentation update describes the new behavior and supports the objective. No unrelated feature, refactor, or dependency change appears in the summary. The trade-off discussion in the PR description (dropping fallback, honoring Retry-After) is deferred and is not implemented, so it adds no out-of-scope code. Limitation: the assessment uses the whole-PR summary and did not read every hunk.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the proxy's reply, A tagged 503 goes hopping by. The breaker clears its miss-streak score, The node pool answers once more. “Ratelimited,” the logs now say, And carrots mark a calmer day.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 6795c656-818a-44f2-b67a-5d8494adc625
Commits
Reviewing files that changed from the base of the PR and between af6ad5a and 89a126c.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2146. Part of #2043.
What
The SSR proxy (vapi) now answers upstream throttling as
503withX-Ssr-Cache: RATELIMITED(ecency/vision-api#124). The SDK reads that as its own miss reason,ratelimited:rpcerror. The proxy answered correctly; opening the breaker sent every following read straight to the same throttling nodes, per process and without the proxy's coalescing.503without the tag, or the tag on any other status, is still astatusmiss and still counts.[rpc-proxy]line reportsratelimited=.Known trade-off (measure after deploy)
Under a sustained throttle of the whole pool, the breaker no longer opens. A throttled read then costs one proxy call plus the SDK's own node attempts, against node attempts only while the breaker was open. The gain is that every other read keeps the proxy's cache and coalescing. Whether to also skip the direct fallback on
ratelimited, or honourRetry-After, will be decided from the[rpc-proxy]counters and the proxy'srate_limitedstats after both ship.Rollout
Either order is safe. An old proxy never sends the tag. An old SDK reads the new 503 as
status, the same as today's 502.Tests (written first, seen failing)
pnpm --filter @ecency/sdk test src/hive-tx/helpers/server-rpc-proxy.spec.tsan upstream-throttled answer falls back but neither opens nor advances the breakerfailed withexpected [ …(2) ] to have a length of 4 but got 2(the breaker opened after two throttled answers).ratelimitedfrom the breaker exemption fails the spec, and so does accepting the tag on any status (pinned after a first mutant survived).Full runs:
pnpm --filter @ecency/sdk test: 1548 passed.pnpm test(web): 7172 passed.apps/web/src/specs/core/sdk-init-proxy.spec.ts: 9 passed, covering the report line.Ships in the SDK dist, so it needs a version label to take effect.
Summary by CodeRabbit