Repository navigation
perf(web): shared DAPI request budget, rate-limit failover and seeded contracts (P-1) - #72
Merged
Merged
Conversation
…ntracts Every DAPI request goes through a per-node token bucket shared across tabs. A rate-limited reply is held until ratelimit-reset and retried on the same node, and the SDK runs with banFailedAddress false, so rate limits no longer ban every node (D-102, D-902). Contracts are seeded from a snapshot in forge-contracts/deployments/contracts, so pages make no getDataContract request. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review fixes. A rate-limited node is held and the reply goes back at once so the SDK moves to another node; the gate waits only for short resets, when the IP is busy everywhere, or after two fail-overs a minute, within a 70 s call deadline (H1). Only the gateway's over-limit reply counts as a rate limit (H2). Holds and bucket times are clamped (M1). Unreachable nodes are kept out for 15 s now that the SDK bans nothing (M2). Seeded contracts are checked against getDataContractsLatestVersions at most hourly and refetched on a version change or an unknown document type (M3). Waits have per-waiter jitter, abort with the signal reason, and the gate is guarded against a double install. Writes follow the SDK version. dapiBudget exposes hold, status, subscribe and retryAfterMs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedNext included review available in 36 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (14)
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 |
PastaPastaPasta
added a commit
that referenced
this pull request
Sep 27, 2026
…chedDocument, open_for_write) Rebased onto master after #67, #68, #72, #73 and #74: the settings sections use the AA text shades the contrast test requires; the test fixture fills FetchedDocument.updated_at_block_height; the archive check opens through Session::open_for_write so dg pr create stays within the line limit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Sep 27, 2026
Merged
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
P-1: shared DAPI request budget, rate-limit handling, seeded contracts
Implements platform-parity-spec §3.2, §3.4 (contracts), §3.6 win 3 and §7 Group P item P-1.
Fixes:
Design
forge-web/lib/sdk/budget.ts: every DAPI request goes through one gate.installDapiFetchGate()wrapsglobalThis.fetch. evo-sdk 4.2's wasm glue calls the globalfetchfor every attempt (__wbg_fetch_…: function(t,e){return fetch(t,e)}), including its internal retries. So the gate covers SDK queries, counts, composites, broadcasts and waits, the inbox poller, the quorum cross-check and the Core-over-DAPI client. The SDK builds its URLs ashost:1443//org.dash…(double slash), and the matcher handles that.One token bucket per node. The gateway counts requests per IP separately on each node (verified live:
ratelimit-remainingdiffers between nodes in the same second). Each bucket allows a burst of 60, then 1 request/s. That is at most 120 per node per 60 s, against the gateway's limit of 150.Shared across tabs. The budget is shared over
BroadcastChanneland mirrored tolocalStorage, so a new tab or a reload starts from the shared state.Fail over rather than stall. The wasm transport has no client timeout;
grpc-timeoutis only a header. So a request aimed at a held node is refused at once with a synthetic gRPCResourceExhausted("rate limited"), unless the wait is ≤ 2 s. The SDK then moves to another node.banFailedAddress: false, so the refused node is only dropped from its sticky rotation and never banned.ratelimit-resetplus jitter. A reset of ≤ 1 s is retried on the same node.Wait when failover would fail. The gate waits instead of refusing when:
dgimport running next to the tab), orEvery gated call has a 70 s deadline. "Platform is busy — waiting Ns" shows while it waits.
Only the gateway's real over-limit reply counts. That is
grpc-status 8withratelimit-remaining: 0orgrpc-message: rate limited(dashmate envoylocal_reply_config), or an HTTP 429, withratelimit-reset. Envoy putsratelimit-*headers on every reply, andResourceExhaustedalso covers Drive size limits, a full mempool and "too many pending waits". None of those is treated as a rate limit.Unreachable nodes. A network error, HTTP 5xx or gRPC
Unavailablekeeps the node out for 15 s. With banning off, this replaces the SDK's down-node banning. Trade-off, documented inservice.ts: the SDK's DPNS-registration owner failover is off too, and this app registers no names.Bad state can't wedge a node. Holds and bucket times from storage, other tabs or
hold()are clamped, so a clock jump or a bad value cannot hold a node forever.Waits get per-waiter jitter and reject with
signal.reason. The install is guarded bySymbol.for, so HMR can't wrapfetchtwice.API for P-2 / P-3 / D-013 / F-1:
installDapiFetchGate(nodes).dapiBudget.status()andsubscribe(fn).hold(node, untilMs).retryAfterMs(): how long until most nodes are free; D-013'srecover()will wait for it.waitFor,take, …) are marked@internal.Seeded contracts (spec §3.4):
forge-contracts/scripts/snapshot-contracts.mjswritesforge-contracts/deployments/contracts/<key>.json: DPNS, forge-core, forge-collab and keyExchange, from one provedgetDataContracts.service.tsseeds them withcontracts.addKnown(wasm-sdk #4746) and fetches only what is still missing.drop_stale_contractrefetch when a document's$contractVersionis newer;getDataContractsLatestVersions, checked off the critical path at most once an hour per profile, refetching any contract whose version moved (forge-collab will change at C-1);sdk.version()as it changes.components/platform-busy.tsx: a small "Platform is busy — waiting Ns" status, bottom-left,role=status. It shows only while a rate-limit wait is actually being waited out. It is not an error.Sticky node: evo-sdk 4.2 already rotates over a sticky set of 5 nodes (
AddressList, slots of 5–7.5 min). The set size is Rust-only (with_active_set_size), and neither wasm-sdk nor evo-sdk exposes it, so we keep the default. With banning off, the set stays warm, because a rate limit no longer ejects a node.Measurements (moutai,
forge-v2-demo, Playwright interception, perf-scalemeasure.mjs)Cold = a fresh browser profile. Warm = a reload in the same profile.
getDataContract: 0 on every page, down from 3.getDataContractsLatestVersionsrequest; after that the check runs at most once an hour.Tests
Unit tests:
lib/sdk/budget.test.ts(23 tests):ResourceExhaustedthat is not a rate limit, never holds a node.retryAfterMssignal.reason//pathlib/sdk/query.test.ts(M3): "document type not found" refreshes the seeded contract and retries once; other errors are not retried.lib/sdk/contract-seed.test.ts: every snapshot is wired in, matches the deployment file (snapshotIdsfrom the script), decodes at its recorded version, and forge-core matchescontracts/forge-core.json.e2e/rate-budget.spec.ts(live on moutai, with a mock that matches dashmate's over-limit reply):getDataContract/getDataContractson repo home, issues and PR build: make the Rust workspace buildable and pin the Platform SDK #1.master: rb-1b and all three rb-2 tests fail. rb-1a passes, because the SDK's own failover also handles a single bad node.Full runs:
E2E_WRITE=1).tscandnext lintare clean.Browser QA (real Chromium on moutai; evidence in
dash-forge-qa/evidence/impl/perf-web-rate-budget/)master: "That read did not land — … 'Some resource has been exhausted'".master, tab B sent the request to X.Coordination
perform()seeds contracts and installs the gate; the reconnect path callsseed();withQuorumRetrywaitsdapiBudget.retryAfterMs()first.recover()(write-refusals agent): will skip whileretryAfterMs() > 0, and does not classify the gate's synthetic refusals as consensus errors.🤖 Generated with Claude Code