Skip to content

fix(config): an upgrade never refuses settings the previous release accepted - #198376

Open
obviyus wants to merge 6 commits into
mainfrom
fix/tolerant-upgrade-config
Open

obviyus wants to merge 6 commits into
mainfrom
fix/tolerant-upgrade-config

Conversation

@obviyus

@obviyus obviyus commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Upgrades refuse or lose config that the previous release accepted. From 2,720 classified real upgrade failures:

Cause Reports
Config validation rejects previously valid config 14
Doctor rewrites/migrates config unexpectedly 12
Renamed or removed config key not migrated 11
Removed config key rejected by validation 8
Post-update Doctor restores stale last-known-good config (data loss) 4

Reproduced with a real [email protected] npm install and a managed LaunchAgent Gateway. 2026.10.10 accepts this config (openclaw config validate → valid: true):

{
  "agents": { "defaults": {
    "embeddedAgent": { "cyberFailover": { "model": "openai/gpt-6-astra" } },
    "compaction": { "memoryFlush": { "model": "openai/gpt-6-astra" } } } },
  "channels": { "defaults": { "heartbeatVisibility": { "showOk": true } } },
  "skills": { "workshop": { "autonomous": { "mode": "off" } } }
}
  • openclaw update to main works: candidate Doctor migrates the keys before restart.
  • Any path that starts the new release before Doctor runs (npm/brew/image replacement, npm i -g, a host that boots the new image) leaves the Gateway down: gateway start exits 78 with OpenClaw config is invalid ... Unrecognized key: "workshop".
  • Doctor restores openclaw.json.last-good whenever a readable config is invalid and it has no automatic repair, replacing newer settings with older ones.
  • Doctor keeps only the rotating .bak ring and the per-attempt .pre-update copy, so the file the old release wrote is eventually overwritten.

What changed

  • Tolerant read on upgrade (src/config/io.snapshot.ts): when a config whose meta.lastTouchedVersion is an older supported release (2026.7.1 or newer) fails validation, the Gateway runs Doctor's own state-free transform in memory: applyLegacyDoctorMigrations (with plugin contracts off), retired-heartbeat projection, then unknown-key removal. If that result validates, the Gateway starts with it and one warning lists every change and asks for openclaw doctor --fix. The file and sourceConfig are unchanged. This is Doctor's transform, not a new runtime reader: runtime still consumes canonical config.
  • Original kept beside (src/config/backup-rotation.ts): the first rewrite by a newer release keeps the older release's bytes as openclaw.json.pre-<version>, outside the .bak ring.
  • No stale restore (doctor-config-preflight-legacy-config.ts): Doctor restores last-known-good only when openclaw.json cannot be parsed. A readable invalid config keeps its newer settings for repair. The prompt-permission guard that existed only to block that restore is deleted.
  • Doctor still saves it (automatic-config-repair.ts): a snapshot that is valid only through this projection carries olderReleaseMigration (source version and the list of changes), and Doctor's repair planner treats it like the invalid file it replaces, so doctor --fix and update preflight write the migrated config as before. Without this, Doctor saw a valid snapshot and skipped the write (caught by doctor-config-preflight.process.test.ts, stable-upgrade case).
  • Projected config is never a "good" file (io.snapshot.ts, io.observe.ts, io.factory.ts): a snapshot valid only through the projection is not promoted to last-known-good and is skipped by Doctor's suspicious-read recovery, so a larger older .bak is never restored over it. Doctor migrates and saves it instead.
  • Original kept atomically (backup-rotation.ts): openclaw.json.pre-<version> is written to a temp file and published with link, so a failed write leaves no partial original and the next write retries; an existing original is never replaced.
  • openclaw status shows it: a "Config migration pending" block lists every in-memory change and names openclaw doctor --fix. Status reads the local snapshot, so it shows whether or not the Gateway is running.
  • Docs: config migrations, configuration, Doctor checks.

Diff vs main: production +188 / -24, tests +147 / -29, docs +40 / -10. The growth is the in-memory projection hook (~50 lines, reusing Doctor's transform), the staged .pre-<version> writer (~45 lines), the projection module (~40 lines) and the status block (~25 lines). Deleted: the prompt-permission guard and the readable-config last-known-good restore path in Doctor. A follow-up could fold the per-attempt .pre-update copy into .pre-<version>; it sits in update rollback code another PR owns.

Validation boundary

The boundary is the writer stamp meta.lastTouchedVersion:

  • Tolerant only when an older supported release (2026.7.1 or newer) last wrote the file. Once the current release writes it (config set, Doctor, any validated writer), validation is strict again.
  • Writes stay strict: config set on a tolerated config refuses the retired key and names openclaw doctor --fix. openclaw config validate stays strict (it validates the file as written).
  • Heartbeat settings from an older release start paused (the warning names them) until Doctor converts them to automations; before this change the Gateway did not start at all.
  • A config valid only through this projection is never treated as a good file: it is not promoted to last-known-good and Doctor's stale-backup recovery does not restore over it. Doctor migrates and saves it instead.

Proof

Real installs, isolated profile (own LaunchAgent and port, clean env). Packed exact head 954dce0 (self-contained package, build-info.json commit 954dce0a119a); later commits change only a test type and drop an unused status --json field.

Package replacement on a config an older release wrote (published [email protected] with the config above, meta.lastTouchedVersion: 2026.11.2, serving /readyz ready). Database migration is held constant by running Doctor with the config read-only:

npm install -g --prefix "$PREFIX" <packed tarball>                   # direct replacement, 11.2 -> head
OPENCLAW_CONFIG_READONLY=1 openclaw doctor --fix --non-interactive   # DB migration; config bytes unchanged (cmp)
openclaw gateway start && curl http://127.0.0.1:$PORT/readyz
openclaw status
Check main (before) this branch, 954dce0 (after)
gateway start exit 78: OpenClaw config is invalid ... skills: Unrecognized key: "workshop" exit 0; /readyz → ready: true, coreReady: true
Gateway log n/a Config written by OpenClaw 2026.11.2 uses settings this release retired. Running with Doctor's migration until it is saved: ...
plain openclaw status Gateway down Config migration pending: block (below)
openclaw config set gateway.port 28794 before Doctor n/a exit 1, refused; file unchanged (cmp)
openclaw doctor --fix — exit 0; openclaw.json.pre-2026.11.2 equals the original bytes (cmp); config validate → valid: true; skills.workshop moved to plugins.entries.skill-workshop.config (autonomous.mode: off); port kept
after Doctor — Gateway restarts ready; status shows no migration block
Config migration pending:
- Config written by OpenClaw 2026.11.2 uses settings this release retired; running with Doctor's migration in memory. The file is unchanged.
- Removed retired agents.defaults.embeddedAgent.cyberFailover.model; automatic cyber-policy retries use the active model through approved Daybreak access. Existing mode and cooloffMs settings were not changed.
- Removed agents.defaults.compaction.memoryFlush.model; memory flushes now use the active session model and its fallback chain.
- Moved skills.workshop to plugins.entries.skill-workshop.config.
- Retired heartbeat settings are paused until Doctor converts them to automations.
- Fix: openclaw --profile upg112cp doctor --fix (saves the migration; keeps the original file)

Latest stable 2026.11.3 → head via openclaw update (published [email protected], managed LaunchAgent, a third-party plugin, gateway.port/auth set, 2 cron jobs, 1 user profile, a device identity; openclaw update --tag <head tarball> --yes):

Check Result
update exit 0; Recorded verification: ... HTTP ready; core ready; /readyz ready on 954dce0
settings gateway.port 28792, auth.mode token, plugin config.label demo, stamp unchanged before and after Doctor
original bytes openclaw.json.pre-update equals the pre-update file (cmp); no .pre-<version> (same-version writer, as designed)
stored data cron job IDs 60764235…, e8f8c2d8… identical; 1 user profile; main agent database; device ID b88f38fa… identical (moved by main's schema migration into client/credentials.sqlite)
status no Config migration pending block (config is current)
doctor --fix, gateway restart settings and IDs unchanged; Gateway ready. Doctor exits 1 only for the old-SDK test plugin's load error, which #198350 owns

Fresh install of the head (new profile, npm install -g <head tarball>, config set gateway.mode/port, gateway install): exit 0, /readyz ready, config stamped 2026.11.3, status shows no migration block, no .pre-* file.

openclaw update from 2026.10.10 (real npm install, same keys): main already succeeds, because candidate Doctor migrates the keys before restart; the only kept copy of the original is .pre-update, which the next update attempt overwrites. This branch keeps openclaw.json.pre-2026.10.10 permanently.

Next blocker after config (out of scope, item 4): a direct replacement from 2026.10.10 or 2026.11.2 to main now passes config admission and stops at agent database ... uses schema version 27; ... run openclaw doctor --fix to upgrade it to schema version 42. The copy-and-swap work owns that.

Regression tests, red on the previous head and green here: doctor-config-preflight.recovery.test.ts (1,024-byte .bak with port 19091 vs compact older-stamped config with port 19092: before, Doctor restored the backup; now it keeps 19092 and migrates), config.backup-rotation.test.ts (injected ENOSPC mid-write: before, a partial .pre-2026.10.10 stayed forever; now none is left and the next write keeps the full original). status.usage-routing.test.ts covers the status block.

Focused tests: io.snapshot.test.ts (older writer tolerated, heartbeat case, current writer still strict), config.backup-rotation.test.ts (.pre-<version> kept once), doctor-config-preflight.test.ts (readable invalid config is no longer replaced by last-known-good; unreadable file still restored), recovery, container-upgrade and state-migration suites.

Accepted edge cases

  • status --json does not carry the migration notice. With the Gateway online it reports the Gateway's status projection and reads no local config; reporting it there needs a Gateway-side fact kept across config reloads. Follow-up if wanted; text status, the Gateway log and Doctor show it.
  • A hand edit made after the upgrade but before any current-release write is also tolerated, because the stamp still names the old release. Accepted: it is visible (Gateway log, openclaw status, Doctor), recoverable (openclaw doctor --fix), and warned. No per-release key-acceptance records are kept.
  • Sync loadConfig() callers keep strict validation; the Gateway reads config through the async snapshot path, which is tolerant.
  • Unknown keys inside plugin-owned schemas (plugins.entries.<id>.config, plugin channel schemas) are not stripped; they remain plugin validation errors.
  • A Doctor migration that refuses (for example, conflicting prompt-permission values) leaves the config invalid, as before.

…ccepted

When the Gateway reads a config an older supported release wrote and it fails
validation, run Doctor's state-free config transform in memory (known
migrations, then unknown-key removal) and start with a warning instead of
refusing. The file is unchanged; the current release's writers stay strict.

The first rewrite of an older release's config keeps the original as
openclaw.json.pre-<version>. Doctor no longer restores last-known-good over a
readable invalid config, which discarded newer settings.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 13, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: M labels Nov 13, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets older-release configs run through Doctor migrations in memory, preserves versioned originals, and prevents stale recovery from replacing readable settings.

Example: Replace OpenClaw 2026.11.2 with the candidate while the config still contains skills.workshop.

  • Before: Gateway startup exits 78 because workshop is unrecognized.
  • After: The Gateway starts with migrated settings in memory, and Doctor can save them while retaining openclaw.json.pre-2026.11.2.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The focused repair has applicable shipped-entry-point and upgrade evidence, resolved prior findings, and no remaining actionable defects.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied terminal evidence exercises the packaged config owner through real replacement, Gateway startup, text status, strict config writes, and Doctor repair; latest-stable upgrade and fresh-install runs preserve settings and stored identities, resolving the previous compatibility gap.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Replacing an installation before Doctor runs can prevent Gateway startup, and recovery can discard newer readable settings.
Reason: The maintainer-authored direction repairs demonstrated upgrade failures while retaining explicit migration ownership and recoverable originals.

Merge readiness

✅ Ready for maintainer review

This maintainer-authored upgrade repair remains necessary on main; the earlier findings are fixed, and no actionable correctness or security findings remain.

Priority: P1
Reviewed head: c694daad9524544ed81f78e36c356526c7f13f05

Before merge

None.

Findings

None.

Agent review details

How this fits together

Config snapshots resolve authored settings and validate them for Gateway and CLI consumers; Doctor owns persistent migration, while the config writer owns backups and publication.

flowchart TD
  A[Authored config] --> B[Config snapshot reader]
  B --> C[Strict validation]
  C --> D[Doctor migration projection]
  D --> E[Gateway runtime and status]
  A --> F[Doctor repair]
  F --> G[Config writer and retained original]
Loading

Technical review

Best possible solution:

Use Doctor's existing transforms for temporary runtime admission, preserve original bytes, and keep canonical persistence under Doctor and the config writer.

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

Current-main validation and recovery source support the reported failures, and the supplied real-install comparison records exit 78 before the fix; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change reuses Doctor's migration owners, preserves strict writes and authored input, and removes the narrower recovery exception without adding competing persistent migration machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3991f8f22494.

Provenance checked

  • Runtime config admission changes intended behavior with a stated reason (2a1402c: General startup repair was moved to Doctor to avoid rewriting legacy state during ordinary startup; this PR deliberately adds a state-free projection while leaving persistent repair there.)
  • Readable invalid config recovery changes intended behavior with a stated reason (4017a1a: Migratable active settings were protected before backup recovery; this PR extends that preservation to readable invalid configs to avoid stale replacement.)
  • Prompt-permission recovery exception keeps the original intent (13374fd: An older backup must not replace an active grant or denial when includes prevent repair planning; the broader readable-config rule preserves that invariant.)
  • Backup publication keeps the original intent (535fcd9: Backup preparation and config publication preserve recovery history on failed writes; the additional original uses staged, non-replacing publication.)
  • Status diagnostics keeps the original intent (bc1f960: Status must expose invalid configuration instead of silently presenting substituted defaults as healthy; the new notice exposes temporary migration explicitly.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still rejects the affected shape: Fetched main proceeds directly from snapshot validation to invalid-config handling; the older-release projection is introduced by this PR. (src/config/io.snapshot.ts:272, 3991f8f22494)
  • Bounded migration through existing owners: The projection applies existing Doctor migrations, heartbeat projection, and unknown-key removal, then requires successful validation; authored bytes and sourceConfig remain available for repair. (src/config/io.snapshot.ts:303, c694daad9524)
  • Earlier recovery findings resolved: Projected snapshots are excluded from prepared stale-backup recovery and last-known-good promotion; the regression preserves port 19092 instead of restoring the larger backup's port 19091. (src/config/io.snapshot.ts:515, c694daad9524)
  • Complete original published without replacement: The retained original is written to a private temporary file before linking to its final name; the injected partial-write regression verifies cleanup and a successful later retry. (src/config/backup-rotation.ts:295, c694daad9524)
  • Upgrade and fresh-install evidence: The PR records real package-replacement startup, strict write refusal, Doctor migration with byte-identical original retention, a 2026.11.3 upgrade preserving settings and stored identities, and fresh-install readiness. The unrelated plugin failure is separately owned by fix(update): plugin failures never fail an update or Gateway health #198350. (c694daad9524)
  • Recorded proof remains applicable: Comparison with the exercised package revision confirms that subsequent edits only adjust a test override and remove the JSON migration field and its assertion; the exercised config, backup, and text-status owners are unchanged. (c694daad9524)

Likely related people:

  • Peter Steinberger: Raw commit 4017a1a adds src/commands/doctor-config-preflight-legacy-config.ts:36 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4017a1a2f44c; files: src/commands/doctor-config-preflight-legacy-config.ts)
  • Vincent Koc: Raw commit d3e5129 adds src/commands/doctor/shared/automatic-startup-config-repair.ts:145 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: d3e512906b63; files: src/commands/doctor/shared/automatic-startup-config-repair.ts)

PR surface

Source +164, Tests +118, Docs +30. Total +312 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 188 24 +164
Tests 5 147 29 +118
Docs 3 40 10 +30
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 375 63 +312

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The repair addresses upgrade-related Gateway startup refusal and replacement of newer settings by stale recovery.
  • merge-risk: 🚨 compatibility: Older-writer admission and recovery behavior change; the maintainer-authored PR explicitly accepts the documented tolerance and paused-heartbeat tradeoffs.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-13T17:31:03.504Z sha 74e5ff8 :: blocked before merge. :: [P1] Keep projected snapshots out of stale-backup recovery | [P2] Publish the retained original only after its write completes
  • reviewed 2026-11-13T19:22:33.849Z sha 29ef483 :: blocked before merge. :: [P1] Keep projected snapshots out of stale-backup recovery | [P2] Publish the retained original only after its write completes
  • reviewed 2026-11-13T20:29:11.454Z sha c694daa :: blocked before merge. :: none

Reviewed November 13, 2026, 3:52 PM ET / 20:52 UTC (Revision 4).

@obviyus
obviyus marked this pull request as ready for review November 13, 2026 17:58
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
obviyus and others added 3 commits November 14, 2026 01:02
…he migration in status

- A config valid only through the older-release projection is not restored over,
  promoted to last-known-good, or recovered from a larger stale backup.
- The kept openclaw.json.pre-<version> is staged and linked, so a failed write
  never leaves a partial original and the next write retries.
- openclaw status and status --json show the pending migration.

Co-authored-by: obviyus <[email protected]>
The online status --json path reads Gateway projection, not local config, so a
JSON field would appear only while the Gateway is down.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 13, 2026
@clawsweeper clawsweeper Bot removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

This branch has not been deployed

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

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: M 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