LearnNewsExamplesServices
Frontmatter
id8312
titleFix Neural Link Window Topology Race Condition
stateClosed
labels
bugai
assigneestobiu
createdAtJan 4, 2026, 3:20 PM
updatedAtJan 4, 2026, 3:37 PM
githubUrlhttps://github.com/neomjs/neo/issues/8312
authortobiu
commentsCount1
parentIssue8169
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 4, 2026, 3:37 PM

Fix Neural Link Window Topology Race Condition

Closed v11.18.0 bugai
tobiu
tobiu commented on Jan 4, 2026, 3:20 PM

The Neural Link Client (Neo.ai.Client) currently relies on Neo.manager.Window to report connected windows. However, Neo.manager.Window is imported dynamically in Neo.worker.App only when useSharedWorkers is true. This creates a race condition where the Client might connect and attempt to send the window topology before the Window Manager is loaded, resulting in an empty window list (0 connected windows) in the Neural Link status.

Proposed Fix: Add a static import for Neo.manager.Window in src/ai/Client.mjs. Since the Neural Link functionality inherently requires window awareness (for topology, drag-drop, etc.), the Window Manager should be a hard dependency for the AI Client, ensuring it is always available when the Client initializes.

Tasks:

  1. Modify src/ai/Client.mjs to import Neo.manager.Window.
  2. Remove the optional chaining checks for Neo.manager.Window inside Client.mjs where appropriate, as it will now be guaranteed.
tobiu added the bug label on Jan 4, 2026, 3:20 PM
tobiu added the ai label on Jan 4, 2026, 3:20 PM
tobiu added parent issue #8169 on Jan 4, 2026, 3:21 PM
tobiu assigned to @tobiu on Jan 4, 2026, 3:21 PM
tobiu referenced in commit 8374db6 - "Fix Neural Link connection logic & race condition #8312" on Jan 4, 2026, 3:35 PM
tobiu
tobiu Jan 4, 2026, 3:37 PM

Input from Gemini 3:

✦ Fixed the window topology race condition and a WebSocket double-encoding bug.

Changes:

  1. Race Condition: src/worker/App.mjs now captures the import('../ai/Client.mjs') promise and awaits it in onConnect. This ensures Neo.ai.Client is fully loaded before the connect event is fired, guaranteeing that window_connected notifications are sent reliably.
  2. Dependency: src/ai/Client.mjs now statically imports Neo.manager.Window, ensuring the Window Manager is always available when the Neural Link Client is active.
  3. Communication Bug: Removed double JSON stringification in Client.mjs sendMessage calls. The Neo.data.connection.WebSocket class handles serialization internally; the previous double encoding caused the server to receive strings instead of objects, leading to ignored messages.
tobiu closed this issue on Jan 4, 2026, 3:37 PM