Skip to content

Wait for a lagging Cloudflare Worker version list during deploy - #892

Open
konaito wants to merge 7 commits into
voidzero-dev:mainfrom
konaito:fix/retry-stale-cloudflare-version-history
Open

konaito wants to merge 7 commits into
voidzero-dev:mainfrom
konaito:fix/retry-stale-cloudflare-version-history

Conversation

@konaito

@konaito konaito commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #891 for the version-list paths. The triggers-failed case in the issue is not changed here.

Change

Cloudflare's Worker version list can trail a write by minutes. The deploy now waits for it in the two places where the expected state is known:

  • Before the upload: while the list does not contain the active version that deployments status reported. This read had no retry.
  • After the upload: while the list is still identical to the pre-upload baseline, or is an older snapshot of it (it ends below the baseline and agrees with it on every shared version number). The existing retry stopped after 250 ms and 500 ms.
  • Both places: when versions.list fails because its two pages disagreed ("The Cloudflare Worker version history changed during inspection"). The runner now marks that failure as version-history-changed, and it is retried on the same schedule. Page 2 is read only above 10 versions, so this is the inheritance-source-unavailable shape in the second report on Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed) #891.

After either wait, production is read again: before the upload, and before the candidate receipt is saved. If a rollback or another deploy changed it during the wait, the deploy stops with deployment-changed and saves no receipt, so the next deploy does not find a receipt with the wrong parent. Production is read again only after a wait for a lagging list, not after the quick retries of a failed read. If that read fails after the upload, the deploy stops with status-failed ("uploaded, but Cloudflare deployment status could not be verified before activation"); a handoff deploy keeps its verified receipt so the retry can use it.

These waits use STALE_VERSION_HISTORY_DELAYS_MS: 250 ms doubling up to 30 s, 17 waits, about 5.5 minutes in total. Each wait checks verifyUploader(), and the first wait for a lagging list reports progress. The schedule can be overridden with the new versionHistoryRetryDelaysMs option. STALE_VERSION_HISTORY_DELAYS_MS is exported from the package entry.

Why this length: in the runs in #891 a new version was still missing 52 s after creation and was listed within about 4.5 minutes. #880 and #868 retried for a second or less, which does not reach that. If maintainers want a shorter cap, change the constant.

What does not change

  • A list that never catches up, or whose pages keep disagreeing, fails with inheritance-source-unavailable, before or after the upload. Nothing is uploaded when the pre-upload wait runs out, on handoff and direct deploys alike. (Before, a direct deploy could go on to pin the active secrets and upload.)
  • Any other mismatch (a concurrent version, a different history) still fails at once, with no wait.
  • Any other failed read (not stale, not page overlap) keeps its behavior: it fails at once before the upload and gets two quick retries after it.
  • A rollback to a version older than the list's page of 10 never appears in the list, so it does not wait. Before waiting, the active version's number is read with versions.view; the wait happens only when that number is not below the list's lowest number. If the number cannot be read (failed or thrown read, or no integer number; the API marks the field optional), it is read again on the next wait, and the deploy keeps waiting while it stays unreadable, since a version the list trails may not be readable yet either.
  • void link keeps a saved candidate receipt only when its parent is still the active version.
  • stabilizeCloudflareVersionTriggers is untouched. The logs in Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed) #891 do not show what its reads returned.

Tests

packages/deploy-cloudflare/test/unit/version.test.ts:

  • Pre-upload: active version present (no wait), list recovers after two stale reads, list never catches up (no upload), uploader changes during the wait.
  • Page overlap: retried and recovers, retried until the schedule runs out, and a different failure does not wait, before and after the upload. The runner test in packages/void/test/unit/cf-version-runner.test.ts checks the version-history-changed marker.
  • Post-upload: the existing stale-list cases now expect the full schedule; failed reads still expect two waits. An older snapshot waits like a stale list, and a list that names another version at a shared number still fails at once. A quick retry after a failed read adds no production read, and a wait that starts after a failed read still reports progress.
  • The default schedule is used, is between 5 and 6 minutes, and reports progress.
  • A rollback during the wait, before and after the upload: the deploy stops with deployment-changed, and recordVerifiedCandidate is never called.
  • An active version older than ten listed versions does not wait. A failed, thrown or unnumbered versions.view still waits the whole schedule.

The new pre-upload tests and the changed stale-list case fail on main and pass here (5 failures without the change; measured before the page-overlap commit).

Verified locally

Run in a shell with no CLOUDFLARE_*, CF_* or wrangler variables (env | grep -ciE 'cloudflare|^CF_|wrangler' printed 0). The tests inject runWrangler, so no cf or wrangler process starts.

  • vp test run packages/deploy-cloudflare/test/unit/version.test.ts: 237 passed after the page-overlap commit (231 before)
  • After the page-overlap commit, vp check, vp run check:types (35/35) and vp test run packages/deploy-cloudflare packages/deploy-core packages/void/test/unit were re-run: 10069 passed, 17 failed. The 17 are init.test.ts (16) and nitro.test.ts (1), which also fail on the commit before this one in the same shell.
  • vp check: no warnings, lint errors or type errors
  • vp run check:types: 35/35 successful
  • vp run test:all: 92 of 93 tasks passed. The one failing task was platform-api-integration-threads, 12 tests, because Playwright's Chromium was not installed. After playwright install chromium the six failing files passed (204 tests).
  • No user-facing documentation changes: this is an internal retry window.

Cloudflare's Worker version list can trail a write by minutes. Before the
upload, wait while the list lacks the active version. After the upload, wait
while the list still equals the baseline, on a schedule of about 5.5 minutes
instead of 250 ms and 500 ms. Failed reads keep their two quick retries.

Refs voidzero-dev#891

@0froq 0froq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looked into this and commented

The version list reads page 2 only above 10 versions. If a write lands
between the two page reads, the pages overlap and the read fails. That
failure ended the pre-upload check with no wait and left only two quick
retries after the upload.

The runner now marks this failure as version-history-changed, and both
waits retry it on the same schedule as a stale list. Other failures keep
their behavior, and an overlap that outlasts the schedule still stops
with inheritance-source-unavailable. Export
STALE_VERSION_HISTORY_DELAYS_MS from the package entry.

Refs voidzero-dev#891
@0froq

0froq commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

in packages/void/src/cli/cloudflare-process.ts:65

!['not-found', 'durable-migration', 'containers-unavailable'].includes(envelope.failure))

should include 'version-history-changed'. Not reachable today (the cf runner is in-process), but the whitelist and the failure union in execute.ts should stay in sync.

Thank you!

@cpojer

cpojer commented Nov 23, 2026

Copy link
Copy Markdown
Member

Slop review:

[P2] A rollback during either wait can break the next deploy. Void saves the uploaded candidate against the previously active version, then detects the rollback and aborts. Production traffic stays on the rollback version, but the next attempt uploads another candidate and fails because the saved receipt names the wrong parent. Recheck the active deployment before uploading after a pre-upload wait and before saving the receipt after a post-upload wait. Post-upload retry loop
[P2] A valid rollback can add 5½ minutes to an otherwise successful deploy. Cloudflare supports rolling back beyond the ten versions Void lists. In a direct deploy with no remote secrets, the base proceeded immediately. The PR waited 331.75 seconds before proceeding because the active version could never appear in that list. Compare the active version number with the list’s range before deciding to wait. Pre-upload retry condition · Cloudflare rollback limits

The process envelope decoder accepted only three of the four runner
failures, so a version-history-changed envelope from a child process
would have been rejected as invalid. The cf runner is in-process today,
so this path was not reachable.

The accepted failures are now a record keyed by the
CloudflareCommandResult failure union, so a failure added to the union
fails the typecheck until it is accepted here too.

Refs voidzero-dev#891
@konaito

konaito commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed in f72b076. decodeCloudflareOperationResult in cloudflare-process.ts now accepts version-history-changed; it was the only value missing from the whitelist. The accepted failures are now a Record keyed by CloudflareCommandResult['failure'], so a value added to the union in execute.ts fails the typecheck until it is added here too. A test checks that each of the four failures decodes from the envelope.

A rollback during either version list wait was not seen until after
the candidate receipt was saved with the old active version as its
parent. The deploy then stopped, and the next deploy failed on that
receipt. After a wait, production is now read again before the upload
and before the receipt is saved. If it changed, the deploy stops with
deployment-changed and saves no receipt.

A rollback to a version older than the ten listed versions can never
appear in the list, but the pre-upload check waited the whole schedule
for it. The active version's number is now read with versions.view,
and the deploy waits only when that number is not below the list's
lowest number. A number that cannot be read keeps the wait.

Refs voidzero-dev#891
@konaito

konaito commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed in e4fbe90.

Rollback during a wait. After the pre-upload wait, activateCloudflareVersion reads deployments status again before it uploads. After the post-upload wait, it reads it again before recordVerifiedCandidate. If production no longer matches the version read at the start, the deploy stops with deployment-changed and saves no receipt, so the next deploy does not find a receipt with the wrong parent. The re-read happens only after a wait. A test rolls production back inside sleep, before and after the upload, and checks that recordVerifiedCandidate is never called and that nothing is uploaded in the pre-upload case.

The same hazard exists on main for a rollback during the readiness probe, because the receipt is saved before readiness. This PR does not change that.

Rollback beyond the listed versions. This applies to the pre-upload wait only. The post-upload wait compares against the pre-upload baseline and does not look for the active version. When the list does not contain the active version, the deploy now reads that version once with versions.view and waits only if its number is not below the list's lowest number. An older active version proceeds at once, as on main. If the number cannot be read (a failed or thrown read, or no integer number; the API marks the field optional), the deploy still waits. A version the list trails may not be readable by id yet either. Skipping the wait in that case would bring back the failure this PR fixes, and the wait is bounded. A test with ten listed versions and an older active version expects no wait. Failed, thrown and unnumbered reads still expect the full schedule.

@cpojer
cpojer requested a review from Brooooooklyn November 23, 2026 07:46
cpojer
cpojer previously approved these changes Nov 23, 2026

@cpojer cpojer left a comment

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.

Looks good to me, I'd like a review by @Brooooooklyn before we merge.

Brooooooklyn and others added 2 commits November 25, 2026 20:00
# Conflicts:
#	packages/deploy-cloudflare/src/version.ts
… upload

- After the upload, a list that ends below the pre-upload baseline and
  agrees with it on every shared number is an older snapshot, not a
  concurrent write. Wait for it like an unchanged list instead of
  failing with inheritance-source-changed.
- Read production again only after a wait for a lagging list. The quick
  retries of a failed read no longer add a status read that could fail
  a deploy.
- Report the wait when it starts after a failed read, not only when the
  first read is stale.
- Fix lint rules enabled on main since the branch was opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T12:32:12.576558Z 0700e95 Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 0700e95c9a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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.

Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed)

4 participants