LearnNewsExamplesServices
Frontmatter
id8694
titleService Worker: Robust Version Synchronization (Boot Check & 404 Recovery)
stateClosed
labels
enhancementaicore
assigneestobiu
createdAtJan 16, 2026, 5:39 AM
updatedAtJan 16, 2026, 5:45 AM
githubUrlhttps://github.com/neomjs/neo/issues/8694
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 16, 2026, 5:45 AM

Service Worker: Robust Version Synchronization (Boot Check & 404 Recovery)

Closed v11.23.0 enhancementaicore
tobiu
tobiu commented on Jan 16, 2026, 5:39 AM

To strictly enforce version synchronization between the Client (App/Main) and the Service Worker, ensuring users never get stuck in a "Zombie" state (Old App + New SW + Deleted Assets):

  1. Boot-Time Version Check:

    • Update ServiceBase to handle getVersion message.
    • Update main.addon.ServiceWorker to query the SW version upon connection.
    • If Client.version !== SW.version, trigger immediate location.reload(true).
  2. Runtime 404 Recovery (Safety Net):

    • Update ServiceBase.onFetch to intercept 404s on guarded paths (dist/production, etc.).
    • If a 404 occurs (implying a race condition where SW updated mid-session or cache was lost), send Neo.Main.reloadWindow({force: true}) to the client.
    • Throttle this to prevent loops.

This two-pronged approach ensures:

  • Fast Failure: We catch the mismatch at boot time before assets fail.
  • Resilience: We recover if the update happens during the session.
tobiu added the enhancement label on Jan 16, 2026, 5:39 AM
tobiu added the ai label on Jan 16, 2026, 5:39 AM
tobiu added the core label on Jan 16, 2026, 5:39 AM
tobiu referenced in commit 76f0d23 - "enhancement: Service Worker: Robust Version Synchronization (Boot Check & 404 Recovery) (#8694)" on Jan 16, 2026, 5:44 AM
tobiu
tobiu Jan 16, 2026, 5:45 AM

Input from Gemini 3 Pro:

✦I have implemented the robust version synchronization strategy.

Changes Implemented:

  1. Boot-Time Version Check (src/main/addon/ServiceWorker.mjs):

    • Upon establishing a connection with the Service Worker, the client now queries the SW version (getVersion action).
    • If a mismatch is detected (Client.version !== SW.version), the client immediately triggers location.reload(true) to fetch fresh assets. This prevents the "Zombie App" state at the earliest possible moment.
  2. Runtime 404 Recovery (src/worker/ServiceBase.mjs):

    • Implemented on404(event) handler in ServiceBase.
    • Updated onFetch to invoke on404 when a request returns status 404.
    • Configured to guard critical paths: /dist/production/, /dist/esm/, and /src/.
    • If a 404 occurs on these paths, the SW sends a remoteMethod message to Neo.Main.reloadWindow with force: true.
    • Added a 5-second throttle (lastReload) to prevent infinite reload loops in case of persistent server errors.
  3. Core Support (src/Main.mjs):

    • Updated Neo.Main.reloadWindow to accept a {force: true} parameter, which maps to location.reload(true).

Outcome: Users encountering a version mismatch (either at boot due to stale index, or mid-session due to an update) will now experience a single automatic hard reload instead of a crash or blank page. The system is protected against infinite loops.

tobiu closed this issue on Jan 16, 2026, 5:45 AM
tobiu assigned to @tobiu on Jan 16, 2026, 5:45 AM