Skip to content

fix(state): keep divergent retired device identity from blocking gateway readiness - #126748

Merged
steipete merged 2 commits into
openclaw:mainfrom
VACInc:fix/device-identity-preserve-notice
Aug 22, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
VACInc:fix/device-identity-preserve-notice

Conversation

@VACInc

@VACInc VACInc commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes #117270. A gateway can enter a permanent restart loop when identity/device.json is recreated with different bytes after its identity has already been migrated successfully to canonical SQLite. The runtime does not read that retired file, but its cleanup warning is treated as a startup-readiness failure.

Redacted journal excerpt from the 2026-08-19 incident:

OpenClaw startup migrations did not complete cleanly; refusing to report the gateway ready.
- Retired device identity cleanup preserved <state>/identity/device.json: bytes differ from the migration receipt.
Run "openclaw doctor --fix" against the same state/config, then restart the gateway.

The process exited 1 and systemd started a fresh PID roughly every 20 seconds. The suggested Doctor remedy could not clear the condition because cleanup intentionally preserved the divergent file.

Why This Change Was Made

Root Cause

The readiness owner is src/commands/doctor-config-preflight.ts:669-677: any startupMigrationWarnings calls throwStartupMigrationRefusal. The cleanup owner emitted that warning for every bytes-different retired identity file at src/infra/state-migrations.device-identity.ts:350-361, even when canonical SQLite was valid.

That conflicts with the authority ordering landed in #120610: the canonical SQLite identity row is authoritative and runtime never reads the retired JSON. The affected deployed dist was reflog-verified at base 11997bf2117; git merge-base --is-ancestor d9ff862823a 11997bf2117 exited 0, proving #120610 was already present. Its loader-side fix could not help because the readiness gate refused boot before normal runtime identity loading.

The producer-side repair leaves the gate untouched. canonicalRowIsValid (src/infra/state-migrations.device-identity.ts:168-180) recognizes a valid canonical row, and cleanup reports only that inert divergent file as a notice (src/infra/state-migrations.device-identity.ts:350-380). Missing or invalid canonical state still follows the existing fatal-warning path. Startup logs notices at info (src/node-host/startup-state-migrations.ts:25-34).

This replaces closed #126414 and carries forward the evidence from the follow-up comment. steipete correctly rejected its quarantine approach: ordinary startup must not move key material, and a divergent branch must not bypass canonical validation. This PR makes no file moves and changes no startup authority; it only classifies an already-preserved retired file by the authority state that #120610 established.

The reporter host recreated differing bytes on Aug 1, Aug 19, and Aug 20 at 02:03. The producer remains unidentified and is tracked separately; this PR prevents those inert recreations from becoming a boot outage.

User Impact

Gateways with a valid canonical device identity now boot and serve while clearly logging a non-fatal notice for a divergent retired JSON file. Operators can archive or delete that retired file to clear the notice. Gateways without a valid canonical row remain fail-closed instead of silently accepting divergent key material.

Release note context: prevents a restart loop caused by a recreated retired device-identity JSON after a verified SQLite migration.

Evidence

Focused tests

  • node scripts/run-vitest.mjs src/infra/state-migrations.device-identity.test.ts — 27/27 passed.
  • The valid-canonical test uses a genuinely different generated Ed25519 keypair, not merely a timestamp change.
  • The invalid-canonical test proves the divergent-file condition remains fatal.
  • Pre-fix regression proof: stashing the two production files to origin/main made the valid-canonical notice test fail with AssertionError: expected [ Array(1) ] to deeply equal []: it received the old warning where no warning was allowed.

Changed-file and build gates

  • node scripts/check-changed.mjs -- src/infra/state-migrations.device-identity.ts src/infra/state-migrations.device-identity.test.ts src/node-host/startup-state-migrations.ts — passed.
  • pnpm build — passed (only existing third-party bundler direct-eval warnings).
  • git diff origin/main --numstat: production +32/-4 (state-migrations.device-identity.ts, startup-state-migrations.ts); tests +39/-2 (state-migrations.device-identity.test.ts).

Isolated live proof

All commands used an isolated throwaway OPENCLAW_STATE_DIR; the operator state and managed gateway were not touched.

  1. Generated a fresh Ed25519 legacy JSON identity, ran node dist/index.js doctor --fix --non-interactive, verified one canonical primary SQLite identity row, and verified the retired source JSON was removed.
  2. Copied the incident artifact bytes into only that isolated retired-file path without printing their contents. doctor --fix --non-interactive produced canonical SQLite identity remains authoritative as a notice and no fatal divergent-file cleanup warning.
  3. Ran node dist/index.js gateway run --allow-unconfigured --auth none --port 19257; both GET /readyz and GET /healthz returned 200. Startup logged the new notice, logged no readiness refusal, and the isolated process shut down cleanly on SIGTERM.

Review

  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — clean; no accepted/actionable findings.

What was not tested

No reproduction was run against the operator state or managed Gateway, and no attempt was made to identify or change the external producer that recreates the retired file. The pre-fix crash loop is the recorded 2026-08-19 journal incident above; this PR proves the repaired path in disposable state using the real incident artifact bytes.

…way readiness

Classify a divergent retired identity file as a startup notice when the canonical SQLite identity remains valid and authoritative under openclaw#120610. Preserve the fatal warning for missing or invalid canonical state, so the readiness gate itself remains unchanged.

Fixes openclaw#117270.

Release note: prevents gateway crash loops caused by a recreated retired device identity JSON after a verified SQLite migration.
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@VACInc
VACInc marked this pull request as ready for review August 20, 2026 17:00
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 8:37 PM ET / August 22, 2026, 00:37 UTC.

ClawSweeper review

What this changes

The PR changes divergent retired device-identity files from readiness-blocking warnings to informational notices when the canonical SQLite identity is valid, while retaining failure behavior for invalid canonical state.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness findings. This remains a focused, evidence-backed repair for the reported gateway readiness loop and awaits the assigned maintainer plus exact-head checks.

Priority: P1
Reviewed head: 5ff8721917f9619f8aa735e3938db207a0c445c8

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong isolated behavior proof and focused owner-boundary coverage support a clean, narrowly scoped repair.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies an after-fix isolated Doctor and gateway run with recorded 200 readiness and health responses, alongside focused regression results.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies an after-fix isolated Doctor and gateway run with recorded 200 readiness and health responses, alongside focused regression results.
Evidence reviewed 7 items Current-main failure path: Current main treats a receipt-byte mismatch as a migration warning, and gateway startup refuses readiness whenever startup migration warnings are present.
Canonical authority contract: The runtime already returns a valid canonical SQLite identity before checking retired JSON; it only rejects retired files when no canonical row is available.
Patch preserves the security boundary: The changed cleanup path uses the read-only canonical-store reader, which validates key material and device fingerprint; invalid rows throw and retain the existing fatal warning.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw doctor --help

Result: PASS (completed)

pnpm openclaw doctor --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126748-NnuZjy/target$ pnpm openclaw doctor --help
$ node scripts/run-node.mjs doctor --help
pnpm openclaw doctor --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 104.57 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 14.1s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4296ms (slowest: built plugin control-plane loads 3564ms)
│
◇

OpenClaw 2026.8.1 (5ff8721) — All your chats, one OpenClaw.

Usage: openclaw doctor [options]

Health checks + quick fixes for the gateway and channels

Options:
  --all                          With --lint: run all registered checks, including opt-in checks (default: false)
  --allow-exec                   Allow doctor to execute exec SecretRefs while verifying configured secrets (default: false)
  --deep                         Scan system services 
… output truncated …

Assertions:

  • PASS expect_output: --fix

How this fits together

Doctor and startup migration move legacy device identity JSON into canonical SQLite state. Their warnings feed gateway startup preflight, which refuses readiness on unresolved migration failures.

flowchart LR
A[Retired device JSON] --> B[Identity migration cleanup]
C[Canonical SQLite identity] --> D{Canonical row valid?}
B --> D
D -->|valid, divergent bytes| E[Informational notice]
D -->|missing or invalid| F[Migration warning]
E --> G[Gateway readiness proceeds]
F --> H[Gateway readiness refuses]
Loading

Before merge

  • Resolve merge risk (P1) - This bug fix adds 23 net production lines in a persisted identity migration path; the added notice propagation and incomplete-receipt guard are justified by the owner boundary, but exact-head validation remains important for upgrade safety.
  • Complete next step (P2) - No repair lane is needed: the reviewed branch is a coherent fix and now awaits the assigned maintainer and exact-head checks.
Agent review details

Security

None.

PR surface

Source +23, Tests +76. Total +99 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 25 2 +23
Tests 2 78 2 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 103 4 +99

Review metrics

Metric Value Why it matters
Production versus regression coverage production +23 net, tests +76 net The production growth is limited to a notice channel and receipt-integrity condition; tests cover valid, invalid, and interrupted-claim states.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/state-migrations.device-identity.test.ts, migration/backfill/repair: src/infra/state-migrations.device-identity.ts, serialized state: src/infra/state-migrations.device-identity.test.ts, serialized state: src/infra/state-migrations.device-identity.ts, unknown-data-model-change: src/infra/state-migrations.device-identity.test.ts, unknown-data-model-change: src/infra/state-migrations.device-identity.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head migration validation (recommended)
    Merge after the exact head has green required checks confirming valid canonical state proceeds while invalid canonical state remains readiness-blocking.

Technical review

Best possible solution:

Keep the canonical SQLite row as the sole authority, emit a visible non-fatal notice only after read-only canonical validation, and retain fatal warnings for missing or invalid canonical state.

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

Yes, source reproducible: current main emits the divergent-file warning and startup preflight refuses readiness on any startup migration warning. The PR body also documents an isolated after-fix gateway run.

Is this the best way to solve the issue?

Yes. The patch repairs the warning producer rather than weakening the readiness gate, and uses the existing canonical SQLite validator to preserve fail-closed behavior for invalid state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 980e67e2aee8.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The repaired condition can otherwise make a gateway restart repeatedly and unavailable despite a valid canonical identity.
  • merge-risk: 🚨 compatibility: The branch changes how existing migrated identity receipts and retired files affect startup.
  • merge-risk: 🚨 security-boundary: The branch makes readiness depend on validated canonical key material rather than untrusted retired-file bytes.
  • merge-risk: 🚨 availability: Warning versus notice classification directly determines whether gateway readiness is refused.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies an after-fix isolated Doctor and gateway run with recorded 200 readiness and health responses, alongside focused regression results.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix isolated Doctor and gateway run with recorded 200 readiness and health responses, alongside focused regression results.

Evidence

What I checked:

  • Current-main failure path: Current main treats a receipt-byte mismatch as a migration warning, and gateway startup refuses readiness whenever startup migration warnings are present. (src/infra/state-migrations.device-identity.ts:335, 980e67e2aee8)
  • Canonical authority contract: The runtime already returns a valid canonical SQLite identity before checking retired JSON; it only rejects retired files when no canonical row is available. (src/infra/device-identity.ts:119, 5ff8721917f9)
  • Patch preserves the security boundary: The changed cleanup path uses the read-only canonical-store reader, which validates key material and device fingerprint; invalid rows throw and retain the existing fatal warning. (src/infra/state-migrations.device-identity.ts:337, 5ff8721917f9)
  • Regression coverage: The tests cover a valid divergent source notice, a divergent interrupted claim that must keep its receipt incomplete, and an invalid canonical row that remains fatal; startup logging is covered separately. (src/infra/state-migrations.device-identity.test.ts:711, 5ff8721917f9)
  • History and ownership: Blame attributes the new classification and receipt-integrity condition to the exact PR head; prior merged work established canonical SQLite identity as authoritative over retired JSON. (src/infra/state-migrations.device-identity.ts:337, 5ff8721917f9)
  • Proof and release status: The PR body records an isolated after-fix Doctor and gateway run with readyz and healthz returning 200. The head is unmerged and no release contains it. (5ff8721917f9)

Likely related people:

  • steipete: Authored the merged canonical-identity authority repair and the exact-head receipt-integrity follow-up. (role: feature owner and recent area contributor; confidence: high; commits: d9ff862823a7, 5ff8721917f9; files: src/infra/device-identity.ts, src/infra/state-migrations.device-identity.ts)
  • Josh Lehman: Recently maintained the state-repair and startup-upgrade neighborhood that contains the migration owner. (role: recent adjacent contributor; confidence: medium; commits: eeed2c92cf65; files: src/infra/state-migrations.device-identity.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-20T17:09:10.566Z sha a7b423d :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Aug 22, 2026
Reuse canonical SQLite identity validation and retain incomplete receipts for preserved divergent claims.

Co-authored-by: Vito Cappello <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 22, 2026
@steipete
steipete merged commit eee9059 into openclaw:main Aug 22, 2026
253 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 22, 2026
…way readiness (openclaw#126748)

* fix(state): keep divergent retired device identity from blocking gateway readiness

Classify a divergent retired identity file as a startup notice when the canonical SQLite identity remains valid and authoritative under openclaw#120610. Preserve the fatal warning for missing or invalid canonical state, so the readiness gate itself remains unchanged.

Fixes openclaw#117270.

Release note: prevents gateway crash loops caused by a recreated retired device identity JSON after a verified SQLite migration.

* fix(state): preserve device identity migration receipt integrity

Reuse canonical SQLite identity validation and retain incomplete receipts for preserved divergent claims.

Co-authored-by: Vito Cappello <[email protected]>

---------

Co-authored-by: VACInc <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

[Bug]: Conflicting retired device identity leaves running gateway unusable after new client activation

2 participants