Skip to content

fix(update): keep database restoration available when progress polls during Doctor - #192083

Merged
steipete merged 1 commit into
mainfrom
codex/g31-doctor-progress-custody
Nov 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/g31-doctor-progress-custody

Conversation

@steipete

@steipete steipete commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: every update driven by a current-main updater loses automatic database restoration and skips post-plugin Doctor maintenance, because the updater's own progress display keeps the shared state database open while the post-plugin Doctor needs exclusive access.

User Impact

User impact: updates keep automatic database restoration available, and the post-plugin Doctor completes its maintenance. Before this change, every second update from a current build (for example a 10.10 build updating to a newer one) printed Automatic database restoration unavailable: databases changed after snapshot capture; the writer is unknown, left the database snapshots on disk, and logged Doctor could not complete maintenance from the post-plugin Doctor, even though the update reported success.

Why This Change Was Made

The CLI progress display polls the update ledger every 250 ms. Each poll borrows the shared-state reader pool, which retains the SQLite connection for reuse. During finalization the display is active again, so the parent process holds an open reader on state/openclaw.sqlite. The post-plugin Doctor child then takes exclusive native custody for its state migration (PRAGMA locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE). An open reader on another connection makes that fail with database is locked. Update capture records the failed migration as unattributable writes, so restoration is refused for the rest of the update. The parent's observeUpdateParentDatabaseWrites already closes its handles before the child, but the next progress tick reopens a reader about 200 ms later.

runUpdateDoctorProcess owns every update Doctor child: the activation Doctor, the fresh pre- and post-plugin Doctors, and run-main Doctor results. It now pauses the run's progress observer, waits for any in-flight poll to settle, and closes parent state handles before the child starts. Observation resumes after the child settles and its existing post-child close runs. If another owner had already paused the observer, for example activation, that pause stays in place.

Rejected alternatives:

  • Non-retaining reads for the progress poller. A 250 ms poll can still race the child's exclusive lock.
  • Retrying the exclusive lock inside Doctor. The poller keeps reopening its reader, so the retry can never win.

Evidence

  • Regression test. src/cli/update-cli/update-command-doctor-child.test.ts, "keeps live progress observation from refusing the Doctor's exclusive state custody". It starts real progress observation, waits until a ledger read has landed, then runs a real child process that takes PRAGMA locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE. Red on base: the child exits 1 with Error: database is locked (errcode 5). Green with the fix. The doctor-child, progress.test.ts and progress.observation.test.ts suites all pass, 37 tests.
  • Native Linux reproduction on Crabbox (AWS, systemd, live Gateway). Published 2026.10.9 updated to a main build, then that build updated to itself. This reproduced 4 out of 4 times on main d615435. The post-plugin Doctor logged Automatic database restoration cannot attribute migration writes: SQLite migration publication could not be verified: database is locked. The update then warned Automatic database restoration unavailable. An instrumented build traced the blocking handle to the parent's state-read worker, reopened by updateRuns.get from the 250 ms progress poller about 200 ms after the parent closed its handles. Native red/green on the same box, clean packages, 2026.10.9 → build → same build relabelled 2026.10.11 with a live systemd Gateway: base main d615435, second hop: database is locked x3, Doctor could not complete maintenance x1, Automatic database restoration unavailable x1. Fixed head (main 01838fc + this change), second hop: 0 / 0 / 0; both hops rc=0 and Gateway /readyz ready afterwards.
  • Static checks. Type-aware oxlint core shard and tsgo:core pass.
  • Review. $autoreview is scoped-clean. An independent codex exec review returned NO FINDINGS.

@clawsweeper

clawsweeper Bot commented Nov 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 cli CLI command changes size: S labels Nov 3, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Pause progress polling and drain parent database handles while an update Doctor child runs.

Example: A current-build updater runs post-plugin Doctor while polling progress every 250 ms.

  • Before: The retained progress reader blocks exclusive SQLite access, preventing maintenance and disabling automatic database restoration.
  • After: Polling pauses, parent handles close, Doctor runs, and observation resumes after child settlement and schema admission invalidation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and appears correct; required after-fix evidence through the shipped update flow remains outstanding.
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: An update can report success while post-plugin maintenance fails and automatic database restoration becomes unavailable.
Reason: Restoring maintenance and recovery availability has clear value, and the supplied maintainer-authored direction requires no further product decision.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a concrete update recovery failure still present on current main, and the focused patch introduces no identified correctness defect.

Priority: P1
Reviewed head: ad0d6bac0ddb09996b29b35bff0ad25f43063717

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide fixed-head native update evidence with progress enabled, including a latest-stable upgrade preserving settings and data and confirming post-plugin maintenance and restoration availability.
Agent review details

How this fits together

The update CLI observes its durable run ledger through a reusable shared-state reader; the Doctor-child owner coordinates subprocess execution, database handoff, and settlement.

flowchart TD
  A[Update CLI] --> B[Progress observer]
  B --> C[Shared state reader]
  A --> D[Doctor child owner]
  D --> B
  D --> E[Database lifecycle owner]
  E --> C
  D --> F[Doctor subprocess]
  F --> G[SQLite maintenance]
Loading

Technical review

Best possible solution:

Keep the existing reusable reader and suspend its observation through the shared Doctor-child lifecycle, as this patch does.

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

Source connects the retained live progress reader to the missing pre-Doctor suspension, and the body reports four native reproductions plus a regression failing with SQLite error 5; no target code was run during this review.

Is this the best way to solve the issue?

This is a focused fix at the existing process owner: it prevents the blocking reader rather than retrying Doctor, preserves prior suspension ownership, and retains post-child schema readmission.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Reusable live progress observation keeps the original intent (6e6458a: Avoid synchronous full-database snapshots on every progress poll while preserving committed phase observation.)
  • Activation suspension and deferred ledger observation keeps the original intent (d1a69c0: Keep candidate validation and exclusive maintenance under the existing transactional activation owner.)
  • Post-Doctor database drainage and admission revocation keeps the original intent (e72e9a5: Prevent parent handles from reusing schema admission established before a Doctor migration, including failed child exits.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e72e9a5 adds src/cli/update-cli/update-command-doctor-child.ts:177 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e72e9a566d35; files: src/cli/update-cli/update-command-doctor-child.ts)
  • Vincent Koc: Raw commit 11091f0 adds src/cli/update-cli/progress.ts:49 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 11091f0bf62f; files: src/cli/update-cli/progress.ts)
  • Dallin Romney: Raw commit c6b9bd6 adds src/cli/update-cli/progress.ts:168 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c6b9bd69c99d; files: src/cli/update-cli/progress.ts)

PR surface

Source +35, Tests +40. Total +75 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 53 18 +35
Tests 1 41 1 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 94 19 +75

Labels

Label changes:

  • add P1: The reported current-main update path skips Doctor maintenance and loses automatic database restoration despite reporting success.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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:

  • P1: The reported current-main update path skips Doctor maintenance and loses automatic database restoration despite reporting success.
  • 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 3, 2026, 11:52 AM ET / 16:52 UTC.

@steipete
steipete marked this pull request as ready for review November 3, 2026 17:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-03T17:32:57.357396Z ad0d6ba Draft marked ready
ℹ️ 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.

@steipete
steipete merged commit d50ccce into main Nov 4, 2026
215 of 218 checks passed
@steipete
steipete deleted the codex/g31-doctor-progress-custody branch November 4, 2026 14:53
@steipete

steipete commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Nov 4, 2026
Keep distinct route, ordering, trigger, publication, custody, and fixture-lifecycle contracts from #192769, #192540, #192250, #192812, #191643, #192584, #192588, and #192083. Raise only the scalar by the exact measured inherited deficit; production and test LOC remain unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 5, 2026
Keep distinct route, ordering, trigger, publication, custody, and fixture-lifecycle contracts from openclaw#192769, openclaw#192540, openclaw#192250, openclaw#192812, openclaw#191643, openclaw#192584, openclaw#192588, and openclaw#192083. Raise only the scalar by the exact measured inherited deficit; production and test LOC remain unchanged.
RomneyDa added a commit that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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