Repository navigation
fix(state): keep divergent retired device identity from blocking gateway readiness - #126748
Conversation
…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.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 8:37 PM ET / August 22, 2026, 00:37 UTC. ClawSweeper reviewWhat this changesThe 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 readinessNo 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 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherDoctor 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +23, Tests +76. Total +99 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Reuse canonical SQLite identity validation and retain incomplete receipts for preserved divergent claims. Co-authored-by: Vito Cappello <[email protected]>
|
Merged via squash.
|
…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]>
What Problem This Solves
Fixes #117270. A gateway can enter a permanent restart loop when
identity/device.jsonis 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:
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: anystartupMigrationWarningscallsthrowStartupMigrationRefusal. The cleanup owner emitted that warning for every bytes-different retired identity file atsrc/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 11997bf2117exited 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.origin/mainmade the valid-canonical notice test fail withAssertionError: 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.node dist/index.js doctor --fix --non-interactive, verified one canonical primary SQLite identity row, and verified the retired source JSON was removed.doctor --fix --non-interactiveproducedcanonical SQLite identity remains authoritativeas a notice and no fatal divergent-file cleanup warning.node dist/index.js gateway run --allow-unconfigured --auth none --port 19257; bothGET /readyzandGET /healthzreturned 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.