Skip to content

fix(sw): do not let a busy worker's silence cancel the reload that repairs a torn page - #204

Merged
chaxus merged 1 commit into
mainfrom
sw-version-patience
Aug 23, 2026
Merged

fix(sw): do not let a busy worker's silence cancel the reload that repairs a torn page#204
chaxus merged 1 commit into
mainfrom
sw-version-patience

Conversation

@chaxus

@chaxus chaxus commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

The failure

sw-silent-update.spec.ts (the @serial batch) failed once on main with a completely white page. It passed on rerun, so it is intermittent — but the trace says what happened, and it is not a test problem.

From the trace:

  • Creating new editor instance appears three times, Document loaded twice. After the third boot, not one of the twelve [OO] … guard lines appears — it died before onAppReady, i.e. before any of our patch code ran.
  • The test's own wait for vendorVersion === 'e2e-next' passed (the failure is on the next line, settleEditor). So the controller did change, and the new worker did answer a three-second question.
  • No fourth boot ever started. The reload that repairs a page torn in half by the swap never happened, and the tab stayed blank for the full 90 s.

What cancelled the reload

shouldReloadOnControllerChange needs isNewBuild, which comes from isUnseenBuild, which opens with:

const version = await askVersion(waiting);           // 1000 ms
if (!vendorVersion || !cacheStorage) return false;   // cannot tell -- do nothing

A worker answers VERSION from its message handler, which it cannot run while it is busy — and it is busiest in precisely that moment: just activated, terminating the worker it replaced, with the page refetching a vendor tree that is not in its cache. One second of silence became "nothing new to tell you", so the page did not reload.

This file already learned that lesson once ("a worker under load does not answer within a timeout, silence got read as 'it is old'") — but on the promotion side, which was then moved to cache evidence. The controllerchange side kept asking. The asymmetry matters: there, a wrong answer costs a wasted reload; here it costs a white page with no way out but a manual reload.

The change

askVersionPatiently() — three tries of two seconds — used by isUnseenBuild. Silence still decides; it just cannot decide early.

Deliberately not:

  • the judgement conditions. "Is a document open" is already documented as the wrong one, and "unsaved changes" was not the cause here: the boot that died was a fresh page load, dirty flag false.
  • cache evidence. A page torn mid-boot may not have completed a single vendor request, so the incoming build has no runtime cache yet to be recognised by.

Tests

Three new cases in test/unit/sw-update.test.ts, on fake timers so they cost no wall clock: a busy worker that drops the first question is still identified as a new build; a worker that never answers still falls back to doing nothing; and the default budget is at least three seconds. The existing "does not answer" case moves to fake timers too — giving up now takes six seconds and would blow the 5 s per-test default.

Reverse-verified: with askVersion put back, exactly one case (keeps asking a worker that was too busy…) fails and the other 52 pass; restored, 53 pass. Locally: 2700 unit tests, and sw-silent-update + sw-warm E2E green.

Known gap

The CI failure was intermittent, so there is no E2E that reproduces it on demand — pinning it would need a hook to make a worker too busy to answer, which does not exist. The unit cases pin the decision logic; the white-page path itself is still guarded only by sw-silent-update.

Write-up: docs/explorations/2026-08-24-sw-version-question-timeout.md.

…pairs a torn page

A blank editor in CI, on the silent-heal case. The trace says the controller
did change (the test's own three-second VERSION question to the new worker was
answered), the third editor boot started and died before a single guard
installed -- and no fourth boot ever began. The reload that repairs a page the
swap tore in half never happened.

What cancelled it was the one-second question in isUnseenBuild. A worker
answers VERSION from its message handler, which it cannot run while it is
busy, and it is busiest in exactly that moment: just activated, terminating
the worker it replaced, with the page refetching a vendor tree it has not
cached. The silence was read as "nothing new", so isNewBuild came back false
and the tab stayed blank until the test gave up.

This file already learned that lesson once -- "a worker under load does not
answer within a timeout" -- but on the promotion side, which was moved to
cache evidence. The controllerchange side kept asking, and here a wrong answer
is not a wasted reload: it is a white page with no way out but a manual one.

So: askVersionPatiently, three tries of two seconds. Silence still decides,
it just cannot decide early.

Not the judgement conditions, deliberately. "Is a document open" is already
known to be the wrong one, and "unsaved changes" was not the cause -- the boot
that died was a fresh page load with the dirty flag false. Not cache evidence
either: a page torn mid-boot may not have completed one vendor request, so the
incoming build has no runtime cache to be seen by.

Reverse-verified: with askVersion back in place, exactly one of the new cases
fails and the other 52 pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chaxus
chaxus enabled auto-merge (rebase) August 23, 2026 16:01
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying document with  Cloudflare Pages  Cloudflare Pages

Latest commit: 68a2426
Status: ✅  Deploy successful!
Preview URL: https://d00b0333.document-7hm.pages.dev
Branch Preview URL: https://sw-version-patience.document-7hm.pages.dev

View logs

@chaxus
chaxus merged commit 8099703 into main Aug 23, 2026
18 checks passed
@chaxus
chaxus deleted the sw-version-patience branch August 23, 2026 16:07
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