Skip to content

fix(config): prevent recovery from stale or invalid backups - #117100

Merged
steipete merged 1 commit into
mainfrom
codex/loc-config-recovery-2d45
Jul 31, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/loc-config-recovery-2d45

Conversation

@steipete

@steipete steipete commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Async stale-fingerprint recovery: SQLite contained a healthy promoted config with gateway.mode=local; the primary contained update.channel=beta; the actual backup contained only meta.lastTouchedVersion. Recovery incorrectly returned and restored the invalid backup instead of preserving the primary.
  2. Sync stale-fingerprint recovery: the same on-disk primary/backup and SQLite fingerprint incorrectly restored the gateway-less backup during synchronous startup.
  3. Async metadata recovery: the actual backup contained meta.authoredBy=operator and gateway.mode=local; the primary retained gateway.mode=local but dropped meta. Recovery incorrectly ignored the missing authored metadata and returned the truncated primary.
  4. Sync metadata recovery: the same real backup/primary mismatch was incorrectly ignored during synchronous startup.
  5. Sync stat recovery: a real recoverable primary and backup plus an EACCES fault only on the primary stat caused startup recovery to throw; the matching asynchronous path already recovered gateway.mode=local.

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.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 31, 2026
@steipete
steipete marked this pull request as ready for review July 31, 2026 23:10
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 7:29 PM ET / 23:29 UTC.

ClawSweeper review

What this changes

This 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 readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for explicit maintainer review. Current main still uses the stale health fingerprint as the backup eligibility fingerprint, while this branch reads and validates the actual backup before restoring it; the branch is also behind main and carries the protected maintainer label. Likely related people: steipete (high confidence, recovery feature history) and Vincent Koc (medium confidence, config-health ownership).

Priority: P2
Reviewed head: 6c82346f7e0fbb769c799b2a831fd638f8463526

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has coherent shared-path coverage and credible real-boundary proof; a rebase refresh is the remaining material confidence step.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.
Evidence reviewed 6 items Current-main behavior remains unfixed: The current-main recovery path obtains backup from backupBaseline before considering the backup file, so a stored last-known-good fingerprint can authorize different backup bytes. The PR changes this by fingerprinting the backupRaw that was parsed and approved.
Actual-backup validation on the branch: The branch first parses and runs caller validation on the backup bytes, then builds a fingerprint from those same bytes and rejects the backup when it has no gateway mode before any restore is attempted.
Both runtime entry points use recovery: Snapshot reads pass a validated recovery candidate and caller policy into the asynchronous path; startup configuration loading invokes the synchronous path. The patch’s shared effect runner is therefore aimed at the two affected execution modes rather than adding a parallel recovery flow.
Findings None None.
Security None None.

How this fits together

OpenClaw 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]
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes automatic recovery behavior for existing operator backups and persisted SQLite health entries; the branch should be rebased and its real recovery proof refreshed against the resulting exact merge head before approval.
  • Resolve merge risk (P1) - The protected maintainer label requires explicit human handling even though the patch and supplied proof are otherwise strong.
Agent review details

Security

None.

PR surface

Source -327, Tests +86, Other -1. Total -242 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 376 703 -327
Tests 1 86 0 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 5 462 704 -242

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/config/io.observe-recovery.test.ts, serialized state: src/config/io.observe-recovery.ts, vector/embedding metadata: src/config/io.observe-recovery.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase and refresh recovery proof (recommended)
    Rebase onto current main and rerun the real sync and async backup-recovery fixtures against the exact merge head before approving this compatibility-sensitive change.
  2. Pause for maintainer review
    Keep the PR in human review if maintainers want to reconsider automatic restoration policy for existing backups and health records.

Technical review

Best possible solution:

Rebase onto current main, retain the single shared recovery policy that validates the exact backup payload, and merge only after a maintainer confirms the resulting upgrade behavior for existing health-state entries and backup files.

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 lastKnownGood rather than the bytes in the .bak file, while both startup and snapshot callers route through this recovery code.

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.

Labels

Label changes:

  • add P2: The PR repairs a bounded configuration-recovery defect with meaningful but non-emergency operator impact.
  • add merge-risk: 🚨 compatibility: It changes when existing backup files and persisted health fingerprints authorize automatic configuration restoration during upgrade and startup.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.

Label justifications:

  • P2: The PR repairs a bounded configuration-recovery defect with meaningful but non-emergency operator impact.
  • merge-risk: 🚨 compatibility: It changes when existing backup files and persisted health fingerprints authorize automatic configuration restoration during upgrade and startup.
  • 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. Sufficient (live_output): The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents after-fix runs using real temporary config and backup files plus the SQLite health store across both startup and snapshot recovery, and the supplied exact-head checks include a successful Real behavior proof job.

Evidence

What I checked:

  • Current-main behavior remains unfixed: The current-main recovery path obtains backup from backupBaseline before considering the backup file, so a stored last-known-good fingerprint can authorize different backup bytes. The PR changes this by fingerprinting the backupRaw that was parsed and approved. (src/config/io.observe-recovery.ts:776, d0b6a92f85c7)
  • Actual-backup validation on the branch: The branch first parses and runs caller validation on the backup bytes, then builds a fingerprint from those same bytes and rejects the backup when it has no gateway mode before any restore is attempted. (src/config/io.observe-recovery.ts:372, 6c82346f7e0f)
  • Both runtime entry points use recovery: Snapshot reads pass a validated recovery candidate and caller policy into the asynchronous path; startup configuration loading invokes the synchronous path. The patch’s shared effect runner is therefore aimed at the two affected execution modes rather than adding a parallel recovery flow. (src/config/io.snapshot.ts:239, d0b6a92f85c7)
  • Regression coverage: The branch adds paired async/sync tests for rejecting a gateway-less backup authorized by stale health state, recovering canonical metadata, and tolerating stat failures; the PR body reports real temporary-file and SQLite-backed proof plus successful exact-head CI. (src/config/io.observe-recovery.test.ts:740, 6c82346f7e0f)
  • Feature-history ownership: Recovery behavior appears to originate with steipete’s suspicious gateway startup recovery work, while later config-health SQLite ownership and duplicate-policy refactoring were carried by Vincent Koc. (src/config/io.observe-recovery.ts:1, c8d21fe7f05b)
  • Current-main and release status: The PR head is not an ancestor of the checked-out main; no v* tag contains the PR commit, so this remains unmerged and unshipped work rather than an implemented-on-main cleanup candidate. (src/config/io.observe-recovery.ts:1, 6c82346f7e0f)

Likely related people:

  • steipete: Introduced the suspicious gateway startup recovery path in commit c8d21fe7 and authored this branch’s focused recovery repair. (role: original recovery-path contributor and recent area contributor; confidence: high; commits: c8d21fe7f05b, 6c82346f7e0f; files: src/config/io.observe-recovery.ts, src/config/io.load.ts, src/config/io.snapshot.ts)
  • Vincent Koc: Recent history attributes SQLite config-health ownership and shared observation-policy refactoring to this area. (role: config-health state contributor; confidence: medium; commits: 6daabd23f821, 72628f906b9e; files: src/config/io.health-state.ts, src/config/io.observe.ts, src/config/io.observe-recovery.ts)

Rank-up moves

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

  • Rebase onto current main and refresh the supplied sync/async real recovery proof for the exact merge head.

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.

@steipete
steipete merged commit f937775 into main Jul 31, 2026
195 of 203 checks passed
@steipete
steipete deleted the codex/loc-config-recovery-2d45 branch July 31, 2026 23:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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