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):
- Both calls pass
if (me.isDestroyed || me.#openingCompanion) return; while #openingCompanion is still false.
- Both calls suspend at
await CompanionSurface.isWindowOpen(windowId) and receive false.
- 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
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"
Context
Promotes
@neo-gpt-euclid's post-mergedefect-note(MESSAGE:7e9f6149-293a-43f7-9f9d-793aba38f312) observed onexamples/stateProvider/advanced/MainContainerController.mjsafter#22028(#21879, under Epic #21358) landed ondev.#22050..#21346, folding under Epic #21358) + open and closed search (stateProvider companion onOpenSecondWindowClick,stateProvider advanced companion,#21879Out of Scope/Avoided Trapsread) at2026-11-23T01:11:07Z; no equivalent or prior exclusion found.2026-11-23T00:37Z–01:11Z); no overlapping[lane-claim]or[lane-intent].onOpenSecondWindowClick openingCompanion isWindowOpen overlapping companion launch, 5 results, no prior decision found.#22046with PR#22048in review,#21847post-cut live verification), none overlapping.2026-11-23 07:00 UTCEngine 14 examples lock (no contributor labels).The Problem
In
MainContainerController#onOpenSecondWindowClick()(examples/stateProvider/advanced/MainContainerController.mjs:176-217), the#openingCompanionreentrancy flag is set at line195afterawait CompanionSurface.isWindowOpen(windowId)(line 182).When a visitor double-clicks Open Second Window (or triggers two overlapping invocations before the worker-to-main
CompanionSurface.isWindowOpenRPC settles):if (me.isDestroyed || me.#openingCompanion) return;while#openingCompanionis stillfalse.await CompanionSurface.isWindowOpen(windowId)and receivefalse.openWindowpath and invokeCompanionSurface.openWindow(me.component)->Neo.Main.windowOpen. BecauseNeo.Main.windowOpen(src/Main.mjs:1366-1408) reusestargetName, calls#invalidateNativeWindowEntry(existingWin), and mints a fresh one-time#pendingWindowRoutestoken, the second overlapping launch invalidates the first launch's staged route and re-stages the companion popup.The Architectural Reality
"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)) wheneverhasLiveCompanion()has not yet observed a connected companion app inNeo.apps.src/Main.mjs:1366-1408:Neo.Main.windowOpeninvalidates any prioropenWindows[windowName]entry and replaces its one-time#pendingWindowRoutestoken when called a second time for the samewindowName.The Fix
Acquire
me.#openingCompanion = trueimmediately afterif (me.isDestroyed || me.#openingCompanion) return;at entry toMainContainerController#onOpenSecondWindowClick(), wrapping both thehasLiveCompanion() || await CompanionSurface.isWindowOpen(windowId)focus branch and theCompanionSurface.openWindow(me.component)launch branch inside a singletry { ... } finally { me.#openingCompanion = false }block.Decision Record impact
none— localized controller reentrancy guard inexamples/stateProvider/advanced.Acceptance Criteria
onOpenSecondWindowClick()calls invoked whileCompanionSurface.isWindowOpen()is pending dispatchCompanionSurface.openWindow()/Neo.Main.windowOpenat most once and zerowindowFocuscalls when the probe resolvesfalse.onOpenSecondWindowClick()calls invoked whileCompanionSurface.isWindowOpen()is pending dispatchCompanionSurface.focusWindow()/Neo.Main.windowFocusat most once and zerowindowOpencalls when the probe resolvestrue, and#openingCompanionresets infinally(including after focus or rejection) so a subsequent settled click still executes.test/playwright/unit/examples/stateProvider/AdvancedSurfaces.spec.mjsfails against unpatcheddev(openCalls.length === 2) and passes with the fix (openCalls.length === 1).Out of Scope
src/Main.mjs#windowOpenorCompanionSurface.mjsRPC contracts.state-provider-14catalog covers (zero visual or DOM change).Avoided Traps
#openingCompanion = trueonly aroundopenWindow(): Leaves theawait CompanionSurface.isWindowOpen(windowId)suspension window unguarded, which is the exact race reported inMESSAGE:7e9f6149-293a-43f7-9f9d-793aba38f312.focusWindow()branch outsidetry/finally: Would leave#openingCompanion = truepermanently wedged after focusing an already-open popup.Related
#21879/#22028Origin Session ID: 12bb6bb7-21ca-4b36-824f-66ea4320e1d8 Retrieval Hint: "stateProvider advanced onOpenSecondWindowClick openingCompanion isWindowOpen overlapping launch"