Skip to content

Add server-managed stale client handling with build IDs#1222

Draft
justinvdm wants to merge 13 commits into
mainfrom
stale-build-ids
Draft

Add server-managed stale client handling with build IDs#1222
justinvdm wants to merge 13 commits into
mainfrom
stale-build-ids

Conversation

@justinvdm

@justinvdm justinvdm commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

Stale RedwoodSDK tabs keep talking to a newer deployment without any framework-managed version check. Core RSC requests continue to succeed when they should tell the client to reload, and synced state websocket sessions continue to open against a newer build.

Solution

We generate a RedwoodSDK build ID through the Vite plugin, expose it to the worker and client runtime, and use it as the shared stale version signal. Core requests now send their client build ID, synced state websocket URLs carry the same version, asset URLs include the build ID, and the server returns a reload response when an older client talks to a newer build. We also added permanent deploy-only playground coverage for the core stale request path and the synced state stale session path.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a031f70
Status: ✅  Deploy successful!
Preview URL: https://cf4d2cdd.redwood-sdk-docs.pages.dev
Branch Preview URL: https://stale-build-ids.redwood-sdk-docs.pages.dev

View logs

justinvdm added 12 commits June 10, 2026 19:00
… check

Replace handleStaleResponse (check + act) with pure isStaleReloadResponse.

Remove triggerStaleReload, clearStaleReloadGuard, and sessionStorage state.

A stale reload is a full page load that always fetches fresh HTML and assets.

The new client bundle has no stale state, so a guard is unnecessary.
Lift await fetchPromise before handleResponse branch so stale check runs once.

Remove stale check from navigation.ts handleResponse; stale is handled upstream.
- Rename getStaleEvent → isStaleRequest (boolean predicate)

- Add buildStaleEvent for custom policies that need event data

- Rename withClientVersionQuery → addClientVersionToUrl

- Remove dead withClientVersionQueryString wrapper

- Extract createClientVersionHeaders for DRY header building

- Add docs/architecture/staleClientHandling.md
Detect stale clients on every RPC message in SyncedStateProxy, not just at WebSocket handshake time. A stale client sending getState/setState/subscribe/unsubscribe over an already-open WebSocket now receives StaleClientError, and client-core reloads the page.

- Add StaleClientError and message-based isStaleClientError

- Store client build version in SyncedStateProxy and assert before each forwarded RPC call

- Wrap all use-synced-state RPC promises to reload on stale errors

- Add playground debug route and deploy-only E2E test

- Add unit tests for stale error detection and proxy behavior

- Update architecture doc
The __rwsdk_client_version query parameter on use-synced-state WebSocket URLs was not leading to recovery. A stale client whose upgrade was rejected just reconnected with the same stale URL.

The only meaningful stale case for use-synced-state is an established WebSocket session that outlives a deployment. That is already handled by the per-message StaleClientError check in SyncedStateProxy.

- Remove build version query parameter from WebSocket URL in client-core

- Remove isStaleRequest handshake check from syncedStateRoutes

- Store session creation build ID in SyncedStateProxy instead of reading it from the request

- Delete stale-session.e2e.test.mts and update client-core test

- Update architecture doc
Remove outdated references to a WebSocket handshake stale check that no longer exists. Clarify that use-synced-state relies on per-message detection in SyncedStateProxy.
- Add createDeployment().redeploy() for programmatic rebuild/redeploy

- Use dynamic ports in runPreviewServer so concurrent testSDK.deploy tests do not collide

- Fix reconnect to clear baseClientPromiseByEndpoint and create a fresh capnweb session

- Restore client build-version query parameter for use-synced-state WebSocket URLs

- Add VITE_RWSDK_SYNCED_STATE_TEST_FAST_RECONNECT env var for test reconnect speed

- Add deploy-twice E2E test verifying build A -> build B redeploy

- Add stale-message E2E test using a debug route to simulate a build-ID change

- Add unit tests for StaleClientError and proxy behavior

- Update architecture doc
- Remove stray -- separator so vite preview actually receives --port 0

- Relax deploy-twice assertion because preview mode assigns a new port per preview server

- Clear stale build-id override after reload to avoid a reload loop in concurrent runs
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