molecule-core/canvas/src/components
Hongming Wang 4028b81e04 refactor(canvas): route panel WS subscriptions through global socket
Both AgentCommsPanel and ChatTab's activity-feed opened raw
`new WebSocket(WS_URL)` instances per mount, with no onclose handler
and no reconnect logic. When the underlying connection dropped — idle
timeout, browser background-tab throttle, network jitter — the per-
panel sockets stayed dead until the panel re-mounted (refresh or
sub-tab unmount/remount). Live agent-comms bubbles and live activity
feed lines silently went missing in the gap, manifesting as "the
delegation didn't show up until I refreshed."

The global ReconnectingSocket in store/socket.ts already owns
reconnect, exponential backoff, health-check, and HTTP fallback poll.
Routing component subscribers through it gives every consumer those
guarantees for free, with one TCP connection per tab instead of N.

Three new pieces:

  - store/socket-events.ts: tiny pub/sub bus. emitSocketEvent fan-outs
    every decoded WSMessage to the listener Set; subscribeSocketEvents
    returns an unsubscribe. A throwing listener is logged and isolated
    so it can't break siblings.

  - store/socket.ts: ws.onmessage now calls emitSocketEvent(msg) right
    after applyEvent(msg), so the store's derived state and component
    subscribers stay in lockstep on every event arrival.

  - hooks/useSocketEvent.ts: React hook that registers exactly once
    per mount, capturing the latest handler in a ref so the closure
    sees current state/props without re-subscribing on every render.

Refactored sites:

  - AgentCommsPanel: replaced its WebSocket-in-useEffect block with
    useSocketEvent. Same parsing logic; the panel no longer opens its
    own connection.

  - ChatTab activity feed: split the previous useEffect in two — one
    seeds the activity log when `sending` flips, the other subscribes
    unconditionally and gates work on `sending` inside the handler.
    Hooks can't be conditional, so the gate has to live in the body
    rather than around the effect.

The ws-close graceful-close helper is no longer needed in either
site; the global socket owns its own teardown.

Tests: 6 new tests for the bus contract (single delivery, fan-out
order, unsubscribe, throwing-listener isolation, no-subscriber emit,
duplicate-subscribe Set semantics). All 27 existing socket tests
still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:12:47 -07:00
..
__tests__ merge: sync staging into refactor/remove-canvas-hermes-runtime-profile-2054 (pickup #2099+#2107 TLS fixes) 2026-04-26 12:12:51 -07:00
canvas fix(canvas): clear sendInFlightRef on WS-push reply path 2026-04-27 11:11:58 -07:00
settings fix(canvas/a11y): add type=button to tab toolbar and settings buttons 2026-04-24 14:41:35 +00:00
tabs refactor(canvas): route panel WS subscriptions through global socket 2026-04-27 13:12:47 -07:00
ui fix(canvas/a11y): add aria-hidden to 6 decorative SVGs + aria-label to OrgTokensTab input 2026-04-24 12:40:52 +00:00
A2ATopologyOverlay.tsx fix(canvas): bundle of UX hardening — modals, position stability, error UX, paste 2026-04-24 19:54:43 -07:00
ApprovalBanner.tsx fix(canvas): add type=button to ApprovalBanner action buttons (bug #1669) 2026-04-23 02:15:52 +00:00
AuditTrailPanel.tsx fix(canvas/a11y): add type="button" to ConfirmDialog, AuditTrailPanel, DeleteCascadeConfirmDialog 2026-04-24 12:40:52 +00:00
AuthGate.tsx fix(auth): break infinite redirect loop on /cp/auth/login 2026-04-23 11:16:22 -07:00
BatchActionBar.tsx fix(canvas/a11y): add type="button" to BatchActionBar, EmptyState, SidePanel, CreateWorkspaceDialog 2026-04-24 12:40:52 +00:00
BundleDropZone.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
Canvas.tsx fix(canvas): cascade delete locally so children disappear without WS 2026-04-24 20:51:09 -07:00
CommunicationOverlay.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
ConfirmDialog.tsx fix(canvas/a11y): add type="button" to ConfirmDialog, AuditTrailPanel, DeleteCascadeConfirmDialog 2026-04-24 12:40:52 +00:00
ConsoleModal.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
ContextMenu.tsx fix(canvas/a11y): add type="button" to MissingKeysModal, ContextMenu, CreateWorkspaceDialog tier radio 2026-04-24 12:40:52 +00:00
ConversationTraceModal.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
CookieConsent.tsx fix(quickstart): keep Canvas working post first workspace + hide SaaS cookie banner on localhost 2026-04-23 14:55:33 -07:00
CreateWorkspaceDialog.tsx feat(external-runtime): first-class BYO-compute workspaces + manifest-driven registry 2026-04-24 15:34:10 -07:00
DeleteCascadeConfirmDialog.tsx fix(canvas/a11y): add type="button" to ConfirmDialog, AuditTrailPanel, DeleteCascadeConfirmDialog 2026-04-24 12:40:52 +00:00
EmptyState.tsx feat(canvas+org): env preflight, EmptyState parity, shared useTemplateDeploy hook 2026-04-24 15:15:33 -07:00
ErrorBoundary.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
ExternalConnectModal.tsx fix(canvas): ExternalConnectModal redundant null check on Dialog.Root open prop 2026-04-26 16:36:03 -07:00
Legend.tsx fix(canvas): bundle of UX hardening — modals, position stability, error UX, paste 2026-04-24 19:54:43 -07:00
MemoryInspectorPanel.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
MissingKeysModal.tsx fix(canvas): bundle of UX hardening — modals, position stability, error UX, paste 2026-04-24 19:54:43 -07:00
OnboardingWizard.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
OrgImportPreflightModal.tsx fix(canvas): bundle of UX hardening — modals, position stability, error UX, paste 2026-04-24 19:54:43 -07:00
PricingTable.tsx feat(canvas): /pricing route with plan selector + Stripe checkout 2026-04-15 13:41:44 -07:00
ProvisioningTimeout.tsx refactor(canvas): ProvisioningTimeout uses pruneStaleKeys helper 2026-04-26 14:05:28 -07:00
SearchDialog.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
SidePanel.tsx fix(canvas): plugin install POSTed to /workspaces/undefined/plugins 2026-04-24 22:36:35 -07:00
Spinner.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
StatusDot.tsx fix(canvas): a11y fixes + budget_used TypeScript guard + orgs-page test fix (#1367) 2026-04-21 11:08:24 +00:00
TemplatePalette.tsx fix(canvas): suppress stale provisioning banners + add WS-down HTTP fallback poll 2026-04-24 20:22:15 -07:00
TermsGate.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
Toaster.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
Toolbar.tsx fix(canvas/a11y): add type="button" to remaining canvas component buttons (batch 3) 2026-04-24 12:40:52 +00:00
Tooltip.tsx fix: CWE-78 rm scope, go vet failures, delegation idempotency 2026-04-21 18:22:30 +00:00
WorkspaceNode.tsx merge(staging): resolve conflicts + fix 7 test regressions on top of #2061 2026-04-24 13:50:39 -07:00
WorkspaceUsage.tsx fix(canvas): guard undefined lastErrorRate and period dates in metrics (PR #1250) 2026-04-21 03:22:17 +00:00