Skip to content

refactor(gateway): retire the standalone node pairing store - #103120

Merged
steipete merged 7 commits into
mainfrom
claude/drop-legacy-node-pairing-store
Jul 9, 2026
Merged

steipete merged 7 commits into
mainfrom
claude/drop-legacy-node-pairing-store

Conversation

@steipete

@steipete steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves the last piece of node-pairing duplication: OpenClaw kept two pairing stores for the same machines. Device pairing (devices/paired.json) has gated the WS connect handshake since the TCP bridge was removed in January 2026, but the standalone gateway-owned node pairing store (nodes/{paired,pending}.json, "Option B") lived on — holding the approved capability surface plus a per-node token that nothing has consumed since the bridge died. Two stores meant duplicated rows for every node, duplicated lastSeen writes on every presence event, an entire cleanup-claim system reconciling the two, and two dead RPCs (node.pair.request, node.pair.verify) with no callers anywhere in core, apps, or the SDK.

Why This Change Was Made

Six months after deprecation, the store is dropped and its one remaining job — the approved node capability surface with its pending re-approval queue — moves onto the paired device record (PairedDevice.nodeSurface / pendingNodeSurface), behind the same store lock as device pairing. node-pairing.ts keeps its exported functions and semantics (pending reuse/supersede rules, cleanup-claim race guards, approval scope checks, rate-limit integration) but reads/writes device records; the standalone per-node token is deleted outright (node auth is the device pairing token). The shipped node.pair.list/approve/reject/remove + node.rename RPCs and the openclaw nodes CLI keep their response shapes minus the token field, which the CLI only carried in order to delete it before output. node.pair.request and node.pair.verify are removed from the protocol (no production caller existed; pending requests are created by the gateway during connects). A one-time startup migration — following the runStartupSessionMigration precedent — folds legacy rows into device records, drops orphans that no longer map to a node-role device (they cannot pass the WS handshake), and archives the files as nodes/*.json.migrated; a failed fold logs and retries next boot without blocking startup.

Non-goals: no change to device pairing auth, silent/trusted-CIDR approval policy, node command gating semantics, or the Control UI.

User Impact

  • One store, one row per node: node.pair.list, node.list, the Control UI, and the CLI all read the device record, so approving/removing/renaming a node can no longer leave a stale twin in a second store.
  • Upgrades are hands-off: existing approved node surfaces migrate at first gateway start; nodes keep their approved commands without re-approval. Orphaned legacy rows (machines whose device pairing is long gone) are finally cleaned up.
  • Operators lose nothing: pending re-approvals, approval scopes, rename, and removal behave as before. The retired node.pair.request/node.pair.verify RPCs had no clients.

Evidence

  • src/infra/node-pairing.test.ts respec'd against the device-backed store (13 tests: pending reuse/supersede, cleanup-claim races, approval scopes, rename, runtime metadata); new src/infra/node-pairing-migration.test.ts (fold, orphan drop, .migrated archive, idempotence, token never crossing over, existing-surface precedence).
  • Updated suites green: reapproval coordinator (36), node pairing authz + rate limit, server-node-events presence (single write), nodes/devices handlers, watch-node-http, environments, connect reconcile, auto-approve, silent-scope-upgrade POC — ~200 tests across the touched surfaces, plus tsgo core clean.
  • macOS approval prompter decoders verified token-free (node.pair.list/approve/reject only); iOS/Android have no node.pair.* usage; gateway-client SDK exposes none.
  • Docs updated: docs/gateway/pairing.md rewritten for the folded store (removal notice for the two RPCs, new storage layout, migration note), docs/gateway/protocol.md, docs/refactor/database-first.md.
  • pnpm check:changed delegated to Blacksmith Testbox + Codex autoreview on the final branch state (results in PR discussion).

@steipete
steipete requested a review from a team as a code owner July 9, 2026 21:29
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes size: XL maintainer Maintainer-authored PR labels Jul 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9df2a995b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (device.nodeSurface) {
continue;
}
device.nodeSurface = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve legacy node last-seen during migration

For upgraded gateways where an offline node only has lastSeenAtMs/lastSeenReason in the retired nodes/paired.json row, this migration archives that legacy file without copying those fields onto the device record. Current listNodePairing/node.list project last-seen from devices/paired.json, and new node.presence.alive writes go there, so existing offline nodes lose their persisted last-seen status until they reconnect or emit another presence event. Copy the legacy last-seen fields to the device record before archiving the old store.

Useful? React with 👍 / 👎.

@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready verification:

  • Head d692f7cc2ca (branch cut from current main): hosted CI green for this exact SHA (first run caught a stale generated Swift protocol bundle and the now-dead src/infra/pairing-pending.ts — both fixed).
  • Full remote gates: pnpm check:changed delegated to Blacksmith Testbox, all lanes green (conflict markers, typecheck core + core tests, lint, dead-code, test lanes; 10m17s).
  • Focused local proof: pnpm test over every touched suite (~250 tests: node-pairing respec incl. surface preservation across device re-approval, migration fold/orphan/archive/idempotence, reapproval coordinator, pairing authz + rate limit with real-key seeding, presence single-write, nodes/devices handlers, watch-node-http, catalog/reconcile, protocol index, nodes CLI).
  • Codex autoreview: round 1 found 3 issues (stale protocol test import; node surface dropped when device pairing rebuilds a record; removed defensive CLI token redaction) — all fixed with regression tests; round 2 clean ("patch is correct", no actionable findings).
  • Compatibility checks: macOS approval prompter uses only node.pair.list/approve/reject (decoders token-free), iOS/Android have no node.pair.* usage, gateway-client SDK exposes none; removed node.pair.request/node.pair.verify had no callers anywhere.
  • Known gaps: no live mixed-version (old gateway + new CLI) run; that boundary is covered by the retained token strip in openclaw nodes list --json and permissive parsers.

@steipete
steipete merged commit f5806d0 into main Jul 9, 2026
98 checks passed
@steipete
steipete deleted the claude/drop-legacy-node-pairing-store branch July 9, 2026 21:58
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Landed as f5806d0 (squash). The standalone nodes/{paired,pending}.json store and its per-node token are gone; node capability approvals now live on the paired device record, existing surfaces migrate automatically at first gateway start (legacy files archived as .migrated), and node.pair.request/node.pair.verify were removed from the protocol.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
…#103120)

* refactor(gateway): fold node pairing store into device records

* docs+cli: retire standalone node pairing store references

* test(infra): respec node pairing as device-backed surface approvals

* test(infra): assemble migration token fixtures dynamically

* fix(pairing): preserve node surface across device re-approval, strip legacy tokens in CLI JSON

* test(gateway): drop retired node token from pairing fixtures

* chore(protocol): regenerate Swift models, drop dead pairing-pending module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant