Repository navigation
refactor(pairing): move device pairing store to shared SQLite state DB - #103160
Merged
Merged
Conversation
Device pairing, pending requests, and bootstrap tokens now live in the
device_pairing_* / device_bootstrap_tokens tables of state/openclaw.sqlite
instead of devices/{paired,pending,bootstrap}.json. Gateways import legacy
paired records once at startup (before the node-surface fold) and archive
the JSON files with a .migrated suffix; transient pending/bootstrap rows
are dropped. The unshipped node_pairing_* tables are removed from the
schema and dropped from existing DBs. Doctor now flags un-imported legacy
store files instead of corrupt-JSON reads.
Contributor
Author
|
Live upgrade test (production state copy, personal cloud gateway host, branch build at 91e400a):
|
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 10, 2026
openclaw#103160) * refactor(pairing): move device pairing store to shared SQLite state DB Device pairing, pending requests, and bootstrap tokens now live in the device_pairing_* / device_bootstrap_tokens tables of state/openclaw.sqlite instead of devices/{paired,pending,bootstrap}.json. Gateways import legacy paired records once at startup (before the node-surface fold) and archive the JSON files with a .migrated suffix; transient pending/bootstrap rows are dropped. The unshipped node_pairing_* tables are removed from the schema and dropped from existing DBs. Doctor now flags un-imported legacy store files instead of corrupt-JSON reads. * refactor(pairing): drop stale awaits now that store persistence is synchronous * refactor(pairing): extract leaf record types to break store/domain module cycle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Device pairing state (paired devices with role tokens, pending pairing requests, bootstrap tokens) was the last auth-critical store still living in loose JSON files (
devices/{paired,pending,bootstrap}.json). Per the database-first storage policy, OpenClaw-owned runtime state belongs in the shared SQLite state DB — the JSON files were migration debt with hand-rolled snapshot writes, and the schema already carried emptydevice_pairing_*/device_bootstrap_tokenstables (plus deadnode_pairing_*tables) from an earlier reverted attempt.Why This Change Was Made
src/infra/device-pairing.tsandsrc/infra/device-bootstrap.tsnow load/persist through a newsrc/infra/device-pairing-store.tsrow-mapping module backed bystate/openclaw.sqlite(device_pairing_pending,device_pairing_paired,device_bootstrap_tokens). Persistence replaces table contents in one immediate transaction, preserving the exact snapshot semantics of the retired JSON files; WAL + busy_timeout keep concurrent gateway/CLI access safe. An explicitbaseDirroutes to that dir's DB, so all existing per-test temp-dir isolation keeps working.refreshed_at_ms(pending TTL keepalive) andapproved_via/node_surface_json/pending_node_surface_json(paired) columns, additively for existing DBs. Removed the never-writtennode_pairing_*tables from the schema and dropped them from existing DBs (no shipped writer ever existed; provably empty).migrateLegacyDevicePairingStoreimports legacydevices/paired.jsonrecords at gateway startup (existing SQLite rows win) and archives all three files with a.migratedsuffix. It is ordered strictly before the node-surface fold, which writes onto the imported device records. Transient pending (5 min TTL) and bootstrap (10 min TTL) rows are dropped, not imported.devices/*.jsonstill exists (migration has not run or the file is unreadable) and never treats it as empty.docs/gateway/pairing.md,docs/channels/pairing.md,docs/nodes/index.md,docs/refactor/database-first.md).User Impact
Transparent for upgrades: the first gateway start after the update imports existing paired devices (tokens, roles, scopes, node surfaces, approval provenance) into SQLite and archives the JSON files. Devices stay paired; nodes reconnect without re-approval. In-flight pending pairing requests and unredeemed setup codes at upgrade time expire (both are minutes-lived transients; devices re-request and setup codes can be reissued).
openclaw doctorflags a store that could not be imported.Evidence
tsgocore + core-test typechecks clean; import-cycle, deadcode, and database-first legacy-store guards pass; Kysely generated types regenerated viapnpm db:kysely:gen.