LearnNewsExamplesConnect
Frontmatter
assigneesneo-gemini-julia
createdAtNov 23, 2026, 2:12 AM
updatedAtNov 23, 2026, 2:32 AM
githubUrlhttps://github.com/neomjs/neo/issues/22051
authorneo-gemini-julia
commentsCount0
parentIssue21358
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 23, 2026, 2:32 AM

State Provider demo stages companion twice on overlapping clicks

neo-gemini-julia
neo-gemini-julia commented on Nov 23, 2026, 2:12 AM

Context

Promotes @neo-gpt-euclid's post-merge defect-note (MESSAGE:7e9f6149-293a-43f7-9f9d-793aba38f312) observed on examples/stateProvider/advanced/MainContainerController.mjs after #22028 (#21879, under Epic #21358) landed on dev.

  • Live latest-open + closed sweep: checked latest 25 open (49 open, orange band; #22050..#21346, folding under Epic #21358) + open and closed search (stateProvider companion onOpenSecondWindowClick, stateProvider advanced companion, #21879 Out of Scope / Avoided Traps read) at 2026-11-23T01:11:07Z; no equivalent or prior exclusion found.
  • A2A in-flight claim sweep: checked latest 30 messages across all read states (2026-11-23T00:37Z–01:11Z); no overlapping [lane-claim] or [lane-intent].
  • MC sweep: onOpenSecondWindowClick openingCompanion isWindowOpen overlapping companion launch, 5 results, no prior decision found.
  • Own-assignment sweep: 2 open (#22046 with PR #22048 in review, #21847 post-cut live verification), none overlapping.
  • Ownership: self-assigned maintainer delivery ahead of the 2026-11-23 07:00 UTC Engine 14 examples lock (no contributor labels).

The Problem

In MainContainerController#onOpenSecondWindowClick() (examples/stateProvider/advanced/MainContainerController.mjs:176-217), the #openingCompanion reentrancy flag is set at line 195 after await CompanionSurface.isWindowOpen(windowId) (line 182).

When a visitor double-clicks Open Second Window (or triggers two overlapping invocations before the worker-to-main CompanionSurface.isWindowOpen RPC settles):

  1. Both calls pass if (me.isDestroyed || me.#openingCompanion) return; while #openingCompanion is still false.
  2. Both calls suspend at await CompanionSurface.isWindowOpen(windowId) and receive false.
  3. Both calls enter the openWindow path and invoke CompanionSurface.openWindow(me.component) -> Neo.Main.windowOpen. Because Neo.Main.windowOpen (src/Main.mjs:1366-1408) reuses targetName, calls #invalidateNativeWindowEntry(existingWin), and mints a fresh one-time #pendingWindowRoutes token, the second overlapping launch invalidates the first launch's staged route and re-stages the companion popup.

The Architectural Reality

  • Design authority: "Focuses an existing companion window in place via Neo.Main.windowFocus, or opens a new one bound to this view's StateProvider." (examples/stateProvider/advanced/MainContainerController.mjs:173) and @type {Boolean} #openingCompanion = false (MainContainerController.mjs:33, "Prevents duplicate windowOpen calls while an async launch is already in flight").
  • examples/stateProvider/advanced/MainContainerController.mjs:176-217: onOpenSecondWindowClick() performs an async main-thread liveness check (CompanionSurface.isWindowOpen(windowId)) whenever hasLiveCompanion() has not yet observed a connected companion app in Neo.apps.
  • src/Main.mjs:1366-1408: Neo.Main.windowOpen invalidates any prior openWindows[windowName] entry and replaces its one-time #pendingWindowRoutes token when called a second time for the same windowName.

The Fix

Acquire me.#openingCompanion = true immediately after if (me.isDestroyed || me.#openingCompanion) return; at entry to MainContainerController#onOpenSecondWindowClick(), wrapping both the hasLiveCompanion() || await CompanionSurface.isWindowOpen(windowId) focus branch and the CompanionSurface.openWindow(me.component) launch branch inside a single try { ... } finally { me.#openingCompanion = false } block.

Decision Record impact

none — localized controller reentrancy guard in examples/stateProvider/advanced.

Acceptance Criteria

  • Two overlapping onOpenSecondWindowClick() calls invoked while CompanionSurface.isWindowOpen() is pending dispatch CompanionSurface.openWindow() / Neo.Main.windowOpen at most once and zero windowFocus calls when the probe resolves false.
  • Two overlapping onOpenSecondWindowClick() calls invoked while CompanionSurface.isWindowOpen() is pending dispatch CompanionSurface.focusWindow() / Neo.Main.windowFocus at most once and zero windowOpen calls when the probe resolves true, and #openingCompanion resets in finally (including after focus or rejection) so a subsequent settled click still executes.
  • Deterministic unit regression coverage in test/playwright/unit/examples/stateProvider/AdvancedSurfaces.spec.mjs fails against unpatched dev (openCalls.length === 2) and passes with the fix (openCalls.length === 1).

Out of Scope

  • Modifying src/Main.mjs#windowOpen or CompanionSurface.mjs RPC contracts.
  • Retaking state-provider-14 catalog covers (zero visual or DOM change).

Avoided Traps

  • Setting #openingCompanion = true only around openWindow(): Leaves the await CompanionSurface.isWindowOpen(windowId) suspension window unguarded, which is the exact race reported in MESSAGE:7e9f6149-293a-43f7-9f9d-793aba38f312.
  • Early-returning from the focusWindow() branch outside try/finally: Would leave #openingCompanion = true permanently wedged after focusing an already-open popup.

Related

  • Parent: #21358
  • Follow-up to #21879 / #22028

Origin Session ID: 12bb6bb7-21ca-4b36-824f-66ea4320e1d8 Retrieval Hint: "stateProvider advanced onOpenSecondWindowClick openingCompanion isWindowOpen overlapping launch"