Skip to content

fix(config): stop auto-restoring hand-authored configs missing meta (#126806) - #126932

Closed
ruel225 wants to merge 3 commits into
openclaw:mainfrom
ruel225:fix/config-meta-restore-126806
Closed

ruel225 wants to merge 3 commits into
openclaw:mainfrom
ruel225:fix/config-meta-restore-126806

Conversation

@ruel225

@ruel225 ruel225 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #126806.

A valid, schema-passing openclaw.json that an operator wrote by hand (or deployed via dotfiles/Ansible/Nix) — one without a meta block — was silently replaced by the previous openclaw.json.bak generation the next time any command loaded config, including read-only ones like openclaw models list. The operator's update.channel value and agent roster were dropped into a openclaw.json.clobbered.<ts> sidecar behind a single log line: recoverable, but not obvious.

Why This Change Was Made

loadConfig runs suspicious-read recovery after validation succeeds, so the restore only ever applies to configs that validate cleanly. missing-meta-vs-last-good was on the recoverable-reason list, and OpenClaw's own writer always stamps meta.lastTouchedVersion — so a valid config lacking meta was, by construction, hand-authored, the exact file a silent revert hurts most. The write path already treats the identical signal as benign (missing-meta-before-write is only logged; resolveConfigWriteBlockingReasons does not block), so the read path was stricter than the write path and reverted on it.

The fix removes missing-meta-vs-last-good from isRecoverableConfigReadSuspiciousReason (src/config/io.observe-recovery.ts). A valid config is now left untouched on read; the independent observe path (observeConfigSnapshot) still records the anomaly as a warning (Config observe anomaly: … (missing-meta-vs-last-good)) — the "at most, a warning" the issue asks for. gateway-mode-missing-vs-last-good and update-channel-only-root stay recoverable because they describe genuinely clobbered shapes.

Two follow-up commits close the residual windows that first fix left open:

  • 9637d635e2b — once a metadata-free config has been accepted and recorded as the last-known-good baseline, a later suspicious read could still auto-restore an older .bak generation over the operator's accepted file. The recovery source-eligibility check refuses a .bak whose bytes differ from a hand-authored accepted baseline, so a revert to older bytes is blocked while a .bak holding the accepted bytes itself still restores.
  • 40bf9d02050 — that skip still left a recognized valid clobber active when Gateway had promoted the accepted bytes to ${configPath}.last-good. The read recovery path now prefers that retained payload, accepting it only when its bytes hash to the recorded accepted-baseline hash (prepareLastGoodRecoverySource); a recognized clobber is then repaired from the operator's own accepted config instead of staying active. When no hash-verified copy exists (no .last-good, or its bytes diverged), the skip remains fail-closed with an explicit unavailable-baseline warning (Config auto-restore from backup skipped: … accepted baseline is hand-authored and no verified last-good copy exists) — divergent bytes are never restored. The last-known-good promote/recover owner moves to its own module (src/config/io.last-known-good.ts) so the read path stays under the file-size budget.
  • 634bab43c8e (40fac9dcfc3 adds docs only) — closes the two findings from that review. Acceptance bookkeeping (P1): both observers (observeConfigSnapshot/observeConfigSnapshotSync) advanced lastKnownGood only on completely clean reads, so the accepted warning-only read itself — the hand-authored edit — left the stale product-written fingerprint in place; a later recognized clobber then compared against that stale baseline, bypassed the hand-authored guard, and restored the pre-edit .bak over the live settings. A valid read whose anomalies are not recoverable now advances the baseline while the warning stays, with the recoverable/acceptance predicates owned in one place (isAcceptedConfigRead in src/config/io.observe-suspicious.ts). Source selection before backup preparation (P2): the .last-good branch sat behind .bak read/parse/prepare/gateway.mode checks, so a missing, unparsable, rejected, or gateway-mode-less .bak short-circuited recovery before the verified promoted payload was ever consulted. Selection now needs only the retained baseline's hash and runs before any source-specific preparation; .bak preparation runs only when .bak is the selected source.

User Impact

Operators who hand-author or config-manage a valid openclaw.json without a meta block no longer have it silently reverted to an older .bak generation by a read-only command — neither on the metadata-only read itself, nor later when a clobbered shape arrives (Scenario F). The accepted read itself becomes the recorded baseline, so later recovery compares against the operator's bytes rather than the pre-edit generation. When Gateway has promoted their accepted config, a later recognized clobber is repaired from that exact accepted payload even when the .bak is missing, unreadable, or rejected (Scenario D); otherwise the clobber is left in place with an explicit warning instead of being silently reverted or silently ignored (Scenarios C/E). Configs that genuinely lost their gateway.mode or collapsed to an update.channel-only root are still auto-restored as before whenever the accepted baseline is a product-written config (Scenario B).

Evidence

Real behavior (exact-head CLI transcript) — Scenarios A–E were captured at 40bf9d02050cc16badf05283774616ebd746af2e against the freshly built dist of that exact commit (OpenClaw 2026.8.1 (40bf9d0)); Scenario F re-runs the acceptance sequence at the current head 40fac9dcfc3 (banner OpenClaw 2026.8.1 (40fac9d), via the repo dev runner — source is byte-identical to 634bab43c8e, the docs commit sits on top). Every command runs against an isolated OPENCLAW_STATE_DIR and an isolated OPENCLAW_CONFIG_PATH (no operator state touched). Seven scenarios cover the metadata-only preservation, the product-written-baseline sibling, both halves of the accepted-baseline recovery semantics, the accepted-read baseline advancement, and the published-updater-to-candidate upgrade transition (Scenario G, captured at the current reviewed head d72b2078f90, banner OpenClaw 2026.9.5 (d72b207) — source identical to the reviewed head 70b177d5622).

Scenario A — a valid hand-authored config missing only meta (the regression the issue reports): baseline load stamps the last-known-good fingerprint, then the operator's file is rewritten without the meta block and re-read through the real openclaw models list --json CLI.

$ cat $OPENCLAW_CONFIG_PATH            # baseline generation WITH meta
{
  "meta": { "lastTouchedVersion": "2026.8.1" },
  "gateway": { "mode": "local", "port": 19001 }
}
$ openclaw models list --json          # baseline load
baseline exit=0
$ cat $OPENCLAW_CONFIG_PATH            # rewrite WITHOUT meta (same valid config otherwise)
{
  "gateway": { "mode": "local", "port": 19001 }
}
$ openclaw models list --json
run exit=0
$ grep -E 'observe anomaly|auto-restor' stderr.log
Config observe anomaly: /tmp/oc-126932-a/openclaw.json (missing-meta-vs-last-good)
$ cat $OPENCLAW_CONFIG_PATH            # after: byte-identical to what the operator wrote
{
  "gateway": { "mode": "local", "port": 19001 }
}
$ ls | grep -c clobbered
0

The hand-authored file is left byte-identical (no meta re-inserted), no .clobbered sidecar is written, no restore log — and the anomaly is still observed as a warning. Detection preserved; only the silent auto-restore is gone.

Scenario B — the same missing meta combined with a genuinely clobbered shape (gateway.mode lost, file reduced to a bare update.channel root), with an openclaw.json.bak generation present. The accepted baseline is product-written (hasMeta: true), so the new guard must not apply:

$ cat $OPENCLAW_CONFIG_PATH && cp $OPENCLAW_CONFIG_PATH $OPENCLAW_CONFIG_PATH.bak
{
  "meta": { "lastTouchedVersion": "2026.8.1" },
  "gateway": { "mode": "local", "port": 19001 }
}
$ openclaw models list --json          # baseline load
baseline exit=0
$ printf '{\n  "update": { "channel": "stable" }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json
run exit=0
$ grep -E 'observe anomaly|auto-restor' stderr.log
Config auto-restored from backup: /tmp/oc-126932-b/openclaw.json (missing-meta-vs-last-good, gateway-mode-missing-vs-last-good, update-channel-only-root)
$ cat $OPENCLAW_CONFIG_PATH            # after: restored to the last-known-good generation
{
  "meta": { "lastTouchedVersion": "2026.8.1" },
  "gateway": { "mode": "local", "port": 19001 }
}
$ ls | grep clobbered
openclaw.json.clobbered.2026-09-05T02-24-04-312Z

Restore for product-written baselines is unchanged — the guard is scoped to metadata-free accepted baselines only.

Scenario C — the two-read sequence with no promoted payload: a hand-authored config is accepted as the baseline (read 1), an older product generation sits in .bak, then an update.channel-only clobber arrives (read 2). No .last-good exists, so there is no verified copy to restore and the skip is fail-closed:

$ printf '{\n  "gateway": { "mode": "local", "port": 19001 }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json          # read 1: accepted, recorded as last-known-good (hasMeta false)
read1 exit=0
$ printf '{\n  "meta": { "lastTouchedVersion": "2026.7.1" },\n  "update": { "channel": "beta" },\n  "gateway": { "mode": "local", "port": 19002 }\n}\n' > $OPENCLAW_CONFIG_PATH.bak
$ printf '{\n  "update": { "channel": "stable" }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json          # read 2: suspicious clobber, .bak predates the accepted baseline
read2 exit=0
$ grep -E 'observe anomaly|auto-restor' stderr.log
Config auto-restore from backup skipped: /tmp/oc-126932-c/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root); accepted baseline is hand-authored and no verified last-good copy exists
Config observe anomaly: /tmp/oc-126932-c/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root)
$ cat $OPENCLAW_CONFIG_PATH            # after: NOT reverted to the older .bak bytes
{
  "update": { "channel": "stable" }
}
$ ls | grep -c clobbered
0

Scenario D — the repaired recognized-clobber path: the same accepted hand-authored baseline, but this time Gateway actually started once and promoted the accepted bytes. The Gateway is started against the same isolated state (openclaw gateway run --port 19003 --auth none), reaches [gateway] ready, promotes, and is then stopped before the clobber is written — the recovery read is a plain CLI load:

$ printf '{\n  "gateway": { "mode": "local", "port": 19003 }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json          # read 1: accepted (fingerprint 9f4067a355…, 52 bytes, hasMeta false, gatewayMode local)
$ openclaw gateway run --port 19003 --auth none   # isolated gateway on the same state dir
… [gateway] ready                       # startup promotes the accepted snapshot
$ cat $OPENCLAW_CONFIG_PATH.last-good   # promoted payload == the operator's bytes
{
  "gateway": { "mode": "local", "port": 19003 }
}
# recorded health entry after promotion: hash 9f4067a355…, 52 bytes, gatewayMode "local", hasMeta false
# (gateway stopped; older .bak + clobber written next)
$ printf '{\n  "update": { "channel": "stable" }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json          # read 2: recognized clobber, verified last-good exists
read2 exit=0
$ grep -E 'observe anomaly|auto-restor' stderr.log
Config auto-restored from last-good: /tmp/oc-126932-h/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root)
$ cat $OPENCLAW_CONFIG_PATH            # after: the operator's accepted bytes are back
{
  "gateway": { "mode": "local", "port": 19003 }
}
$ ls | grep clobbered
openclaw.json.clobbered.2026-09-05T02-19-39-699Z

The restore takes the operator's own accepted values (port 19003), not the older .bak generation sitting next to it (port 19002 — Scenario C's .bak would have restored that value before this PR). The config-audit record for the read shows the repaired provenance: "restoredFromBackup": true, "restoredBackupPath": "/tmp/oc-126932-h/openclaw.json.last-good", and the clobbered bytes preserved in the sidecar.

Scenario E — the fail-closed twin of Scenario D: the promoted .last-good bytes have diverged (here overwritten with { "tampered": true }), so the recorded hash no longer matches and nothing is restored:

$ printf '{\n  "tampered": true\n}\n' > $OPENCLAW_CONFIG_PATH.last-good
$ printf '{\n  "update": { "channel": "dev" }\n}\n' > $OPENCLAW_CONFIG_PATH
$ openclaw models list --json
read exit=0
$ grep -E 'observe anomaly|auto-restor' stderr.log
Config auto-restore from backup skipped: /tmp/oc-126932-h/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root); accepted baseline is hand-authored and no verified last-good copy exists
Config observe anomaly: /tmp/oc-126932-h/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root)
$ cat $OPENCLAW_CONFIG_PATH            # after: divergent bytes NOT restored, clobber left in place
{
  "update": { "channel": "dev" }
}
$ cat $OPENCLAW_CONFIG_PATH.last-good  # .last-good untouched
{
  "tampered": true
}

Scenario F — the acceptance-bookkeeping sequence at the current head (634bab43c8e, banner OpenClaw 2026.8.1 (40fac9d)): a product-written baseline with a matching .bak (read 1), the operator's hand-authored edit that drops meta and adds channel settings (read 2), then a recognized clobber that loses gateway.mode (read 3). Read 2 must leave the edit live with only a warning and record it as the accepted baseline; read 3 must not restore the pre-edit .bak, which still holds the product bytes with meta:

$ pnpm dev models list --json          # read 1: product baseline load
exit=0                                 # (no config warnings)
$ sha256sum $OPENCLAW_CONFIG_PATH
13bb9e4f1c3f4d42…
$ cat > $OPENCLAW_CONFIG_PATH          # hand-authored edit: no meta, adds channels
{
  "update": { "channel": "beta" },
  "gateway": { "mode": "local" },
  "channels": { "discord": { "enabled": true, "dmPolicy": "pairing" } }
}
$ pnpm dev models list --json          # read 2
exit=0
$ grep -E 'Config ' stderr.log
Config observe anomaly: /tmp/proof-126806/state/openclaw.json (missing-meta-vs-last-good)
$ sha256sum $OPENCLAW_CONFIG_PATH      # warning retained, operator bytes untouched
c8de3f13c921b621…                      # (identical to what was written)
$ cat > $OPENCLAW_CONFIG_PATH          # recognized clobber: gateway.mode disappears
{
  "update": { "channel": "beta" },
  "channels": { "discord": { "enabled": true, "dmPolicy": "pairing" } }
}
$ pnpm dev models list --json          # read 3
exit=0
$ grep -E 'Config ' stderr.log
Config auto-restore from backup skipped: /tmp/proof-126806/state/openclaw.json (gateway-mode-missing-vs-last-good); accepted baseline is hand-authored and no verified last-good copy exists
Config observe anomaly: /tmp/proof-126806/state/openclaw.json (gateway-mode-missing-vs-last-good)
$ sha256sum $OPENCLAW_CONFIG_PATH      # the pre-edit .bak (holding meta) was NOT restored
3e2dca8acf0f105d…                      # (identical to the clobbered bytes)
$ grep -c '"meta"' $OPENCLAW_CONFIG_PATH
0

Read 2's acceptance is what repairs read 3: because the accepted hand-authored read advanced the baseline (hasMeta: false, its own hash), the recovery guard treats the operator's file as the accepted state and refuses the pre-edit .bak. Before this commit the baseline stayed on the product fingerprint (hasMeta: true), the guard was bypassed, and the .bak — with its stale meta and without the operator's channel settings — was restored (the new regressions fail exactly there).

Scenario G — the published-updater-to-candidate upgrade transition at the current head (d72b2078f90, banner OpenClaw 2026.9.5 (d72b207)): the published v2026.9.5 release (commit ec9c1a1) first owns the same isolated state — a hand-authored baseline load through its real CLI, then a promotion through the same promoteConfigSnapshotToLastKnownGood seam (src/config/io.runtime.ts) its Gateway startup calls — leaving existing config-health records and a hash-verified promoted .last-good copy behind. The candidate head then consumes exactly that published state with no migration step in between:

$ openclaw models list --json          # v2026.9.5 (ec9c1a1): baseline load of the hand-authored config
baseline exit=0
$ # v2026.9.5 health record after that read (read-only query on the isolated state DB):
$ #   last_known_good_json  = {hash 70556f5d340e8b70…, bytes 52, hasMeta false, gatewayMode "local"}
$ #   last_promoted_good_json = null
$ tsx probe.mts                        # v2026.9.5: await promoteConfigSnapshotToLastKnownGood(
                                       #   await readSourceConfigSnapshot()) — the same createConfigIO
                                       #   entry its Gateway startup calls (server-startup-finish.ts)
promote returned: true
$ # v2026.9.5 state left behind for the upgrade:
$ #   last_promoted_good_json = {hash 70556f5d340e8b70…}
$ sha256sum $OPENCLAW_CONFIG_PATH.last-good
70556f5d340e8b70…  openclaw.json.last-good   # (52 bytes; hash equals the recorded promoted fingerprint)
$ printf '{\n  "update": { "channel": "stable" }\n}\n' > $OPENCLAW_CONFIG_PATH   # clobber
$ openclaw models list --json          # candidate head (d72b207) reads the v2026.9.5 state
candidate exit=0
$ grep -E 'Config ' stderr.log
Config auto-restored from last-good: /tmp/oc-126932-upgrade/openclaw.json (gateway-mode-missing-vs-last-good, update-channel-only-root)
$ cat $OPENCLAW_CONFIG_PATH            # after: exactly the promoted v2026.9.5 payload
{
  "gateway": { "mode": "local", "port": 19113 }
}
$ openclaw models list --json          # candidate stability read after the restore
read2 exit=0
$ grep -cE 'restor|anomaly' stderr.log
0                                      # no repeated restore, no anomaly: the promoted bytes are the accepted state
$ cmp after-restore.bytes $OPENCLAW_CONFIG_PATH && echo IDENTICAL
IDENTICAL

The upgrade transition needs no schema migration to consume the published state: the config_health_entries kernel (src/config/io.health-state.kernel.ts) and fingerprint types (src/config/io.health-state.types.ts) are byte-identical between v2026.9.5 and this head, and the generated DB-type diff between the two releases touches only unrelated subsystems — so the candidate opens the v2026.9.5 state database, reads the recorded last-known-good and last-promoted-good fingerprints (70556f5d340e8b70…), verifies the promoted .last-good copy against that hash, and repairs the recognized clobber from the published payload in one read (Config auto-restored from last-good: …). The post-restore stability read confirms the trust boundary stays where it was: the restored bytes are the accepted state, no further restore or anomaly fires, and the file is untouched.

Docs updated in this PR: docs/gateway/troubleshooting.md lists update-channel-only-root among the recoverable observe signatures, separates the metadata-only warn-only case, describes .clobbered.* preservation as best effort (the bounded snapshot can be skipped under disk or rotation limits), and documents the hand-authored-baseline behavior with its exact skip warning plus the .last-good-first restore (Config auto-restored from last-good:); docs/help/faq.md states that a valid config missing only its meta block is left in place on its own and that last-known-good restoration still runs when the same read trips a recoverable signal — preferring a hash-verified .last-good copy when Gateway promoted one, and skipping with the warning otherwise.

ClawSweeper review findings addressed:

  • P1 "Record warning-only reads as the accepted recovery baseline" (latest review; src/config/io.observe.ts, src/config/io.observe-suspicious.ts, commit 634bab43c8e): both observers now advance lastKnownGood for a valid read whose anomalies are not recoverable, while the Config observe anomaly warning and audit stay. The acceptance predicate (isAcceptedConfigRead) lives beside isRecoverableConfigReadSuspiciousReason in src/config/io.observe-suspicious.ts — the single owner of both sides of the recovery/acceptance boundary — and requires snapshot.valid, so an unparsable file can never be promoted to the baseline by a missing-meta-only reason. Covered by the complete three-step sequence (product baseline → accepted metadata-free edit → recognized clobber keeps the operator's bytes) through both readers (loadConfig/observeConfigSnapshotSync and readConfigFileSnapshot/observeConfigSnapshot): loadConfig records accepted hand-authored edits so a later clobber keeps them and read snapshots record accepted hand-authored edits so a later clobber keeps them. Both fail on the pre-fix code at the baseline assertion (hasMeta stays true after the accepted edit) and end with the pre-edit .bak restored over the accepted settings.
  • P2 "Select the retained baseline before requiring a usable backup" (latest review; src/config/io.observe-recovery.ts, commit 634bab43c8e): the .last-good branch no longer sits behind .bak read/parse/prepare/gateway.mode checks. Source selection needs only the retained baseline's hash and runs first; .bak preparation happens only when .bak is the selected source (hash equal to the accepted baseline keeps the .bak path — byte-identical restore, unchanged). Covered by unusable-backup regressions through both recovery lanes: missing .bak (loadConfig restores a promoted accepted baseline when no backup exists, read snapshots restore a promoted accepted baseline when no backup exists) and unparsable .bak (… when the backup is unparsable, sync + async). All four fail on the pre-fix code with the clobber left active (gateway.mode never restored).
  • P1 "Restore the verified accepted baseline for recognized clobbers" (src/config/io.observe-recovery.ts, commit 40bf9d02050): the recovery source-eligibility guard no longer returns the recognized clobber unchanged "solely because .bak differs". When the accepted baseline is metadata-free and the .bak bytes differ, the recovery path now reads the retained ${configPath}.last-good payload Gateway promoted at startup, accepts it only if its bytes hash to the recorded accepted-baseline hash, parses and re-validates it through the same candidate-preparation seam as .bak, and restores it — logging Config auto-restored from last-good: … and recording restoredBackupPath: <configPath>.last-good in the config audit (Scenario D). When no hash-verified copy exists (missing file, diverged bytes, unparsable JSON5, rejected candidate, or a payload without a gateway mode), the source preparation returns null and the existing skip remains, now with the explicit unavailable-baseline reason accepted baseline is hand-authored and no verified last-good copy exists (Scenarios C/E) — divergent bytes are never restored.
    • Covered by two new loadConfig-level regressions: loadConfig restores a promoted accepted baseline over a recognized clobber (promote → clobber → asserts the operator's bytes are restored, the from last-good warning, and the audit restoredBackupPath) and read snapshots keep a recognized clobber when the retained baseline diverged (diverged .last-good → asserts no restore and the skip warning). Both fail on the pre-fix code: the first restored nothing and left the clobber active, the second's assertion target (the skip warning text/behavior) did not exist.
  • P1 "Preserve the accepted configuration for later recovery" (src/config/io.observe-recovery.ts, commit 9637d635e2b): the .bak-vs-accepted-baseline refusal that started this repair — see the follow-up list in Why This Change Was Made.
  • P2 "Qualify the clobbered-copy recovery guarantee" (docs/gateway/troubleshooting.md): both bullets describe .clobbered.* preservation as best effort instead of a guarantee.

Regression (node scripts/run-vitest.mjs src/config/io.observe-recovery.test.ts — 71 tests at this head after removing six byte-identical merge duplicates, and node scripts/run-vitest.mjs src/config/io.write-config.test.ts — 129 tests at the pre-merge head; both pass):

  • Pre-fix: the two-read accepted-baseline regression fails — the clobbered read restores the older .bak bytes over the accepted hand-authored baseline. The original two tests (does not auto-restore when only metadata is missing …, loadConfig leaves a valid hand-authored config without meta untouched) fail on pre-PR code for the restored meta/rewritten bytes.
  • Pre-fix for the latest two findings (verified by reverting only the three source files and re-running): all six new regressions fail for the intended reasons — the two acceptance-sequence tests at hasMeta staying true after the accepted edit (then the pre-edit .bak restored over the accepted settings), and the four unusable-backup tests with the clobber left active (gateway.mode never restored).
  • Post-fix: both suites pass — the promoted-baseline scenarios restore the operator's bytes, the no-verified-copy scenarios keep the skip with its explicit reason, all product-written-baseline restore tests stay green, and the whole src/config lane (3914 tests across 281 files) passes at this head.

Sibling coverage: the recovery path is shared by load + read-snapshot. gateway-mode-missing-vs-last-good, update-channel-only-root, and size-drop-vs-last-good restore tests stay green for product-written baselines (their entries carry meta, so the new check does not apply — Scenario B is the live-CLI twin); a .bak byte-identical to an accepted hand-authored baseline still restores, so the skip never blocks restoring the operator's own bytes.

Checks: oxlint --type-aware clean and oxfmt clean on every file this PR touches; tsgo:core clean at this head, and the core-test-config-cli test shard reports no errors in any file this PR touches. The local tsgo:core:test shard run reports five errors, all in files this PR never touches (io.write-config.test.ts, io.write-reread.test.ts, session-accessor.test.ts, agents/workspace.test.ts — vi.spyOn mockImplementation implicit-any and SuiteAPI.sequential), consistent with stale local vitest typings rather than this change; CI is authoritative for those lanes. node scripts/check-changed.mjs -- <touched files> passes its conflict-marker lane; its max-lines ratchet lane reports nine entries that this PR never touches (dreaming-narrative.*, xai/web-search.test.ts, plugin-auto-enable.shared.ts, schema.ts, exec-approval-manager.ts, server-close.ts, exec-approval-forwarder.ts, logger.ts) — all nine are already removed from config/max-lines-baseline.txt on current main (verified via the GitHub contents API), so the local lane red is branch-base lag, and the CI merge-commit run evaluates the ratchet against the up-to-date baseline.

Focused-suite test-cost measurements (recorded as requested): local focused-suite wall times at head d72b2078f90 on an 8-vCPU Xeon dev host (node scripts/run-vitest.mjs run <file>, one shard per file): src/config/io.observe-recovery.accepted-baseline.test.ts (new sibling, 11 tests) — 22.1s vitest duration / ~28s wall; src/config/io.observe-recovery.test.ts (60 tests after the split) — 29.1s / ~35s; src/cli/gateway-cli/pre-bootstrap.process.test.ts (17 tests, spawns real child processes) — 137.8s / ~143s. Available CI durations (head 82c803c81bf, run 35819716853, the last completed run of this test surface; the two later commits only split a test file within the same shard and touch no production code): the changed src/config tests run inside the core-runtime-config-hosted-3 shard of job checks-node-compact-large-23 — 224 test files, 442.76s vitest duration; the pre-bootstrap file runs inside the agentic-cli shard of job checks-node-compact-small-13 — 543.48s vitest duration (that shard exited red on the since-repaired discarded-env fixture regression fixed in 15c0680a19d, all 17 tests executed).

reviewMetrics

  • src/config/io.observe-recovery.ts (first commit): prod net −1 behavioral line (removed missing-meta-vs-last-good from the recoverable-reason list); +3 comment lines documenting the non-obvious exclusion. Why it matters: removes a read-path auto-restore that silently destroyed valid hand-authored configs on read-only commands (silent failure / data-loss — highest severity).
  • src/config/io.observe-recovery.ts (follow-up 9637d635e2b): prod +11/+0 — one guarded skip (comment + condition + warn) inside the existing source-eligibility block. Positive delta justified: it adds the concrete ownership invariant that a hand-authored accepted baseline may not be reverted by an older product-written .bak, which cannot be expressed by reshaping the existing eligibility list without weakening restore for product-written baselines.
  • 40bf9d02050: prod +349/−247 across io.observe-recovery.ts (+99/−245), the new io.last-known-good.ts (+248), and io.factory.ts (+2/−2). Of that, ~205 lines are a verbatim move of the last-known-good promote/recover/clobber owner out of io.observe-recovery.ts into its own module (required by the 700-line max-lines ratchet — the file was at 723 with the fix inlined), leaving ≈ +95 net-new behavioral lines: the hash-verified .last-good source preparation generator, the restore-source switch, and the source-labeled restore log/audit path. Tests +98/−2 (two new load/snapshot regressions), docs +2/−2. Why it matters: turns the fail-closed skip into an actual repair for the default Gateway-promoted path while keeping the skip for unverifiable bytes; the positive delta is the verified-source recovery seam itself, which cannot be expressed by reshaping the existing .bak eligibility branch.
  • 634bab43c8e (current head): prod +114/−52 across io.observe-recovery.ts (+50/−49 — the source-selection restructure largely replaces the old prepare-then-discard ordering line for line), io.observe.ts (+44/−3 — acceptance bookkeeping in both observers), and io.observe-suspicious.ts (+20 — the two predicates moved to, or added at, their single owner). Tests +180/−0 (six new regressions), docs +3/−3. Why it matters: closes both reviewed recovery defects — accepted warning-only reads now advance the baseline so clobber recovery compares against the operator's bytes, and a verified .last-good payload is reachable even when the .bak is missing, unparsable, rejected, or gateway-mode-less.
  • 4dd29dc3086 (semantic merge of current main): carries the recovery semantics above onto main's capture/patch health-state architecture — accepted-baseline advancement injected into both of main's capture/patch observers (async and sync symmetric), verified-source selection spliced into main's planSuspiciousConfigRead, and io.last-known-good.ts folded away because main owns the promote/recover cores in io.observe-recovery.ts. No behavior beyond the commits above; the merge review confirmed the earlier findings resolved and flagged two integration defects, fixed next.
  • 82c803c81bf (post-merge repair; current head): prod +15/−5, tests −129. Restores the no-source startup fast path: planSuspiciousConfigRead returns before fingerprinting the file or opening the health worker when neither .bak nor .last-good exists on disk, while a missing .bak alongside a possible promoted payload still continues (the .last-good lane is not gated on .bak) — skips recovery health reads without a backup and admits a later backup in src/commands/doctor-config-preflight.recovery.test.ts guards it (6/6 pass at this head). Removes the six byte-identical test copies the merge created (one copy of each scenario stays), drops a redundant Boolean() wrapper on an already-boolean expression, adds the three missing SAFETY invariants in the extracted io.last-good-recovery-source module, and removes a stray blank line. io.observe-recovery.test.ts (71 tests) and doctor-config-preflight.recovery.test.ts (6 tests) pass at this head.

risks

  • Removed recovery fallback for missing-meta-vs-last-good: configs that previously auto-restored on missing-meta alone no longer do. This is the intended fix — those were almost exclusively hand-authored valid files; a genuine clobber that lost only meta while keeping every other field valid is near-impossible (corruption truncates/damages, it does not surgically strip meta), and even then the file still validates and is left flagged. The observe path still records the anomaly; .bak/.clobbered backups remain for manual restore.
  • Skip is fail-closed only when no verified copy exists: with a recognized clobber and a metadata-free accepted baseline whose .bak differs, recovery now repairs from the hash-verified .last-good payload (Scenario D). Only when that payload is missing or diverged does the read leave the recognized clobber active with the explicit unavailable-baseline warning — the operator compares against the retained .bak/.last-good/.clobbered artifacts and restores manually, or rewrites the file. This trades one automatic repair for never restoring unverified bytes; the skip warns with the exact reason and the observe anomaly is still audited.
  • .last-good payload trust is hash-scoped: the promoted payload is accepted only when its bytes hash to the recorded accepted-baseline fingerprint hash; a diverged .last-good (partial write, operator edit, tampering) is never restored (Scenario E). The fingerprint itself is Gateway-promoted state in the shared SQLite health store, so the trust boundary matches the existing last-known-good promotion contract rather than widening it.
  • size-drop-vs-last-good sibling: the issue traces the same read-stricter-than-write asymmetry for size drops but did not reproduce it; the write side blocks size-drop: unless allowConfigSizeDrop is set, so it is a weaker case. Intentionally out of scope here — flagged for a separate change with its own reproduction.

bestSolution

Removing missing-meta-vs-last-good from the recoverable-reason list at its owner (isRecoverableConfigReadSuspiciousReason), plus source eligibility that prefers the hash-verified promoted .last-good payload and otherwise fails closed with an explicit warning, is the canonical fix set: the observe path provides the warning, recognized clobbers are repaired from the operator's own accepted bytes whenever a verified copy exists, and recovery for the unverifiable state stays explicit instead of silently reverting or silently ignoring.

Main rebase (head 718ae1765c4)

Resolved the merge conflicts flagged in the review against current main (which now includes the config deslop in #157146):

  • src/config/io.observe-suspicious.ts: main's deslop removed isRecoverableConfigReadSuspiciousReason and made any suspicious reason trigger recovery (suspicious.length === 0). The merge restores this branch's policy — missing-meta-vs-last-good is excluded from auto-restore and drives the accepted-baseline advance instead — because reverting a valid hand-authored config is exactly the bug this PR fixes.
  • src/config/io.observe.ts: kept the isAcceptedConfigRead import alongside main's move of NormalizedConfigIoDeps to io.read.types.js.
  • src/config/io.observe-recovery-effects.ts / io.last-good-recovery-source.ts: follow main's @openclaw/fs-safe/atomic and io.read.types.js import locations.

Verified on the merged head: tsgo clean; the recovery suites (io.observe-recovery.test.ts, io.observe-recovery.accepted-baseline.test.ts, io.health-state.test.ts, io.load-env-restore.test.ts, io.observe-freshness.test.ts) — 109/109 pass. The remaining before-merge items are the maintainer decisions on the accepted-baseline fallback behavior, which the Scenario G / real-CLI evidence above documents.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@ruel225
ruel225 marked this pull request as ready for review August 21, 2026 01:38
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 656f77ffb358444db0b0a64a0931580b5bbaea7a, but the PR head is now cd3887e5e38f041019cc6bd91b9b718b2cca9ac2. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (41 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-23T13:08:52.008Z sha 70b177d562223d9f3521795937e3f032723b4586 :: blocked before merge. :: none
  • reviewed 2026-09-23T20:52:32.604Z sha 70b177d562223d9f3521795937e3f032723b4586 :: blocked before merge. :: none
  • reviewed 2026-09-25T04:52:26.280Z sha 70b177d562223d9f3521795937e3f032723b4586 :: blocked before merge. :: none
  • reviewed 2026-09-25T20:52:27.933Z sha 718ae1765c4f0b59ccc26d77d924f2238c43f179 :: blocked before merge. :: none
  • reviewed 2026-09-26T00:31:28.154Z sha bc14687f6bb434cc38dfc61ba07649d02eb9470d :: blocked before merge. :: none
  • reviewed 2026-10-09T19:23:44.511Z sha bc14687f6bb434cc38dfc61ba07649d02eb9470d :: blocked before merge. :: none
  • reviewed 2026-10-18T05:30:48.949Z sha bc14687f6bb434cc38dfc61ba07649d02eb9470d :: blocked before merge. :: [P3] Preserve Doctor ownership of legacy-key repair
  • reviewed 2026-10-26T08:23:22.647Z sha 656f77f :: needs real behavior proof before merge. :: [P2] Allow verified last-good recovery when the backup is unreadable | [P2] Update the retained metadata-only recovery assertion

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 21, 2026
@ruel225

ruel225 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Added exact-head real CLI proof to the Evidence section (built from cb09a5c8ad74). Redacted transcript of a read-only openclaw models list --json against an isolated OPENCLAW_STATE_DIR: a hand-authored openclaw.json (no meta) + an openclaw.json.bak carrying meta is left byte-identical after the read (no .clobbered sidecar, no restore log), while the missing-meta-vs-last-good observe warning still fires. "PR context and evidence" re-ran green on the edit.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 21, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 21, 2026
@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 21, 2026
@ruel225
ruel225 force-pushed the fix/config-meta-restore-126806 branch from 98cc83a to 1e36801 Compare August 30, 2026 00:44
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 7, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L and removed size: XL labels Sep 23, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Sep 23, 2026
@ruel225

ruel225 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

A valid, schema-passing openclaw.json written by hand — one without a
meta block — was silently replaced by the previous openclaw.json.bak
generation on any read-only command that loaded config. Only
hand-authored files ever match that shape: OpenClaw's own writer always
stamps meta.lastTouchedVersion.

Detection stays on the observe path (warning-only); auto-restore now
requires the identity signals only a product-written accepted baseline
provides:

- A hand-authored accepted baseline refuses a .bak whose bytes differ
  from it, blocking reverts to older generations.
- Recovery prefers a retained .last-good payload only when its bytes
  hash to the recorded accepted baseline, and source selection runs
  before backup preparation so a missing or rejected .bak cannot
  short-circuit the verified promoted payload.
- A valid read whose anomalies are not recoverable advances the
  accepted baseline, so later recovery compares against the operator's
  bytes rather than a stale product-written fingerprint.

Closes openclaw#126806.
@ruel225

ruel225 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebuilt on the current main (3037992) as 656f77f — main's observe-system refactor absorbed part of the previous head, so this replays the remaining net change on top:

  • the recovery gate is re-established on the refactored read path (missing-meta-vs-last-good stays out of the recoverable set, hand-authored accepted baselines exempt)
  • last-good recovery source selection moved to its own module (io.last-good-recovery-source.ts) and runs before .bak preparation, with the hash-verified .last-good preference and the hand-authored .bak refusal preserved
  • the accepted-baseline bookkeeping (isAcceptedConfigRead) and the test suite were redone against the main base

Verification on this head:

  • pre-fix red: with the four implementation files reverted to main, does not auto-restore when only metadata is missing fails — meta is silently re-stamped from the backup (the issue symptom)
  • post-fix green: the same test passes at 656f77f; the full io.observe-recovery.test.ts suite and the accepted-baseline suite (11 e2e scenarios) pass locally (vitest, forks pool)
  • pre-bootstrap.process.test.ts fixture changes were statically reviewed only — the process suite OOMs in this sandbox, CI has the final word

Test trade-off: the previous head carried a 1467-line main-side test file; the main base caps test files at 1000 lines, so the proof surface here is the 4 core recovery tests plus the 11 accepted-baseline e2e scenarios.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale after 7 days without qualifying human activity.
Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. scripts Repository scripts size: XL stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: valid hand-edited openclaw.json without a meta block is silently replaced by openclaw.json.bak on any read-only command

1 participant