Skip to content

fix(doctor): doctor fails with an internal lease error instead of explaining an unwritable state database - #178178

Merged
steipete merged 1 commit into
mainfrom
codex/stab-doctor-unwritable-state
Oct 20, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stab-doctor-unwritable-state

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #178107

What Problem This Solves

Fixes: openclaw doctor fails with the internal error "failed to acquire plugin lifecycle lease core:plugin-lifecycle/global: store unavailable (storage-error)" instead of explaining the problem when the shared state database is not writable, for example after a sudo openclaw … run left root-owned files, on a read-only mounted volume, or with an immutable file.

User Impact

User impact: Doctor names the unwritable database or directory and gives the concrete fix (ownership/permissions for the user running OpenClaw, remounting the volume writable, or clearing an immutable flag), and points to openclaw doctor --lint for read-only checks. A database the user owns with a too-restrictive mode is repaired by the existing permission owner and Doctor continues normally. Writable databases owned by another user (Docker fsGroup, NFS) and writable volumes that reject chmod keep working. Doctor never changes ownership or immutable flags itself.

Why This Change Was Made

Doctor's first write is the shared-state lease taken during post-core plugin convergence; the lease wrapper reduced the SQLite failure to "store unavailable" without the path. Failed storage admission now runs an effective-access check (non-truncating opens of the database and existing sidecars, plus an exclusive disposable file in the parent directory) and, only when access is actually denied, reports the path and remedy; other errors keep their original cause. Doctor's existing write-admission step now runs the permission owner before config convergence, so an owned read-only file is hardened instead of leaving a read-only connection. Ownership alone is never treated as a problem. No schema, migration, public config, run-order or exit-policy change. This complements #178107, which fixes the Gateway startup message for the same situation.

Evidence

  • Live, isolated state created by a real Gateway (two agents) and stopped cleanly:
    • immutable database (chflags uchg): before, Doctor printed only the internal lease error; after, Doctor exits 1 with "State storage is not writable at … Fix ownership and permissions for the user running OpenClaw (for example: sudo chown "$(id -u):$(id -g)" '') … Or remount the volume writable. If the file or directory is immutable, clear its immutable flag (on macOS: chflags nouchg ''). Then rerun openclaw doctor. For read-only diagnostics, use openclaw doctor --lint."
    • owned database at mode 0444: Doctor hardens it to 0600 and completes (exit 0).
  • Command-layer regressions with real SQLite files (immutable, owned 0444, writable foreign-owned via real file metadata with the current uid mocked, chmod-rejecting but writable): the immutable and owned-0444 cases fail before the change (internal lease error) and pass after; 6 cases, 57 s wall. Focused Doctor/state suites: 57 tests across six files pass.
  • pnpm tsgo:core, oxlint, oxfmt, madge (0 cycles), git diff --check pass. Autoreview (Codex): scoped-clean, no actionable findings.
  • Production +94/-9.

Landing validation

The exact head 9beb3a65c634104c4a3345175c45d346759950ac passes the offline newer-schema Doctor regression, including unchanged database/sidecar bytes, inode, birth time, mtime, and ctime. Fresh isolated Codex review with the maintenance/admission source context found no actionable P0–P2 findings.

CI run 39382672660 completed with three inherited failing test jobs and their downstream gate; security-fast passed. Compared job-level logs with the same cases in scheduled main run 39382483409:

  • checks-node-changed-compact-large-16: three openclaw-state-db.transactions.test.ts cases fail with the same Gateway ownership namespace error (main job 118494854830).
  • checks-node-changed-compact-large-21: both foreign-owner checkpoint cases in openclaw-state-db-open.test.ts fail with that same namespace error (main job 118494854815).
  • checks-node-changed-compact-small-6: restart-intent.test.ts / “records restart options while an older Gateway owns a pending-migration database” fails the same boolean assertion (main job 118494854333).

The failing tests and their relevant ownership/restart source inputs are unchanged between the CI baseline and its tested PR merge. Landing uses the native inherited-failure exception; this does not claim CI is green.

Report effective database, sidecar, and directory access failures with the
blocked path and manual ownership, mount, and immutable-flag remedies.
Preserve the original error when storage remains writable.

Harden existing state through its permission owner before config convergence
can retain a read-only SQLite handle. Keep foreign-owned writable stores
usable when chmod returns EPERM without relaxing owned-file hardening.

Release-note context: doctor --non-interactive explains unwritable state
storage instead of exposing an internal plugin lifecycle lease error.
@clawsweeper

clawsweeper Bot commented Oct 20, 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 Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T06:52:47.279468Z 9beb3a6 PR opened
ℹ️ 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: M labels Oct 20, 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR repairs owned read-only state files before config preparation and replaces opaque storage failures with path-specific recovery guidance.

Example: An owned state database has mode 0444 when openclaw doctor --non-interactive runs.

  • Before: Doctor can retain a read-only SQLite handle and fail with an internal plugin lifecycle lease error.
  • After: The existing permission owner restores mode 0600 before config preparation, allowing Doctor to continue.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful patch with reported production-path results and no definite code finding; upgrade validation and unresolved CI attribution limit readiness.
Proof confidence 🦐 gold shrimp (3/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 reports an internal plugin lease failure instead of explaining why state storage cannot be written.
Reason: The maintainer-authored direction addresses a concrete recovery failure without adding configuration or a competing permission owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a concrete Doctor failure still present on current main, and inspection found no definite introduced code defect.

Priority: P2
Reviewed head: 9beb3a65c634104c4a3345175c45d346759950ac

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a latest-stable upgrade run exercising Doctor with existing settings and data preserved; the supplied live report does not cover that required scenario.
Agent review details

How this fits together

Doctor prepares database and config state before running health checks; the shared permission owner hardens database files, while the command boundary translates confirmed storage-access failures into recovery instructions.

flowchart TD
  A[Doctor CLI] --> B[Database schema admission]
  B --> C[State permission owner]
  C --> D[Config and plugin preparation]
  D --> E[Health checks]
  D --> F[Storage failure diagnosis]
  F --> G[Path and recovery guidance]
Loading

Technical review

Best possible solution:

Keep permission repair in the existing shared owner and diagnose confirmed access failures at Doctor's command boundary.

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

Current-main source exposes the reported path, and the PR records before/after immutable-file and owned-0444 reproductions; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch reuses the permission owner, retains schema admission before config preparation, and preserves original errors when effective access succeeds; the simplification review found no clearly unnecessary production machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared-state permission failure policy changes intended behavior with a stated reason (fix(state): tolerate chmod failures when opening the state database #91934: Unsupported chmod must not prevent writable-volume use, while ordinary ownership failures remain visible.)
  • Doctor config write-admission ordering keeps the original intent (abb9723: The existing admission step was measured alongside shared preflight work; this PR retains admission and adds hardening before a read-only handle can be retained.)
  • Doctor health-flow command boundary keeps the original intent (14ee725: Carry prepared database facts through Doctor while preserving admission and migration ordering.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +85, Tests +174, Docs +7. Total +266 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 94 9 +85
Tests 1 174 0 +174
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 275 9 +266

Labels

Label changes:

  • add P2: This improves a bounded terminal recovery workflow for unwritable state storage without evidence of a widespread urgent regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This improves a bounded terminal recovery workflow for unwritable state storage without evidence of a widespread urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show Doctor after upgrading existing v2026.10.5 state, with settings and data preserved.

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 20, 2026, 3:05 AM ET / 07:05 UTC.

@steipete
steipete merged commit 11ad47f into main Oct 20, 2026
200 of 208 checks passed
@steipete
steipete deleted the codex/stab-doctor-unwritable-state branch October 20, 2026 07:13
@steipete

Copy link
Copy Markdown
Contributor Author

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 21, 2026
Report effective database, sidecar, and directory access failures with the
blocked path and manual ownership, mount, and immutable-flag remedies.
Preserve the original error when storage remains writable.

Harden existing state through its permission owner before config convergence
can retain a read-only SQLite handle. Keep foreign-owned writable stores
usable when chmod returns EPERM without relaxing owned-file hardening.

Release-note context: doctor --non-interactive explains unwritable state
storage instead of exposing an internal plugin lifecycle lease error.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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