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:
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')).
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'.
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
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"
Context
Measured 2026-09-04 09:12Z on engine
dev@35d468b51fwhile running the multi-window reload rig for D#18224 (receipt: https://github.com/neomjs/neo/discussions/18224#discussioncomment-18284759). AuseSharedWorkers: trueapp, one popup open, main window reloaded:typeof Neo.worker.App'object'createNeoInstance, destroyNeoInstance, fireEvent, getConfigs, getWorkerId, loadModule, moveComponent, setConfigs, setGlobalConfiglocation.reload()(worker kept alive by the popup)'undefined'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 storedregisterRemoteto 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.Appundefined.Consequence today:
src/worker/Manager.mjs:693callsNeo.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:src/worker/Base.mjs:209–210(the #8339 replay, insideonConnected):me.remotesToRegister.forEach(remote => { me.sendMessage(id, {action : 'registerRemote', ...remote}) });idis the new port id (Neo.getId('port')).src/worker/Base.mjs:449insidesendMessage(dest, opts):opts.destination = dest;— so the replayed message reaches the right port but carriesdestination: 'port-N'.src/worker/mixin/RemoteMethodAccess.mjs:176, the main thread's receiver:if (remote.destination === Neo.workerId) { … }—Neo.workerIdis'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 withdest === 'main'. The deprecation guard atsrc/worker/Base.mjs:445already exemptsregisterRemotefrom the "destination main is deprecated" warning — the intended shape of a registration message isdestination: '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}intocurrentWorker.remotesToRegisterfor every singleton in a SharedWorker, includingNeo.worker.Appitself. The list is right; the envelope is wrong.The Fix
src/worker/Base.mjs:210— send the replay addressed tomainwith 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 whiledestinationstays'main':me.sendMessage('main', {action: 'registerRemote', port: id, ...remote})dest === 'main'here is not the deprecated broadcast shape:opts.portis an explicit routing key, so the last-resort first-port fallback never runs, and theregisterRemoteexemption at:445keeps the console clean. The receiver's guard atRemoteMethodAccess.mjs:176is 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
sendMessagecannot silently re-break it.Contract Ledger Matrix
Neo.worker.App.<method>proxies on the main thread of every connected windowremote.mainconfig (src/worker/App.mjs:40–51) +core/Base.mjs#initRemoteTypeErrorat the call sitesrc/worker/Base.mjs#onConnecteddocblock names the replay contractregisterRemotemessage envelopesrc/worker/Base.mjs#sendMessagecascade docblock (:431–436)destination: 'main',port: <new port id>src/worker/Base.mjs#onConnecteddocblockregisterRemoteadmission (RemoteMethodAccess#onRegisterRemote)remote.origin !== 'main'guard of59a2a4010ce(#698), narrowed rather than removedclassName,method,originequal — 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 throwsonRegisterRemote+generateRemotedocblocks (remoteProvenance)Decision Record impact
none — no ADR governs the worker message envelope; #8339's intent is restored, not changed.
Acceptance Criteria
Neo.worker.Base: withisSharedWorkertrue and oneremotesToRegisterentry, a secondonConnectedposts aregisterRemotewhosedestinationis'main'and whoseportis the new port's id; the message reaches only that port.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 theneuralLinkfixtures); the same arm reds atdev@35d468b51f.Duplicate remote method definitionthrow, andpkg[method] ??=stays idempotent when both the startup path and the replay reach the same window.sendMessage destination "main" is deprecatedwarning is emitted by the replay (the:445exemption covers it; the arm asserts the console).Out of Scope
Neo.appsByName[name]retaining both Application generations after a reload (controller/Application.mjs:84–85,component/Abstract.mjs:151fallback) — separate lifecycle question, tracked on D#18224.initRemote's ID-driven branch) — unaffected; they never use the broadcast path.Avoided Traps
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.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.afterConnectfor 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
c3a4e13cc9(2026-01-05): addedremotesToRegister+ theonConnectedreplay whose envelope this ticket corrects.windowIdand routed to the first port: the misrouting class the routing key avoids.'main'destination; the:445exemption forregisterRemoteis its trace.registerRemotemessages.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"