Skip to content

fix(doctor): keep state repairs running with an externally managed read-only config - #164235

Merged
steipete merged 1 commit into
mainfrom
upd/upd-docker-entrypoint-readonly-config-doctor
Oct 3, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-docker-entrypoint-readonly-config-doctor

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #162259

What Problem This Solves

Fixes official Docker image upgrades failing before Gateway startup when OPENCLAW_CONFIG_READONLY=1 protects an externally managed config. Reported by @JD8855122.

User Impact

Doctor can repair writable state while leaving externally managed config untouched. It prints a redacted merge patch for external config edits; valid config permits startup with optional repairs pending. Legacy or invalid config that still blocks startup produces a nonzero exit and actionable edits. Existing Nix repair restrictions remain unchanged.

Why This Change Was Made

The image entrypoint correctly runs doctor --fix --non-interactive, but Doctor previously treated any repair as permission to write config and rejected the entire run. Doctor now handles the external-config outcome at its config-write boundary, restores the persisted config for subsequent work, and preserves the persistence requirement for dependent auth cleanup and cron repairs. The legacy config-copy path also honors immutability. Gateway's existing admission gate already accepts valid read-only config; no Gateway exception or new option is needed.

State-first migration is intentional: plugin migration obligations need the current shared SQLite schema before later config work. The reported 18 → 19 advance is readable by the candidate build, rather than database corruption. Older builds cannot safely read the newer authorization semantics, so an image rollback requires the matched, verified pre-upgrade state backup. This change does not alter schema versions or downgrade guards.

Evidence

  • The new Doctor-boundary regression failed on the original blanket refusal. It now proves writable workspace-state migration, unchanged read-only config bytes, exact external edit reporting, success with optional edits, and failure for a startup-required legacy edit. It calls the real Gateway config-admission function for both outcomes.
  • Seven owner suites passed three times on the final source: 222 tests per pass; wall times 176.43s, 158.09s, and 157.03s on Linux/Node 24. The standalone regression command (pnpm test src/flows/doctor-health.readonly-config.test.ts --maxWorkers=1) took 20.43s wall time, with 2.867s and 1.038s for its two cases.
  • All 24 stock Docker entrypoint mock-image tests passed (2.61s wall time). All 12 config snapshot reader tests also passed, including include/reference preservation.
  • Final local importer run: all seven ordered batches (at most 15 files each) passed on this exact commit. Across 93 selected files, 91 passed and two retained platform skips; 1,177 tests passed and 11 were skipped (Windows cloud-state and Linux NOCOW). Batch wall times: 1802.49s, 471.41s, 541.03s, 447.73s, 444.27s, 339.13s, and 136.96s (4183.02s total). The read-only-config regression passed again in this run: 3.766s and 1.577s per case.
  • Final local node scripts/check-changed.mjs passed, including core typechecking, all 27 test typechecking graphs, core/script lint, and schema/storage/import-cycle/security guards. git diff --check passed.
  • Local Codex P1 review of the committed source: scoped-clean, with no accepted/actionable P0 or P1 findings.
  • New-module gates: eager-import closure (17 tests), PR wrapper source closure (3 tests), export-name collision check, restart-fixture module load, and all four CI test-plan suites (125 tests, 95.98s wall) passed. PR worktree provisioning passed the authorized standalone retry (16 passed, one existing skip); see the timing record below. No wrapper-closure inventory change was needed.
  • Production: +137/−36 lines. Tests and routing: +90/−0. Docs: +11/−1. No dependency, schema, config-option, or CLI-option changes.

Slow pre-existing suites (waived)

test/scripts/pr-worktree-provision.test.ts took 456.576s of test time in the three-file batch. Its cold/warm/sparse transition case hit the existing 120s timeout (128.735s observed); the authorized file-only retry passed all 16 active tests with one existing skip, in 354.162s of test time / 384.29s wrapper wall time. The same case passed in 111.459s. The batch also measured 33.602s for disabled-acceleration seed/checkpoint/cleanup custody and 39.171s for command-scoped safe.directory parameter transport. These are unchanged provisioning tests on the loaded host; no timeout, retry configuration, assertion, or skip was changed. A passing retry is recorded as the approved isolation check, not a flake fix.

Additional local importer timings: doctor-config-flow.cron-owners.test.ts accumulated 136.558s across its cases; managed-handoff-build-config.test.ts took 31.965s, including 30.952s for loading the staged production package runtime without neighboring assets. Batch 1 passed all 266 tests in 1802.49s wall time; roughly 20 minutes were shared build/compiler preparation, not test time.

doctor-config-flow.billing-route.test.ts accumulated 136.459s, including package-swap deferral through run-id (31.228s) and result-channel (35.585s). update-command-fresh-preview.test.ts accumulated 145.145s. The unchanged July-upgrade composition case in doctor-config-flow.legacy-composition.test.ts took 44.750s. All passed.

doctor-health.managed-settlement.test.ts accumulated 159.399s, including the ready multi-agent settlement case (43.647s). doctor-health.test.ts accumulated 236.596s, and the unchanged fleet-preflight evidence revalidation case took 31.454s. These also passed under the standing slow-suite waiver.

Live bind-mount replay (pending)

The 24 mock-image entrypoint tests and the Doctor/Gateway admission regression cover the changed path. A live read-only bind-mount replay remains pending. From a checkout of this PR head, set PROOF_STATE_DIR to an absolute path containing a disposable, container-writable copy of retained state and PROOF_CONFIG_PATH to an absolute path containing its external config. Then run:

docker build -t openclaw:l1412-readonly .
docker run --rm --name openclaw-l1412-readonly \
  -e OPENCLAW_CONFIG_READONLY=1 \
  -e OPENCLAW_CONFIG_PATH=/etc/openclaw/openclaw.json \
  -e OPENCLAW_STATE_DIR=/home/node/.openclaw \
  --mount "type=bind,src=${PROOF_CONFIG_PATH:?set an absolute config path},dst=/etc/openclaw/openclaw.json,readonly" \
  --mount "type=bind,src=${PROOF_STATE_DIR:?set an absolute disposable state-copy path},dst=/home/node/.openclaw" \
  openclaw:l1412-readonly node openclaw.mjs gateway --bind loopback --port 18789

Use a valid config with an optional repair, such as a custom tools.exec.safeBins entry lacking its scaffold profile. Expected: Doctor reports the external edit, leaves the bind-mounted config unchanged, repairs writable state, and the Gateway starts. A startup-required legacy config edit should instead produce the exact edit and a nonzero exit. Stop the disposable container with Ctrl-C after inspecting the result. Hosted CI is pending; the completed validation above is local or earlier isolated test proof.

Keep writable state repairs enabled for externally managed configuration. Report config edits without writing them or authorizing dependent cleanup, and fail when the persisted config still blocks Gateway startup.

Preserve Nix repair restrictions and the state-first migration order.

Reported by @JD8855122 in #162259.
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: M labels Oct 3, 2026
@steipete
steipete marked this pull request as ready for review October 3, 2026 10:02
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 6:09 AM ET / 10:09 UTC.

ClawSweeper review

What this changes

Doctor repairs writable runtime state while reporting externally managed config edits without writing them, and refuses startup when the persisted config still requires repair.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains a useful fix: current main and the latest release still reject repairing Doctor with read-only config. No concrete introduced defect was found, but the stock-image upgrade behavior remains unverified.

Priority: P1
Reviewed head: 769170093240a31324b1477d2f265bba0d9982a4

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 8 items Pinned introduced change: Read the merge-base-to-head patch. The branch removes the generic early refusal, preserves the Nix refusal, and handles immutable config at the shared config-write boundary.
Persisted config remains authoritative: External repair reporting uses the existing reference-restoration, merge-patch, schema-hint, and redaction owners, then restores the persisted snapshot. The writer returns false, preventing dependent auth cleanup and cron rewrites from treating advisory edits as committed.
Current main still needs the repair: Fetched main still calls assertConfigWriteAllowedInCurrentMode for repair, yes, or token-generation requests before Doctor maintenance. The stock Docker entrypoint invokes doctor --fix --non-interactive and stops on a nonzero exit.
Findings None None.
Security None None.

How this fits together

The official Docker entrypoint runs Doctor before starting the Gateway. Doctor coordinates state migrations and config repairs, and its exit status determines whether container activation continues.

flowchart TD
  A[Docker activation] --> B[Doctor maintenance]
  B --> C[Writable state repairs]
  B --> D[Config repair candidate]
  D --> E[Report external edits]
  E --> F[Validate persisted config]
  F -->|Valid| G[Start Gateway]
  F -->|Invalid or legacy| H[Exit with repair guidance]
Loading

Before merge

  • Resolve merge risk (P1) - Fresh-state and retained-state stock-image activation with an actual read-only config mount remain unverified, including successful Gateway startup and the required-edit failure outcome; the supplied boundary tests bypass full contribution dispatch.
  • Complete next step (P2) - Complete the pending stock-image activation proof with fresh and released retained state, immutable config, required-edit refusal, and matched-backup recovery; post redacted runtime evidence.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +101, Tests +90, Docs +10. Total +201 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 137 36 +101
Tests 2 90 0 +90
Docs 1 11 1 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 238 37 +201

Review metrics

Metric Value Why it matters
Configuration surface 0 new options, flags, dependencies, or schema versions The repair uses the existing read-only selector and Doctor lifecycle rather than introducing a parallel operating mode.
Production growth production +101 net lines; tests and routing +90 net lines The stated production growth adds external-edit reporting and extracts startup preparation while preserving existing repair ownership.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/flows/doctor-auth-health.ts, migration/backfill/repair: src/flows/doctor-external-config.ts, migration/backfill/repair: src/flows/doctor-health-contribution-runners.config.ts, migration/backfill/repair: src/flows/doctor-health-contribution-types.ts, migration/backfill/repair: src/flows/doctor-health-startup.ts, migration/backfill/repair: src/flows/doctor-health.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #162259
Summary: This PR directly targets the reported stock Docker read-only-config activation failure; the other Doctor proposal overlaps but adds a distinct explicit mode.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Complete the Docker activation evidence (recommended)
    Record the candidate stock entrypoint handling fresh and released retained state with immutable config, including startup, required-edit refusal, and matched-backup recovery.

Technical review

Best possible solution:

Keep Doctor as the single repair owner, preserve deployment-owned config bytes, and establish stock-image activation and backup recovery on disposable retained state.

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

Yes from source: stock Docker activation invokes repairing Doctor, and current main rejects that invocation when OPENCLAW_CONFIG_READONLY=1. No complete container reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes, the config-write boundary is the narrowest supported repair point; preserving persisted config for later work avoids a second repair orchestrator. Full image-upgrade validation remains necessary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: This repairs a reported official Docker upgrade failure that prevents Gateway startup.
  • add merge-risk: 🚨 compatibility: The changed activation path now permits state repair under immutable config, but actual fresh-install and retained-state image compatibility remain unverified.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Label justifications:

  • P1: This repairs a reported official Docker upgrade failure that prevents Gateway startup.
  • merge-risk: 🚨 compatibility: The changed activation path now permits state repair under immutable config, but actual fresh-install and retained-state image compatibility remain unverified.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

  • Pinned introduced change: Read the merge-base-to-head patch. The branch removes the generic early refusal, preserves the Nix refusal, and handles immutable config at the shared config-write boundary. (src/flows/doctor-health-startup.ts:34, 769170093240)
  • Persisted config remains authoritative: External repair reporting uses the existing reference-restoration, merge-patch, schema-hint, and redaction owners, then restores the persisted snapshot. The writer returns false, preventing dependent auth cleanup and cron rewrites from treating advisory edits as committed. (src/flows/doctor-external-config.ts:15, 769170093240)
  • Current main still needs the repair: Fetched main still calls assertConfigWriteAllowedInCurrentMode for repair, yes, or token-generation requests before Doctor maintenance. The stock Docker entrypoint invokes doctor --fix --non-interactive and stops on a nonzero exit. (src/flows/doctor-health.ts:153, 48ff3d1efde5)
  • Latest-release check: The supplied v2026.9.8 release revision also retains the blanket Doctor refusal. Its source was read through GitHub because the local release blob was unavailable. (src/flows/doctor-health.ts:127, fc23bc864e45)
  • Useful regression coverage with a runtime gap: The new two-case regression exercises real config planning, workspace-state migration, and Gateway config admission, but replaces contribution dispatch. The captured PR body reports extensive passing tests and explicitly marks the live read-only bind-mount replay pending; no observed stock-container activation result is supplied. (src/flows/doctor-health.readonly-config.test.ts:52, 769170093240)
  • Upgrade proof policy and intentional ordering: Root policy requires published-driver/candidate proof for Doctor upgrade changes. The PR explicitly retains state-first migration, existing schema versions, downgrade guards, and matched pre-upgrade backup recovery; this review does not request reversing that ordering. (AGENTS.md, 769170093240)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • sallyom: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 260a319 into main Oct 3, 2026
223 of 224 checks passed
@steipete
steipete deleted the upd/upd-docker-entrypoint-readonly-config-doctor branch October 3, 2026 10:15
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…ad-only config (openclaw#164235)

The official Docker image's entrypoint runs doctor --fix before the Gateway; with the documented externally managed config mode (OPENCLAW_CONFIG_READONLY=1, read-only mounted config) Doctor refused the whole run because it could not write the config, so a working 2026.9.6 deployment went down on the 2026.9.7 image bump. Doctor now keeps state repairs and migrations running, reports config edits instead of writing them, and fails only when a persisted config change is required for startup; Gateway admission covers both cases. State-first migration (18→19 before config repair) is intentional and documented. Closes openclaw#162259. Thanks @JD8855122 for the report.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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.

[Bug]: 2026.9.7 Docker activation conflicts with OPENCLAW_CONFIG_READONLY

1 participant