Repository navigation
fix: keep an update's Doctor pass from locking itself out of the state database - #207535
daniel-lxs merged 5 commits into
Conversation
…ntenance Schema maintenance in the config preflight retires the cached Doctor writer that prepareDoctorRuntimeChecks opened under an update capture. Later config writes go through the shared-state worker, which keeps its connection for the maintenance scope, so the next synchronous writer could not take the capture's exclusive access. Before openclaw#207274 the Skill Workshop retirement reopened the writer by accident; reopen it explicitly after the schema step.
|
🦞👀 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: passed. What this changesReopen the captured Doctor writer after successful state-schema preparation so later repairs can reuse it. Example: An update repairs session.idleMinutes: 45 and then imports an openai:default auth profile.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a source-supported Doctor database self-lockout still present on main, with no actionable patch defects found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDoctor's state-schema step prepares the shared database before config and auth repairs; an update capture records database changes for safe update settlement. flowchart TD
A[Update Doctor capture] --> B[State schema preparation]
B --> C[Retire database resources]
C --> D[Reopen captured writer]
D --> E[Config worker writes]
E --> F[Auth repair reuses writer]
Technical reviewBest possible solution: Restore the captured writer at the schema-preparation boundary using the existing Doctor database and maintenance owners. Do we have a high-confidence way to reproduce the issue? Source inspection establishes the resource-retirement, worker-open, synchronous-cold-open sequence, and supplied regression logs show the original lock failure; this read-only review executed no target code. Is this the best way to solve the issue? The repair restores the writer where schema maintenance retires it, preserves the intentional read-only Skill Workshop path, and requires no new lifecycle owner or retry mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4c43b0f29357. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +22. Total +22 across 1 file. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed November 28, 2026, 10:40 AM ET / 15:40 UTC (Revision 2). |
Inherited CI failure attribution (head
|
## What Problem This Solves Related: #207448. When update preflight cannot write an installation owned by a service account, it currently suggests taking that installation away from the account with `sudo chown -R`. The same guidance can target a symlink or missing directory, misclassify a symlinked home, or suggest ineffective commands to root and callers who already own the directory. ## User Impact Permission failures name the owning account and tell the caller to update as that account or run `sudo openclaw update`. Ownership repair is suggested only for a root-owned existing directory inside the caller's resolved home. Windows receives no POSIX commands; read-only filesystems and already-owned directories get plain permission guidance with the path. ## Why This Change Was Made Keep the existing refusal path and reason types. Reuse the existing NSS account-name resolver, falling back to the numeric UID when lookup fails. Remove the unused preflight state-directory argument and obsolete numeric command-options branches, and correct the host-prerequisite documentation to the installation-only 1.4 GB check. Simplification: one inline classifier, no new status, phase, record, lease, notice, retry, trigger, or flag. +15 production lines: naming the owning account so no service-user prefix is chowned away; Ayaan's lock allows stated exceptions. Net test delta: +67 lines, consolidating the previous ownership tests into one table. ## Evidence - Red on base `4f8d4f5a36d7`: the service-owned system-prefix case prints `sudo chown -R` instead of naming the service account (one expected regression failure). - Green on head `5fd0f031f1ce8869085247dca269e06f525ab7a0`: `ocx test src/update/preflight.test.ts src/update/cli.system-service.test.ts --maxWorkers=1` — 32 passed, including all 14 ownership-table cases. Vitest-source tier; 139.39 seconds including compiled-worker preparation, test bodies under 4 seconds. - Scoped formatting passed; LSP diagnostics reported no issues in the ownership test. Local lint reached SDK declaration preparation but timed out; a separate filtered prepare-test invocation also timed out before running. Those checks remain for hosted CI. - Author pr-simplify pass complete: only the existing error-message path, specified dead-code removals, consolidated ownership proof, and stale prerequisite text remain. - Local ClawSweeper reviewed `4f8d4f5a36d7..5fd0f03`: complete, patch correct, no correctness findings, security cleared. It notes the absence of a shipped-CLI end-to-end capture; the supplied red/green proof exercises the preflight owner boundary, not a full update. - Exact-head [hosted CI](https://github.com/openclaw/openclaw/actions/runs/46155465855): 32 jobs passed; `docker-seed-e2e` is still running. [check-lint-core-5](https://github.com/openclaw/openclaw/actions/runs/46155465855/job/141012641078) failed on the unchanged `ui/config/control-ui-chunking.ts:178` duplicate case for `src/shared/assistant-display-content.ts` (also present at line 345 in base `4f8d4f5a36d7`). This is outside the six-file repair and is not changed or suppressed here. No full local build, release branch change, merge, or update-restart-auth dispatch is included. The update-restart-auth lane has an unrelated Doctor state-database lock failure tracked by #207535 and remains with its owner. Co-authored-by: Ayaan Zaidi <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
End-to-end update cells: a real dev-channel update does not fail without this fixResult: a plain Harness: Linux Docker cells, one fresh container per cell. Each has a real systemd user Gateway ( Two drivers:
Two targets:
The capture failure needs a cold synchronous state writer after a config-flow write. The table only checked whether the update logged "exclusive access". Its absence does not prove the triggering sequence happened in these cells; that part is inferred from code. Cells that could not reach the target (recorded rather than dropped):
Harness notes: the base images were snapshotted with the Gateway stopped. Each cell copies the checkout and state into the container's own layer first, because Docker's overlay filesystem refuses directory renames inside image layers (EXDEV), and the updater's activation makes such renames. Recordings (inside the container; idle time compressed, 2× speed): c1110-a1, 2026.11.10 → (a) without the fix: c1110-b1, 2026.11.10 → (b) with the fix: c1110-a-auth, 2026.11.10 → (a) with a legacy auth store: c1110-a1: 2026.11.10 → (a) 023e548c3bfc1110-a2: 2026.11.10 → (a)c1110-a3: 2026.11.10 → (a)c1110-a-auth: 2026.11.10 → (a), legacy auth storec1110-b1: 2026.11.10 → (b) afff74da36ccmain-a1: de354e4 → (a) beb28f6c1110-a-cfg2: 2026.11.10 → (a), legacy session.idleMinutesc1110-a1.rebase-conflict: 2026.11.10 → (a) beb28f6, no tag history |
…07585) ## Problem Native release updates launch advisory Doctor inspections after activation. The 120-second subprocess gates nothing and can time out even though the update has already succeeded. ## Change - Delete the native Gateway's post-activation inspection task, its legacy-trial completion callback, and the unused selector export. - Remove tests for that deleted task and clarify the native-versus-legacy behavior in Doctor docs. - Keep the frozen legacy bridge's inspection helper, callers, step names, and coverage unchanged. - In a separate test-only commit, pin ownership-guidance POSIX fixtures to Linux so Windows hosts do not select Windows guidance. Native updates still succeed at core readiness; boot plugin maintenance and rollback behavior remain unchanged. Operators can run `openclaw doctor --lint` explicitly. No new mechanisms. ## Simplification and impact Removed the advisory subprocess, scheduling path, projection loop, and error-reporting branch rather than replacing them. Production: +2/-68, net -66 lines. Tests: +2/-125, net -123 lines. Docs: +5/-2. ## Validation - Local builds/tests were not run; hosted PR CI is the requested verification route. - Do not dispatch the update-restart-auth lane: the known unrelated Doctor state-db lock is tracked by #207274 / #207535 and its validation is owned separately. - No autoreview; no release-branch changes; do not merge. Co-authored-by: Ayaan Zaidi <[email protected]>
…207563) ## What Problem This Solves Related: openclaw#207448. When update preflight cannot write an installation owned by a service account, it currently suggests taking that installation away from the account with `sudo chown -R`. The same guidance can target a symlink or missing directory, misclassify a symlinked home, or suggest ineffective commands to root and callers who already own the directory. ## User Impact Permission failures name the owning account and tell the caller to update as that account or run `sudo openclaw update`. Ownership repair is suggested only for a root-owned existing directory inside the caller's resolved home. Windows receives no POSIX commands; read-only filesystems and already-owned directories get plain permission guidance with the path. ## Why This Change Was Made Keep the existing refusal path and reason types. Reuse the existing NSS account-name resolver, falling back to the numeric UID when lookup fails. Remove the unused preflight state-directory argument and obsolete numeric command-options branches, and correct the host-prerequisite documentation to the installation-only 1.4 GB check. Simplification: one inline classifier, no new status, phase, record, lease, notice, retry, trigger, or flag. +15 production lines: naming the owning account so no service-user prefix is chowned away; Ayaan's lock allows stated exceptions. Net test delta: +67 lines, consolidating the previous ownership tests into one table. ## Evidence - Red on base `dea7fa5cc19b`: the service-owned system-prefix case prints `sudo chown -R` instead of naming the service account (one expected regression failure). - Green on head `5fd0f031f1ce8869085247dca269e06f525ab7a0`: `ocx test src/update/preflight.test.ts src/update/cli.system-service.test.ts --maxWorkers=1` — 32 passed, including all 14 ownership-table cases. Vitest-source tier; 139.39 seconds including compiled-worker preparation, test bodies under 4 seconds. - Scoped formatting passed; LSP diagnostics reported no issues in the ownership test. Local lint reached SDK declaration preparation but timed out; a separate filtered prepare-test invocation also timed out before running. Those checks remain for hosted CI. - Author pr-simplify pass complete: only the existing error-message path, specified dead-code removals, consolidated ownership proof, and stale prerequisite text remain. - Local ClawSweeper reviewed `dea7fa5cc19b..5fd0f03`: complete, patch correct, no correctness findings, security cleared. It notes the absence of a shipped-CLI end-to-end capture; the supplied red/green proof exercises the preflight owner boundary, not a full update. - Exact-head [hosted CI](https://github.com/openclaw/openclaw/actions/runs/46155465855): 32 jobs passed; `docker-seed-e2e` is still running. [check-lint-core-5](https://github.com/openclaw/openclaw/actions/runs/46155465855/job/141012641078) failed on the unchanged `ui/config/control-ui-chunking.ts:178` duplicate case for `src/shared/assistant-display-content.ts` (also present at line 345 in base `dea7fa5cc19b`). This is outside the six-file repair and is not changed or suppressed here. No full local build, release branch change, merge, or update-restart-auth dispatch is included. The update-restart-auth lane has an unrelated Doctor state-database lock failure tracked by openclaw#207535 and remains with its owner. Co-authored-by: Ayaan Zaidi <[email protected]>
…e database (openclaw#207535) Reopen the captured Doctor writer after successful state schema preparation. Later auth repairs can reuse it even after the config worker opens its own connection.
…enclaw#207585) ## Problem Native release updates launch advisory Doctor inspections after activation. The 120-second subprocess gates nothing and can time out even though the update has already succeeded. ## Change - Delete the native Gateway's post-activation inspection task, its legacy-trial completion callback, and the unused selector export. - Remove tests for that deleted task and clarify the native-versus-legacy behavior in Doctor docs. - Keep the frozen legacy bridge's inspection helper, callers, step names, and coverage unchanged. - In a separate test-only commit, pin ownership-guidance POSIX fixtures to Linux so Windows hosts do not select Windows guidance. Native updates still succeed at core readiness; boot plugin maintenance and rollback behavior remain unchanged. Operators can run `openclaw doctor --lint` explicitly. No new mechanisms. ## Simplification and impact Removed the advisory subprocess, scheduling path, projection loop, and error-reporting branch rather than replacing them. Production: +2/-68, net -66 lines. Tests: +2/-125, net -123 lines. Docs: +5/-2. ## Validation - Local builds/tests were not run; hosted PR CI is the requested verification route. - Do not dispatch the update-restart-auth lane: the known unrelated Doctor state-db lock is tracked by openclaw#207274 / openclaw#207535 and its validation is owned separately. - No autoreview; no release-branch changes; do not merge. Co-authored-by: Ayaan Zaidi <[email protected]>
…e database (#207535) Reopen the captured Doctor writer after successful state schema preparation. Later auth repairs can reuse it even after the config worker opens its own connection. (cherry picked from commit 3e55ac1) Companion disposition: #207585 is a later main update-process refactor, not needed by the retained Doctor flow; #207595 is a Codex fixture change. Co-authored-by: RomneyDa <[email protected]>
…e database (#207535) Reopen the captured Doctor writer after successful state schema preparation. Later auth repairs can reuse it even after the config worker opens its own connection. (cherry picked from commit 3e55ac1) Companion audit: a922203 changes the updater subprocess lifecycle and is not necessary for reopening the captured writer; d5db03d is unrelated Codex registration. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Since #207274, two Doctor update cases on
mainfail after a 30-second wait withUpdate migration could not take exclusive access to …/state/openclaw.sqlite: another connection still has it open(database is locked, errcode 5): "completes retirement after Doctor migrations and native parent bookkeeping" and "… worker parent bookkeeping" insrc/infra/update-doctor-migration-attribution.test.ts. Scheduled CI shows it on the Bun infra shard (run 46130442319 at2837e84640b, still red ata63df4e7ba1). It reproduces locally under both Bun and Node, so it is not Bun-specific.The connection that holds the database is this same process's shared-state SQLite worker. During an update's Doctor run:
prepareDoctorRuntimeChecksopens the captured Doctor writer before the config flow (fix: await Doctor shared-state repair preparation #190875). The capture's migration step takeslocking_mode=EXCLUSIVEon a cold open, and it needs every other connection closed.prepareOpenClawStateDatabaseSchema) drains state resources and retires that cached writer.writeConfigMachineStateAsync, config audit and snapshot records) go through the shared-state worker. Under a maintenance scope that worker keeps its connection until the scope closes; it is never idle-retired.repairAuthProfileMigration→readLegacyMigrationReceipt→openOpenClawStateDatabase) cold-opens the database under the capture, waits out the busy timeout against the worker's connection, and fails.Before #207274, the Skill Workshop retirement step opened the state database for writing between steps 2 and 3. That incidental open re-published the captured writer before the worker opened, and later writers reused it. #207274 made that step read-only for a healthy store, which is correct for its own purpose, and the ordering hazard appeared.
User Impact
Updates on unreleased
mainbuilds can no longer fail this way when a config repair write is followed by a synchronous state writer in the same Doctor pass. No change outside an update's Doctor capture. Shipped releases do not contain #207274 (merged to main on 2026-11-28).Why This Change Was Made
The state-schema step is where the captured Doctor writer gets retired, so that step now reopens it (
openOpenClawStateDatabaseForDoctor) right after schema maintenance. It does this only when an update capture is active, the maintenance scope owns schema maintenance, the step reported no warnings and the state database exists. That matches the guardprepareDoctorRuntimeChecksalready uses. At that point nothing else holds the database, so the capture's exclusive migration succeeds, and later synchronous writers reuse the published handle as they did before #207274.Alternatives considered:
Neither test case changed: both already fail on the original defect.
Update behavior
This runs inside Doctor on the candidate (the new release's code), which is the code a published updater calls into, so no driver change is needed. Without an update capture (standalone
doctor --fix, Gateway startup), the new branch does not run.Evidence
Tested commit:
b774393bdb2on base24b7801f980. The PR headf39611b4040merges 14 latermaincommits (24b7801f980..beb28f6f7ad). None of them touch the state database, the Doctor capture, the config preflight or this step; they cover UI, i18n, test fixtures and thesrc/updatesystem-service preflight (#207448). So the proof above was not rerun on the merge.Bisect (
git bisect run, two runs per point, Node): first bad commit0d24c65470f(#207274). Its parentde354e4c4e3passes. Both endpoints were rechecked under Bun:0d24c65470ffails 2/2 andde354e4c4e3passes 2/2.Who holds the database. I instrumented
openNodeSqliteDatabaseto record every open and close ofstate/openclaw.sqlite, with thread id and stack, pluslsofat the failure point. This was in a disposable worktree only. Results:infra/sqlite-store.worker.js(createSqliteWorkerBackend→openOpenClawStateDatabase). That open was requested bywriteConfigMachineStateAsync←recordConfigWriteMetadata←writeConfigFileFromContextinsiderunDoctorConfigPreflight.readDatabaseProposals→openOpenClawStateDatabase) opened before it and stayed cached, so the auth repair reused it.openOpenClawStateDatabaseForDoctorin the test before the preflight (asprepareDoctorRuntimeChecksdoes) still failed. The trace showed that handle being retired inside the preflight by the state-schema step's resource drain. That is why the reopen sits after the state-schema step.Red on base
24b7801f980, Bun,OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs run src/infra/update-doctor-migration-attribution.test.ts -t "completes retirement":red output
Green on the tested head, same command:
green output
Affected suites on the tested head:
affected suites
Other checks:
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjson the tested head: exit 0 (typecheck core, typecheck core tests, lint, import cycles and the guards). The full run's dead export scan fails on base exports this branch does not touch (cli-root-options.mjs: getCommandOptionsWithRootOptions,shouldDisableCodexToolSearchForModel,AgentHarnessSideQuestionRequest,CORE_TOOL_CATALOG_FAMILIES,PendingInputHistoryRunState).--max-priority P2 --thinking high, with source context for the Doctor startup, capture, worker owner, state database, preflight and test files. Result: scoped-clean, "patch is correct (0.89)". The report lists the files it inspected.Files audited:
src/infra/state-migrations.state-schema.ts(whole file).src/infra/update-doctor-migration-attribution.test.tsis unchanged: its two cases are the regression and fail on the original defect.Not proven:
openclaw updatecell was run. A real update reaches this failure only if a config repair write lands between the state-schema step and the next synchronous state writer with no drain in between. I traced that code path but did not observe it end to end.doctor-config-preflight.schema-preparation.test.ts"points failed setup…" took 31.5 s against a 30 s limit. It uses no update capture, so this branch does not run there. Alone it passes in 9.7 s.Timing on this host: the two cases take 22–26 s green on the parent of #207274 and 22–26 s green on this head (Bun), so the fix adds no hidden wait. Red runs end at the busy timeout. In scheduled CI the good run took 34 s and 32 s (run 46125888240) and the red run 43 s and 37 s (run 46130442319).
PR CI: the first run (46149712291 on
f39611b4040) failed onlycheck-lint-core-5, on the duplicate case label thatmainlater fixed in #207548. The head is now449278ab21d: it mergesmainat3740d8762a4, and none of the 22 new commits touch the capture, the state database or the config preflight. On that head both regression cases pass again under Bun and Node:The changed-scope Node shards ran 29
state-migrations*and Doctor preflight files, and all passed. They did not selectupdate-doctor-migration-attribution.test.ts, so the local red/green runs above cover that regression.End-to-end update cells: in progress; results will be added here.