Repository navigation
fix(config): preserve root and recovery backups after failed saves - #146291
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 12, 2026, 5:34 PM ET / 21:34 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR shares config-save staging and recovery across root and included files, preserves backups when staging fails, and reports partial-write recovery outcomes. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful repair absent from current main. The previous backup-permission finding is addressed, and no new blocking code defect was established; published-updater compatibility evidence remains outstanding. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s config writer accepts changes from CLI commands, Gateway requests, login, and setup flows. It publishes configuration files and recovery backups before callers apply the resulting runtime configuration. flowchart TD
A[CLI and Gateway changes] --> B[Validate config and capture ownership]
B --> C[Prepare backup bytes]
C --> D[Stage candidate file]
D --> E[Recheck authority and publish]
E --> F[Apply config and acknowledge]
E --> G[Restore owned file or report recovery details]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +132, Tests +538, Docs +6, Other 0. Total +676 across 23 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one guarded publication and recovery owner, with demonstrated preservation of existing configuration and successful service recovery when invoked by a published updater. Do we have a high-confidence way to reproduce the issue? Yes, source inspection establishes the backup-consumption path, and the PR describes permission-denied fallback and disk-full CLI scenarios. This read-only review did not execute them. Is this the best way to solve the issue? Yes, sharing staged publication and guarded restoration is a focused owner-level repair; update compatibility still needs the applicable published-driver evidence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9b59fe4ef7da. LabelsLabel 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
HistoryReview history (3 earlier review cycles)
|
|
landpr-approve-admin-merge |
|
landpr-approve-unrelated-red |
|
Thanks @obviyus! Proof: Real config saves preserve recovery files, and the recovered configuration starts an authenticated Gateway.
|
…penclaw#146291) ## What Problem This Solves Fixes root config write regressions introduced by openclaw#145983: failed config saves could remove the root and recommend a destructive retry, or discard recovery backups before staging succeeded. ## Why This Change Was Made Root and included-file saves share staged publication and safe restoration. Backup bytes are prepared asynchronously; rotation follows successful staging. Partial failures report the original error, recovery status, and backup location. The writer rechecks captured include path identities during publication and restoration. Backup permissions change only through admitted regular-file descriptors. The decision `which backup files may be mutated` is made by exactly one mechanism at `src/config/backup-rotation.ts:78`. The decision `whether captured include paths are unchanged` is made by exactly one mechanism at `src/config/io.write-safety.ts:80`. ## User Impact Failed staging preserves all five recovery generations. Interrupted saves restore the original file when safe. Gateway clients receive complete recovery details. Cancelled login and setup writes retain the cancellation reason. ## Evidence Before: permission-denied fallback plus a concurrent include edit removed the root; following retry advice lost Gateway settings and cold startup failed. Five disk-full saves consumed the backup history. The same CLI scenarios now restore the root, preserve all five root and include backups, and retain Gateway settings on the next save. Authenticated cold health passes; a wrong token is rejected. All three Gateway save methods return complete structured recovery failures. Aliased includes survive denied rename, validate, and cold-start; linked backup targets retain their bytes and permissions. Detailed consumer coverage is retained in `proof/consumers.md`. ## Compatibility No config keys, stored formats, protocol schema, or protocol version change. Partial publication failures use the existing `UNAVAILABLE` outcome. Plain-root legacy mutation adapters retain their supplied revision; include-bearing adapters without a committed snapshot use the existing unknown revision and can refresh before their next edit. ## Consumers - Config CLI saves preserve root and include recovery backups, including through symlinked includes, and report restoration outcomes. - Gateway `config.set`, `config.patch`, and `config.apply` preserve complete recovery messages and structured details. - Login and service-install writers check live authority immediately before file effects. - Deferred chat and Telegram native login consent recheck retained flow and caller authority at publication. - Gateway setup activation carries cancellation through the shared config writer. - Legacy include mutation adapters receive an unknown revision when no committed composite revision is available. <details> <summary>Internal call migration</summary> The counts below refer to retired adapters and synthetic test-fixture fields. Filesystem options, the public authority callback, and real token/version contracts remain supported. census: generic assertConfigPathForWrite reviewed — 0 callers listed census: generic chmod reviewed — 0 callers listed census: generic copyFallbackOnPermissionError reviewed — 0 callers listed census: generic copyFile reviewed — 0 callers listed census: generic dirMode reviewed — 0 callers listed census: generic fileSystem reviewed — 0 callers listed census: generic maintainConfigBackups reviewed — 0 callers listed census: generic mkdir reviewed — 0 callers listed census: generic open reviewed — 0 callers listed census: generic overwrite reviewed — 0 callers listed census: generic promises reviewed — 0 callers listed census: generic rename reviewed — 0 callers listed census: generic tempPrefix reviewed — 0 callers listed census: generic to reviewed — 0 callers listed census: generic token reviewed — 0 callers listed census: generic unlink reviewed — 0 callers listed census: generic version reviewed — 0 callers listed </details> ## Invalidation Existing config watchers and runtime refresh remain unchanged. Captured path facts are scoped to one write and its restoration. Failed saves publish no success acknowledgement. ## Contention Backup preparation yields to unrelated Gateway requests. With a 2,000 ms injected preparation delay, an unrelated health request completed in 90 ms (limit: 1,000 ms). Candidate staging, backup renames, and final checks stay synchronous. ## Tests 374 targeted config-owner and CLI tests passed, including linked backup slots, alias fallback, alias replacement, and missing-parent repair. Registered `openclaw config set`, `config.set`, `config.patch`, `config.apply`, `models.authLogin`, and `wizard.next` cover config writes. Provider login is synthetic. Service-token/install tests use a mocked writer and prove forwarding and refusal, not native service effects. Package-entry consumers cover legacy revision compatibility. CI hits the same `server-startup-finish.ts:416` type error as [main run 34718269980](https://github.com/openclaw/openclaw/actions/runs/34718269980), introduced by openclaw#146275. The config tests, formatting, line limits, assertions, and unused-export checks pass. Follow-up: Settings reload/save after a missing root can create defaults; that existing UI behavior is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
…146856) ## What Problem This Solves After a partially saved settings file cannot be restored, Settings can misread the error as a stale conflict. Reloading the missing file and editing again can overwrite the complete configuration and prevent Gateway startup. ## User Impact Settings keeps the draft, shows recovery instructions, and blocks further writes in existing and fresh tabs. “Discard draft and reload” accepts only an existing, valid file. Ordinary conflicts keep Reload. Ordinary invalid files keep their validation issues, even when a routine backup exists. ## Why This Change Was Made The decision `how a config save error is classified` is made by exactly one mechanism at `ui/src/lib/config/config-gateway-operations.ts:72`. The decision `whether this running Gateway has an unresolved publication outcome to expose` is made by exactly one mechanism at `src/gateway/server-methods/config.ts:785`. The added state retains actual write failures for fresh readers without inferring recovery from a backup file. Related: #146291. AI-assisted. ## Consumers - Settings save indicators retain drafts and expose guarded recovery reload. - Workshop, cloud-worker, Labs and MCP configuration edits receive recovery failures through shared write admission. - Provider login, logout and API-key edits, model setup, agent identity and shared GitHub operations wait for recovery. - Config-backed preference sync keeps pending edits when writes are refused. - Skill and plugin changes share admission; wrappers retain an originating request error and use the owner message for pre-dispatch refusal. ## Invalidation The Gateway records actual unresolved publication failures. A matching fresh valid read or successful write can clear its captured record; older operations cannot clear a newer failure. Settings retains its draft until explicit valid reload. Failure recording has one writer at the publication outcome boundary. ## Evidence A real Gateway and browser reproduced Reload → reduced settings → cold startup exit 78 before the fix. Afterward, failed restoration retained the original draft and blocked a fresh tab; restoration enabled a complete save. A normal backup plus an unrelated invalid port preserved the concrete validation issue without claiming failed restoration. ## Compatibility Existing diagnostic snapshots and revision fields remain intact. Optional `writeError` carries the actual publication error. No configuration keys, storage schemas, migrations or protocol versions change. ## Contention The existing queue is unchanged. A held pre-failure read cannot retire a newer recovery record; no lock or awaited publication step is added. ## Tests Targeted integration tests passed: 7 Gateway, 87 UI owner and 4 Settings browser cases. Existing ordinary-conflict coverage remains. Sanitized browser captures show retained drafts, blocked fresh-tab fields and preserved validation issues. Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#146856) ## What Problem This Solves After a partially saved settings file cannot be restored, Settings can misread the error as a stale conflict. Reloading the missing file and editing again can overwrite the complete configuration and prevent Gateway startup. ## User Impact Settings keeps the draft, shows recovery instructions, and blocks further writes in existing and fresh tabs. “Discard draft and reload” accepts only an existing, valid file. Ordinary conflicts keep Reload. Ordinary invalid files keep their validation issues, even when a routine backup exists. ## Why This Change Was Made The decision `how a config save error is classified` is made by exactly one mechanism at `ui/src/lib/config/config-gateway-operations.ts:72`. The decision `whether this running Gateway has an unresolved publication outcome to expose` is made by exactly one mechanism at `src/gateway/server-methods/config.ts:785`. The added state retains actual write failures for fresh readers without inferring recovery from a backup file. Related: openclaw#146291. AI-assisted. ## Consumers - Settings save indicators retain drafts and expose guarded recovery reload. - Workshop, cloud-worker, Labs and MCP configuration edits receive recovery failures through shared write admission. - Provider login, logout and API-key edits, model setup, agent identity and shared GitHub operations wait for recovery. - Config-backed preference sync keeps pending edits when writes are refused. - Skill and plugin changes share admission; wrappers retain an originating request error and use the owner message for pre-dispatch refusal. ## Invalidation The Gateway records actual unresolved publication failures. A matching fresh valid read or successful write can clear its captured record; older operations cannot clear a newer failure. Settings retains its draft until explicit valid reload. Failure recording has one writer at the publication outcome boundary. ## Evidence A real Gateway and browser reproduced Reload → reduced settings → cold startup exit 78 before the fix. Afterward, failed restoration retained the original draft and blocked a fresh tab; restoration enabled a complete save. A normal backup plus an unrelated invalid port preserved the concrete validation issue without claiming failed restoration. ## Compatibility Existing diagnostic snapshots and revision fields remain intact. Optional `writeError` carries the actual publication error. No configuration keys, storage schemas, migrations or protocol versions change. ## Contention The existing queue is unchanged. A held pre-failure read cannot retire a newer recovery record; no lock or awaited publication step is added. ## Tests Targeted integration tests passed: 7 Gateway, 87 UI owner and 4 Settings browser cases. Existing ordinary-conflict coverage remains. Sanitized browser captures show retained drafts, blocked fresh-tab fields and preserved validation issues. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes root config write regressions introduced by #145983: failed config saves could remove the root and recommend a destructive retry, or discard recovery backups before staging succeeded.
Why This Change Was Made
Root and included-file saves share staged publication and safe restoration. Backup bytes are prepared asynchronously; rotation follows successful staging. Partial failures report the original error, recovery status, and backup location. The writer rechecks captured include path identities during publication and restoration. Backup permissions change only through admitted regular-file descriptors.
The decision
which backup files may be mutatedis made by exactly one mechanism atsrc/config/backup-rotation.ts:78.The decision
whether captured include paths are unchangedis made by exactly one mechanism atsrc/config/io.write-safety.ts:80.User Impact
Failed staging preserves all five recovery generations. Interrupted saves restore the original file when safe. Gateway clients receive complete recovery details. Cancelled login and setup writes retain the cancellation reason.
Evidence
Before: permission-denied fallback plus a concurrent include edit removed the root; following retry advice lost Gateway settings and cold startup failed. Five disk-full saves consumed the backup history. The same CLI scenarios now restore the root, preserve all five root and include backups, and retain Gateway settings on the next save. Authenticated cold health passes; a wrong token is rejected. All three Gateway save methods return complete structured recovery failures. Aliased includes survive denied rename, validate, and cold-start; linked backup targets retain their bytes and permissions. Detailed consumer coverage is retained in
proof/consumers.md.Compatibility
No config keys, stored formats, protocol schema, or protocol version change. Partial publication failures use the existing
UNAVAILABLEoutcome. Plain-root legacy mutation adapters retain their supplied revision; include-bearing adapters without a committed snapshot use the existing unknown revision and can refresh before their next edit.Consumers
config.set,config.patch, andconfig.applypreserve complete recovery messages and structured details.Internal call migration
The counts below refer to retired adapters and synthetic test-fixture fields. Filesystem options, the public authority callback, and real token/version contracts remain supported.
census: generic assertConfigPathForWrite reviewed — 0 callers listed
census: generic chmod reviewed — 0 callers listed
census: generic copyFallbackOnPermissionError reviewed — 0 callers listed
census: generic copyFile reviewed — 0 callers listed
census: generic dirMode reviewed — 0 callers listed
census: generic fileSystem reviewed — 0 callers listed
census: generic maintainConfigBackups reviewed — 0 callers listed
census: generic mkdir reviewed — 0 callers listed
census: generic open reviewed — 0 callers listed
census: generic overwrite reviewed — 0 callers listed
census: generic promises reviewed — 0 callers listed
census: generic rename reviewed — 0 callers listed
census: generic tempPrefix reviewed — 0 callers listed
census: generic to reviewed — 0 callers listed
census: generic token reviewed — 0 callers listed
census: generic unlink reviewed — 0 callers listed
census: generic version reviewed — 0 callers listed
Invalidation
Existing config watchers and runtime refresh remain unchanged. Captured path facts are scoped to one write and its restoration. Failed saves publish no success acknowledgement.
Contention
Backup preparation yields to unrelated Gateway requests. With a 2,000 ms injected preparation delay, an unrelated health request completed in 90 ms (limit: 1,000 ms). Candidate staging, backup renames, and final checks stay synchronous.
Tests
374 targeted config-owner and CLI tests passed, including linked backup slots, alias fallback, alias replacement, and missing-parent repair. Registered
openclaw config set,config.set,config.patch,config.apply,models.authLogin, andwizard.nextcover config writes. Provider login is synthetic. Service-token/install tests use a mocked writer and prove forwarding and refusal, not native service effects. Package-entry consumers cover legacy revision compatibility.CI hits the same
server-startup-finish.ts:416type error as main run 34718269980, introduced by #146275. The config tests, formatting, line limits, assertions, and unused-export checks pass.Follow-up: Settings reload/save after a missing root can create defaults; that existing UI behavior is tracked separately.