Skip to content

fix(doctor): diagnose immutable state without pending writes - #199509

Merged
steipete merged 1 commit into
mainfrom
fix/doctor-immutable-state-admission
Nov 21, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/doctor-immutable-state-admission

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #178178

What Problem This Solves

Fixes: on macOS, openclaw doctor reports "Doctor complete." and exits 0 when the state database is immutable (chflags uchg) and no migration is pending. Nothing can write to that database, and Doctor doesn't say so.

User Impact

User impact: Doctor again reports an immutable or otherwise unwritable state database, with its path and the macOS chflags nouchg remedy, and exits unsuccessfully, even when no migration is pending.

Doctor runs during openclaw update, so an installation whose state database is immutable or on a read-only mount now gets this diagnosis and a non-zero Doctor exit there too. That's the behavior #178178 intended, and the Gateway can't write state on those installations anyway. Installations with writable state behave exactly as before.

Why This Change Was Made

The storage diagnosis only fired when some write during the Doctor run happened to fail. Doctor's state admission now checks write access itself: after the existing permission hardening, it opens the existing database read-write without truncating it, then closes it. An immutable file, a read-only mount or an unwritable file now reaches the existing command-boundary diagnosis and recovery guidance. Database contents are untouched. Owned 0444 files are still hardened first, and foreign-owned writable files and unsupported chmod still pass. docs/gateway/doctor/running.md describes the check.

Root cause

The macOS-only regression src/commands/doctor-state-storage.test.ts › "diagnoses an immutable database at the command boundary" (it.skipIf(process.platform !== "darwin"), so Linux CI skips it) has failed since 6ce3260 (#184245). Until then, the test's plugin fixture caused an incidental state write that hit the immutable file. When the fixture was removed, a current database with no pending migrations finished without ever attempting a write. The test's assertions are unchanged here.

Evidence

  • End-to-end on macOS, real CLI, isolated state, migration-current database: with the fix, Doctor names the path, gives the chflags nouchg remedy and exits 1 with the database bytes unchanged. After chflags nouchg it completes with exit 0. With only the new line reverted, it prints "Doctor complete." and exits 0. Transcripts: fix(doctor): diagnose immutable state without pending writes #199509 (comment)

  • Published driver × candidate: published-upgrade-survivor with published [email protected] updating to f4fbc7ca4925 passed (849 s): updater success, candidate Doctor, post-Doctor config validation, seeded state survival, Gateway start and readiness. Fresh install docker-package-install passed (84 s) with npm, pnpm, Bun and npm on musl. This was the manual-restart variant; automatic restart and idempotence were not covered.

  • Bisect, single case under Node, from 11ad47f (fix(doctor): doctor fails with an internal lease error instead of explaining an unwritable state database #178178, passes) to main: first bad is 6ce3260 (test(runtime,ui,plugins): remove low-value tests (batch d593) #184245). 15 historical runs, none skipped.

  • The macOS case, --maxWorkers=1:

    Node pinned Bun
    before the fix fail fail
    with the fix pass pass
    fix reverted fail fail
  • Full doctor-state-storage.test.ts: 6/6 pass on both runtimes (60.5 s Node, 33.5 s Bun).

  • 24 direct-consumer test files: 296/296 pass on both runtimes.

  • Targeted lint, both core type-check lanes, formatting, ratchets, MDX validation and commit hooks pass. Independent review is clean.

  • Test cost: no new tests. The existing macOS case is unchanged (about 18 s Bun, 53 s Node in single-worker local runs).

Rebased-head validation

  • Rebased without conflicts onto main 786cd278fb1d51e5256b374a654483969242e871; candidate 045047bac19d912d62b660e3c203b9f238287e58. git range-diff confirms the product patch is unchanged.
  • Focused doctor-state-storage.test.ts and doctor-config-preflight*.test.ts selection: 122 tests across 16 collected files passed under Node and the default pinned Bun runtime. All six storage-diagnosis cases passed on macOS under both runtimes, including the immutable-database regression. Runtime preparation and git diff --check passed.
  • Codex autoreview of 786cd278fb1d51e5256b374a654483969242e871..045047bac19d912d62b660e3c203b9f238287e58: scoped-clean through P2, no actionable findings.
  • The standard test configuration excludes the opt-in doctor-config-preflight.legacy-driver.live.test.ts. An explicit optional invocation stopped in shared live setup before executing tests because the local auth source uses schema 19; no local installation was modified. That optional proof remains a gap. The published-driver evidence above remains prior-head evidence, including its manual-restart limitation.
  • Fresh PR CI for this exact candidate: https://github.com/openclaw/openclaw/actions/runs/44852229076

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T01:49:28.815680Z 045047b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: XS labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Doctor checks whether an existing state database can be opened read-write even when no migration needs to write to it.

Example: On macOS, ~/.openclaw/openclaw-state.sqlite is immutable after chflags uchg, with no pending migrations.

  • Before: Doctor can report completion and exit successfully without detecting the unwritable database.
  • After: Doctor reports the blocked path, recommends chflags nouchg, and exits unsuccessfully.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-supported, but required shipped-CLI and upgrade evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor can say an installation is healthy while its immutable state database cannot accept writes.
Reason: This restores the documented storage diagnosis, and the maintainer-authored body explicitly accepts the resulting update-time failure for unusable state.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR restores a documented Doctor diagnosis with a focused change, and no introduced correctness or security defect was found.

Priority: P2
Reviewed head: f4fbc7ca492565260694a2712beb4c460d6cde96

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted CLI output showing the immutable, migration-current database diagnosis after this fix, plus fresh-install and latest-stable upgrade behavior with writable settings and data preserved.
Agent review details

How this fits together

Doctor's config preflight admits state access before migration and plugin convergence; filesystem failures reach the existing command-boundary storage diagnosis and recovery guidance.

flowchart LR
  A[Doctor command] --> B[State ownership admission]
  B --> C[Permission hardening]
  C --> D[Read-write open check]
  D --> E[Continue Doctor]
  D --> F[Storage diagnosis]
  F --> G[Recovery guidance and exit 1]
Loading

Technical review

Best possible solution:

Keep the non-truncating check in the existing state-admission owner and reuse the established recovery diagnosis.

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

The source shows that existing admission need not attempt a write, and the unchanged macOS test supplies a concrete immutable-file reproduction with reported before/fix/revert results; this read-only review executed no tests.

Is this the best way to solve the issue?

The patch is the smallest complete fix for the reported trigger: check effective write access after permission repair without changing database contents or introducing another diagnosis owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 11ad47f adds src/commands/doctor-config-preflight.ts:95 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 11ad47f0ea86; files: src/commands/doctor-config-preflight.ts)

PR surface

Source +2, Docs 0. Total +2 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 0 0 0 0
Docs 1 4 4 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 7 5 +2

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:

  • P2: Doctor can falsely report success for immutable state, but the demonstrated trigger is a limited filesystem condition in an operator CLI workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 November 15, 2026, 2:17 AM ET / 07:17 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

I verified the real macOS CLI against f4fbc7ca492565260694a2712beb4c460d6cde96 using fresh, isolated state. Doctor completed once before each immutable check, so both databases were migration-current.

With the fix, the immutable database is diagnosed without changing its bytes:

$ chflags uchg '<state>/state/openclaw.sqlite'
$ pnpm openclaw doctor --non-interactive
$ node scripts/run-node.mjs doctor --non-interactive
Doctor: startup
┌  OpenClaw doctor
Config warnings: <state>/openclaw.json: Config unavailable; using environment and default agent directory settings.
Doctor: maintenance begin
Doctor: state preflight
Doctor: database preflight
Doctor: schema admission
Doctor: state schema
Doctor: Agent deletion journal
Doctor: UI protocol
Doctor: Source install
Doctor: CLI launcher
Doctor: Plugin runtime links
Doctor: config flow
Doctor: state write admission
Doctor: maintenance release
State storage is not writable at <state>/state/openclaw.sqlite (database: <state>/state/openclaw.sqlite). Fix ownership and permissions for the user running OpenClaw (for example: sudo chown "$(id -u):$(id -g)" '<state>/state/openclaw.sqlite'); the database and sidecars need read/write access and parent directories need write/search access. Or remount the volume writable. If the file or directory is immutable, clear its immutable flag (on macOS: chflags nouchg '<state>/state/openclaw.sqlite'). Then rerun openclaw doctor. For read-only diagnostics, use openclaw doctor --lint.
[ELIFECYCLE] Command failed with exit code 1.
exit: 1
sha256 before: ca6ee6a878d65d7c674bb78e66ea1aaba0b4c506b392802883497dbb641ba986
sha256 after:  ca6ee6a878d65d7c674bb78e66ea1aaba0b4c506b392802883497dbb641ba986

After clearing the flag, Doctor completes. This and the control transcript below show the end of the captured output; unrelated checks and fresh-state configuration warnings are omitted.

$ chflags nouchg '<state>/state/openclaw.sqlite'
$ pnpm openclaw doctor --non-interactive
[earlier standard Doctor output omitted]
Doctor: maintenance release
│
└  Doctor complete.
exit: 0

For the control, I removed only the new read-write-open line, rebuilt, and repeated the check on a separate fresh database. It reproduced the bug:

$ chflags uchg '<state>/state/openclaw.sqlite'
$ pnpm openclaw doctor --non-interactive
[earlier standard Doctor output omitted]
Doctor: maintenance release
│
└  Doctor complete.
exit: 0
sha256 before: ea3425e19f5ed2b8841b1b7a72bb01156e4afaa912bd1b3c554949a7d4cb8cc5
sha256 after:  ea3425e19f5ed2b8841b1b7a72bb01156e4afaa912bd1b3c554949a7d4cb8cc5

I restored the source file and rebuilt afterward. The checkout is clean, the buildstamp names f4fbc7ca492565260694a2712beb4c460d6cde96, and both scratch databases have their immutable flags cleared.

Published-driver / fresh-install cell Result
Published openclaw@latest (2026.11.3) → candidate, published-upgrade-survivor PASS, 849 s
Candidate fresh install, docker-package-install PASS, 84 s

The published updater completed the tarball update. The installed candidate passed Doctor, post-Doctor config validation, seeded state-survival assertions, and Gateway startup/readiness. Fresh installs passed with npm, pnpm, Bun, and npm on musl. Both lanes passed on their first attempt. This was the manual-restart upgrade variant; automatic restart and update idempotence were not tested. Candidate package SHA-256: 063312b1fcf143c2a96d8f7db0d7804b2b10a86740120e1fb9b0872c52a09624.

Verify effective database write access during Doctor state admission after
permission hardening. A current database with no plugin migrations can otherwise
complete diagnostics without ever attempting a write, hiding immutable storage.
The non-truncating open preserves database contents and uses the existing
command-boundary diagnosis and recovery guidance.

The existing macOS regression started failing in 6ce3260 (#184245), which
removed a plugin fixture whose writes had incidentally exposed this condition.
Keep its assertions unchanged and document the independent admission check.

Release-note context: Doctor reports an immutable state database's path and the
macOS chflags nouchg remedy, and exits unsuccessfully even when no migration is
pending. Writable shared stores and owned read-only mode repair remain supported.
@steipete
steipete force-pushed the fix/doctor-immutable-state-admission branch from f4fbc7c to 045047b Compare November 21, 2026 01:47
@steipete
steipete merged commit 39c3099 into main Nov 21, 2026
127 checks passed
@steipete
steipete deleted the fix/doctor-immutable-state-admission branch November 21, 2026 02:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…w#199509)

Verify effective database write access during Doctor state admission after
permission hardening. A current database with no plugin migrations can otherwise
complete diagnostics without ever attempting a write, hiding immutable storage.
The non-truncating open preserves database contents and uses the existing
command-boundary diagnosis and recovery guidance.

The existing macOS regression started failing in 1b7b2d7 (openclaw#184245), which
removed a plugin fixture whose writes had incidentally exposed this condition.
Keep its assertions unchanged and document the independent admission check.

Release-note context: Doctor reports an immutable state database's path and the
macOS chflags nouchg remedy, and exits unsuccessfully even when no migration is
pending. Writable shared stores and owned read-only mode repair remain supported.

Co-authored-by: Peter Steinberger <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
Verify effective database write access during Doctor state admission after
permission hardening. A current database with no plugin migrations can otherwise
complete diagnostics without ever attempting a write, hiding immutable storage.
The non-truncating open preserves database contents and uses the existing
command-boundary diagnosis and recovery guidance.

The existing macOS regression started failing in 6ce3260 (#184245), which
removed a plugin fixture whose writes had incidentally exposed this condition.
Keep its assertions unchanged and document the independent admission check.

Release-note context: Doctor reports an immutable state database's path and the
macOS chflags nouchg remedy, and exits unsuccessfully even when no migration is
pending. Writable shared stores and owned read-only mode repair remain supported.

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 39c3099)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 0de3eb1eac1666561c6e4051b6f233420eb40766)
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 P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS 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