Repository navigation
fix(doctor): update fails when another OpenClaw process has an agent database open - #172772
Merged
Merged
Conversation
Contributor
|
ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment |
RomneyDa
force-pushed
the
fix/doctor-agent-lease-wait
branch
from
October 16, 2026 22:48
7384590 to
8fa7e9c
Compare
RomneyDa
force-pushed
the
fix/doctor-agent-lease-wait
branch
from
October 16, 2026 23:26
8fa7e9c to
38ac589
Compare
RomneyDa
force-pushed
the
fix/doctor-agent-lease-wait
branch
from
October 17, 2026 00:27
38ac589 to
43fc290
Compare
RomneyDa
enabled auto-merge (squash)
October 17, 2026 00:49
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 17, 2026
…database open (openclaw#172772) * fix(doctor): wait for transient agent database leases before update maintenance * fix(doctor): wait for agent database leases under the published updater's external policy * fix(doctor): end the agent lease wait at the shared update Doctor deadline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes: an update fails or leaves maintenance pending with "Doctor could not enter maintenance. An agent database is in use." when another OpenClaw process, such as a plugin command run while the Gateway is stopped, has an agent database open at the moment update-time Doctor enters maintenance.
User Impact
User impact: update-time Doctor now waits for that process to close its agent database, printing the holder's PID, how long it will wait, and progress every 30 seconds, then continues. The wait ends at the same deadline as #172636's state wait (up to 20 minutes by default from Doctor's start, less on a slow host), so time already spent waiting for state ownership shortens it. Before this change, the measured outcomes were:
openclaw updatefrom published 2026.10.3: the update rolled back to 2026.10.3.openclaw update repair: exited 2, with Doctor and plugin maintenance left pending.If the database is still open at the deadline, Doctor refuses with the same deferred refusal (
agent-database-in-use, fact codeagent-database-lease-active). The message now names the holder's PID: "Waited 1200 s; OpenClaw process N still has an agent database open."Update behavior: the change lives in the new version's Doctor, so it applies to any update to a release that contains it, from any installed updater, including the published 2026.10.3 driver (cell below). It changes no config, schema, lease rows, or installed-updater code. Unchanged cases, which still refuse immediately:
openclaw doctor --fixWhy This Change Was Made
Where it sat. The lease check (
assertDoctorAgentLeaseAdmission) runs only after Doctor holds state ownership (sqlite-maintenance). The leases live in the shared state database. To close its database, a holder has to write that database, and while Doctor's maintenance owner exists that write is refused with "undergoing offline maintenance". So waiting while holding ownership would leave the holder unable to finish. Retrying by re-acquiring ownership on each poll would refuse its close intermittently in the same way.Shape. Admission now goes through one owner,
admitDoctorAgentLeasesinsrc/commands/doctor-agent-lease-refusal.ts. In each attempt it does the following:state.release()that legacy state-dir migration already uses mid-admission. Service-stop custody stays held.Kinds of holder:
Budget and messaging. The lease wait has no budget of its own. On the first foreign lease it resolves #172636's
resolveDoctorMaintenanceWaitDeadlineMs(30 min default step allowance less max(10 min, 2 × the rehearsalcandidate-doctortime), on Doctor's process clock) and ends there. Because the deadline is absolute, a long state wait before it leaves correspondingly less for the lease wait, and the worst case for the whole Doctor run stays one allowance: about 1,200 s of waiting plus the slowest measured Doctor (258 s), ~24.3 minutes, instead of the previous 2 × 660 s + 258 s ≈ 26.3 minutes. If no allowance is left at the first foreign lease, Doctor refuses immediately with the unchanged message. The progress cadence,formatDoctorWaitSeconds, and wording come from the same owner; "Waiting up to N s" shows the remaining allowance. Polling backs off from 100 ms to 2 s. SIGINT/SIGTERM interrupts the wait through Doctor's maintenance exit signal. (Published drivers give activation Doctor no step timeout unless the operator passes--timeout; see #172636 for the facts behind the rule.)Published updaters. Published drivers (2026.10.3 included) run activation Doctor with
OPENCLAW_SERVICE_REPAIR_POLICY=external, after stopping the Gateway themselves. That policy runs a read-only lease preflight before any lock, which refused at once. In update-repair mode the preflight now refuses only while a live Gateway owns the state (readActiveGatewayLockIdentity; an unreadable lock refuses too). Otherwise it leaves the lease to the waiting admission above. Without this, the first after-build still rolled back on the published-driver cell.Small contract change.
OpenClawAgentDatabaseLeaseActiveErrornow carries the observed live owner PIDs as diagnostic evidence, never as authority. Lease semantics are unchanged.Evidence
Published driver 2026.10.3 × candidate (Docker
openclaw-published-driver-update-e2e, repopublished-driver-update-docker.shcell with a lease holder added; candidate packed from8fa7e9c, which differs from the current head only in a comment and docs).openclaw update --tag <candidate> --yes. The holder is a separate process that waits until the driver has recorded the rehearsal in the update run, inserts a liveagent_database_leasesrow formainwith its own PID and start time, holds it until the driver stops the Gateway and 120 s more, then deletes it. Times PT, 2026-10-16:candidate-doctor(8.3 s) in the running run, phasevalidating. That is the ledger fact the budget reads.openclaw doctorstep: exit 0 in 99.5 s (12.1 s in the same cell without a held lease). The update exits 0 with statusok, the candidate build…-8fa7e9cb26af-…installed,/readyz200, and the durable session marker still visible; the cell's own assertions pass.update repaircell shows the message text ("Waiting up to 1197 s …").Before this PR (from the previous revision's cell, unchanged): the same holder made the update fail with "Doctor could not enter maintenance. An agent database is in use." and roll back to 2026.10.3;
openclaw update repairexited 2 with maintenance pending.Regression tests:
src/commands/doctor-maintenance.agent-lease-wait.test.tsdrives realbeginDoctorMaintenanceagainst a real state database, with a lease row owned by another live PID, using fake timers and an injectedperformance.now(no real sleeps). It covers:agent-database-in-userefusal and one failure fact naming the PIDdoctor --fix, a lease held by Doctor's own process, and a lease while a live Gateway owns state under the external policy, which all still refuse immediately with the unchanged messagepnpm test <file> --maxWorkers=1, Node, on a heavily loaded host (load average 14–30 from other sessions):src/commands/doctor-maintenance.agent-lease-wait.test.ts: 7/7, 72 s wall, 51 s Vitest duration (about 20 s of test time here, a few seconds on an idle host). Bun (OPENCLAW_VITEST_RUNTIME=bun): 7/7, 39 s wall.src/commands/doctor-maintenance.contention-wait.test.ts: 6/6, 55 s wall. Bun: 6/6, 14 s wall.src/flows/doctor-health.migration-refusal.test.ts: 18/18, 116 s wall.src/commands/doctor-maintenance.settlement.test.ts: 42/42, 57 s wall.src/commands/doctor-maintenance.foreground-update.test.ts: 4/4, 67 s wall.src/commands/doctor-maintenance.interruption.process.test.ts: 7/7, 40 s wall.pnpm tsgo:core,pnpm tsgo:core:test, type-aware oxlint on the changed files, oxfmt,pnpm format:docs:check, andgit diff --checkare clean.Docs:
docs/cli/update/how-updates-run.mddocs/install/update-troubleshooting.mddocs/cli/doctor/recovery.mdGaps:
openclaw update repairlease cell was not rerun for the shared deadline (its behavior is covered by the unit cases and fix(doctor): update repair fails when a short-lived OpenClaw command holds state #172636's repair cell); in the previous revision's run, repair left the hand-stopped Gateway stopped both before and after, which is unrelated.Autoreview and Testbox were skipped (release follow-up work, targeted local checks only).