Any same-origin GET with a hashed-looking name, API and download URLs
included, was routed through the worker. The fallback now applies only under
the build asset directory of the registration scope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker sent ACTIVATE_REJECTED for a client refusal, a drain timeout and a
failed skipWaiting() alike, so the page blamed a dirty tab. Two worker reply
kinds now carry the timeout and the commit failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No test used disabledCleanup: true, so a mutation that skipped the unregister
survived. The new cases pin resolveRuntimeCapabilities and the owned/foreign
unregister outcomes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
web-push/codec-primitives.ts now owns OPAQUE_ID/validOpaqueId, isRecord,
hasExactKeys, exactRecord, validAuthority, base64UrlDecode and (to share the
alphabet) base64UrlEncode. push-codec,
push-registration-gateway, push-association-fence-store,
push-subscription-adapter and service-worker-runtime import them instead of
carrying their own copies (the fence store's control/association key checks
now use exactRecord/hasExactKeys with the same key lists). The duplicate-key
JSON scan in push-codec.ts is untouched (realtime lane, T76).
Where the copies differed, the stricter validated behavior is kept:
- validAuthority: the fence store's null guard. The gateway's copy threw a
TypeError for a null authority, so register()/reconcile() rejected instead
of returning INVALID_INPUT; they now return INVALID_INPUT (the only change a
caller can observe; characterization test was RED before the merge).
Non-record values (arrays) are also refused.
- base64UrlDecode: the gateway's decoder, which refuses a lone trailing
character (length % 4 == 1). The window adapter's copy accepted it when the
spare bits were zero; its only caller pre-checks an 87-char VAPID key, so
that difference was not reachable. `>>` vs `>>>` gave identical bytes.
- OPAQUE_ID, isRecord/hasExactKeys/exactRecord were already identical.
Page controller: PageControllerDependencies gains optional `document`; the
6-hour update check reads it (falling back to the global document), and
bootstrap/register-service-worker.ts now passes host.document through.
New adapter file: INVENTORY.md row 126 + renumber, total 137/137; detail row in
docs/reviews/adapters/05-service-worker-and-web-push.md.
Verified: characterization tests pinned the caller-visible behavior of every
copy before the merge (spare-bit keys, VAPID key, null authority in fence
store and gateway, array/extra-key backend answers, opaque ids); all pass
after, plus direct base64UrlDecode tests and an encode round-trip against
Node's base64url for lengths 0..66. Document injection test was RED
(update() ran while the injected document was hidden), green after. Gates:
check:architecture, types app/test/service-worker, lint, test:unit (only
pre-existing removal-fixture failure), test:component,
check:realtime-boundaries, check:adapter-inventory.
Realtime reference bundle (check:optional-recipes:source, already over budget
at b953142): 40139 -> 40097 gzip bytes after T89+T90.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page and the worker both used clientDrainMs (30s). A tab that drained at
29.999s let the worker call skipWaiting() and commit after the page had
already resolved CLIENT_DRAIN_TIMEOUT, so the requesting tab never reloaded.
The page now waits clientDrainMs + activationReplySlackMs (new additive
SERVICE_WORKER_BOUNDS field, 5s).
Verified: RED first with the real page/worker seam (last drain at 29.999s,
skipWaiting 50ms): page resolved CLIENT_DRAIN_TIMEOUT; green after.
Gates: check:architecture, types app/test/service-worker, lint, test:unit
(only pre-existing removal-fixture failure), test:component.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onActivate wrote the activation marker first, so a quota failure on
currentCache.put threw before the stale-cache delete loop and space never came
back. Stale owned caches are now deleted first (each delete failure is counted
as not deleted instead of aborting the loop), and a failed marker write is
swallowed: activation stands, the only loss is that the next release cannot
use this cache as its previous-release fallback.
Verified: RED first (onActivate rejected with QuotaExceededError and deleted
nothing), then green with order [delete stale, marker]. Gates:
check:architecture, types app/test/service-worker, lint, test:unit (only
pre-existing removal-fixture failure), test:component.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The static cache name is the asset-set digest, so a worker built with the same
assets (same VITE_BUILD_ID, new worker code) installs into the cache the active
worker serves from. A failed install then deleted that serving cache and its
activation marker. installStaticAssets now checks caches.keys() first and rolls
back (including the deferred post-deadline delete) only a cache this install
created. Rewriting an existing cache only puts identical sha256-verified bytes.
InstallDependencies.caches gains an optional keys(); without it the old
behavior (always roll back) is kept.
Verified: RED first (existing-candidate test saw one delete), then green; a
second test pins that a newly created candidate is still deleted. Gates:
check:architecture, types app/test/service-worker, lint, test:unit (only
pre-existing removal-fixture failure), test:component.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fetch listener only called respondWith for URLs in the current manifest,
so the previous-cache fallback (T29) never ran for the one case it exists for:
a tab of the previous build lazy-loading a chunk the new release no longer
lists. classifyFetch now returns PREVIOUS_RELEASE_FALLBACK for a same-origin,
non-navigate GET whose path is a content-hashed name (HASHED_STATIC_ASSET_NAME)
and that is not in the manifest; the runtime answers it only from the marked
previous release cache, otherwise the entry falls back to the network. The
decision is a synchronous runtime.intercepts() so respondWith is still called
only for requests the worker may answer. Runtime config and release manifest
stay network-only even though `-manifest.json` matches the hash pattern.
Verified: RED first (3 new tests failed: runtime onFetch returned null, entry
did not call respondWith), then green. New entry tests cover old chunk from
previous cache, previous miss -> network, and no interception for navigate,
POST, API, cross-origin, unhashed same-origin and release-manifest.json.
Gates: check:architecture, types app/test/service-worker, lint, test:unit
(only pre-existing removal-fixture failure), test:component.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fetch listener called respondWith() for every request, so every
navigation, API call and cross-origin request went through
onFetch -> fetch(request) inside the worker, even when only WEB_PUSH was
selected.
The listener now decides synchronously and calls respondWith() only for
a non-navigation GET whose URL is in runtime.manifestUrls; everything
else returns without touching the event. The fetch listener is only
registered when PWA_STATIC_ASSETS is selected, so a push-only worker is
not booted for fetches at all.
RED before fix:
- "service worker entry fetch interception (R-6.6) > answers only
same-origin GETs for manifest assets": respondWith was called for a
navigation.
- "... > registers no fetch listener without the static asset handler":
a fetch listener was registered.
The test loads the real entry module against stubbed worker globals and
build-time constants.
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Static install compared content-type by exact match, so a server
answering `.js` with `application/javascript` failed every install with
CONTENT_TYPE_INVALID. It also compared Content-Length with the decoded
byte count, so any gzip/br response (whose Content-Length is the
encoded size) failed with BYTES_MISMATCH.
- A response type and a manifest type that are both JavaScript MIME
essences (WHATWG MIME Sniffing list) now match.
- With a content-encoding header, the declared Content-Length is not
compared. The streamed decoded byte count and sha256 checks are
unchanged.
RED before fix (both REJECTED):
- installs JavaScript served under a JavaScript MIME synonym (R-6.5)
- does not compare an encoded Content-Length with the decoded size (R-6.5)
Guard: "still checks the decoded byte count of an encoded response"
(BYTES_MISMATCH).
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
register() resolves while the first worker is still installing. With no
active or waiting worker, start() fell through to ACTIVE, and kept doing
so on every visit even when the install failed.
When there is no active worker, start() now waits for the installing
worker to reach `activated` or `redundant`, bounded by the worker's own
install deadline (installDeadlineMs) and by stop(). Activated -> the
existing RELOAD_TO_ENABLE path (no clients.claim()); redundant ->
FAILED INSTALL_FAILED; deadline -> FAILED INSTALL_TIMEOUT; no worker at
all -> FAILED INSTALL_FAILED. start() is fire-and-forget after mount,
so the wait does not block rendering.
Test fixture: pageContainer gains an `installing` option backed by a
statechange-capable fake worker.
RED before fix (both resolved ACTIVE immediately):
- does not report a first install as ACTIVE while it is installing (R-6.4)
- reports a failed first install instead of ACTIVE (R-6.4)
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onActivate keeps one previous release cache, but onFetch only ever read
the current one, so the retained cache was never used.
On a current-cache miss, onFetch now looks up the owned non-current cache
with the highest activation marker (same rule onActivate uses; extracted
as highestMarkedCache) and serves a valid 200 hit from it. Per D-7 this
only applies to content-hashed file names; any other URL goes to the
network as before. The hashed-name rule moves to
HASHED_STATIC_ASSET_NAME in src/contracts/service-worker.ts and the
build generator imports it, so the generator and the worker share one
definition.
Scope note: the fallback runs inside onFetch's VERIFIED_CACHE_FIRST
branch, i.e. for URLs in the current manifest. Old-build chunks that are
not in the current manifest stay network-only (R-6.6 limits interception
to manifest URLs).
RED before fix: "serves a hashed asset missing from the current cache
from the previous release cache (R-6.3)" got null. Guard test "never
answers a non-hashed URL from the previous release cache (D-7)" added.
Gates: check:architecture, check:types:{app,node,test,service-worker},
lint, test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tabs that did not request an activation only observe()d
ACTIVATED_RELOAD_REQUIRED, and the host contract had no way to tell the
app. Worse, the worker targeted that broadcast at the requester's build,
so a tab on another build dropped it as TARGET_BUILD_MISMATCH. A waiting
worker produced by the periodic registration.update() was never reported
either.
- ServiceWorkerRuntimeHost gains optional onReloadRequired/onUpdateWaiting
(additive; existing host implementations still type-check).
- The page controller notifies reload subscribers when an expected worker
source sends ACTIVATED_RELOAD_REQUIRED, and watches `updatefound` +
`statechange` to announce an update that reached `installed` while an
active worker exists (a first install is never announced). Listeners
are removed on stop(); a throwing subscriber is isolated.
- Worker post-commit/reject notifications are untargeted; the requester
still pairs by nonce.
- Test fixtures: registration and workers are now EventTarget-backed.
RED before fix (listener called 0 times):
- announces an update that finished installing as waiting (R-6.3)
- page ↔ worker activation seam > tells a tab that did not ask that a
reload is required (R-6.3)
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The waiting worker sent CLIENT_DRAIN_REQUEST with
`targetBuildId: requesterBuildId`, so a tab on any other build dropped
it as TARGET_BUILD_MISMATCH, and the worker also ignored replies whose
`sourceBuildId` differed from the requester's. With a build N tab and a
reloaded build N+1 tab open, every activation ran into the 30s
CLIENT_DRAIN_TIMEOUT.
The drain request is now untargeted and replies are paired only by the
worker's own buildId (reply target), the nonce and the exact client id.
The unused requesterBuildId field and parameter are removed.
RED before fix: "page ↔ worker activation seam > drains tabs of another
build and completes the activation (R-6.2)" resolved CLIENT_DRAIN_TIMEOUT.
The test wires two page controllers (builds N and N+1) to one worker
runtime with async postMessage in both directions.
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page's activation listener checked the reply source and
`registration.waiting` before looking at nonce/kind. After skipWaiting()
the registration can already show the worker as active, so a genuine
ACCEPTED/RELOAD_REQUIRED became PROTOCOL_MISMATCH, and any unrelated
message (SYNC_WAKE_OBSERVED, CACHE_RESET_RESULT) from another source
ended a pending activation the same way (first half of 6.6-10).
Replies are now filtered by nonce and reply kind first. ACCEPTED and
RELOAD_REQUIRED (post-commit) are success when the worker is still the
waiting one or is already the active one; REJECTED still requires it to
be waiting. Source identity is still enforced.
RED before fix (both returned PROTOCOL_MISMATCH):
- accepts a post-commit reply after the waiting worker was promoted (R-6.1)
- ignores unrelated worker messages while an activation is pending (R-6.1)
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The marker read added a whole chunk to a running total and compared the
total afterwards, so a corrupt body could hand activation a 1 MiB chunk
against a 257-byte ceiling. It now reads at most the remaining allowance —
through a BYOB reader where the source offers one, and by refusing an
oversized chunk before copying it otherwise. A declared oversize cancels
the body it refuses instead of leaving the stream open, and the reader
lock is released on every path.
The build generator and the runtime decoder shared only the extension
table, not the path grammar. The generator happily emitted
`/assets/bad@name-abcdefgh.js`, which the decoder then refused — a correct
build failing at install time. Both now use one exported canonical path
predicate and the generator decodes its own output before returning it.
The notification click handler emitted its terminal record from inside
`process` and again from the `waitUntil` wrapper, so an ordinary click was
counted twice. Worse, a late rejection downgraded `MAYBE_APPLIED` to
`NOT_APPLIED` — telling operators the click had definitely not been
applied when nobody knew that — and the late observation ran outside
`waitUntil`, so a worker shutdown lost the evidence. There is one
observation authority per click now, certainty is monotone, only an
explicit null window confirms `NOT_APPLIED`, and the bounded tail is owned
by `waitUntil` without extending the public deadline.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
SW-06: correlate activation, reset and drain replies by source object identity
against the captured waiting worker or controller, so an arbitrary same-origin
source cannot close this page's admission, and end a request immediately as
PROTOCOL_MISMATCH when the source is swapped instead of waiting for the drain
timeout. requestActivation() and resetOwnedCaches() are single-flight, so ten
concurrent callers share one nonce, listener and postMessage.
SW-07: an empty in-scope client set is vacuously drained rather than rejecting
a waiting worker when the requester already closed.
SW-08: isolate per-client postMessage failures. A client that cannot receive the
drain request fails immediately instead of holding pending state to the timeout,
skipWaiting() is the activation commit and its failure is a rejection, and the
accepted and reload notifications are sent afterwards as best effort.
SW-09: fence late install work. A fenced worker starts no new candidate work, a
late response body from a non-cooperative fetch is cancelled, a throwing digest
maps to a closed outcome, and a second exact delete of the owned candidate cache
is registered once the abandoned install settles - without extending the public
60s bound.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
WP-01: a CAS receipt is only evidence when it names the expected key and the
exact next revision. Write and remove now share one validator, so a stale or
arbitrary repository receipt can no longer be packaged as a confirmed control.
WP-05: a pre-aborted command records the operation the caller requested instead
of always reporting an inspection.
WP-06: bounded fan-out is reported honestly. The subscriptionchange client
handoff and the notification cleanup both emit countBucket and truncated, and an
incomplete cleanup returns { complete: false } and is observed as DEGRADED
separately from revoke authority.
WP-07: the user-visible native notification effect is tracked through
NOT_APPLIED, MAYBE_APPLIED and CONFIRMED phases and surfaced as observation
evidence, never as retry authorization.
WP-02, WP-03 and WP-04 stay open: they need the V2 wire protocol with server
request-shape negotiation, which belongs to the versioned-migration task rather
than this correctness pass. The ledger records them as DEFERRED_TO_MIGRATION.
Web Push remains NOT_SELECTED and AVAILABLE_NOT_COMPOSED.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
SW-URL-01: canonicalize each generated root-relative manifest URL against the
registration scope once, re-check same-origin, and share that absolute identity
across install cache keys, fetch classification and cache lookup or delete.
Previously every verified asset fell through to the network.
SW-01: serve verified static requests only from the current release cache. A
CacheStorage-wide match could return a previous release's response for the same
URL while the delete targeted a cache that was never read. The worker scope
facade no longer exposes a wide match at all.
SW-02: cache reset deletes only names that parse as owned, so a foreign cache
sharing the ca-static-v1- prefix survives.
SW-03: unregister() resolving to false is a FAILED unregister, not UNREGISTERED.
SW-04: staged removal reports what happened - ABSENT, UNREGISTERED and PURGED
map to DISABLED, OWNERSHIP_MISMATCH to INCOMPATIBLE and FAILED to FAILED - so a
later release cannot delete the worker while a registration or owned cache is
still present.
SW-05: add the runtime-neutral service-worker-static-manifest codec that owns
exact row keys, the extension and content-type allowlist, the root-relative URL
rule and the length-prefixed canonical bytes. The generator and the build gate
hash those same bytes, and the build gate now decodes and recomputes the set
digest instead of type-casting the manifest.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>