Skip to content

fix(web): SDK wasm loads separately with progress; quorum refresh; recover from Platform outages (D-025, D-024, D-058) - #80

Merged
PastaPastaPasta merged 2 commits into
masterfrom
fix/web-network-resilience
Sep 27, 2026
Merged

PastaPastaPasta merged 2 commits into
masterfrom
fix/web-network-resilience

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Summary

This PR fixes D-025, D-024 and D-058, and adds a regression guard for D-702, in forge-web's Platform connection (lib/sdk/service.ts, fix/web-network-resilience).

D-025: the SDK download no longer dies on Slow 3G

The published @dashevo/evo-sdk entry is one 11.4 MB JS file with the 23 MB wasm inlined as base64 gzip. On 400 kbps, webpack's chunk-load timeout killed it at ~130 s, with no progress and no retry.

  • next.config.js builds the SDK from its own unbundled modules (dist/sdk.js). A NormalModuleReplacementPlugin swaps its wasm loader (dist/wasm.js, which imports the inlined build) for lib/sdk/wasm-shim.ts. The shim re-exports @dashevo/wasm-sdk/raw (the plain wasm-bindgen glue, now a direct dependency, same pinned 4.2.0-beta.4) and initializes it from a module compiled by lib/sdk/wasm-fetch.ts.
  • wasm_sdk_bg.wasm is now its own content-hashed static asset (_next/static/wasm/…). It is fetched with fetch + WebAssembly.compileStreaming, so there is no chunk timeout. Progress is counted per chunk. A download that receives nothing for 60 s is abandoned, and a failed download is forgotten, so the next attempt fetches it again.
  • The SDK's JS chunk drops from 11.4 MB (8.2 MB gzipped) to 579 kB (63 kB gzipped). output.chunkLoadTimeout goes from 120 s to 10 min.
  • A progress bar shows while the SDK downloads (components/ui/platform-status.tsx). The wasm fetch starts next to the JS chunk rather than after it.
  • e2e/static-server.mjs now gzips like GitHub Pages does, so throttled runs move real bytes. It already served .wasm as application/wasm.

Checked:

  • CSP script-src 'wasm-unsafe-eval' allows compileStreaming.
  • A NEXT_PUBLIC_BASE_PATH=/dash-forge build loads the wasm from /dash-forge/_next/static/wasm/….
  • vitest (node) still resolves @dashevo/evo-sdk to the bundled module; the alias is webpack-only.

D-024: stale quorum keys (~10 min) and D-702: recovery after an outage

I verified this against the pinned Platform source. packages/wasm-sdk/src/context_provider.rs builds its TrustedHttpContextProvider with .with_refetch_if_not_found(false) and prefetches quorums only at connect. refresh_quorums is pub(crate) and runs only before a broadcast (state_transitions/broadcast.rs). From JS, the only refresh is a new connection.

EvoSdkService now treats connections as generations behind one stable handle:

  • getSdk() returns a Proxy that forwards every call to the connection that is current when the call is made. A call already running finishes on its own connection. lib/sdk/write.ts keeps working across a swap, and writes and broadcasts are never re-sent.
  • A new connection (with a new quorum prefetch) is built every 5 minutes while the tab is visible. It is swapped in only once it is connected and warm, and a failed refresh keeps the old connection.
  • A read that fails with "Quorum not found in cache" or "no available addresses" triggers one reconnect and then one retry. Concurrent failures share a single reconnect, reconnects are rate-limited to one per 15 s, and before reconnecting on "no available addresses" the service waits out dapiBudget.retryAfterMs().
  • The trust panel's quorum cross-check is keyed by connection generation, so it re-runs whenever the keys are fetched again.
  • P-1's hooks (the DAPI fetch gate, banFailedAddress: false, contract seeding and revalidation, the stale-contract handler, followSdkVersion) are unchanged and now apply to each connection.

D-058: quorum service unreachable at connect

  • The service keeps a connection status: idle, downloading, connecting, ready, or error with the time of the next retry. A failed connect retries with backoff (5/15/30/60/120 s), and only while the tab is visible.
  • "Try again" reconnects immediately. Page mounts during a failure do not start new attempts (at most one every 3 s). The quorum prefetch and warm-up have a 60 s deadline, so a hung quorum service fails and is retried instead of spinning forever.
  • The repo pages, home and explore show a plain-language banner ("Can't reach Dash Platform right now", when the next retry is, Try again, and the raw error behind Details). This replaces the raw "Could not reach Platform: Failed to prefetch quorums…" page.
  • If this tab already read the repo, its home stays on screen under the banner. The banner says the page is not being re-checked. When Platform comes back, the page reads again.
  • It fails closed. Every connection is trusted, and there is no unverified fallback. The home page's verification chip says "Not connected" during an outage.

Measurements: Slow 3G (400 kbps, 400 ms, cache off, gzip like GitHub Pages, moutai)

before (master b82be64) after
First contentful paint 1.53 s 1.61 s
App shell visible 2.5 s 2.5 s
Download progress on screen never 8.5 s
First repo content never: "Loading chunk 7138 failed (timeout)" at 128.6 s 180.7 s
SDK bytes (gzipped) 8.21 MB JS 63 kB JS + 8.14 MB wasm
Total transferred 8.58 MB (then dead) 8.70 MB

At 1.6 Mbps: first repo content 50.7 s before, 48.5 s after (progress shows at 4.5 s).

Tests

  • lib/sdk/service.test.ts (12 tests, fake clock and connector):
    • refresh every 5 min, and the handle follows it;
    • a rotated quorum gives one reconnect plus a retry, and concurrent failures share it;
    • no reconnect for ordinary errors, and writes are never re-sent;
    • a call in flight finishes on its old connection;
    • a failed refresh keeps the connection;
    • recovery rate limit;
    • connect backoff and recovery, Try again, and no hammering on page mounts;
    • DAPI outage recovery;
    • unreachable → recovered.
  • lib/sdk/wasm-fetch.test.ts: progress per chunk; application/wasm; HTTP error; a slow but live download is never cut off; a stalled download aborts.
  • e2e/network-resilience.spec.ts (live moutai):
    • nr-1: Slow 3G with budgets: shell < 20 s, progress visible and advancing, repo content < 5 min, no chunk failure;
    • nr-2: quorum service down → banner, Try again, recovery;
    • nr-3: full outage mid-session → Try again recovers;
    • nr-4: a stale quorum list → one reconnect, then the read succeeds.

Before and after runs of the new e2e spec, same spec against both builds:

spec master this branch
nr-1 Slow 3G fail (no progress; the chunk dies) pass (shell 1.8 s, content 179 s)
nr-2 quorum down fail (raw error, no retry) pass
nr-3 full outage pass (P-1's banFailedAddress: false already fixed it; kept as a regression guard) pass
nr-4 stale quorums fail ("Quorum not found in cache") pass

pnpm typecheck, pnpm lint and pnpm test (1,556 tests) pass. Rebased on #79: its s2 (the library cannot download) now also routes the separate wasm file, and passes.

Notes

  • The first visit on Slow 3G still takes ~3 minutes, because 8 MB of wasm is 8 MB. It now shows progress and finishes, and a repeat visit uses the browser cache. Making the wasm smaller (for example brotli: 5.2 MB) depends on the host: GitHub Pages serves gzip only.

🤖 Generated with Claude Code

PastaPastaPasta and others added 2 commits September 27, 2026 11:45
…er from outages

D-025: build evo-sdk from its unbundled modules and fetch wasm_sdk_bg.wasm as its own asset with progress, compileStreaming, a stall abort and retry; the SDK JS chunk drops from 8.2 MB to 63 kB gzipped and no longer hits webpack's chunk timeout on Slow 3G.

D-024/D-702: the SDK service swaps whole connections behind a stable handle, refreshing every 5 min while visible and reconnecting once when a read fails on a rotated quorum or no usable node.

D-058: a failed connect retries with backoff, shows a plain-language banner with Try again, and keeps already-read repo content on screen without marking it re-checked.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 23 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7ab54d5a-4b67-40b1-9f2d-9afc8e8539ea

📥 Commits

Reviewing files that changed from the base of the PR and between 03cdc2b and 6ccfa2e.

⛔ Files ignored due to path filters (1)
  • forge-web/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • forge-web/app/explore/page.tsx
  • forge-web/app/page.tsx
  • forge-web/components/repo/repo-scaffold.tsx
  • forge-web/components/ui/platform-status.tsx
  • forge-web/e2e/network-resilience.spec.ts
  • forge-web/e2e/signin-resilience.spec.ts
  • forge-web/e2e/static-server.mjs
  • forge-web/hooks/use-quorum-check.ts
  • forge-web/hooks/use-repo.ts
  • forge-web/hooks/use-sdk.ts
  • forge-web/lib/auth/connect.ts
  • forge-web/lib/sdk/index.ts
  • forge-web/lib/sdk/service.test.ts
  • forge-web/lib/sdk/service.ts
  • forge-web/lib/sdk/wasm-fetch.test.ts
  • forge-web/lib/sdk/wasm-fetch.ts
  • forge-web/lib/sdk/wasm-shim.ts
  • forge-web/lib/view/quorum-check.ts
  • forge-web/next.config.js
  • forge-web/package.json

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.

@PastaPastaPasta
PastaPastaPasta merged commit fbd3e83 into master Sep 27, 2026
5 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
Adopts master's WriteEngine::replace_document (from #66) and drops F-1's duplicate; update_target/update_comment call it. Issue pages honour the archive gate. The CLI issue-parity scenario is renumbered 20 (18 is repo settings). e2e helpers use master's E2E_IDENTITY_DIR.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
The SDK service no longer strands itself when a mount adds contract ids (network epoch instead of config identity), live tests connect in Node again, a refresh keeps the learned protocol version, reads share one recovery including its rate-limit wait, a connection is never swapped under a write, every connection revalidates its seeded snapshots, and superseded or timed-out connects are aborted and freed. The UI degrades trust while Platform is unreachable, falls back to cached content only on unreachable errors, re-runs the quorum check hourly instead of per reconnect, stops re-announcing the outage countdown, and fills the download bar at 3:1.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
The SDK service no longer strands itself when a mount adds contract ids (network epoch instead of config identity), live tests connect in Node again, a refresh keeps the learned protocol version, reads share one recovery including its rate-limit wait, a connection is never swapped under a write, every connection revalidates its seeded snapshots, and superseded or timed-out connects are aborted and freed. The UI degrades trust while Platform is unreachable, falls back to cached content only on unreachable errors, re-runs the quorum check hourly instead of per reconnect, stops re-announcing the outage countdown, and fills the download bar at 3:1.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
…llowup

fix(web): network-resilience follow-ups from the #80 post-merge reviews
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