Skip to content

fix(update): prevent database lock failures after validation - #155138

Merged
steipete merged 2 commits into
mainfrom
upd/candidate-settlement-lifecycle
Sep 21, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/candidate-settlement-lifecycle

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #154381, #154114, #144858, #154674.

What Problem This Solves

Fixes updates failing with database is locked after candidate validation passes when deferred transcript reconciliation overlaps Doctor's agent-database cleanup.

User Impact

Updates wait for admitted transcript work and its database leases to settle before closing agent databases. Transcript contents remain intact, and incomplete native cleanup remains an error rather than being reported as success.

Why This Change Was Made

The transcript pool tracked its own operations, but agent maintenance did not own or await them. A delayed transcript worker could start claiming a lease while Doctor released a cached agent's lease in the same shared database. Registering the entire operation with the existing agent-resource lifecycle closes that gap: revocation prevents new work while preserving the release task needed to finish already admitted work.

This is the standalone settlement repair. It retains all Doctor lint checks and the base canary behavior. Schemas, stored data formats, options, dependencies, and busy timeouts are unchanged.

Thanks to @ZaneMc-AO and @agebreak0083 for the reports that led to this investigation.

Evidence

Lifecycle follow-up at 65a362fcd52f23f9bc200127a519f6b347161283

The failing CI rows are regressions introduced by the original settlement change. Incognito disposal revoked a successor's queued projection work; cached-handle closure canceled a projection before admission and blocked its polling reader; and a retained lease-cleanup error survived fault removal, preventing test teardown from resetting mocks and causing later FIFO/projection failures.

The reconciliation owner now preserves incognito authority, revalidates an interrupted disk projection within the waiting caller's captured environment and lifecycle, and retains the exact lease release input so canonical drainage can recover. Drainage joins recovery before pool shutdown and native database closure. Persistent cleanup failure still refuses closure; the original reconciliation error is preserved.

Failed shard runs out of three, using the original CI file queue and effective hosted setting of two forks:

Row Original head fe70cf7e433 Main 9950ed5640aa Local rebase 903deef6baf Repaired candidate + same main
Incognito successor 3/3 0/3 3/3 0/3
Polling handle 3/3 0/3 3/3 0/3
Lease drainage / maintenance FIFO 3/3 0/3 3/3 0/3

The FIFO assertion itself fails 2/3 on both original variants. In each remaining run, the same retained cleanup errors instead poison other mocks. Main and the repaired candidate pass the assertion 3/3. All 36 queue receipts match the original CI merge's file-size order; no serial worker pin was introduced. Head's incognito shard has 84 rather than 85 files because one newer main test does not exist at that revision.

The repaired matrix passed 10,506 assertions, with zero failures or unhandled errors and 15 existing platform skips. Its longest individual test was 19.059 seconds; the longest file executed in 39.796 seconds. Maintenance FIFO fell from the reproduced 120-second timeout to 20–29 ms.

The strengthened lease test fails against the original production owners and passes after restoration of the exact candidate. It verifies refusal while the injected fault remains, recovery after removal, zero remaining leases, and concurrent pool shutdown. Both the producer lease suite and the maintenance victim pass 20/20 standalone runs; the final seven-file owner/sibling run also passes in 46.01 seconds wall. The required single-worker lease command passes eight tests in 26.83 seconds wall (Vitest: 24.65 seconds, 21% tests and 71% transform). Standalone wall medians are 21.145 seconds for the lease file and 15.525 seconds for the maintenance file; preparation dominates those wall times.

Final-source check:changed: passed (exit 0, 1818.91 seconds wall; includes core and core-test types, lint, export scans, and repository guards). Independent P1 review of the complete PR diff: scoped-clean. PR CI will rerun on the pushed head; its test durations are pending.

Interdiff versus fe70cf7e433: production +87/−30, tests +21/−5. Complete PR: production +134/−33, tests +194/−24. The follow-up introduces no schema, options, dependency, baseline, timeout, suppression, or test-assertion weakening changes. The local rebase was proof only; this follow-up remains a direct child of the original PR head.

Fixed matrix Testboxes: incognito tbx_01m32ysmbk2hpgs1b4pmcxdaey (run); polling tbx_01m32ysj9a78hd19khgwjn57er (run); drainage tbx_01m32ysmannxd66gtxvj7b9rqa (run). The wrapper/test results are the proof; stopping owned leases can mark the provisioning workflows canceled.

Auto-merge remains off for maintainer re-review. No landing.

Original standalone update/package proof at fe70cf7
  • Earlier investigation reproduced post-validation failure in 4 of 6 uninstrumented updates using the published 2026.9.4 updater, ten genuine v19 agent databases (largest 338.7 MiB), and seven external npm plugins. This is historical reproduction evidence, not a failure-rate measurement of this PR's freshly pinned base.
  • A native trace identified the two owners on the same database: Doctor's agent-lease release failed at BEGIN IMMEDIATE while a transcript worker was claiming its independent lease. The peer transaction interval was 0.421 ms; the failed BEGIN occurred after that transaction began and before its COMMIT call. The fix joins that lifecycle rather than adding retries.
  • All three new regressions failed on the original owner code: native closure preceded worker lease release in normal and native-exit cases, and delayed work still entered a disk task after closure. The earlier fixed-source pool/lifecycle replay passed 19 tests; the three new cases took 374 ms, 557 ms, and 77 ms. Exact standalone verification is listed below.
Standalone verification Result
Three published-updater → candidate runs on restored 10-DB / 7-plugin state 3/3 succeeded; 30/30 database checks passed; zero settlement lock errors or surviving marked children.
Existing owner/fixture suites in original order node scripts/run-vitest.mjs src/test-utils/openclaw-test-state.test.ts src/config/sessions/session-transcript-reconcile-pool.test.ts src/config/sessions/session-transcript-reconcile.lifecycle.test.ts: 51 tests / three files passed, two shards, 35.98s wrapper wall. Shards: 17.34s wall (6% tests) and 16.73s wall (47% tests).
Changed-file checks and core/test types The broader 23-path candidate at e62832eb31df99cbc684c99dbf31c8f4e0f681ea, containing these exact five files on the same pinned main, passed the full changed gate including production/test types. This standalone run adds its own package build and original-order owner tests; no separate standalone typecheck invocation is claimed.
Independent P1 review of the standalone commit Independent commit-mode P1 review: scoped-clean, no actionable P0/P1, at fe70cf7e4335d7f3caea07e8c8ca1eeb385a8049.
Production / test LOC Production +71/−27 (net +44; two files). Tests +173/−19 (net +154; three files).

The tests assert worker-lease release before native closure, zero remaining agent leases, preserved transcript bytes, recovery release after native worker exit, and refusal of delayed first admission. An older assertion expecting immediate maintenance refusal while a worker was deliberately paused was removed because maintenance now waits for that worker's lifecycle to settle; synchronous-close lease protection remains covered.

The original standalone source was pinned main db113b13a3bb8d59409b3c4ecb9d5d1e06c3343a plus exactly these five files. The proof verifies their hashes, 19 unchanged-main invariants, full original Doctor lint, main canary behavior, schema 22, and absence of the generation-sharing modules. The standalone branch merges cleanly with subsequently advanced main 8c56f7239e98dbee1369e036d6b594fd560b9d9d.

The realistic synthetic fixture restores ten agents/ten v19 DBs (365.8 MiB total, 338.7 MiB largest) and seven genuine npm 2026.9.5 plugins before each hop: Codex, WhatsApp, Discord, Slack, Deepseek, Mistral and Venice (477.5 MiB total). Every hop freshly installs the published 2026.9.4 updater and runs openclaw update --tag <candidate.tgz> --yes --json --no-restart --timeout 1800. Its 300-second combined validation clamp is unchanged. Isolated state and free canary ports are used; no inference, operator Gateway or managed-service restart is claimed.

All final DBs reach schema 22 through the v19→v21 path, with correct ownership, integrity_check = ok, zero foreign-key violations, and unchanged raw transcript/trajectory hashes. Advisory plugin migration-pending warnings retain their source inputs and do not fail the update.

Seconds, min / median / max across three uninstrumented hops. The validating ledger begins before staging, so it is a conservative upper bound on the combined-validator interval. These are standalone outcome measurements on a separate lease, not a causal performance comparison with the historical failing runs.

Phase Min Median Max
Rehearsal 30.220 31.128 35.557
Doctor lint 18.720 20.179 22.711
Config validation 1.581 1.614 1.937
Plugin resolution 0.714 0.753 1.202
Migration continuation 0.742 0.770 1.083
Canary 11.580 12.717 16.398
Npm staging 7.938 9.082 9.303
Validating ledger 89.388 92.971 106.583
Post-install Doctor 22.487 23.970 26.755

pnpm build:package passed in 7m07.1s, chiefly declaration generation; packaging passed. Candidate tarball SHA-256: cc48e82d0fd7d2d8ce5ff4e18f5d97e22c1112a8d31e7e71cf6d11113600d699.

Testbox lease tbx_01m32qq832r4e0xbr4qtqvqmen (run): native proof batch exit 0, all post-build/test/hop source checks passed. The owned lease was stopped after evidence collection. The original broader changed gate ran on tbx_01m32k1pzgzmz2rtwbm4jkhdeb (run). No slow or flaky test was encountered in the standalone replay; no retries, larger timeouts, weaker assertions, skips or baseline changes were introduced.

Join accepted reconciliation and native lease release before cached database close during Doctor settlement. Revoke late admission while retaining custody when cleanup fails.

Related: #154381, #154114, #144858.
@clawsweeper

clawsweeper Bot commented Sep 21, 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 size: M maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete steipete changed the title fix(update): settle transcript workers before closing agent databases fix(update): prevent database lock failures after validation Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 20:10
@steipete
steipete enabled auto-merge (squash) September 21, 2026 21:13
@steipete
steipete disabled auto-merge September 21, 2026 21:16
steipete added a commit that referenced this pull request Sep 21, 2026
Include the unchanged lifecycle repair from #155138. The published updater proof reproduced Doctor closing cached agent databases while the transcript worker claimed its lease; the native trace confirms the same owner race.
Keep incognito successor work with its memory owner, and let projection
waiters revalidate cached-handle turnover within their captured lifecycle.
Retain exact failed leases for canonical cleanup instead of replaying a
historic error, and join that recovery before the worker pool closes.

The retained cleanup error had prevented test mock reset and caused later
FIFO and projection assertions to fail. Preserve all existing assertions
and cover failed drainage, recovery after fault removal, and pool shutdown.
@steipete
steipete enabled auto-merge (squash) September 21, 2026 22:54
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 6:53 PM ET / 22:53 UTC.

ClawSweeper review

What this changes

Make database cleanup wait for transcript workers and their lease releases, while preserving incognito sessions and recovering interrupted projection reads.

Merge readiness

✅ Ready for maintainer review

Keep open: the settlement gap remains on current main and in the latest release. The patch addresses it through the existing lifecycle owner, and the reviewed delta has no blocking correctness finding.

Priority: P1
Reviewed head: 65a362fcd52f23f9bc200127a519f6b347161283

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful native-worker and upgrade evidence and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.
Evidence reviewed 9 items Reviewed introduction boundary: Reviewed the pinned merge-base-to-head delta. Only the six identified reconciliation and test paths belong to this PR; endpoint drift was excluded. The supplied test merge is stale and was not used to infer removal of main-branch behavior.
Canonical settlement ownership: Operations register before execution, reject new disk work after revocation, and retain exact failed release inputs for canonical cleanup. Recovery joins pool drainage, and unsuccessful lease cleanup continues to reject database closure.
Existing maintenance integration: Agent maintenance already awaits asynchronous database closure before checking remaining leases. The resource owner drains registered operations before native closure, and maintenance cleanup orders agent resources before agent handles.
Findings None None.
Security None None.

How this fits together

Transcript reconciliation builds searchable projections from stored conversations using background workers. Doctor and update validation must settle those workers before closing agent databases.

flowchart TD
  A[Stored conversations] --> B[Transcript reconciliation]
  B --> C[Background worker and database lease]
  C --> D[Searchable projections]
  E[Doctor or update cleanup] --> F[Revoke new work and await settlement]
  B --> F
  F --> G[Release leases and close databases]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +101, Tests +170. Total +271 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 134 33 +101
Tests 4 194 24 +170
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 328 57 +271

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +101 lines; tests net +170 lines Production growth implements lifecycle registration and recoverable lease settlement, with tests protecting native closure ordering and failure recovery.

Root-cause cluster

Relationship: canonical
Canonical: #155138
Summary: This is the standalone transcript-settlement repair; related update optimizations remain separate, and archive repair carries an earlier version as a prerequisite.

Members:

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

Technical review

Best possible solution:

Keep transcript admission, lease recovery, and database closure under the existing lifecycle owner without changing stored data, timeouts, or user settings.

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

Yes, the source exposes the unjoined worker-lease/agent-close race, and the supplied investigation records a native failure trace and failing regressions. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes. Extending the existing resource lifecycle repairs the ownership gap directly, preserves original reconciliation errors, and avoids retries, larger timeouts, or a competing cleanup owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1497878e0bc6.

Labels

Label changes:

  • add P1: The repair addresses demonstrated database-lock failures that prevent updates from completing after validation.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.

Label justifications:

  • P1: The repair addresses demonstrated database-lock failures that prevent updates from completing after validation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured published-updater runs demonstrate successful settlement and preserved database contents for the original fix; latest-head native-worker fault runs exercise the production reconciliation and closure owners through refusal and recovery. These support the internal lifecycle change without claiming a fresh latest-head full update run.

Evidence

What I checked:

  • Reviewed introduction boundary: Reviewed the pinned merge-base-to-head delta. Only the six identified reconciliation and test paths belong to this PR; endpoint drift was excluded. The supplied test merge is stale and was not used to infer removal of main-branch behavior. (65a362fcd52f)
  • Canonical settlement ownership: Operations register before execution, reject new disk work after revocation, and retain exact failed release inputs for canonical cleanup. Recovery joins pool drainage, and unsuccessful lease cleanup continues to reject database closure. (src/config/sessions/session-transcript-reconcile-pool.ts:76, 65a362fcd52f)
  • Existing maintenance integration: Agent maintenance already awaits asynchronous database closure before checking remaining leases. The resource owner drains registered operations before native closure, and maintenance cleanup orders agent resources before agent handles. (src/state/openclaw-agent-db-resources.ts:211, 65a362fcd52f)
  • Current main still needs the repair: The fetched main implementation tracks reconciliation only within its pool; it lacks registration with agent-database resources and retained cleanup recovery. Comparing the two production files against the introduction base showed no intervening main changes. (src/config/sessions/session-transcript-reconcile-pool.ts:51, 1497878e0bc6)
  • Latest release comparison: The v2026.9.5 source also lacks agent-resource registration in the reconciliation pool. This repair is not already supplied by the identified latest release. (src/config/sessions/session-transcript-reconcile-pool.ts:44, ec9c1a13db89)
  • Recovery and revocation coverage: Inspected native-worker tests asserting release before native close, recovery after worker termination, rejection before delayed disk admission, persistent-fault refusal, and successful cleanup after fault removal. Existing polling-handle and incognito ownership contracts remain relevant; the follow-up specifically addresses their reported regressions. (src/config/sessions/session-transcript-reconcile.lease.test.ts:224, 65a362fcd52f)

Likely related people:

  • steipete: 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 2fe6908 into main Sep 21, 2026
197 checks passed
@steipete
steipete deleted the upd/candidate-settlement-lifecycle branch September 21, 2026 23:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…w#155138)

* fix(update): settle transcript workers before closing agent databases

Join accepted reconciliation and native lease release before cached database close during Doctor settlement. Revoke late admission while retaining custody when cleanup fails.

Related: openclaw#154381, openclaw#154114, openclaw#144858.

* fix(sessions): recover reconciliation across database closure

Keep incognito successor work with its memory owner, and let projection
waiters revalidate cached-handle turnover within their captured lifecycle.
Retain exact failed leases for canonical cleanup instead of replaying a
historic error, and join that recovery before the worker pool closes.

The retained cleanup error had prevented test mock reset and caused later
FIFO and projection assertions to fail. Preserve all existing assertions
and cover failed drainage, recovery after fault removal, and pool shutdown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant