Skip to content

fix(update): snapshot databases consistently under concurrent writes - #158317

Merged
steipete merged 1 commit into
mainfrom
upd/consistent-db-snapshot-and-build-tmp
Sep 25, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/consistent-db-snapshot-and-build-tmp

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #157603

What Problem This Solves

Fixes update schema preflight and candidate snapshots failing after repeated large database copies while a running Gateway continues writing.

User Impact

Updates can snapshot active databases consistently, including committed WAL content, with pages, bytes, and elapsed time visible in the existing update ledger. A genuine storage/access failure is reported once with an actionable next step.

The already-installed 2026.9.5 updater is not retrofitted. Until an updated driver is installed, stop the Gateway service and run openclaw update from a separate terminal, then start the service again. Normal Gateway databases use WAL; a consistent snapshot of a rollback-journal database holds SQLite's required reader lock and can temporarily delay its writer.

Why This Change Was Made

Copying database files and retrying until their metadata stops changing treats ordinary Gateway activity as a failure. Update preflight now uses a dedicated reader, and async snapshot acquisition uses the existing canonical SQLite online-backup primitive with a pinned read transaction. This removes the async stabilization loop and its “did not stabilize” failure, while retaining the separate synchronous artifact-preservation contract. No new schema, configuration, CLI option, dependency, or progress store is introduced.

Native progress flows through the existing worker diagnostics and update ledger. The native backup's resolved page count supplies the completion event, and grouped byte counts preserve useful sizes through existing support redaction.

The plugin-build directory leak is already addressed by #154324 (operation cleanup) and #157727 (stale tokenless capture reclamation). This PR verifies those owners instead of duplicating them. Reported by @Nickfost.

Evidence

  • Negative controls against the original async reader reproduced SQLite source did not stabilize after 10 read-only inspection attempts under concurrent writes/checkpoints. The fixed preflight and snapshot paths succeed on the first acquisition and pass integrity checks.
  • Linux Testbox live proof ran a real development Gateway with recurring cron agent turns against a mock provider and invoked openclaw update --tag file:<candidate.tgz> --yes --json --no-restart. The snapshot contained 3,770,085,376 bytes / 920,476 pages, copied in 3.605 s, with 16 observed database-version transitions during copying; verification/publication finished in 27.9 s. The update succeeded, integrity passed, and the Gateway kept running. System and operation temp-directory censuses contained no openclaw-plugin-build-* roots after cleanup. Lease tbx_01m3cwt6mghc1gwgbeqxhaznfp: https://github.com/openclaw/openclaw/actions/runs/36172908071.
  • The separate published [email protected] → candidate Docker upgrade cell passed with its offline fixture. This does not claim the old driver gained concurrent-write support.
  • Touched suites passed three times. The final direct-import/one-barrel caller run passed 4,149 tests across 204 selected files (14 existing skips), exit 0. Lease tbx_01m3cyn9yxk11ke26nh83k55nt: https://github.com/openclaw/openclaw/actions/runs/36176317620.
  • Existing plugin lifecycle/reclamation coverage passed 46 tests across run-main.cleanup, plugin-source-capture-directory, and plugin-source-capture-recovery.
  • Final node scripts/check-changed.mjs -- <changed paths> completed with exit 0, including core production types, all 25 test type graphs, lint, dead-export scans, and repository guards. Testbox command time: 30m15.492s. Lease tbx_01m3d24rh1hmmqcwnba6j3kr1w: https://github.com/openclaw/openclaw/actions/runs/36182540425. Fresh Codex autoreview found no actionable P0/P1 findings; git diff --check passed. No source edits followed the completed test/live proof, so those results were reused.
  • LOC: production +254/−178 (net +76); tests/support +242/−105; docs +19/−1. Progress transport accounts for the net production growth while the async retry machinery is removed.

Measured single-file pnpm test <file> --maxWorkers=1 wall times on Testbox (shared compiler/worker preparation included):

Test file Wall time
src/cli/update-cli.target-schema.test.ts 30.90 s
src/cli/update-cli/schema-preflight.test.ts 31.10 s; final transfer-list runs 39.04 / 30.74 / 31.87 s
src/infra/sqlite-backup.test.ts 2.27 s
src/infra/sqlite-readonly-location.copy.test.ts 2.15 s
src/infra/sqlite-readonly-location.test.ts 17.58 s
src/infra/update-candidate-canary.test.ts 26.09 s
src/infra/update-candidate-state.online-backup.process.test.ts 16.50 s
src/infra/update-candidate-state.schema.test.ts 21.03 s

Per-PR CI timings are pending. The final canary and candidate-admission suites also passed three times after the byte-format and strict mock-expectation corrections (75 tests per run).

Known gaps / follow-ups

These pre-existing slow cases passed and are explicitly assigned to separate follow-up lanes:

File Case Test time Observed cause
extensions/qa-lab/src/control-ui-media-transcript.real-gateway.e2e.test.ts renders recoverable and omitted image history 70.457 s Real Gateway per test plus a required stop/reseed/restart for resident projection admission. Precise bootstrap/UI/drain split still needs measurement.
Same file delivers PowerPoint and keeps persisted attachment failures replay-safe 45.405 s Separate real Gateway, auth/update-repair bootstrap, and four UI/model turns. Precise phase costs still need measurement.
extensions/memory-core/src/tools.index-upgrade.test.ts keeps the rebuild cost warning when a search deadline expires during embedding 30.951 s Intentionally blocked embedding waits through the real 30-second search deadline; convert to controlled timers in its owning lane.

The controlled offline systemd handoff drain hang reported in #157603 belongs to the #157329/#153401 class and is not changed here.

@clawsweeper

clawsweeper Bot commented Sep 25, 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.

@Nickfost

Nickfost commented Sep 25, 2026 •

Copy link
Copy Markdown

stop the Gateway service and run openclaw update from a separate terminal, then start the service again

Manually stopping the gateway to update does not remedy the issue, see here:
#157603 (comment)

@steipete
steipete merged commit 979a8be into main Sep 25, 2026
267 of 269 checks passed
@steipete
steipete deleted the upd/consistent-db-snapshot-and-build-tmp branch September 25, 2026 20:51
@Nickfost

Copy link
Copy Markdown

roboclaw-bot added a commit that referenced this pull request Sep 27, 2026
Backport the coupled all-database snapshot and pre-start rollback repairs:
- #158317 / 979a8be
- #158163 / d780fdc
Source credit: Peter Steinberger (steipete).

Capture complete source-preserving online snapshots with continuous Gateway
exclusion for automatic restoration eligibility. Account for Doctor writes
through exact native transaction images, ordered worker/heartbeat receipts
and persistent metadata, including default_cache_size. Unknown observations
refuse restoration rather than adopt foreign generations.

Retain native source custody through displacement and separate published
postimage custody through settlement. Missing names use creator-owned locked
file capabilities and no-clobber publication. Published handles settle before
absence-last handback. Preserve foreign replacements/contents, cleanup errors,
WAL publication, live authority and the target restart attempted-start guard.

Review findings were reproduced at actual boundaries and corrected. The final
metadata proof passes 36 Doctor/image cases plus a real rollback positive;
prior 29 current-custody cases and earlier scoped evidence remain retained,
not relabeled as rerun. Production/focused types, lint, format and frozen
eb377ac ratchets pass. Final independent P0-P2 review passes both partitions
on exact tree a16411a.

Linux/Node source proof is not installed-driver or full platform qualification.
Windows/Bun restoration remains explicitly manual when native custody is not
supported. No schema/dependency/version changes or guard/budget waivers.
This component is committed locally only; parent composition and its bound
service-membership fixture patch are still pending. Public size-policy hold
remains active.

Implementation:
https://team.openclaw.ai/chat/roboclaw/dashboard/6dde6dee-8e3f-4d43-aada-2c1cf14afa4e
Persistent metadata correction:
https://team.openclaw.ai/chat/roboclaw/subagent/609bf089-d2c0-499e-8f9f-74c2615d43ac
Original discussion, handback correction and final review:
https://team.openclaw.ai/chat/roboclaw/dashboard/db4d78ac-b19b-4f64-adfb-0ca7973a62e4

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
roboclaw-bot added a commit that referenced this pull request Sep 27, 2026
Merge the reviewed coupled snapshot/rollback component into the prepared
release branch, preserving the existing service, Doctor, APFS, vendor and
already-landed canonical release repairs. Source credit remains Peter
Steinberger for #158317/#158163; all inherited contributor credits remain.

Apply the service-membership fixture only after matching its recorded exact
preimage and verify its postimage. Repair the extracted wrapper closure with
the three existing transaction/image/receipt modules required by the new
SQLite worker flow.

Bind maintenance exclusion to a private live owner: foreign late delegates
and unowned schema work refuse while valid same-owner delegates retain the
fence through release and cleanup. The quarantine inventory review concern
was refuted by its existing producer filter and real create/verify/restore
WAL coverage, with a discriminating filter-removal control. No redundant
backup production filter or schema change was added.

Composed interaction proof: 81 tests across nine files plus two extracted
wrapper checks pass. The final ownership repair passes 108 unique tests in
11 owner/sibling files, production/exact-owner types, lint, formatting and
all frozen eb377ac ratchets. Earlier independent source proof remains
retained rather than relabeled as rerun. Final independent P0-P2 review
completed all five partitions with zero findings on exact tree
d963fed; all 132 file bindings match.

This is local preparation, not canonical release publication or installed
platform qualification. Version remains 2026.9.6 and fs-safe remains0.18.1.
The separately accepted dependency PR and the public size-policy decision
remain external gates. No guard, assertion, lease, timeout or baseline waiver.

## Work sessions

- Original discussion, review and final integration:
  https://team.openclaw.ai/chat/roboclaw/dashboard/db4d78ac-b19b-4f64-adfb-0ca7973a62e4
- Final ownership correction and verification:
  https://team.openclaw.ai/chat/roboclaw/subagent/2a4b17b6-c5cf-4278-b582-debae9da3826
- Database implementation:
  https://team.openclaw.ai/chat/roboclaw/dashboard/6dde6dee-8e3f-4d43-aada-2c1cf14afa4e
- Persistent metadata correction:
  https://team.openclaw.ai/chat/roboclaw/subagent/609bf089-d2c0-499e-8f9f-74c2615d43ac

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
azuretek added a commit to azuretek/nucleo that referenced this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation size: L

Projects

None yet

2 participants