Repository navigation
fix(config): doctor cannot repair a broken config when the state directory is a symlink - #188560
Conversation
Config prefix stripping and backup or last-known-good restores published through the logical config path, so a symlinked OPENCLAW_STATE_DIR made fs-safe reject the write with "Atomic replace parent must be a real directory" and `openclaw doctor --fix` could not repair the config. Publish recovery writes through the resolved physical parent, as regular config writes do since openclaw#155538, keeping the logical path for locking and identity, rechecking the path proof right before the rename, and preserving the state directory's mode. Recovery now refuses a symlinked config file like regular writes do, instead of replacing the link. The refusal names the cause and points at OPENCLAW_CONFIG_PATH.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR lets config recovery publish through a symlinked state directory while preserving the logical path and rejecting config-file symlinks. Example: state-link points to real-state, whose openclaw.json contains a warning line followed by {"gateway":{"mode":"local","port":18999}}.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current recovery failure using the existing guarded publication owner; no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDoctor sends invalid config snapshots to prefix or backup recovery; those owners validate replacement bytes, preserve the original, and publish through the guarded atomic filesystem writer. flowchart TD
A[Doctor config preflight] --> B[Prefix recovery]
A --> C[Backup recovery]
B --> D[Physical publication target]
C --> D
D --> E[Path and source guards]
E --> F[Atomic config replacement]
Technical reviewBest possible solution: Publish both recovery paths through the existing guarded physical-parent target while retaining logical identity, original snapshots, validation, and directory modes. Do we have a high-confidence way to reproduce the issue? The Doctor caller, current-main recovery writers, and pinned dependency establish the failing Linux path; the contributor supplies baseline CLI output and an affected stable release, while this review executed no product code. Is this the best way to solve the issue? The patch addresses the publication boundary directly and is the smallest complete repair using existing owners; each added test protects a distinct recovery or identity failure. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 840672c39645. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +36, Tests +64, Other +2. Total +102 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 30, 2026, 1:37 PM ET / 17:37 UTC. |
Reject foreign logical snapshot paths before physical publication remapping. Use the atomic writer's existing pre-effect path proof in both recovery adapters so changing a state-root alias during synchronous staging refuses publication. Both defects have failing-first public ConfigIO regressions. Recovery/Doctor tests, all recovery modes, targeted types, lint, format and fresh independent Codex P0-P2 review pass on the complete source snapshot. Co-authored-by: steipete <[email protected]> Co-authored-by: Masato Hoshino <[email protected]>
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…ctory is a symlink (openclaw#188560) Repair Doctor config recovery through an explicitly selected symlinked state root using the existing canonical publication owner. Preserve original backups, logical identity, root links and directory modes; retain config-file symlink and foreign-snapshot refusals and revalidate the root at atomic effect for synchronous and asynchronous recovery. Validation: 203 exact-head affected consumers pass; base prefix/LKG reproduce RED. Published 2026.10.9 fails registered Doctor; replacing it with the uninstrumented d620 build in the same prefix/HOME/state reaches Doctor complete with exit 0, with 16,770 installed runtime files matching the artifact and originals/backups/link/mode preserved. Complete-context independent Codex P0-P2 review is clean. CI 41111408083 attempt 1 remains failed on the inherited 2,712 test-line deficit. This PR adds 113 distinct regression-test lines with exactly 113 allocation credit; the shared scalar and failure inputs are unchanged. Land under the approved documented pre-existing-failure exception, preserving security and required review enforcement. The allocation covers recovery, foreign snapshot identity and publication-time retarget refusal regressions. Work sessions: [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/78580230-7d1b-4329-a7dd-72554eb66323) Co-authored-by: steipete <[email protected]> Co-authored-by: Masato Hoshino <[email protected]>
Closes #188559
Related: #153952
What Problem This Solves
Fixes:
openclaw doctor --fixcannot repair a brokenopenclaw.json(a non-JSON prefix, or a restore from the last-known-good copy) when the state directory is a symlink; the repair fails withAtomic replace parent must be a real directoryand Doctor stays blocked.User Impact
User impact: operators whose state directory is a symlink get the same config repair as everyone else, and Doctor continues instead of telling them to run the command that just failed. The symlink, the logical config path, and the state directory's mode stay as they were. Updating needs no action: the next
openclaw doctor --fixrepairs a config that the released version could not.Behavior change: when
openclaw.jsonitself is a symlink, recovery used to replace the link with a regular file and succeed. It now refuses, like regular config writes since #155538 and as the configuration docs describe. The refusal (for recovery and regular writes alike) now saysConfig writes need a regular file, but <path> is a symlink. Point OPENCLAW_CONFIG_PATH at the real file, or replace the symlink with that file.instead of the genericincluded config target changed since last load.Why This Change Was Made
#155538 made regular config writes publish through the resolved physical parent directory, because the atomic replace refuses a symlinked parent. The two recovery writers (the prefix strip, and the backup/last-known-good restore) still published through the logical path. They now resolve the same publication target as regular writes, recheck its path proof right before the write, and take the directory mode from the same state root. A snapshot of a different config path is still refused, as before. No new state or option.
Evidence
Head 02ef4f3 on base d513a11.
Same synthetic home on both sides:
state-link -> real-state, andopenclaw.jsonholdingWarning: shell profile noisefollowed by{"gateway":{"mode":"local","port":18999}}; thenOPENCLAW_STATE_DIR=<home>/state-link openclaw doctor --fix --non-interactive.Before (main):
Exit 2 on main;
openclaw.jsonunchanged on both.After (this branch):
real-state/openclaw.jsonis now{"gateway":{"mode":"local","port":18999}}, the original is kept beside it, andstate-linkstill points atreal-state. This matches what main already prints for a real (non-symlinked) state directory.Upgrade: the released 2026.10.9, installed into an isolated prefix and HOME, fails on this fixture with the same
Atomic replace parent must be a real directoryerror and leavesopenclaw.jsonunchanged (its last line differs: "Doctor could not complete maintenance..."). Running this branch'sopenclaw doctor --fixon that same state repairs it with the output above.Regression tests in
src/config/io.symlinked-root.test.ts:.bakrestore shares the last-known-good writer's publication path and is covered through it. Both cases fail on the base with the error above and pass with the fix.openclaw.jsonis refused with the new message and leaves the link and its target untouched. On the base, recovery replaced the link.Checks:
pnpm testonio.symlinked-root,io.observe-recovery,io.snapshot.promotion,io.write-configandmutate(201 tests) passes.pnpm tsgo:coreandpnpm tsgo:core:testpass. Lint and format are clean on the touched files.pnpm check:changedpassed on an earlier revision of this branch except the dead export scan, whose entries are all in files this PR does not touch (tts, gateway, auto-reply) and come from main. Novi.mockadded. Test lines: +64, allocated inconfig/test-lines-allocations/config-recovery-symlinked-state-root.txt.Test cost:
src/config/io.symlinked-root.test.tstakes about 43 s wall time with--maxWorkers=1, almost all of it transform and import. The new cases add well under a second of test time.Not covered: Windows (the test uses a junction there; CI runs it). In the CLI runs, Doctor's later SQLite copy and temp-root steps refused because the test host's scratch directories are group-writable; main does the same with a real state directory there, so this is a host property. Other writers that may take a symlinked state directory (secrets file writes, update migration) are unchanged here.
Maintainer qualification at d620e45
The original contributor commit is retained. The correction rejects a snapshot from either an unrelated logical path or the physical publication path before remapping, and puts root-path revalidation in the existing atomic writer's pre-effect callback for both synchronous and asynchronous recovery. No second config writer or filesystem-safety exception is introduced.
385f0d8eaaf1d64ad67bbc46e25661049c298908: the exact registered Doctor fixture exits 2 at the atomic parent check, leaving config bytes unchanged; the direct real-root control completes Doctor with exit 0. Original02ef4f3: full registered Doctor completes with exit 0 and 201 affected tests pass in isolated Crabbox.02ef4f3and pass with the correction: accepting a foreign physical-path snapshot, and synchronous.bakrecovery publishing after the state-root link changes during staging. The complete final source snapshot, byte-identical to d620, passes 36 recovery/Doctor tests, scoped config CLI types, type-aware lint, and format..bak, and synchronous.bakrecovery; exact original and backup bytes, logical path, link, and mode2750survive. Asynchronous staging retargets and config-file symlinks refuse across the recovery producers without changing either config target. The initial backup-harness API setup failure was corrected separately and is not counted as product RED. Crabbox runs:run_6f14a911d1f07cd59a699fdee6855bbd,run_4d2fad9faab20cc37832a71c7d810909, andrun_b66753140c95999d00ec3950a254beae. These are source-snapshot evidence, not a fresh d620 lease or installed d620 build.113, matching this PR's net regression-test LF growth; the shared scalar is unchanged.Current-head CI run 41111408083 completed with a failing baseline-ratchet job. The failing test-line check reports
6307562lines against ceiling6304850, debt2712, net delta+113. Static Git-blob accounting of its exact basef9b9af087c59c36c0e70e6d50ab67fa0f415fb5egives6307449lines against ceiling6304737, the same debt2712: this PR adds 113 lines and 113 allocation credit, preserving the inherited deficit. The aggregate CI gate also fails. Other checks completed successfully, skipped, or neutral; current-head security/dependency review succeeds. CI is not green; no rerun or ceiling reset is claimed. The cancelled original-head five-minute gate is historical evidence only.Exact-head Crabbox qualification is now complete on a fresh no-role/public/no-Tailscale AWS
c7a.8xlarge, with only CI forwarded and no hydration. Run run_e94376b26bfcc3108cb3509325827211 verified full d620 SHA, IAM404, expected instance/source path, and source/proof hashes before candidate dependency execution. All 203 affected consumers pass. Both base prefix/LKG cases fail at the expected atomic-parent boundary. The canonical uninstrumented package build and tarball integrity checks pass.An actual published
2026.10.9install (8b18b5578f66eab1501cba4cef2310d88bfb9a41) fails registereddoctor --fix --non-interactivewith exit1 and the atomic-parent error, retaining the broken config and original snapshot. Installing the built d620 tarball into the same prefix, HOME, and state, then invoking that installed CLI, repairs the config and reachesDoctor complete.with exit0. All 16,770 installed runtime/entry/manifest files match the tarball byte for byte; build commit d620 and build ID2026.10.9-d620e452247d-2026-10-30T20-07-29.643Zprove the new installed build despite the unchanged package version. Tarball SHA256:8beb17f13acfd3b233705ab5710ffde6c555b40e695067de525f75d2f7ee8a99. Installed entry SHA256:fca855a910792b669426b4a64e69743e5dd74f7df84f110df7c7e0881b530b3e.The same-state proof preserves old original snapshots, saves a new exact original, keeps the state symlink and directory mode0700, and retains gateway local/port18999. Baseline install used a private bare working directory under sticky temp without a package-policy edit. Current symlink-root tests cover physical-snapshot and synchronous-retarget refusals; the earlier byte-identical source proof of asynchronous recovery-retarget/file-link refusals and mode2750 remains valid. No product change or review rerun was needed. Receipt collection separately verified hashes and the complete CLI logs. Prior quota-limited tiny leases ran no candidate code and remain settled; the fresh proof lease is released with a verified --wait terminal receipt. Windows proof remains with ordinary PR CI. No custom fork-harness green or green CI is claimed. Native preparation and exact-head landing were approved by the lead at 2026-10-30 20:17Z under the documented pre-existing-failure exception; security and review enforcement remain required.
Credit: original implementation by Masato Hoshino (
[email protected]), preserved in ancestry and the correction's coauthor trailers, withCo-authored-by: steipete <[email protected]>.Work sessions
Discussion, implementation and verification