Skip to content

fix(identity): prevent cross-runtime device identity races - #120643

Merged
steipete merged 2 commits into
mainfrom
steipete/keen-clarke-8b8cae
Aug 8, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/keen-clarke-8b8cae

Conversation

@steipete

@steipete steipete commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users running the TypeScript and Swift runtimes against the same selected state tree could have each runtime coordinate device identity SQLite ownership through a different lock database. During mixed-version upgrades or alternate state-directory use, that split ownership could allow overlapping initialization and produce mismatched device identities.

Why This Change Was Made

The selected state tree now owns the canonical coordinator under tmp/openclaw-<uid>. For rolling upgrades, both runtimes first acquire the shipped process-temporary coordinator and then the state-local coordinator, release them in reverse order, and unwind every acquired coordinator if a later acquisition fails. A shared ordered JSON fixture pins the full cross-language path and hash contract, and CI routes fixture-only changes through both Node and OpenClawKit coverage. The bridge preserves interoperability with the shipped process-temporary owner without migrating or deleting coordinator files, and it does not change the SQLite schema or schema version. This change was AI-assisted and reviewed before publication.

User Impact

Users can run mixed TypeScript/Swift deployments and rolling upgrades without the two runtimes independently claiming the same device identity database. Existing installations require no configuration change or migration, and the device identity remains stable across the upgrade boundary.

Evidence

  • node scripts/run-vitest.mjs src/infra/device-identity-coordinator.contract.test.ts src/infra/device-identity.test.ts src/infra/device-identity.state-dir.test.ts src/infra/state-migrations.device-identity.test.ts src/infra/gateway-lock.state-dir.test.ts src/scripts/ci-changed-scope.test.ts src/scripts/ci-changed-scope.contract-fixtures.test.ts — 55 infrastructure tests and 38 tooling tests passed.
  • node scripts/run-vitest.mjs test/scripts/test-projects.test.ts --testNamePattern 'keeps CI, dependency, and docs tooling edits on owner tests' — the exact CI routing assertion passed after registering the new fixture suite with its tooling owner.
  • DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer swift test --package-path apps/shared/OpenClawKit --filter DeviceIdentityCoordinatorContractTests — 1 test passed.
  • DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer swift test --package-path apps/shared/OpenClawKit --filter DeviceIdentityStoreTests — 37 tests passed.
  • pnpm tsgo:core, pnpm tsgo:core:test, pnpm tsgo:scripts, targeted Oxlint/oxfmt, SwiftFormat, and git diff --check passed.
  • Fresh branch review of the coordinator repair and fresh uncommitted review of the CI owner-routing follow-up both reported no actionable findings.
  • Exact-head CI run https://github.com/openclaw/openclaw/actions/runs/31268419751 exposed the missing owner-test registration in checks-node-compact-small-2; commit add86a3e6de8623fed90060fa7c83570c7c20871 fixes that deterministic PR-owned failure. A new exact-head hosted run is required before landing.
  • The earlier node scripts/check-changed.mjs delegation could not acquire a Crabbox/Testbox provider; its prescribed trusted-source local fallback passed.
  • No live channel proof was run; this repair is a deterministic local SQLite/path ownership contract and does not change a channel or external API path.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L maintainer Maintainer-authored PR labels Aug 8, 2026
@steipete
steipete force-pushed the steipete/keen-clarke-8b8cae branch from eb6345e to 5c592d2 Compare August 8, 2026 17:00
@steipete
steipete marked this pull request as ready for review August 8, 2026 17:01
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 4:48 PM ET / 20:48 UTC.

ClawSweeper review

What this changes

The PR makes Node and Swift acquire the same ordered temporary and selected-state SQLite coordinator locks before creating or migrating a shared device identity.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for protected maintainer review. The PR remains necessary: current main still lets Node and Swift coordinate the same identity database through different lock locations, while the proposed ordered bridge unifies that boundary without a schema or config change.

Priority: P2
Reviewed head: abf6668b1b3d9bcb74837b6bec0dd67ded16480d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused cross-language contract and cleanup coverage support the patch; exact-current-base validation is the remaining merge-confidence reducer.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored internal SQLite coordination repair is appropriately evidenced by cross-runtime owner-boundary tests rather than a user-facing channel session.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal SQLite coordination repair is appropriately evidenced by cross-runtime owner-boundary tests rather than a user-facing channel session.
Evidence reviewed 5 items Current-main ownership split: Current Node coordination uses the selected-state lock directory, while Swift uses the process temporary directory; the two runtimes therefore do not share one coordinator today.
Proposed canonical bridge: The PR derives process-temporary then state-local paths in a fixed order, deduplicates coincident paths, and acquires them in that order with reverse cleanup.
Cross-language contract coverage: The shared fixture is asserted by Node and OpenClawKit tests, while the Node regression covers both legacy single-lock owners and partial-acquisition cleanup.
Findings None None.
Security None None.

How this fits together

Node and OpenClawKit can use one selected state tree containing the device identity database. Coordinator locks serialize initialization and migration so both runtimes preserve one stable device identity.

flowchart LR
  A[Node runtime] --> C[Ordered coordinator locks]
  B[Swift runtime] --> C
  C --> D[Selected state tree]
  D --> E[Device identity database]
  E --> F[Stable device identity]
Loading

Before merge

  • Resolve merge risk (P1) - The temporary-plus-state-local bridge is intentionally upgrade-sensitive; validate it on GitHub's current merge result because the PR is behind main and the aggregate check rollup is not complete.
Agent review details

Security

None.

PR surface

Source +59, Tests +199, Other +129. Total +387 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 5 128 69 +59
Tests 5 204 5 +199
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 5 163 34 +129
Total 15 495 108 +387

Review metrics

Metric Value Why it matters
Production versus test LOC production +227/-103; tests and fixtures +268/-5 The production growth implements the new cross-runtime ownership boundary and upgrade bridge; the larger test delta pins its Node, Swift, and CI-routing contract.

Stored data model

Persistent data-model change detected: serialized state: src/infra/device-identity-coordinator.contract.test.ts, serialized state: src/infra/state-migrations.device-identity.ts, vector/embedding metadata: apps/shared/OpenClawKit/Tests/OpenClawKitTests/DeviceIdentityCoordinatorContractTests.swift, vector/embedding metadata: src/infra/device-identity-coordinator.contract.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the current merge result (recommended)
    Run the Node and OpenClawKit coordinator suites against the exact current-base merge result before landing the mixed-version compatibility bridge.
  2. Accept the current-base gap
    Land with the existing head evidence while explicitly accepting that the bridge was not exercised on the current merge result.

Technical review

Best possible solution:

Keep one canonical ordered coordinator contract in both runtimes, retain the temporary lock only as the bounded rolling-upgrade bridge, and land after current-base cross-runtime coverage is green.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current Node and Swift select different coordinator locations for the same identity database, and the focused tests exercise the dual-lock bridge and its cleanup path.

Is this the best way to solve the issue?

Yes. A single ordered cross-runtime coordinator with a temporary compatibility bridge fixes the owner boundary; dropping either lock immediately would leave either older binaries or alternate state trees unprotected.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 51960f65794e.

Labels

Label justifications:

  • P2: This is a bounded shared-state reliability repair with no evidence of a current broad outage.
  • merge-risk: 🚨 compatibility: The changed lock sequence must interoperate with separately shipped Node and Swift versions during rolling upgrades.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal SQLite coordination repair is appropriately evidenced by cross-runtime owner-boundary tests rather than a user-facing channel session.

Evidence

What I checked:

Likely related people:

  • steipete: Available history ties the device-identity SQLite migration to steipete, and steipete authored and is assigned to this cross-runtime repair. (role: feature-history and current change owner; confidence: high; commits: 98410d986, c7bf46d8f253, abf6668b1b3d; files: src/infra/device-identity-coordinator.ts, apps/shared/OpenClawKit/Sources/OpenClawKit/DeviceIdentitySQLiteStore.swift)
  • vincentkoc: Current-main CI changed-scope routing history attributes the adjacent owner-test routing surface to vincentkoc. (role: recent adjacent CI-routing contributor; confidence: medium; commits: 13322b2adc; files: scripts/ci-changed-scope.mjs, scripts/test-projects.test-support.mjs)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Validate Node and OpenClawKit coordinator coverage on the current merge result.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-08T18:44:56.115Z sha add86a3 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-08T18:52:02.793Z sha add86a3 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-08T19:44:44.386Z sha b3e1829 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 8, 2026
@steipete steipete self-assigned this Aug 8, 2026
@steipete
steipete force-pushed the steipete/keen-clarke-8b8cae branch from add86a3 to b3e1829 Compare August 8, 2026 19:18
@steipete
steipete force-pushed the steipete/keen-clarke-8b8cae branch from b3e1829 to abf6668 Compare August 8, 2026 20:23
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 21a9428 into main Aug 8, 2026
125 checks passed
@steipete
steipete deleted the steipete/keen-clarke-8b8cae branch August 8, 2026 20:55
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
…120643)

* fix(identity): coordinate SQLite ownership across runtimes

* fix(ci): route changed-scope fixture tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant