Repository navigation
fix(config): prevent recovery from stale or invalid backups - #117100
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 7:29 PM ET / 23:29 UTC. ClawSweeper reviewWhat this changesThis PR unifies synchronous and asynchronous configuration recovery so it validates the backup bytes actually being restored, records canonical health metadata, and ignores nonessential stat failures during recovery. Merge readinessKeep this PR open for explicit maintainer review. Current Priority: P2 Review scores
Verification
How this fits togetherOpenClaw reads configuration during startup and snapshot refresh, records healthy observations in SQLite, and may restore a backup when the current file looks clobbered. This change sits between suspicious-config detection and the file restore/audit path, affecting whether operators’ existing configuration is replaced automatically. flowchart LR
A[Startup or snapshot config read] --> B[Detect suspicious current config]
B --> C[Read health state and backup]
C --> D[Validate actual backup bytes]
D --> E{Recovery allowed?}
E -->|Yes| F[Restore backup and write audit]
E -->|No| G[Keep current config]
F --> H[Update SQLite health state]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -327, Tests +86, Other -1. Total -242 across 5 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current Do we have a high-confidence way to reproduce the issue? Yes, from source and the supplied real-fixture report: current main can authorize a backup using Is this the best way to solve the issue? Yes, subject to the rebase review: validating the parsed backup payload and deriving its fingerprint before restoration repairs the owning recovery boundary without adding a new configuration surface or fallback path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6d8f0a13655c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where operators could have their configuration restored from an invalid backup when a stale healthy fingerprint incorrectly authorized different backup bytes. Synchronous startup recovery could also fail on a metadata-only stat error, while asynchronous recovery continued.
Why This Change Was Made
Canonicalize config observation fingerprints, audit records, and SQLite health ownership across synchronous startup and asynchronous snapshots. Evaluate restoration eligibility against the exact approved backup bytes, preserve backup-validation and caller-policy ordering, and remove duplicated sync/async policy.
User Impact
Startup and snapshot recovery now refuse backups without a usable gateway mode, consistently recognize authored config metadata, preserve last-known-good doctor repair, and tolerate nonessential stat failures without weakening permission hardening or audit visibility. Production code shrinks by 327 lines and one grandfathered oversized-file suppression is removed.
Evidence
Real runtime proof used actual temporary config files, actual backup files, and the shared SQLite config_health_entries store; filesystem/state storage were not replaced by mocks. The only injected fault was the targeted stat permission error.
Before the fix, Blacksmith Testbox reproduced five concrete failures:
After the fix, the same fixtures prove both stale-backup modes preserve the exact original primary bytes and emit no restore audit, both metadata modes recover the authored backup payload, and both stat modes recover gateway.mode=local. Focused initial proof was 5 failed, 1 passed; final exact-head recovery proof was 44 passed.
Additional real-boundary coverage: 65 tests passed across recovery, ordinary config reads, and doctor repair, including actual last-known-good restoration, original clobber artifact preservation, rejected malformed-plugin handling, SQLite health updates, backup byte races, file permission hardening, env cleanup, and operator audit/warning output.
Full remote changed gate passed: production and test typechecks, all lint shards, formatting, dead-code scans, max-lines ratchet, database-first storage enforcement, and zero runtime import cycles. Fresh structured autoreview was clean. Exact-head hosted CI run 30672168417 completed successfully, including required openclaw/ci-gate. Blacksmith Testbox tbx_01kyx51xb2n4va3rksjp4y9dsg was stopped after validation.