Skip to content

fix(hub): reset message deltas across instances - #486

Draft
SaKaNa-Y wants to merge 7 commits into
devframes:mainfrom
SaKaNa-Y:fix/message-cursor-instance
Draft

SaKaNa-Y wants to merge 7 commits into
devframes:mainfrom
SaKaNa-Y:fix/message-cursor-instance

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

A reader that connects to a restarted Hub can keep old messages and miss new ones when both instances reach the same numeric version. A mounted standalone viewer can also show a notification from its new connection while the visible panel still belongs to the first connection.

The Hub includes its instance ID in each list result. The messages panel and Hub UI return that ID with their next read.

same instance + valid version → delta
foreign instance or expired version → full snapshot

A replacement connection gets its own message list, selection, toasts and timers. Replacing a standalone viewer’s context also remounts its dock shell, so clicking a toast opens the panel on the same connection. On a full snapshot from a different instance, the UI drops old notifications and rebuilds the feed in snapshot order. A full refresh from the same instance preserves surviving notifications.

Evidence

  • The host and RPC tests cover foreign cursors below, at and above the new version, and subsequent same-instance removals.
  • WebSocket tests cover both older readers. After the Messages panel calls list(), its next list(version) used to return another full snapshot. It now returns the removal and the replacement entry when the Hub reuses a message ID. The older Hub UI starts with list(null) and receives the same removal across overlapping reads. A fresh connection that sends only a version still gets a full snapshot.
  • In Chrome, replacing the context on a mounted standalone custom element removed the first connection’s pane. Clicking the second connection’s toast opened its messages iframe. The check used two dock contexts with controlled RPC responses.
  • Local lint, Knip, typecheck and build passed. The full unit suite passed 1,883 tests and skipped 14.

Merge Danger

Door: two-way

Blast Radius: message-sync

Direct numeric-only listSince calls receive full snapshots. The live messages RPC can serve deltas to older readers after establishing a snapshot on their connection. Older results and static snapshots may omit the instance ID. Connection replacement remains explicit.

Scope message cursors to their issuing Hub instance so a retained cache can recover after an explicit replacement connection. Return full snapshots for legacy numeric-only readers and pass instance IDs through both message consumers.
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/486?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-16 07:00 UTC
🔗 head b6f75d1
🤖 automated by pulls.review

{
  "headSha": "b6f75d1f642d1175191fb450e828ce9ee72c25c2",
  "result": {
    "overallSummary": "Fixes a message-sync bug where a reader reconnecting to a restarted Hub could receive a stale or foreign delta if the new instance happened to reach the same numeric version, and where a mounted standalone viewer could mix notifications/state between its old and new connections. The Hub now stamps each list result with an instance ID that callers must echo back; the RPC layer tracks that ID per connection so legacy numeric-only callers still get deltas when possible; and the hub-ui keeps messages, toasts, selection and the standalone dock shell scoped per connection so a replacement connection starts clean.",
    "groups": [
      {
        "key": "hub-instance-delta",
        "label": "Hub instance-aware deltas",
        "summary": "`DevframeMessagesHost.listSince` now requires the caller's cursor to match the host's own instance ID before serving a delta, so a reader that survives a Hub restart and happens to land on the same numeric clock value gets a full snapshot instead of a stale or foreign delta.",
        "category": "core",
        "filePaths": [
          "packages/hub/src/node/host-messages.ts",
          "packages/hub/src/types/messages.ts",
          "docs/content/8.references/6.hub-api.md"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/hub/src/node/host-messages.ts",
            "text": "The delta is only returned when `instanceId` matches `_instanceId`; any mismatch (including legacy callers that omit it) now falls back to a full snapshot before the existing trimmed/ahead-of-clock checks run.",
            "critical": true
          }
        ]
      },
      {
        "key": "messages-rpc-cursor",
        "label": "Messages RPC cursor handling",
        "summary": "The `list` RPC function now forwards the host's instance ID to clients and, for callers that only send a numeric cursor, remembers the instance ID from their first snapshot per connection so a legacy or overlapping follow-up read can still resolve to a delta instead of repeating a full snapshot.",
        "category": "api",
        "filePaths": [
          "plugins/messages/src/node/rpc/functions/list.ts",
          "plugins/messages/app/client/state/messages.ts"
        ],
        "fileNotes": [
          {
            "path": "plugins/messages/src/node/rpc/functions/list.ts",
            "text": "Uses a `WeakMap` keyed by the RPC session to pin the instance ID of a peer's first full snapshot, so a subsequent numeric-only `since` call from that same connection can be resolved against the right instance even though the client never returns an instance ID.",
            "critical": true
          }
        ]
      },
      {
        "key": "hub-ui-connection-isolation",
        "label": "Hub UI connection isolation",
        "summary": "Replaces the single global messages/toasts singletons with per-connection state (keyed by the RPC client) and remounts the standalone dock shell when its context changes, so a replacement connection gets its own feed, selection and toasts instead of leaking state from the previous one, and clicking a toast opens the panel on the connection that produced it.",
        "category": "ui",
        "filePaths": [
          "packages/hub-ui/src/client/state/messages.ts",
          "packages/hub-ui/src/client/state/toasts.ts",
          "packages/hub-ui/src/client/components/display/ToastOverlay.vue",
          "packages/hub-ui/src/client/components/dock/DockStandalone.vue",
          "packages/hub-ui/src/client/components/dock/DockStandaloneShell.vue"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/hub-ui/src/client/state/messages.ts",
            "text": "On a full snapshot from a different instance, all cached entries and toasts are dropped before applying the new list in snapshot order; a full refresh from the same instance still preserves surviving toasts.",
            "critical": true
          },
          {
            "path": "packages/hub-ui/src/client/components/dock/DockStandalone.vue",
            "text": "Logic moved verbatim into the new `DockStandaloneShell.vue`; this file now just bumps a `key` to force a remount whenever `context` changes, since panes and trust subscriptions are tied to the context that created them."
          }
        ]
      },
      {
        "key": "tests-and-stories",
        "label": "Tests and stories",
        "summary": "Coverage for the host, RPC and UI changes above: foreign/expired cursors on the host, same-instance ID-reuse races over the wire, and per-connection isolation of the hub-ui messages/toasts state; the toast stories are updated for the new `createToastStore` API.",
        "category": "tests",
        "filePaths": [
          "packages/hub/src/node/__tests__/host-messages.test.ts",
          "packages/hub-ui/src/client/state/messages.test.ts",
          "packages/hub-ui/src/client/state/toasts.test.ts",
          "packages/hub-ui/src/client/components/display/ToastOverlay.stories.ts",
          "plugins/messages/test/dev-server.test.ts",
          "plugins/messages/test/message-state.test.ts"
        ],
        "fileNotes": [
          {
            "path": "plugins/messages/test/dev-server.test.ts",
            "text": "Covers the two legacy-reader scenarios: a numeric-only follow-up after a no-arg snapshot, and a reused message ID observed through overlapping reads on the same connection."
          },
          {
            "path": "plugins/messages/test/message-state.test.ts",
            "text": "New file exercising the plugin's `useMessages` client against a real `DevframeMessagesHost` across a simulated Hub restart (host instance swap plus trust re-flip)."
          }
        ]
      },
      {
        "key": "generated-snapshots",
        "label": "Generated type snapshots",
        "summary": "Auto-generated public API snapshots updated to reflect the new `instanceId` parameter/field on `listSince` and the `list` RPC function.",
        "category": "other",
        "filePaths": [
          "tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts",
          "tests/__snapshots__/tsnapi/@devframes/hub/node.snapshot.d.ts",
          "tests/__snapshots__/tsnapi/@devframes/hub/node.snapshot.js",
          "tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts",
          "tests/__snapshots__/tsnapi/@devframes/plugin-messages/rpc.snapshot.d.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-16T07:00:07.907Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

SaKaNa-Y and others added 6 commits November 14, 2026 16:35
Keep the feed, toast timers and message selection with their RPC client. On a full snapshot from another Hub instance, drop the previous entries and notifications before applying the new list in order.
Keep the toast, dock selection, trust subscription and iframe panes on the same connection when a mounted viewer receives a replacement context.
Keep the first full snapshot cursor for each legacy connection. A new connection starts from a snapshot, while overlapping reads on the same connection can still observe an ID removed and added again.
The legacy Messages panel starts with list() and sends only the version on its next read. Remember the first snapshot for that peer so an ID removed and reused between reads appears in the delta.

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.

1 participant