Skip to content

fix(shared-state): keep initial snapshots local - #454

Draft
SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/shared-state-initial-snapshot
Draft

SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/shared-state-initial-snapshot

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a wire service is installed while the RPC client reads its initial shared-state snapshot, the client can send the old snapshot back to the node side. This removes the service advertisement even though direct RPC calls still work. New connections then also fail to discover the installed service.

Give the initial snapshot its own sync ID and exclude that ID from outgoing writes. Ignore a pending snapshot if its state changed or was deleted. Local writes, including writes triggered by a snapshot listener, still reach the node side.

 initial snapshot arrives
- apply snapshot and send it back to the node side
+ apply locally only if the state is still current

This PR and #422 are independent fixes with no dependency on each other. This PR is based on main and does not include changes from #422. It fixes initial snapshot reads; #422 fixes echoes from received broadcasts and patches.

Evidence

  • Before: five added regression tests fail. After: all five pass, alongside the two existing shared-state tests.
  • Public WebSocket and SSE workflows: early service installation preserves both registries, a new connection discovers the service, and direct RPC calls succeed.
  • pnpm lint, pnpm knip, pnpm typecheck, and pnpm build pass.
  • pnpm test --run: 157 test files pass; 1760 tests pass and 13 are skipped.

Merge Danger

Door: two-way. No wire-format or public API changes.

Blast Radius: shared-state. The change affects initial reads with an initialValue; later local writes retain their existing behavior.

@vercel

vercel Bot commented Oct 21, 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

Copy link
Copy Markdown

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

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-10-21 13:32 UTC
🔗 head 0179d3d
🤖 automated by pulls.review

{
  "headSha": "0179d3d088664c84fd08aa3e4b12472c255d9c43",
  "result": {
    "overallSummary": "Fixes a race where a wire service installed while an RPC client reads its initial shared-state snapshot could have that stale snapshot echoed back to the node side, erasing the service advertisement. The fix gives the initial snapshot its own sync ID (excluded from outgoing writes) and discards it if the state changed or was deleted in the meantime.",
    "groups": [
      {
        "key": "fix",
        "label": "Keep initial snapshots local",
        "summary": "Gives the initial shared-state snapshot its own sync ID and skips sending it back to the node side, so an installed service isn't clobbered by a stale snapshot. Also guards against applying a pending snapshot if the state changed or was deleted while the read was in flight.",
        "category": "core",
        "filePaths": [
          "packages/devframe/src/client/rpc-shared-state.ts"
        ],
        "critical": true,
        "lineNotes": [
          {
            "path": "packages/devframe/src/client/rpc-shared-state.ts",
            "side": "additions",
            "line": 111,
            "text": "Pending snapshot is only applied if the shared-state entry still exists and its value hasn't changed since the read started, preventing it from overwriting a newer local write or broadcast update.",
            "critical": true
          }
        ]
      },
      {
        "key": "tests",
        "label": "Initial snapshot regression tests",
        "summary": "Adds regression tests covering the initial-snapshot race: no write-back on read, preserving concurrent local writes/broadcasts, forwarding writes triggered from within the snapshot listener, and ignoring snapshots for deleted state.",
        "category": "tests",
        "filePaths": [
          "packages/devframe/src/client/rpc-shared-state.test.ts"
        ],
        "critical": true
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-10-21T13:32:18.297Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

@SaKaNa-Y
SaKaNa-Y marked this pull request as draft October 21, 2026 13:36

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