Skip to content

fix: Doctor maintenance closes unrelated database clients - #148126

Merged
steipete merged 3 commits into
mainfrom
codex/maintenance-resources-main-20260914
Sep 14, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/maintenance-resources-main-20260914

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146557

What Problem This Solves

Doctor maintenance can close or wait on database resources admitted by another caller when it finishes a repair or a check that finds no work.

User Impact

Doctor finishes its accepted database work while preserving existing and independently admitted runtime clients. Cleanup failures retain their underlying error details. No schema, stored-data layout, configuration, retention, or version change is included.

Why This Change Was Made

The existing database lifecycle owner associates maintenance work with exact resources through a lexical execution boundary. Cleanup settles owned asynchronous work and native borrows before closing its native handles. Nested and sibling scopes retain their common owner, and failed unpublished opens retain their exact cleanup owner. Current write/admission checks remain authoritative; disposal of owned resources remains possible after write authority is lost.

The five maintenance-lock callers and top-level Doctor use that boundary. This is an independent prerequisite for the KV worker migration in #146557.

Evidence

Current candidate aa5ffff04d78 preserves all 36 qualified repair files while incorporating main's shared Docker assertion fix from #148129. Package and lock inputs are unchanged. The repair passed 36 selected checks and ten ordinary resource/worker/Doctor controls. The cleanup-error correction passed 29 selected checks and two original-red/candidate-green pure error contracts: a lone error keeps its identity/message, and multiple errors keep their original list and first cause. Fresh P2 review of the final composition found no actionable findings.

The published-updater Testbox session completed its original managed command successfully. Published [email protected] drove an actual file-artifact update to exact aa5ffff04d78, despite both manifest versions being 2026.9.4. Recorded build IDs distinguish the published 3a9d69db306c payload from the candidate. Candidate Doctor completed successfully in 15.190 seconds; the updater restored the real Gateway through the maintained test service manager, with a replacement supervisor and healthy readiness/RPC. The ordinary synthetic installation retained agents, disabled cron jobs, approvals, workspace and plugin configuration. Candidate no-op and the named formerly-bundled plugin Doctor checks also passed; Doctor lint reported no findings across 35 checks, with 30 skipped.

The candidate tarball was 71,242,565 bytes, SHA-256 13702623462992bd9abe0bb9c9d59c21384e4ad9e4ed5ebcba54891b7610f212. Source checks passed before build, after build, and after exercise; the package inventory contains 9,695 regular dist files. All 125 collected evidence files were independently hash-verified, and original-run collection and lease cleanup completed. This proves the successful published-updater/Doctor/service-adapter path using the maintained systemctl/busctl fixture and real Gateway processes. Native systemd and a full installed-dist rehash are outside this proof. Service status retained a recommended PATH finding for missing pnpm directories while RPC remained healthy. No recovery or synthetic future-package branch was exercised.

The earlier installed compiled-entry qualification remains tied to exact ba9217daa084: its two ordinary Doctor/shared-worker flows preserved independent handles and worker clients, closed the owned agent handle, and preserved a fresh canonical no-op database. Its distinct tarball SHA-256 is d8a8965e334485e36924372085cb1416d9b68f5c5aa9d22a86b4ee02ca9123d3; all 9,694 packaged regular dist files matched before and after. This remains historical successful-path ownership evidence, not a relabeled current-head package.

One earlier KV-based maintenance candidate produced an unexplained ordinary TaskFlow creation failure. Later ordered passes and the successful upgrade cell do not diagnose its cause or establish that it is fixed. The original evidence remains retained. Current-head CI completed successfully: 123 jobs passed and 14 were skipped. Native landing gates remain; no workflow was replayed.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check could not safely complete for this revision.

ClawSweeper will not retry this unchanged revision.

Next step: No contributor action is requested. Maintainers should inspect the linked workflow run.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 14, 2026 09:21
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: XL maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 8:59 AM ET / 12:59 UTC (Revision 5).

ClawSweeper review

What this changes

Doctor now tracks and drains its own database work while preserving unrelated runtime clients and cleanup error details.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/infra/sqlite-store.worker.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a necessary fix, with no actionable introduced defects found. The new published-updater qualification resolves the previous review’s upgrade-proof blocker within its documented scope.

Priority: P2
Reviewed head: aa5ffff04d782d77b1db12b2b4046516c13daefd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent lifecycle repair with meaningful regression coverage and sufficient installed-runtime and upgrade evidence.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The captured installed-entry qualification demonstrates resource isolation, and the current-head published-updater report exercises candidate Doctor followed by healthy real Gateway restoration through the maintained service adapter. Native systemd and failure-recovery branches remain outside the demonstrated scope.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured installed-entry qualification demonstrates resource isolation, and the current-head published-updater report exercises candidate Doctor followed by healthy real Gateway restoration through the maintained service adapter. Native systemd and failure-recovery branches remain outside the demonstrated scope.
Evidence reviewed 10 items Still needed on fetched main: Fetched main still calls process-wide agent database cleanup and path-wide shared-state drainage when Doctor releases maintenance.
Latest release retains broad cleanup: The v2026.9.4 implementation also closes all agent databases during maintenance release; this scoped fix is not present there.
Resource ownership and drainage: The scope tracks accepted promises, transfers shared handles to their common owner, drains resources in dependency order, and preserves individual cleanup failures.
Findings None None.
Security None None.

How this fits together

Doctor coordinates database repairs before releasing maintenance locks and restoring the Gateway. Its database lifecycle layer manages native handles, asynchronous work, and shared SQLite worker clients.

flowchart TD
  A[Doctor repair] --> B[Maintenance resource scope]
  B --> C[Owned handles and worker jobs]
  C --> D[Drain and close owned resources]
  D --> E[Release locks and restore Gateway]
  F[Independent runtime clients] --> G[Existing runtime resources]
  B -->|Preserve| G
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +645, Tests +284, Docs +2. Total +931 across 36 files.

View PR surface stats
Area Files Added Removed Net
Source 30 1157 512 +645
Tests 5 392 108 +284
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 36 1551 620 +931

Review metrics

Metric Value Why it matters
Production versus test growth Production net +645 lines; tests/support net +284 lines Production growth implements explicit resource custody and worker delegation for the reported cleanup defect.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-sqlite-maintenance-lock.ts, migration/backfill/repair: src/flows/doctor-health.ts, migration/backfill/repair: src/infra/state-migrations.meeting-transcripts.ts, migration/backfill/repair: src/infra/state-migrations.plugin-doctor.ts, unknown-data-model-change: src/commands/doctor-maintenance.ts, unknown-data-model-change: src/flows/doctor-health.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep cleanup scoped within the existing database lifecycle owner, preserving independent clients, current write authority, and retryable cleanup failures.

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

Yes, from source: Doctor release on fetched main invokes global agent cleanup regardless of which caller opened the handles. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Exact resource custody addresses the cleanup boundary while retaining canonical caches, shared worker ownership, and existing admission checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6f21bfa05db4.

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This repairs a bounded Doctor database-lifecycle defect without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured installed-entry qualification demonstrates resource isolation, and the current-head published-updater report exercises candidate Doctor followed by healthy real Gateway restoration through the maintained service adapter. Native systemd and failure-recovery branches remain outside the demonstrated scope.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured installed-entry qualification demonstrates resource isolation, and the current-head published-updater report exercises candidate Doctor followed by healthy real Gateway restoration through the maintained service adapter. Native systemd and failure-recovery branches remain outside the demonstrated scope.

Evidence

What I checked:

  • Still needed on fetched main: Fetched main still calls process-wide agent database cleanup and path-wide shared-state drainage when Doctor releases maintenance. (src/commands/doctor-maintenance.ts:91, 6f21bfa05db4)
  • Latest release retains broad cleanup: The v2026.9.4 implementation also closes all agent databases during maintenance release; this scoped fix is not present there. (src/commands/doctor-maintenance.ts:79, 3a9d69db306c)
  • Resource ownership and drainage: The scope tracks accepted promises, transfers shared handles to their common owner, drains resources in dependency order, and preserves individual cleanup failures. (src/state/openclaw-state-db-async-lifecycle.ts:126, aa5ffff04d78)
  • Complete maintenance caller cutover: Top-level Doctor and all five production sqlite-maintenance lock callers enter the resource scope. The SDK QA helper retains its existing signature and cleanup behavior. (src/flows/doctor-health.ts:257, aa5ffff04d78)
  • Worker authority remains live and bounded: Worker dispatch checks current admission before transferring per-job maintenance delegates. Delegates retain the native coordinator, validate actor/path identity, and check the live revocation flag at schema access; completed transfers release their delegation. (src/infra/state-database-coordinator.ts:291, aa5ffff04d78)
  • Behavioral regression coverage: Reviewed tests exercise independent native handles and worker clients, nested/sibling ownership, resource-before-handle cleanup, committed results after cleanup failure, and failed delegate setup. Tests were inspected, not executed during this read-only review. (src/state/openclaw-state-maintenance-resources.test.ts:63, aa5ffff04d78)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-14T09:37:25.053Z sha ba9217d :: blocked before merge. :: none
  • reviewed 2026-09-14T10:32:45.761Z sha ba9217d :: blocked before merge. :: none
  • reviewed 2026-09-14T11:11:44.261Z sha be735b4 :: blocked before merge. :: none
  • reviewed 2026-09-14T12:04:28.977Z sha aa5ffff :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 14, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 14, 2026
@steipete
steipete merged commit cb24f20 into main Sep 14, 2026
207 of 208 checks passed
@steipete
steipete deleted the codex/maintenance-resources-main-20260914 branch September 14, 2026 17:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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