Skip to content

[vite-plugin] Retry v1 remote binding requests after preview reloads - #16899

Closed
petebacondarwin wants to merge 2 commits into
codex/vite-v1-backport-16838from
codex/vite-v1-backport-16862
Closed

petebacondarwin wants to merge 2 commits into
codex/vite-v1-backport-16838from
codex/vite-v1-backport-16862

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Backports #16862 to the existing retained remote-bindings ProxyWorker. During a remote binding session update, an old preview request can fail after the replacement preview's play message. Its GET/HEAD retry was left queued until another request or reload. Drain the retry queue immediately, allowing processQueue() to wait if the proxy is still paused.

The Vite plugin's retained startRemoteProxySession → DevEnv → ProxyController path bundles this template directly. Upgrading installed Wrangler cannot fix this copy. The change modifies that retained template and adds two tests against its bundled code for failure before and after resume. No absent Wrangler source or tests are restored. The resumed case fails before the fix and both cases pass afterwards. No dependency upgrades are required.

Registered in native GitHub stack #16900, after #16861 and before the publication-blocked Artifacts default draft #16898. This fix can merge with the existing published dependencies; #16898 remains draft pending npm publication.

Validation: pnpm build, pnpm check, and pnpm test:ci; the retained proxy regression covers both event orderings. The test initially needed adjustment for the package's ES library and noImplicitOverride; final checks are recorded after those adjustments. Formatting and git diff --check pass. Credentialed remote E2E tests are not run.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this fixes an internal retry race without changing the configuration API.

Note

This is a contribution from an AI agent: Codex.

@changeset-bot

changeset-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b829a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team November 13, 2026 14:07
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 2 potential issues.

Devin Review

// in a `pause`d state i.e. `this.proxyData` is undefined)
// A replacement preview may already be ready when the old fetch fails.
// Drain immediately; processQueue waits if the proxy is still paused.
this.processQueue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Failed previews trigger unlimited retries

If a replacement preview rejects a GET to /read, processQueue() retries it indefinitely. newUserWorkerUrl has path /, so the active request URL /read never matches it. Requests never settle, and the proxy floods the failing preview.

Learn more

The proxy compares the full URL of the failed request with a URL built from the active preview's origin. The former contains the incoming request path; the latter defaults to /. A failure from the active preview at any other path therefore enters the stale-request retry branch. This change calls processQueue() immediately after requeuing, so another failed fetch repeats that branch without waiting for a reload.

Example: A GET to /read fails on the old preview after play announces a replacement. Its retry to the replacement also rejects. The comparison evaluates https://replacement/read against https://replacement/, and the request retries repeatedly instead of reporting the replacement's failure.

Recommended fix: Compare the failed request's preview origin with the current preview origin before classifying an error as stale. Only call processQueue() for an actual stale failure, and add a regression test where the replacement fetch also rejects.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@edmundhung edmundhung Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petebacondarwin I think the issue here is that the original PR #16862 only changed Wrangler's proxy, while this backport changes how the remote bindings proxy behaves instead.

That being said, Devin's comment does uncover a real bug in that proxy, which main has too. I have put up #16949 to fix it on main, so we can backport that PR instead.

Comment thread .changeset/v1-remote-proxy-retries.md Resolved
@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@petebacondarwin (verified author of #16862) and @edmundhung (verified human ant-core member; approved the original November 12 at 15:06:18Z, before merge): please check this v1 adaptation and approve it if it looks good.

The retained private remote-bindings package bundles its own ProxyWorker through startRemoteProxySession → DevEnv → ProxyController. This existing template has the same stranded-retry gap; a Wrangler dependency bump cannot fix it. This PR changes only that retained implementation, adds two tests against its bundled code, and supplies a plugin patch changeset. No absent public package source/tests are restored. The resumed-order regression fails before the fix; both orderings pass afterwards. Build, all 58 checks and the full package suites pass (including 267 plugin and 40 remote-bindings tests).

Native GitHub stack #16900 puts this PR above #16861 and below the publication-blocked Artifacts draft #16898. This fix uses the already published dependencies and can merge without waiting for that draft's release.

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@cloudflare/vite-plugin@16899

commit: 3b829a7

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of fc531d2b.

This review, of 11f378b1

✅ Approved — Minimal, correct fix for the retry-queue race, with tests covering both event orderings and an accurate changeset; no issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. The changeset is a patch bump for @cloudflare/vite-plugin.


🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

Follows the repository conventions: the test uses the Vitest test-context expect, imports Node built-ins with the node: prefix, and the change ships with a plugin changeset.


📋 Code Quality: ✅ LGTM

Calling processQueue() right after requeueing is safe: it returns early while paused and drains immediately once resumed. The tests cover both orderings and check that the queue ends up empty.


⚡ Performance: ✅ LGTM

No performance concerns. The retry is bounded and cannot loop forever.


📝 Documentation: ✅ LGTM

The changeset accurately describes the fix.


Reviewed commit: 11f378b1

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review


Retry remote binding requests when a replacement preview is already ready

A retriable request could remain queued if the old preview connection failed after a remote binding session update completed. Drain the retained remote binding proxy's retry queue immediately so requests finish without waiting for another request or reload. Requests that fail on the current preview now return the error instead of hanging.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Internal mechanics in user-facing changelog

The changeset includes internal retry-queue mechanics, contrary to the changeset guidance. The surrounding explanation already conveys the user-facing benefit: requests finish without another request or reload.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 3b829a70.

This review, of fc531d2b

✅ Approved — The retry-queue drain and the new check on the proxyData object are correct, and the retry is bounded by preview reloads. Tests cover both event orderings and failures from the current preview; no issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. This is a focused retry fix with a patch changeset for @cloudflare/vite-plugin.


🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

The change follows the repository conventions: the tests use Vitest test-context expect and import Node built-ins with the node: prefix, and the plugin change ships with a changeset.


📋 Code Quality: ✅ LGTM

this.proxyData === proxyData at ProxyWorker.ts:160 correctly recognises failures from an earlier preview. pause clears proxyData, and each play assigns a new object. A failure from the current preview is reported and rejected instead of retried. Requests other than GET and HEAD still get a 503. The tests cover both orderings and the current-preview failure case, and they follow the repository's test conventions.


⚡ Performance: ✅ LGTM

A request is retried only after a pause or play changes proxyData. A second failure with no new reload is rejected, so the number of retries is limited by the number of preview reloads.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: fc531d2b

petebacondarwin and others added 2 commits November 16, 2026 20:44
The retained ProxyWorker treated a failed fetch as stale (from a reloaded
preview) whenever the request's full URL differed from the preview's bare
origin. RPC bindings connect to `/?MF-Binding=<name>`, so every failure
looked like a reload. Now that a requeued request is retried immediately,
a preview that keeps failing made the request retry in a loop.

Comparing origins, as Wrangler does on main, doesn't work here: remote
previews keep the same `<worker>.<subdomain>.workers.dev` host across
reloads and only change the preview token. Compare the proxyData the
request was sent with instead, since every `play` sets a new object.
@petebacondarwin
petebacondarwin force-pushed the codex/vite-v1-backport-16838 branch from f834884 to 4f39ec7 Compare November 16, 2026 20:47
@petebacondarwin
petebacondarwin force-pushed the codex/vite-v1-backport-16862 branch from fc531d2 to 3b829a7 Compare November 16, 2026 20:47

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — The retry-queue drain and the new check on the proxyData object are correct, and the retry is bounded by preview reloads. Tests cover both event orderings and failures from the current preview; no issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. This is a focused retry fix with a patch changeset for @cloudflare/vite-plugin.


🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

The change follows the repository conventions: the tests use Vitest test-context expect and import Node built-ins with the node: prefix, and the plugin change ships with a changeset.


📋 Code Quality: ✅ LGTM

this.proxyData === proxyData at ProxyWorker.ts:160 correctly recognises failures from an earlier preview. pause clears proxyData, and each play assigns a new object. A failure from the current preview is reported and rejected instead of retried. Requests other than GET and HEAD still get a 503. The tests cover both orderings and the current-preview failure case, and they follow the repository's test conventions.


⚡ Performance: ✅ LGTM

A request is retried only after a pause or play changes proxyData. A second failure with no new reload is rejected, so the number of retries is limited by the number of preview reloads.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 3b829a70 — same changes as fc531d2b, so this is that commit's review (no new review was run; line numbers are as of fc531d2b)

@edmundhung

Copy link
Copy Markdown
Member

As discussed with Pete, I am gonna close this backport PR as the original PR does not modify the proxy worker from remote bindings. The issue flagged here will be fixed on main via #16949 and might backport to v1 following it.

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.

3 participants