Skip to content

fix(shell,slack): harden cross-frame validation, catalog sync, and RPC routing - #325

Open
jgindin wants to merge 7 commits into
pr6-samples-demos-v1-0from
pr7-qa-cleanup
Open

jgindin wants to merge 7 commits into
pr6-samples-demos-v1-0from
pr7-qa-cleanup

Conversation

@jgindin

@jgindin jgindin commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary

  • Cross-frame validation & security (CrossFrameValidator, HostCommunication): Define CatalogHandshakeErrorPayload and isCatalogHandshakeErrorPayload in CrossFrameValidator (re-exporting CatalogHandshakeErrorPayload from HostCommunication), validate MCP_REQUEST payloads before mcpManager.callTool, and drop prototype-polluted envelopes immediately after construction (before RENDERER_READY, CONSOLE_LOG, MCP_REQUEST, and DATA_MODEL_CHANGE side effects).
  • Catalog management & test doubles (CatalogManagement, catalog-domain.ts, FakeCatalogManagement): Extract pure mergeCatalogs and resolveProtocolVersion helpers into catalog-domain.ts, guard rawCatalogs cloning against non-cloneable entries, and centralize test doubles via createFakeCatalogManagement (using mergeCatalogs/resolveProtocolVersion by default) across unit specs.
  • Renderer-switch draft sync & Slack recursive refs (StateSync, RawFrame, samples/react-slack-catalog): Reset previousCatalogId on null catalog after handshake and update StateSync.syncCatalogDraft() (void) to prevent stale draft protocol mismatches across renderer switches; add refSchemaOverride in samples/react-slack-catalog to silence recursive-reference warnings with structural assertions in catalog.spec.ts.
  • Unscoped inline & Canvas RPC regression specs (A2aChatView): Cover unscoped inline RPCs with an unrelated open Canvas (fn-unscoped-inline-1) and non-auto-opened Canvas B unscoped RPCs with Canvas A open (fn-unscoped-canvas-b) in a2a-chat-view.spec.ts.
  • Tooling & E2E preflight (scripts/ensure-e2e-samples.mjs, utils/json.ts, shell/e2e/): Harden JSON token scanning, fix E2E mock escaping, ensure E2E sample build preflight, verify Slack-to-Angular v1.0 switching in slack-renderer.e2e.ts, stamp protocolVersion: '1.0' in stubRendererHtml, and reuse stubRendererHtml in v09-compat-regression.e2e.ts.
    feat(samples,shell): restore A2UI v0.9 alongside v1.0 #334 restores v0.9 alongside v1.0; merge it together with this PR.
  • Detached handshake recovery & validator DRY (HostCommunication, CatalogManagement, CrossFrameValidator): Expose HostCommunication.isRegisteredWindow and track handshakeWindow in CatalogManagement so a detached frame remounting under the same resolvedUrl clears the stale watchdog, re-issues GET_CATALOG, and ignores late A2UI_CATALOG responses from a superseded handshakeWindow; extract CrossFrameValidator.validateOptionalObjectPayload across GET_CATALOG, GET_COMPONENT_USAGES, and GET_DEMOS.
  • Handshake window kept across the catalog resource reset (CatalogManagement, 887fcb08): handleRendererReady recorded the announcing window in handshakeWindow before writing the handshake state. When the renderer URL had changed and nothing had read the cached-catalog resource since, that write ran the resource's params function, which cleared handshakeWindow; the watchdog was armed afterwards, so the handshake ran without its window. The source-window check in handleCatalogEnvelope then accepted an A2UI_CATALOG from any window, and the takeover branch could not replace a detached frame. handshakeWindow is now assigned after the state writes, immediately before the watchdog is armed. Five unit tests cover it: two fail without the fix on a URL change (catalog from another window ignored; takeover by a replacement frame), one fails without it on first load (catalog from another window ignored, watchdog reported), and two pass with and without it and guard the first-load path (catalog from the announcing window, and a catalog with no source window, are committed).

Commits

f868485c refactor(shell): share typed CatalogHandshakeErrorPayload guard
c7a33de8 test(shell): centralize CatalogManagement test doubles
a8f84368 fix(shell,e2e): address review nits on json token scanner, e2e mock escaping, and sample build preflight
c38279f9 fix(slack,shell): silence catalog recursive-ref warnings and prevent stale draft protocol mismatch on renderer switch
b4d45c2d fix(shell,slack): address PR #325 review feedback and QA cleanups
549d16f1 fix(shell,e2e): recover detached handshakes and clean up stubs
887fcb08 fix(shell): keep handshake window across catalog resource reset

26 files changed, 2381 insertions(+), 653 deletions(-)

Stack

Stacked PR 7/7 — base: pr6-samples-demos-v1-0 → merge in order:

Verification

Run at 887fcb08 (pr7-qa-cleanup with the handshake-window fix):

  • corepack yarn --cwd shell ng test --no-watch: 2792/2792 passed across 119 files
  • corepack yarn lint, corepack yarn tsc, corepack yarn prettier:check: all exit 0

Run at e3cd9820 (the same fix before three unit tests were added to it; production code identical to 887fcb08):

  • corepack yarn workspace a2ui-bridge clean && corepack yarn build, corepack yarn generate:demos:check: exit 0
  • corepack yarn test: passes across all workspaces (scripts: 48, a2ui-bridge: 331, lit-basic-catalog: 16, ng-basic-catalog: 22, react-basic-catalog: 17, react-slack-catalog: 197, a2ui-composer-shell: 2789)
  • Headless Playwright specs with --workers=1 --retries=0 (e2e/slack-assistant.e2e.ts, e2e/slack-renderer.e2e.ts, e2e/demos.e2e.ts, e2e/v09-compat-regression.e2e.ts): 48/48 passed (6.1m)
  • Full headless E2E suite (corepack yarn --cwd shell e2e-headless): 232/232 passed (10.1m)

Unresolved observation: one demos stress run (e2e/demos.e2e.ts --repeat-each=5 --workers=4 --retries=0) on the rebased #334 branch, which carries this fix, failed 2/90 at demos.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); the pre-fix #334 tip 930143a2 passed 360/360 in the same session. Static analysis found no path by which the fix can stall the workspace handshake. The artifacts of the failing run were not kept; cause not established.

The results below were recorded before the fix.

Run at the tip of the stack (pr7-qa-cleanup, 549d16f1):

  • corepack yarn test passes across all workspaces (scripts: 48, a2ui-bridge: 331, lit-basic-catalog: 16, ng-basic-catalog: 22, react-basic-catalog: 17, react-slack-catalog: 197, a2ui-composer-shell: 2787)
  • corepack yarn prettier:check, corepack yarn generate:demos:check, corepack yarn build, corepack yarn lint, corepack yarn tsc, and corepack yarn --cwd shell tsc --project tsconfig.spec.json --noEmit all exit 0
  • Headless Playwright E2E specs with --workers=1 --retries=0: the 6 core specs (e2e/function-rpc-journeys.e2e.ts, e2e/guest-frame-sends.e2e.ts, e2e/v09-compat-regression.e2e.ts, e2e/slack-renderer.e2e.ts, e2e/a2a-multi-frame-surfaces.e2e.ts, e2e/a2a-inline-surface-order.e2e.ts) pass (45/45), and e2e/slack-assistant.e2e.ts --repeat-each=10 passes (160/160)

Pre-launch Checklist

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

⚡ A2UI Composer PR Preview

Your automated preview is successfully live (commit 887fcb0):
👉 Launch PR Preview

Note: This environment will be wiped automatically when the PR is merged or closed.

@jerelvelarde

Copy link
Copy Markdown
Contributor

Two things I noticed on this branch while recording the renderer-panels follow-up to #216. Both appear on this branch (17ea0bdc) and neither appears on main (fb0a4281), checked with the same Playwright run on each.

  1. Recursive-reference warnings when the Slack renderer loads. The Errors tab reads "Errors (37)", and every entry is "Recursive reference detected at #! Defaulting to any". They come from the Slack sample's catalog, and the preview logs each one as WARN [PREVIEW].
  2. A protocol-version error after switching renderers. Switching from the Slack renderer to Angular Basic logs "Payload protocol version v0.9 does not match active renderer protocol version v1.0."

To reproduce: open Composer on this branch, load the Slack renderer and look at the Errors tab, then switch to Angular Basic.

@jgindin

jgindin commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @jerelvelarde for catching these! Both regressions have been addressed and verified in commit c38279f9301b37b11d34322248e3248052f48951:

  1. 37 Recursive reference detected warnings when the Slack renderer loads:

    • Root Cause: Under @a2ui/web_core: 0.15.0, basic component and function schemas reference AccessibilityAttributes and DynamicValue, which form a cyclic FunctionCall -> args -> DynamicValue -> FunctionCall Zod schema graph. Because catalog.ts previously ran zodToJsonSchema with $refStrategy: 'none' before running processRefs() to substitute REF: descriptions with $ref, zod-to-json-schema traversed into those cyclic definitions and logged 37 WARN [PREVIEW] Recursive reference detected at #/...! Defaulting to any warnings.
    • Fix: Added override: refSchemaOverride to zodToJsonSchema in samples/react-slack-catalog/src/catalog.ts to short-circuit Zod definitions whose description starts with REF: (returning {description} immediately). This prevents cyclic recursion during schema generation while allowing processRefs() to subsequently rewrite the nodes to clean $ref pointers, producing the exact same slackCatalogJson with 0 warnings. Added a unit test in samples/react-slack-catalog/src/catalog.spec.ts asserting zero console.warn calls and exact schema parity.
  2. PROTOCOL_VERSION_MISMATCH error after switching from Slack renderer to Angular Basic:

    • Root Cause: When switching from Slack (v0.9, custom samplePayload) to Angular Basic (v1.0), StateSync's toObservable(activeCatalog) subscription and RawFrame's queueMicrotask draft update ran asynchronously, while RawFrame's synchronous catalog/protocol effect() and RENDERER_READY/A2UI_CATALOG message handlers ran immediately, validating the stale v0.9 samplePayload against v1.0.
    • Fix:
      • In StateSync, tracked lastSamplePayload and added synchronous syncCatalogDraft() to reconcile _activeDraft with active protocol and catalog changes without waiting for asynchronous observable ticks, while safely preserving user edits.
      • In RawFrame, extracted renderSynchronizedCurrentLayout() to invoke stateSync.syncCatalogDraft() and skip validating or dispatching a stale layout when currentLayout !== this.stateSync.activeDraft().
      • Added comprehensive unit tests in state-sync.spec.ts and raw-frame.spec.ts, as well as a full Playwright E2E regression test in shell/e2e/slack-renderer.e2e.ts verifying that switching from Slack to Angular Basic produces 0 warnings and 0 errors.

Comment thread shell/e2e/slack-renderer.e2e.ts Resolved
Comment thread shell/src/app/preview/raw/raw-frame.ts Resolved
Comment thread package.json Resolved
@jgindin
jgindin added this pull request to stack #332 November 16, 2026 13:16
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 17, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 17, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 17, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
@jgindin jgindin changed the title refactor(shell): unify cross-frame validation contracts and CatalogManagement test doubles fix(shell,slack): harden cross-frame validation, catalog sync, and RPC routing Nov 17, 2026
jgindin added a commit that referenced this pull request Nov 17, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 19, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and deduplicate A2aChatView RPC stream
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
jgindin added a commit that referenced this pull request Nov 20, 2026
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and add unscoped A2aChatView RPC specs
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
Define isCatalogHandshakeErrorPayload and CatalogHandshakeErrorPayload
in CrossFrameValidator, re-exporting both from HostCommunication.
Enforce the guard in CrossFrameValidator.validateCatalogPayload, guard
the rawCatalogs sanitization loop against uncaught exceptions, and drop
prototype-polluted non-catalog messages prior to recording.
Provide createMockCatalogManagement in testing/catalog-management-fake
to share CatalogManagement test doubles across specs, replacing
duplicate ad-hoc mocks in routes, rendered-frame, and chat specs.
…stale draft protocol mismatch on renderer switch
- Guard prototype pollution before HostCommunication side effects
- Validate MCP_REQUEST payloads and add unscoped A2aChatView RPC specs
- Extract catalog-domain helpers, rename Fake helper, recover clones
- Make syncCatalogDraft void and clear previousCatalogId on null catalog
- Assert non-tautological Slack catalog invariants without TEST_ONLY
- Update slack-renderer E2E v1.0 switch check and package.json scripts
Expose HostCommunication.isRegisteredWindow and track handshakeWindow in

CatalogManagement so a detached frame remounting under the same

resolvedUrl clears the stale watchdog and re-issues GET_CATALOG (calling

isRegisteredWindow directly). Also ignore late A2UI_CATALOG responses

from a superseded handshakeWindow. Extract

CrossFrameValidator.validateOptionalObjectPayload across GET_CATALOG,

GET_COMPONENT_USAGES, and GET_DEMOS, stamp protocolVersion '1.0' in

stubRendererHtml when version is 'v1.0', and reuse stubRendererHtml in

v09-compat-regression.e2e.ts.
handleRendererReady recorded the announcing window in handshakeWindow
and then wrote the handshake state. When the renderer URL had changed
and nothing had read the cached-catalog resource since, that write
made the resource's params function run. It sees a new URL and clears
the watchdog timer and handshakeWindow, on the assumption that they
belong to the previous renderer. The watchdog was armed afterwards, so
the new handshake ran with a timer but without its window.

Two guards compare against handshakeWindow and could not match such a
handshake: the source-window check in handleCatalogEnvelope accepted
an A2UI_CATALOG from any window, and the takeover branch never let a
replacement frame take over from a detached one.

handshakeWindow is now assigned after the state writes, immediately
before the watchdog is armed. No statement in between reads it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants