Repository navigation
Description
Context
registerDefaultRoutes activates a new worker as soon as it installs and claims every open page: skipWaiting() on install and clients.claim() on activate, under the comment "Activate new service worker immediately on deploy" (packages/ui-sdk/src/client/sw-policy.ts:191-202).
When the new worker activates, Workbox's precache controller deletes every entry of the precache that is not in the new manifest (PrecacheController.activate, workbox-precaching 7.4.1, the version packages/ui-kit/package.json pins). A page still running the previous build that then loads a lazy chunk finds it gone from the precache; the request falls through to the network, where the deploy has usually removed it. That is the failure StaleChunkFallback exists to absorb: "A new version is ready", then an automatic or manual reload, or a "held" state when the reload would lose unsent work (StaleChunkFallback, packages/ui-react/src/components/layout/page-boundary.tsx:121-170).
So a busy user, typing a draft with dictation under review, can open a view they have not opened yet and get a fallback screen instead of the view, even though the page reload itself is correctly held by the update holds (reloadWhenIdle, packages/ui-react/src/hooks/use-service-worker-updates.ts:98-106).
Two comments are also inaccurate:
sw-policy.ts:204-207sayscleanupOutdatedCaches()deletes "precaches from previous builds". It only deletes caches left by older, incompatible Workbox versions (-precache-names). Per-entry deletion is the controller'sactivate.sw-policy.ts:250-257calls navigation "network first". A navigation to/(every launch of this hash-routed app) matches the precache route first, which Workbox'sdirectoryIndexmaps to/index.html, so it is served cache-first. Only paths not in the precache reach the network-first handler (sw-policy.ts:264-287).
#2566 makes update checks more frequent while a page is open, which makes this case more common.
Guide: (no guide). The modern-web-guidance performance guide says "DON'T bypass versioning: Failing to update asset hashes/versions will trap users in infinite cache loops", which every option below respects.
Binding: D31 (foundations): a stale PWA must fail loudly. The update-hold registry (offline continuity, #1015, #1112, update proof PR #1194) defers the reload but not the activation.
Rulings (maintainer, 2026-10-22)
All three choices are settled; the rulings are in the comments.
- Lifecycle: B, idle-gated handover. A newly installed worker no longer calls
skipWaiting()on install; it waits until the open pages are idle and activates on a{ type: "SKIP_WAITING" }message. Keeping immediate activation (A) and retaining one previous build's chunks (C) were not selected. - Multi-tab: all open app tabs idle. An idle tab alone cannot trigger handover while another app tab is busy. A suspended or unresponsive tab blocks activation; a missing readiness response is not evidence of idle. This accepts delayed updates, still bounded by the loud stale-client checks (D31).
- Compatibility: required members, breaking.
ServiceWorkerPolicyScopegains required members (anaddEventListener("message", listener)overload andclients.matchAll({ type: "window" })alongsideclaim()). No optional-member fallback, no opt-in flag, no parallel immediate-activation path. A host passing the realselfis unaffected; custom structural scopes and mocks must add the members. - Release classification (maintainer, 2026-10-24): before 1.0.0 an approved break ships as a minor changeset naming the break, never a major one (
docs/decisions/contract-versioning.md:14-20). This replaces the "major changeset" wording in the 2026-10-22 required-members ruling; the breaking classification stands.
Scope
Coordinate readiness across the open app tabs before activating the waiting worker. A busy, suspended or unresponsive tab blocks activation; lack of a response is not evidence of idle.
sw-policy.ts: remove theinstallskipWaiting(), add amessagelistener that callsskipWaiting()for{ type: "SKIP_WAITING" }, and extendServiceWorkerPolicyScopewith the message/client capabilities needed for all-tabs coordination. The required additions are an addEventListener("message", listener) overload and clients.matchAll({ type: "window" }) alongside claim(). They are approved breaking requirements with no optional fallback or opt-in flag. Custom structural scope implementations and mocks must add them. The activation command must be sent only through the coordinated readiness flow.use-service-worker-updates.tsand the worker: when a worker reachesinstalledwith a controller (orregistration.waitingexists at registration), coordinate readiness across all open app tabs using each tab's existingbusy()test. Activate only after all participating open app tabs are confirmed idle. Re-evaluate when holds or the open-tab set change; a busy, suspended or unresponsive tab blocks activation. Do not let one idle tab independently post an unconditional activation command. Keep the existingcontrollerchangereload guard and update holds as a second safety check. Bound and clean up coordination requests/listeners; do not treat timeout or missing response as readiness.- Correct the two comments at
sw-policy.ts:204-207andsw-policy.ts:250-257. - Record the ruling as a dated entry in
docs/decisions/design-kit/offline-continuity.md.
Out of scope
- How often updates are checked (ui-react: an installed app left open never checks for a new service worker #2566).
StaleChunkFallback's copy or decisions; it stays as the safety net.- An "update ready" banner or control.
- Host changes to
service-worker.js. If the handover needs the host to stop callingskipWaiting()itself, file abrain-hosting-templateissue.
Acceptance criteria
- The lifecycle ruling is recorded on this issue: B, idle-gated handover.
- The multi-tab activation policy is recorded: all open app tabs must be idle; suspended or unresponsive tabs block activation.
- The required public worker API compatibility break is approved before implementation.
- Document migration for host scope implementations/test doubles and include a minor changeset explicitly naming the break. Update the API report and package-API contract in the same
CONTRACT:commit. - Record the final lifecycle and tab rulings in
docs/decisions/design-kit/offline-continuity.mdduring implementation. - A real-browser test in
ui-react-layout, built onpackages/ui-react/tests/browser/offline/cold-capture/, holds the page busy, deploys worker v2, then lazy-loads a chunk only the v1 precache holds. The chunk loads, v2 stayswaiting, and after the hold ends onecontrollerchangeand one reload follow. The test fails on the tree before the change. - A real-browser multi-tab test shows an idle tab cannot trigger activation while another app tab is busy; the v1-only lazy chunk remains available in the busy tab. Once every tab is idle, one activation occurs and each eligible tab reloads once.
- Coordination tests show suspended/unresponsive tabs and missing readiness responses do not permit activation; closing a blocking tab allows the remaining idle tabs to proceed. New-tab and idle-to-busy changes during coordination cannot bypass readiness checks.
- A unit test shows activation is never requested from local idle state alone: every open app tab must be confirmed idle, and duplicate readiness notifications do not cause duplicate activation.
- The two comments state what Workbox actually does.
Verification
bun run test packages/ui-sdk/tests/sw-policy.test.ts packages/ui-react/tests/render
bun run test:layout
bun run typecheck
bun run lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit.registerDefaultRoutesandServiceWorkerPolicyScope(packages/ui-sdk/src/client/sw-policy.ts:57-67) are ordinary exports recorded inapi-report/ui-sdk.txt; the required members and the standard coordinated activation are an approved break and carrybreaking. - This changes a published package's behaviour, so it needs a changeset: a minor changeset for
@schlessera/brain-ui-sdk(pre-1.0 policy) that names the break, the new required scope members and the removed install-timeskipWaiting(), with migration notes for custom structural scopes and test doubles. Do not write a major changeset. Updateapi-report/ui-sdk.txtanddocs/integration-contract/package-api.mdin the same commit.
2026-10-24: replaced the "major changeset" instruction with the pre-1.0 minor changeset naming the break (maintainer, 2026-10-24); replaced the "Decision needed" options section and the stacked 2026-10-22 corrections with a summary of the settled rulings (the option texts are preserved in a comment).
Activity
schlessera commentedon Oct 22, 2026
2026-10-22 triage at main
aa8c8966b59f031f054f4876dbca84048b40ae4f: corrected the claim that an ordinary exported service-worker scope is outside the package contract. Verified the exported declarations and recorded signatures, plus the existing install/activate listeners. Add contract for the proposed B API change; preserve needs: decision and the open A/B/C and multi-tab choices. No lifecycle option or breaking change is approved by this review.schlessera commentedon Oct 22, 2026
Decision (maintainer, 2026-10-22): Select option B: idle-gated service-worker handover. A newly installed worker waits rather than activating immediately, so busy pages retain the cached code their current build needs. Options A (keep immediate activation) and C (retain one previous build while activating immediately) are not selected.
The multi-tab policy remains open: one idle tab versus all open tabs idle. The existing scope is only an outline of the one-idle-tab variant, not approval of that policy. Any required public API compatibility ruling also remains open. The body and acceptance criteria now distinguish the settled lifecycle from these unresolved choices;
needs: decisionstays.schlessera commentedon Oct 22, 2026
Decision (maintainer, 2026-10-22): Multi-tab policy: option B, all open app tabs must be idle before service-worker activation. An idle tab alone cannot trigger handover while another tab is busy. A suspended or unresponsive tab blocks activation; missing readiness evidence must not be treated as safe. This accepts additional coordination complexity and potentially delayed updates.
The body, implementation scope and acceptance criteria now require all-tabs coordination and multi-tab runtime proof, replacing the previous one-idle-tab outline. Existing reload holds and loud stale-client checks remain. The public API compatibility approach is still unresolved, so
needs: decisionstays.schlessera commentedon Oct 22, 2026
Decision (maintainer, 2026-10-22): Compatibility option B: approve the required breaking public worker API/scope changes for the selected idle-gated, all-open-app-tabs-idle handover. Make coordinated activation standard behavior; no compatibility adapter or parallel immediate-activation path is required. Host implementations and test doubles may need updates.
Use
breakingandcontract, migration notes, a changeset explicitly naming the break, aCONTRACT:commit prefix and same-commit API report/package-API contract updates. The pre-1.0 policy permits the approved break in a minor release.All three rulings are settled: idle-gated activation; every open app tab confirmed idle, with unresponsive tabs blocking; and the required compatibility break approved. The body and acceptance criteria reflect them. Remove
needs: decisionand addagent-ready; no implementation or runtime verification is claimed. Record the final rulings in offline-continuity.md during implementation.schlessera commentedon Oct 22, 2026
Decision (maintainer, 2026-10-22): public API compatibility. Required members; the break is accepted.
ServiceWorkerPolicyScopegains required members for the idle-gated, all-tabs handover:addEventListener("message", listener)overloadclients.matchAll({ type: "window" }), alongsideclaim(), for readiness coordination across every open app tabThere is no optional-member fallback and no opt-in flag: one lifecycle, and every host gets the fix. A host passing the real
selfis unaffected. Custom structural scope implementations and mocks must add the members.Rationale: D31 states there is no backwards-compatibility burden, and a silent fallback to immediate activation would keep the stale-chunk failure in exactly the hosts that cannot see it.
Required handling, before code:
breakinglabel (contractis already set).@schlessera/brain-ui-sdk, naming the new required scope members and the removed install-timeskipWaiting().api-report/ui-sdk.txtand the package-API contract in the sameCONTRACT:commit as the code.service-worker.jscallsskipWaiting()itself or passes a narrowed scope, file the host issue there.All rulings on this issue are now recorded: lifecycle B, all tabs idle, and the break accepted.
needs: decisionis removed.schlessera commentedon Oct 22, 2026
2026-10-22 readiness reconciliation: folded the maintainer ruling into the body, replacing the unresolved-choice specification and aligning scope/criteria with the accepted branch. The remaining work is explicitly scoped; add agent-ready. Preserve priority, native parent, assignment and release attribution. This is issue preparation, not implementation, runtime proof or delivery.
schlessera commentedon Oct 23, 2026
History, moved from the body on 2026-10-24. The options as offered before the 2026-10-22 rulings:
The dated triage and correction notes that followed in the body are the comments above.
Release classification (maintainer, 2026-10-24): before 1.0.0 an approved breaking change ships as a minor changeset naming the break, never a major one; under the lockstep fixed group a major changeset would publish 1.0.0 (
docs/decisions/contract-versioning.md:14-20). The required-members break stands; only the changeset level in the 10:11 ruling changes.