Skip to content

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

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

SaKaNa-Y wants to merge 8 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-22 07:04 UTC
🔗 head e3c8ee5
🤖 automated by pulls.review

{
  "headSha": "e3c8ee5ab9f81fb3eaec3fd0de5ebd84dbc5b928",
  "result": {
    "overallSummary": "Fixes a bug where a reader reconnecting to a restarted Hub instance could reuse a stale numeric message cursor and either miss removals or keep showing old messages. The Hub now stamps each `listSince` result with its instance ID so readers can detect a foreign/expired cursor and fall back to a full snapshot, while the hub-ui isolates message state, toasts, and the standalone dock shell per connection so a replaced connection doesn't leak stale UI state into the new one.",
    "groups": [
      {
        "key": "cursor-core",
        "label": "Instance-aware message cursor",
        "summary": "The Hub now tags every `listSince` result with its instance ID so a reader can tell whether a cursor belongs to the connection it just received, falling back to a full snapshot on a foreign or expired cursor. The `list` RPC keeps a per-connection fallback cursor so legacy numeric-only readers on the same connection can still receive removal deltas across overlapping reads.",
        "category": "api",
        "filePaths": [
          "packages/hub/src/node/host-messages.ts",
          "packages/hub/src/types/messages.ts",
          "plugins/messages/src/node/rpc/functions/list.ts",
          "plugins/messages/app/client/state/messages.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/hub/src/node/host-messages.ts",
            "text": "`listSince` now requires the caller's `instanceId` to match the host's own; any mismatch, missing ID, or stale version forces a full snapshot."
          },
          {
            "path": "plugins/messages/src/node/rpc/functions/list.ts",
            "text": "Caches the first snapshot cursor per RPC peer so a client that keeps calling with only `since` (no instanceId) still sees removals that happened on its own connection."
          }
        ]
      },
      {
        "key": "hub-ui-isolation",
        "label": "Hub-UI per-connection message state",
        "summary": "Message feeds and toasts were module-level singletons, so a reconnect to a new Hub instance leaked stale toasts/selection into the new connection. Each connection now gets its own toast store and message state keyed by its RPC client, a full snapshot from a different instance discards old entries, and the standalone dock shell remounts when its context changes so a toast click opens the panel on the right connection.",
        "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/toasts.ts",
            "text": "Replaces the single global toast list with a `createToastStore()` factory, one instance per connection."
          },
          {
            "path": "packages/hub-ui/src/client/components/dock/DockStandalone.vue",
            "text": "Logic moved into the new `DockStandaloneShell.vue`; this wrapper now just forces a remount (via an incrementing `:key`) whenever `context` changes."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Tests for message cursor fix",
        "summary": "Covers the new instance-ID handling in `listSince`, legacy numeric-only reader fallbacks, per-connection message/toast state isolation, and updates the toast store stories to the new factory API.",
        "category": "tests",
        "filePaths": [
          "packages/hub/src/node/__tests__/host-messages.test.ts",
          "plugins/messages/test/dev-server.test.ts",
          "plugins/messages/test/message-state.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"
        ]
      },
      {
        "key": "docs",
        "label": "Hub API docs",
        "summary": "Documents the new `listSince(version, instanceId)` contract, including fallback behavior for missing/foreign instance IDs and numeric-only callers.",
        "category": "docs",
        "filePaths": [
          "docs/content/8.references/6.hub-api.md"
        ]
      },
      {
        "key": "snapshots",
        "label": "Generated type snapshots",
        "summary": "Regenerated public API snapshots reflecting the new `instanceId` parameter and field added to the messages types and RPC signature.",
        "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-22T07:04:51.997Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

SaKaNa-Y and others added 7 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.
@SaKaNa-Y
SaKaNa-Y marked this pull request as ready for review November 22, 2026 07:13

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