Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a windowUnregistered$ observable to HostCommunication to notify subscribers when a guest window's registration is removed. CatalogManagement subscribes to this stream to immediately cancel handshakes waiting on unregistered windows when a live catalog is already established, replacing the previous approach of waiting for the 5-second watchdog timer to expire. Comprehensive unit tests have been added to verify the unregistration emission logic and handshake cancellation behavior. I have no feedback to provide.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
| expect(service.isHandshakeInProgress()).toBe(true); | ||
|
|
||
| registered.delete(win2); | ||
| unregisterWindow(registered, win2); |
There was a problem hiding this comment.
Nit: now that 757bc43 switched this spec (L1854-1900) and the next one (L1902-1929) to unregisterWindow, both are strict subsets of the new specs at L2211-2242 and L2274-2302, which assert the state both right after unregistration and after 5000 ms. Could drop the two earlier copies.
HostCommunication gains windowUnregistered$, a plain Subject exposed read-only like sendToServer$. unregisterIframe emits the guest window as its last step, and only when the window was registered before the call and is not registered after it. A window still held by another registration, an unknown target and a repeated unregistration do not emit. registerIframe(null) emits each window the registry held. The subject completes in ngOnDestroy. Nothing subscribes yet; the catalog handshake uses it in the next commit.
CatalogManagement subscribes to HostCommunication.windowUnregistered$ next to its messageStream$ subscription. When the unregistered window is the one the handshake is waiting on and a live catalog is already established for the current renderer URL, the handshake ends at once: the watchdog timer is cleared, the handshake window is dropped and the state settles, with no error. In every other case nothing changes: a different window, no handshake in progress, or no live catalog for the current URL (first handshake, cache-only catalog, prior failure, URL change) leave the 5 s watchdog and the takeover branch as they were. The subscription is outside the concatMap so that a cancellation does not wait behind an asynchronous catalog commit. The live-catalog check calls syncResolutionGeneration() first, so a catalog from the previous renderer URL does not count before the effect has observed the change. The late suppression branch in the watchdog callback is still present; a later commit removes it. The HostCommunication doubles in demos.spec.ts and chat-message.spec.ts gain windowUnregistered$, since both specs build a real CatalogManagement over them.
A RENDERER_READY can wait in the concatMap behind an asynchronous catalog commit. If its frame is unregistered meanwhile, the windowUnregistered$ notification has already passed without finding a handshake to cancel, and the handshake started afterwards could only time out. handleRendererReady now returns without starting a handshake when the announcement has a source window, that window is not registered and a live catalog is established for the current renderer URL. Unchanged: a RENDERER_READY without a source window, a registered source window, and an unregistered source window when no live catalog is established all start a handshake as before. MockHostCommunication in demos.spec.ts gains isRegisteredWindow, returning true. The real service always has the method, and every frame that announces in that spec is a mounted DemoCard frame, which GuestFrame registers. No assertion in that spec changes.
The watchdog callback no longer checks, when the 5 s timer fires,
whether the handshake window is still registered. That case is now
handled when the frame is unregistered (cancel) or when its queued
RENDERER_READY is processed (skip), so the branch, its TODO and the
{settle} option of resetHandshakeWatchdog are removed. The unregister
handler settles the handshake state itself.
_hasEstablishedLiveCatalog stays; its JSDoc now describes the two
places that read it.
Six existing specs that modelled an unregistration only by changing
what the isRegisteredWindow double returns now go through the
unregisterWindow spec helper, which also emits windowUnregistered$,
as the real HostCommunication does. Their assertions are unchanged.
Remove the two earlier detached-window watchdog specs that are strict subsets of the newer immediate-clear and pre-catalog watchdog specs.
757bc43 to
0029c5d
Compare
Description
Summary
This PR cancels an in-flight catalog handshake at the moment its frame is unregistered. It replaces the workaround from
#334, which let the 5 s watchdog run and then suppressed its error if the handshake window was no longer registered./demos, when a card is evicted before it answersGET_CATALOG,isHandshakeInProgress()returns tofalseandhandshakeState()to'settled'immediately, instead of up to 5 s later. No error is reported, as before.A2UI_CATALOGhandshake succeeded for that URL since the last URL change. A cache-only catalog or an earlier failed handshake does not count.RENDERER_READYthat is processed after its frame was already unregistered no longer starts a handshake, under the same live-catalog condition (see Changes).#334: if a registered iframe element's window is replaced in place (the element is registered again, or a new document announces itself in it) while a handshake is waiting on the old window, and the new document never announcesRENDERER_READYwithin the watchdog period, the watchdog error is now reported.#334stayed silent there, because at timer time the old window was no longer registered. No unregister notification exists for that case, since the element is still registered. When the new document does announce, the existing takeover branch handles it as before.Watchdog timeout: A2UI_CATALOG not received within 5 seconds.isStaleContinuation), the source-window guard inhandleCatalogEnvelope, thepriorWindowDetachedtakeover branch,CATALOG_WATCHDOG_TIMEOUT_MSandCATALOG_WATCHDOG_MESSAGE.#325's handshake-window fix (887fcb08): the cancel matches a handshake by its window, and before that fix a handshake started right after a renderer URL change lost its window. That ordering issue was listed here as a known limit in an earlier draft; it is now fixed in#325.Changes
HostCommunication.windowUnregistered$(shell/src/app/shell/host-communication/host-communication.ts): a plainSubject<Window>exposed read-only, likesendToServer$.unregisterIframeemits the window as its last step, only if the window was registered before the call and is not registered after it. A window still held by another registration, an unknown target and a repeated unregistration do not emit.registerIframe(null)emits each window the registry held. A window replaced in place on a still-registered element does not emit. The subject completes inngOnDestroy.shell/src/app/storage/catalog-management/catalog-management.ts):CatalogManagementsubscribes next to itsmessageStream$subscription, outside theconcatMap, withtakeUntilDestroyed()and the handler inuntracked. If the emitted window is the handshake window, a handshake is in progress and a live catalog is established for the current URL, the timer is cleared, the handshake window is dropped and the state settles. The live-catalog check callssyncResolutionGeneration()first, so a catalog from the previous renderer URL does not count.handleRendererReady): aRENDERER_READYcan wait in theconcatMapbehind an asynchronous catalog commit. If its frame is unregistered meanwhile, the notification has already passed. The handshake is therefore not started when the announcement has a source window, that window is not registered, and a live catalog is established for the current URL. ARENDERER_READYwithout a source window, and any announcement when no live catalog is established, start a handshake as before.TODO(follow-up), and the{settle}option ofresetHandshakeWatchdog._hasEstablishedLiveCatalogstays; it is now read by the two places above.Tests Whose Setup Changed / Redundant Specs Dropped
Four existing specs in
catalog-management.spec.tsmodelled an unregistration only by changing what theisRegisteredWindowdouble returns. They now call one spec helper,unregisterWindow, which removes the window from the set and emitswindowUnregistered$, as the realHostCommunicationdoes. Each change is one line (registered.delete(w)->unregisterWindow(registered, w)); no assertion changed:does not swallow watchdog error when a prior handshake failed and a subsequent frame detachescompletes a subsequent RENDERER_READY to A2UI_CATALOG handshake normally after a silent detached clearlogs watchdog error after A -> B -> A renderer URL switches without a fresh live handshakelogs watchdog error when catalog is hydrated only from IndexedDB cache and frame detachesTwo earlier
#334detached-window specs (cancels stale watchdog without error when a secondary frame detaches after catalog receiptandstill fires watchdog error if an unregistered initial frame times out before any catalog receipt) were dropped in0029c5d9because every post-unregistration assertion in them was a strict subset of the new specs below (and the kept spec checksactiveCatalog()?.catalogIdin setup):clears the handshake at once when its window is unregistered after a live catalogandkeeps the watchdog running when the handshake window is unregistered before any live catalog.fires watchdog error when catalog is established and handshake window is still registeredis not changed.Test notes
host-communication.spec.ts(5): emission on unregister with the registry already updated; the remembered window for an iframe detached beforeunregisterIframe; no emission while another registration holds the window; no emission for an unknown or already removed target;registerIframe(null).catalog-management.spec.ts(7): immediate clear with no timer advance and no error after 5000 ms; a different window unregistered; no live catalog (watchdog error at 5 s); a live catalog from the previous URL does not count; queuedRENDERER_READYfor an unregistered window is skipped; an unregistered window with no live catalog still starts a handshake; aRENDERER_READYwithout a source window still starts a handshake.does not count a live catalog from the previous renderer URLchanges the URL and announces with no tick and no signal read in between. It fails if the handler does not callsyncResolutionGeneration()and passes with it.MockHostCommunicationindemos.spec.tsgainswindowUnregistered$andisRegisteredWindow(returnstrue: every frame announcing in that spec is a mounted DemoCard frame, whichGuestFrameregisters). The double inchat-message.spec.tsgainswindowUnregistered$. No assertion in either spec changed.Commits
2373579ffeat(shell): emit windowUnregistered$ from HostCommunication2cd2eb05fix(shell): cancel catalog handshake when its frame unregisters4d643c0efix(shell): skip catalog handshake for an unregistered frame4e897075refactor(shell): drop the late watchdog suppression branch0029c5d9test(shell): drop redundant detached-window handshake specs6 files changed, 471 insertions(+), 101 deletions(-)Stack
Stacked PR — base:
pr8-restore-v0-9-renderers-> merge in order:pr5-shell-v1-0-copilot-rpc-a2apr6-samples-demos-v1-0pr7-qa-cleanup(includes the handshake-window fix887fcb08)pr8-restore-v0-9-renderers(rebased onto887fcb08, tip2dfa7517)pr9-cancel-handshake-on-unregister(this PR;fix(shell): cancel catalog handshake when its frame unregisters, stacked on feat(samples,shell): restore A2UI v0.9 alongside v1.0 #334, tip0029c5d9)Verification
Run locally at
0029c5d9(pr9-cancel-handshake-on-unregistertip, rebased onto2dfa7517), one command at a time:corepack yarn workspace a2ui-bridge clean && corepack yarn build: exit 0corepack yarn test: 3690/3690 passed (scripts: 48,a2ui-bridge: 338,lit-basic-catalog: 26,ng-basic-catalog: 34,react-basic-catalog: 26,react-slack-catalog: 197,a2ui-composer-shell: 3021)corepack yarn lint,corepack yarn tsc,corepack yarn prettier:check,corepack yarn generate:demos:check(46 demos): all exit 0shell/,E2E_HEADLESS=true corepack yarn playwright test --project=e2e --workers=1 --retries=0 e2e/demos.e2e.ts e2e/dual-version-renderers.e2e.ts e2e/slack-assistant.e2e.ts e2e/gallery.e2e.ts: 51/51 passed (6.0m)corepack yarn --cwd shell e2e-headless): initial run 243/244 passed (9.1m; 1 timeout ate2e/guest-frame-sends.e2e.ts:587), sequential rerun (e2e/guest-frame-sends.e2e.ts --workers=1 --retries=0) 24/24 passed (3.8m), clean fulle2e-headlessrerun 244/244 passed (10.4m)Prior pre-R2 stress runs at
757bc433(before rebase onto2dfa7517and dropping the two duplicate specs):demos.e2e.ts --repeat-each=5ran twice (90/90 and 90/90),demo-card-commit-accuracy.e2e.ts --repeat-each=5passed 25/25, ande2e-headlessran twice (244/244 and 244/244).Not run at
0029c5d9: visual regression (test:visual), stress reruns (--repeat-each=5),addlicense -check(no new files), CI.Known limits
isHandshakeInProgress()staystrueuntil the watchdog fires and reports its error. This is deliberate: cancelling silently there can leave the shell with no catalog, no error and nothing pending.#334branch failed 2/90 atdemos.e2e.ts:258(header title missing after 5 s). It was not reproduced in 7 further plain runs of the same command on that branch (630/630, four of them with temporary console logging in the shell) plus 60/60 runs of that test alone, nor in 720 traced runs (4 unrelated timeouts);930143a2passed 360/360 in the same session, and the two pre-R2 stress runs on this branch passed 180/180. Static analysis found no path by which#325's fix can stall the workspace handshake. The artifacts of the failing run were not kept; cause not established.Pre-launch Checklist