Skip to content

fix(sdk): upstream rate limiting behind the SSR proxy does not open its breaker - #2147

Merged
feruzm merged 3 commits into
developfrom
fix/2146-proxy-breaker-ratelimited
Nov 19, 2026
Merged

feruzm merged 3 commits into
developfrom
fix/2146-proxy-breaker-ratelimited

Conversation

@feruzm

@feruzm feruzm commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Closes #2146. Part of #2043.

What

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T13:17:39.720492Z 89a126c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Keep the SSR proxy breaker closed on upstream rate limiting

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

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.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • 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.
Assessed commit 89a126c
Diagram

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.

Files changed (4) +75 / -10

Bug fix (2) +16 / -7
sdk-init.tsReport rate-limited proxy fallbacks +1/-1

Report rate-limited proxy fallbacks

• Adds the ratelimited counter to the periodic [rpc-proxy] diagnostic line, defaulting to zero if the counter is absent.

apps/web/src/core/sdk-init.ts

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.

packages/sdk/src/hive-tx/helpers/call.ts

Tests (2) +59 / -3
sdk-init-proxy.spec.tsVerify the rate-limit diagnostic counter +4/-3

Verify the rate-limit diagnostic counter

• Extends reporter fixtures and assertions to cover ratelimited in both the initial and changed-counter log lines.

apps/web/src/specs/core/sdk-init-proxy.spec.ts

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.

packages/sdk/src/hive-tx/helpers/server-rpc-proxy.spec.ts

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

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

Reviews (2) · Last reviewed commit: "chore: apply changeset versioning for PR..." · Reviewed by Greptile

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

  • Trigger review

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.

Changes: RPC proxy rate-limit handling

Layer / File(s) Summary
Classify rate-limited proxy responses
packages/sdk/src/hive-tx/helpers/call.ts, packages/sdk/src/hive-tx/helpers/server-rpc-proxy.spec.ts
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.
Report rate-limit fallback counts
apps/web/src/core/sdk-init.ts, apps/web/src/specs/core/sdk-init-proxy.spec.ts
The proxy report includes ratelimited, defaulting to zero when absent. Tests check the initial and periodic report values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed 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 Passed 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.

Share

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.

Files selected for processing: 4

  • apps/web/src/core/sdk-init.ts
  • apps/web/src/specs/core/sdk-init-proxy.spec.ts
  • packages/sdk/src/hive-tx/helpers/call.ts
  • packages/sdk/src/hive-tx/helpers/server-rpc-proxy.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@feruzm feruzm added the patch:sdk Patch bump for @ecency/sdk label Nov 19, 2026
@feruzm
feruzm merged commit c85220f into develop Nov 19, 2026
6 checks passed
@feruzm
feruzm deleted the fix/2146-proxy-breaker-ratelimited branch November 19, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch:sdk Patch bump for @ecency/sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK proxy breaker opens on upstream rate limiting and multiplies node load

1 participant