LearnNewsExamplesServices
Frontmatter
id18265
titleA second SharedWorker window drops the replayed registerRemote
stateClosed
labels
bugaicore
assigneesneo-opus-vega
createdAtSep 4, 2026, 11:20 AM
updatedAtSep 13, 2026, 12:51 PM
githubUrlhttps://github.com/neomjs/neo/issues/18265
authorneo-opus-vega
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 4, 2026, 12:34 PM

A second SharedWorker window drops the replayed registerRemote

neo-opus-vega
neo-opus-vega commented on Sep 4, 2026, 11:20 AM

Context

Measured 2026-09-04 09:12Z on engine dev@35d468b51f while running the multi-window reload rig for D#18224 (receipt: https://github.com/neomjs/neo/discussions/18224#discussioncomment-18284759). A useSharedWorkers: true app, one popup open, main window reloaded:

page typeof Neo.worker.App remotes present
first connecting window 'object' createNeoInstance, destroyNeoInstance, fireEvent, getConfigs, getWorkerId, loadModule, moveComponent, setConfigs, setGlobalConfig
the same window after location.reload() (worker kept alive by the popup) 'undefined' none

Two runs, same result. Observation and inference are separated below; the mechanism was then read at source.

#8339 (closed 2026-01-05, direct commit c3a4e13cc9, no PR) fixed exactly this symptom class — "Remote Method Registration Missing for Secondary Windows in SharedWorker" — by replaying every stored registerRemote to each newly connected port. The replay runs. The receiver drops it.

The Problem

A window that connects to an already-running SharedWorker never gets the App worker's main-thread proxies. The first window gets them through the startup path; every later window — a second app window, or the first window after F5 — has Neo.worker.App undefined.

Consequence today: src/worker/Manager.mjs:693 calls Neo.worker.App.setGlobalConfig(config) unguarded, so any global-config write issued from such a window throws; the remote methods documented as main-thread testing support (moveComponent, destroyNeoInstance, createNeoInstance) are unreachable from every window but the first. Nothing logs; the proxies are simply absent.

The Architectural Reality

Three lines, read at dev@35d468b51f:

  1. src/worker/Base.mjs:209–210 (the #8339 replay, inside onConnected):
       me.remotesToRegister.forEach(remote => {
        me.sendMessage(id, {action : 'registerRemote', ...remote})
    });
    id is the new port id (Neo.getId('port')).
  2. src/worker/Base.mjs:449 inside sendMessage(dest, opts): opts.destination = dest; — so the replayed message reaches the right port but carries destination: 'port-N'.
  3. src/worker/mixin/RemoteMethodAccess.mjs:176, the main thread's receiver: if (remote.destination === Neo.workerId) { … } — Neo.workerId is 'main', the message says 'port-N', the registration is silently ignored.

The startup path works because core/Base.mjs#initRemote → Base.promiseRemotes(className, remote) sends with dest === 'main'. The deprecation guard at src/worker/Base.mjs:445 already exempts registerRemote from the "destination main is deprecated" warning — the intended shape of a registration message is destination: 'main' with a routing key, and the replay is the one sender that does not produce it.

core/Base.mjs#initRemote (~:642–660) is not at fault: it pushes {className, methods: remote.main} into currentWorker.remotesToRegister for every singleton in a SharedWorker, including Neo.worker.App itself. The list is right; the envelope is wrong.

The Fix

src/worker/Base.mjs:210 — send the replay addressed to main with the new port as the routing key, so the cascade documented at :431–436 (direct dest → opts.port → opts.windowId → opts.appName) resolves the port while destination stays 'main':

me.sendMessage('main', {action: 'registerRemote', port: id, ...remote})

dest === 'main' here is not the deprecated broadcast shape: opts.port is an explicit routing key, so the last-resort first-port fallback never runs, and the registerRemote exemption at :445 keeps the console clean. The receiver's guard at RemoteMethodAccess.mjs:176 is kept — it is what stops one window's registrations from landing in another.

Plus a witness on the worker side that pins the envelope, so the next refactor of sendMessage cannot silently re-break it.

Contract Ledger Matrix

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
Neo.worker.App.<method> proxies on the main thread of every connected window the worker's remote.main config (src/worker/App.mjs:40–51) + core/Base.mjs#initRemote present on the first window and on every window connecting to the running worker, incl. a reloaded one none — absence is a TypeError at the call site src/worker/Base.mjs#onConnected docblock names the replay contract AC-1, AC-2
registerRemote message envelope src/worker/Base.mjs#sendMessage cascade docblock (:431–436) destination: 'main', port: <new port id> — src/worker/Base.mjs#onConnected docblock AC-1
duplicate registerRemote admission (RemoteMethodAccess#onRegisterRemote) the remote.origin !== 'main' guard of 59a2a4010ce (#698), narrowed rather than removed a registration of the SAME endpoint — className, method, origin equal — is a no-op that keeps the existing proxy (the replay and the startup path both address the first window); any other occupant of the slot — a proxy for a different origin, or a local member — is a collision and throws the throw: a wrong binding is never retained in silence onRegisterRemote + generateRemote docblocks (remoteProvenance) AC-3 + two negative unit controls (different origin, local member)

Decision Record impact

none — no ADR governs the worker message envelope; #8339's intent is restored, not changed.

Acceptance Criteria

  • AC-1 — unit witness on Neo.worker.Base: with isSharedWorker true and one remotesToRegister entry, a second onConnected posts a registerRemote whose destination is 'main' and whose port is the new port's id; the message reaches only that port.
  • AC-2 — a window that connects to a running SharedWorker has typeof Neo.worker.App.moveComponent === 'function' (whitebox or e2e arm on an existing multi-window fixture, e.g. the shared-worker child-app topology used by the neuralLink fixtures); the same arm reds at dev@35d468b51f.
  • AC-3 — the first window's registration is unchanged: no Duplicate remote method definition throw, and pkg[method] ??= stays idempotent when both the startup path and the replay reach the same window.
  • AC-4 — no sendMessage destination "main" is deprecated warning is emitted by the replay (the :445 exemption covers it; the arm asserts the console).
  • AC-5 — mutation-verified: reverting the one-line envelope change reds AC-1 and AC-2.

Out of Scope

  • The dock-layout rebind after reload (D#18224 Option G/H) — its live probe used the Neural Link precisely because this bug made the main-thread route unusable; the design does not depend on this fix.
  • Neo.appsByName[name] retaining both Application generations after a reload (controller/Application.mjs:84–85, component/Abstract.mjs:151 fallback) — separate lifecycle question, tracked on D#18224.
  • Registration of instance remotes (initRemote's ID-driven branch) — unaffected; they never use the broadcast path.

Avoided Traps

  • Relaxing the receiver's guard (remote.destination === Neo.workerId) to accept port-addressed registrations. The guard is what keeps a registration from landing in a window it was not sent to; the envelope is the thing to fix.
  • Sending with dest === 'main' and no routing key. That hits the last-resort first-port fallback and registers the remotes into whichever window connected first — the misrouting class #17895 closed.
  • Re-registering at afterConnect for all ports. Re-sending to already-served windows is harmless (??=) but noisy; the per-connection replay is the right hook, it only needs the right envelope.

Related

  • #8339 — the same symptom, fixed by direct commit c3a4e13cc9 (2026-01-05): added remotesToRegister + the onConnected replay whose envelope this ticket corrects.
  • #17895 — Dock FLIP messages omitted windowId and routed to the first port: the misrouting class the routing key avoids.
  • #17899 — retiring the deprecated 'main' destination; the :445 exemption for registerRemote is its trace.
  • #8366 — the earlier deprecation-warning fix for registerRemote messages.
  • D#18224 — the multi-window transactions Discussion whose reload receipt surfaced this (comment discussioncomment-18284759).

Live latest-open sweep: checked the latest 20 open issues (created-descending) at 2026-09-04T09:19Z; no equivalent found. A2A claim sweep: list_messages({status:'all', limit:30}) at 09:20Z — no [lane-claim] / [lane-intent] on remote registration or SharedWorker reconnect in the last 60 minutes. Structure-map gate: N/A — src/worker/** is engine Body surface, not Agent OS placement.

Origin Session ID: 3464d658-9b64-4f10-a951-6a4836e12ca1

Retrieval Hint: "registerRemote replay destination port id onRegisterRemote guard SharedWorker reload Neo.worker.App undefined"

tobiu referenced in commit 2ee23d7 - "fix(worker): a window joining a running SharedWorker receives the replayed remotes (#18265) (#18266) on Sep 4, 2026, 12:34 PM
tobiu closed this issue on Sep 4, 2026, 12:34 PM