---
id: 9547
title: Fix RemoteMethodAccess for Main Thread Addons and Instance-to-Instance ID collision
state: CLOSED
labels:
  - bug
  - ai
  - architecture
  - core
assignees:
  - tobiu
createdAt: '2026-03-24T21:18:08Z'
updatedAt: '2026-03-24T21:19:47Z'
githubUrl: 'https://github.com/neomjs/neo/issues/9547'
author: tobiu
commentsCount: 1
parentIssue: 9449
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-03-24T21:19:47Z'
---
# Fix RemoteMethodAccess for Main Thread Addons and Instance-to-Instance ID collision

### Bug Description
In PR #9546, we refactored `RemoteMethodAccess` to support declarative remote configs for instance IPC. This introduced two critical regressions:
1. Main thread addons (like `Stylesheet`) were no longer broadcasting `registerRemote` messages because the check in `core/Base.mjs` only checked `me.singleton === true`, failing to account for `me.isMainThreadAddon === true`. This caused errors like `Cannot read properties of undefined (reading 'Stylesheet')`.
2. When the `registerRemote` message was received, `onRegisterRemote` was passing the entire message payload (which includes a message `id` generated by `promiseMessage`) to `generateRemote`. This caused `generateRemote` to mistake the message ID for the remote instance ID, leading to errors like `Invalid remote instance id "neo-main-12"`.

### Proposed Solution
1. Restore `|| me.isMainThreadAddon === true` in `src/core/Base.mjs` inside `initRemote`.
2. Pass a sanitized object to `generateRemote` inside `onRegisterRemote` in `src/worker/mixin/RemoteMethodAccess.mjs` to prevent the message `id` from leaking.
3. Enhance the ID check in `onRemoteMethod` to fallback to `Neo.idMap` if the `Neo.manager.Instance` is not available yet.

## Timeline

- 2026-03-24T21:18:09Z @tobiu added the `bug` label
- 2026-03-24T21:18:09Z @tobiu added the `ai` label
- 2026-03-24T21:18:09Z @tobiu added the `architecture` label
- 2026-03-24T21:18:10Z @tobiu added the `core` label
- 2026-03-24T21:18:42Z @tobiu referenced in commit `b86088c` - "fix(core): Resolve RemoteMethodAccess routing for main thread addons and instance IPC ID collisions (#9547)"
- 2026-03-24T21:18:54Z @tobiu assigned to @tobiu
### @tobiu - 2026-03-24T21:19:11Z

**Input from Gemini 3.1 Pro:**

> ✦ I have successfully resolved the routing issues within `RemoteMethodAccess`.
> 
> **Root Cause Analysis:**
> 1. The first error (`Cannot read properties of undefined (reading 'Stylesheet')`) occurred because `core/Base.mjs` was checking `if (me.singleton === true)` but omitted `|| me.isMainThreadAddon === true`. Main thread addons act like singletons but use `isMainThreadAddon: true`. Because they were excluded, they fell back to the instance routing block and never broadcasted their existence to the App Worker.
> 2. The second error (`Invalid remote instance id "neo-main-12"`) occurred because `onRegisterRemote` in `src/worker/mixin/RemoteMethodAccess.mjs` was passing the raw `registerRemote` message directly to `generateRemote(remote)`. This raw message contains a message `id` appended by `promiseMessage()`. `generateRemote` incorrectly intercepted this message ID and assigned it as the `remoteId` proxy for the target.
> 
> **Implementation Details:**
> - Restored `me.isMainThreadAddon === true` inside `src/core/Base.mjs`'s `initRemote()` to ensure addons broadcast correctly.
> - Sanitized the payload passed to `generateRemote()` inside `onRegisterRemote()` by only passing `className` and `origin`, preventing the `promiseMessage` ID from leaking into the `remoteId` parameter.
> - Enhanced the `onRemoteMethod` resolution logic to optionally fall back to `Neo.idMap` if the `Instance` manager is not yet available, ensuring robustness.
> 
> I will close this ticket.

- 2026-03-24T21:19:35Z @tobiu added parent issue #9449
- 2026-03-24T21:19:48Z @tobiu closed this issue

