Skip to content

fix(config): doctor cannot repair a broken config when the state directory is a symlink - #188560

Merged
roboclaw-bot merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/config-recovery-symlinked-state-root
Oct 30, 2026
Merged

roboclaw-bot merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/config-recovery-symlinked-state-root

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Current qualification: the original contributor text below is preserved as historical evidence for 02ef4f3. The final section records published d620e452247d70976c97b0c66532c33820be54b8, completed exact-head Crabbox and installed-upgrade proof, and the inherited CI ratchet failure. Counts and setup notes in the original evidence refer to that earlier revision.

Closes #188559

Related: #153952

What Problem This Solves

Fixes: openclaw doctor --fix cannot repair a broken openclaw.json (a non-JSON prefix, or a restore from the last-known-good copy) when the state directory is a symlink; the repair fails with Atomic replace parent must be a real directory and 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 --fix repairs a config that the released version could not.

Behavior change: when openclaw.json itself 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 says Config 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 generic included 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, and openclaw.json holding Warning: shell profile noise followed by {"gateway":{"mode":"local","port":18999}}; then OPENCLAW_STATE_DIR=<home>/state-link openclaw doctor --fix --non-interactive.

Before (main):

│  Config invalid; doctor will run with best-effort config.
│  <home>/state-link/openclaw.json
│  - <root>: JSON5 parse failed: SyntaxError: JSON5: invalid character
│    'W' at 1:1
│  Atomic replace parent must be a real directory:
│  <home>/state-link
│  Run `openclaw config validate` to inspect the parse error.
...
└  Doctor blocked. Database checks remain unknown; no state migrations were performed.

Exit 2 on main; openclaw.json unchanged on both.

After (this branch):

Config auto-stripped non-JSON prefix: <home>/state-link/openclaw.json (original saved as <home>/state-link/openclaw.json.clobbered.<timestamp>)
│
◇  Config ──────────────────────────────────────╮
│                                               │
│  Removed non-JSON prefix from openclaw.json.  │
│                                               │
├───────────────────────────────────────────────╯
Doctor: startup

real-state/openclaw.json is now {"gateway":{"mode":"local","port":18999}}, the original is kept beside it, and state-link still points at real-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 directory error and leaves openclaw.json unchanged (its last line differs: "Doctor could not complete maintenance..."). Running this branch's openclaw doctor --fix on that same state repairs it with the output above.

Regression tests in src/config/io.symlinked-root.test.ts:

  • The prefix strip and the last-known-good restore recover a broken config through a symlinked state root, keeping the bytes, the link and the directory mode. The .bak restore 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.
  • Recovery through a symlinked openclaw.json is refused with the new message and leaves the link and its target untouched. On the base, recovery replaced the link.
  • Prefix recovery from a snapshot of another config path is still refused. This case and the other 10 in the file pass on both sides.

Checks: pnpm test on io.symlinked-root, io.observe-recovery, io.snapshot.promotion, io.write-config and mutate (201 tests) passes. pnpm tsgo:core and pnpm tsgo:core:test pass. Lint and format are clean on the touched files. pnpm check:changed passed 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. No vi.mock added. Test lines: +64, allocated in config/test-lines-allocations/config-recovery-symlinked-state-root.txt.

Test cost: src/config/io.symlinked-root.test.ts takes 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.

  • Main 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. Original 02ef4f3: full registered Doctor completes with exit 0 and 201 affected tests pass in isolated Crabbox.
  • Both additional regressions fail on 02ef4f3 and pass with the correction: accepting a foreign physical-path snapshot, and synchronous .bak recovery 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.
  • That final source snapshot also proves prefix, last-known-good, asynchronous .bak, and synchronous .bak recovery; exact original and backup bytes, logical path, link, and mode 2750 survive. 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, and run_b66753140c95999d00ec3950a254beae. These are source-snapshot evidence, not a fresh d620 lease or installed d620 build.
  • Fresh complete-context independent Codex P0–P2 review covers the entire final change and 17 intact owner/caller/dependency files. The first physical-snapshot finding is resolved; the final review is scoped-clean. The justified test-line allocation is now exactly 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 6307562 lines against ceiling 6304850, debt 2712, net delta +113. Static Git-blob accounting of its exact base f9b9af087c59c36c0e70e6d50ab67fa0f415fb5e gives 6307449 lines against ceiling 6304737, the same debt 2712: 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.9 install (8b18b5578f66eab1501cba4cef2310d88bfb9a41) fails registered doctor --fix --non-interactive with 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 reaches Doctor complete. with exit0. All 16,770 installed runtime/entry/manifest files match the tarball byte for byte; build commit d620 and build ID 2026.10.9-d620e452247d-2026-10-30T20-07-29.643Z prove 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, with Co-authored-by: steipete <[email protected]>.

Work sessions

Discussion, implementation and verification

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.
@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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}}.

  • Before: openclaw doctor --fix rejects the symlinked parent and leaves the invalid config unchanged.
  • After: Doctor saves the original, removes the warning line, and preserves the directory symlink.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with shipped CLI evidence, a same-state stable-release upgrade run, and distinct regression coverage; exact-head CI remains in progress.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): At the reviewed head, the supplied Linux Doctor trace exercises prefix recovery through a real symlinked state directory and shows repaired bytes, retained original, and an intact link after the baseline failure; production-owner regressions support last-known-good recovery and refusal boundaries.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor cannot repair an otherwise recoverable config when the selected state directory is a symlink.
Reason: Recovery should support the same documented state-directory layout as regular writes; the config-file refusal follows the existing regular-file contract.

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
Reviewed head: 02ef4f3262ad1451f0fd7c77b7f221b1013f2764

Before merge

None.

Findings

None.

Agent review details

How this fits together

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

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 267268f adds src/config/io.observe-recovery.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 267268f646cd; files: src/config/io.observe-recovery.ts)
  • MFA: Raw commit 2f330ca adds src/config/io.write-safety.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2f330ca69ff4; files: src/config/io.write-safety.ts)

PR surface

Source +36, Tests +64, Other +2. Total +102 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 51 15 +36
Tests 1 64 0 +64
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 5 117 15 +102

Labels

Label changes:

  • add P2: This fixes a bounded operator CLI recovery failure for explicitly configured symlinked state directories.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This fixes a bounded operator CLI recovery failure for explicitly configured symlinked state directories.
  • 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.

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]>
@roboclaw-bot
roboclaw-bot merged commit 70051b4 into openclaw:main Oct 30, 2026
148 of 151 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

[Bug]: doctor --fix cannot repair a broken config when the state directory is a symlink

2 participants