Repository navigation
fix: let package updates start while the Gateway is writing to an agent database - #201545
Conversation
Candidate admission inspects agent databases with artifact preservation, so every agent store went through a private full copy. A copy of a store the serving Gateway keeps writing never stabilizes, and `openclaw update` refused at database-schema-preflight (wal-copy-unstable) after up to 96 seconds. A complete WAL family is now read in the isolated reader through SQLite's read-only shared-memory index (`readonly_shm=1`): no reader mark, no index rebuild, no sidecar creation, so every source byte is preserved and the WAL-only committed schema is still seen. Any other family, or a read-only index SQLite cannot use, keeps the private snapshot path. The capture warning no longer claims manual recovery is needed. It says the write generation changed or could not be confirmed and that automatic rollback keeps the live database instead of that snapshot.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…reads-schema-without-copy
|
Codex review: needs maintainer review before merge. What this changesThis PR reads eligible live agent schemas through SQLite’s read-only shared-memory index and clarifies the backup warning. Example: A package update inspects a 512 MiB agent database receiving 8 MiB/s of writes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes database-sized admission copies beyond the merged fallback, and no concrete introduced defect was found; the failing restart-handoff check remains unattributed. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI and Gateway-triggered updates send database paths and supported schema versions through candidate admission to the shared preflight owner, which returns compatibility results from an isolated inspection child. flowchart TD
A[CLI or Gateway update] --> B[Candidate admission]
B --> C[Database schema preflight]
C --> D[Isolated schema reader]
D --> E[Read only WAL index]
D --> F[Existing private snapshot fallback]
E --> G[Compatibility result]
F --> G
Technical reviewBest possible solution: Use the existing inspection child for byte-preserving live WAL reads while retaining private snapshots for families SQLite cannot inspect that way. Do we have a high-confidence way to reproduce the issue? Current-main source confirms artifact-preserving agent admission still copies the database, and the supplied red/green evidence exercises the checkpointing-writer trigger; no target code was executed during this review. Is this the best way to solve the issue? The patch addresses the unnecessary copy at its existing owner, preserves schema rejection and fallback behavior, and introduces no competing state or configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 895091c98787. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +35, Tests +137. Total +172 across 11 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 18, 2026, 8:20 PM ET / November 19, 2026, 01:20 UTC. |
…ing a preserving read
…s owner The close-race fallback read errcode through an uncommented type assertion, which the assertion-safety ratchet rejects. Use sqlitePrimaryResultCode from sqlite-error-diagnostics instead.
…reads-schema-without-copy
|
Merged via squash.
|
…nt database (#201545) * fix(update): read live agent schemas without a stable copy Candidate admission inspects agent databases with artifact preservation, so every agent store went through a private full copy. A copy of a store the serving Gateway keeps writing never stabilizes, and `openclaw update` refused at database-schema-preflight (wal-copy-unstable) after up to 96 seconds. A complete WAL family is now read in the isolated reader through SQLite's read-only shared-memory index (`readonly_shm=1`): no reader mark, no index rebuild, no sidecar creation, so every source byte is preserved and the WAL-only committed schema is still seen. Any other family, or a read-only index SQLite cannot use, keeps the private snapshot path. The capture warning no longer claims manual recovery is needed. It says the write generation changed or could not be confirmed and that automatic rollback keeps the live database instead of that snapshot. * test(update): check live-owner progress across admission and shrink the idle fixture * fix(update): fall back to the snapshot when the last owner closes during a preserving read * fix(update): read the SQLite open failure code through its diagnostics owner The close-race fallback read errcode through an uncommented type assertion, which the assertion-safety ratchet rejects. Use sqlitePrimaryResultCode from sqlite-error-diagnostics instead. (cherry picked from commit 911e7c1) Co-authored-by: RomneyDa <[email protected]>
…nt database (openclaw#201545) * fix(update): read live agent schemas without a stable copy Candidate admission inspects agent databases with artifact preservation, so every agent store went through a private full copy. A copy of a store the serving Gateway keeps writing never stabilizes, and `openclaw update` refused at database-schema-preflight (wal-copy-unstable) after up to 96 seconds. A complete WAL family is now read in the isolated reader through SQLite's read-only shared-memory index (`readonly_shm=1`): no reader mark, no index rebuild, no sidecar creation, so every source byte is preserved and the WAL-only committed schema is still seen. Any other family, or a read-only index SQLite cannot use, keeps the private snapshot path. The capture warning no longer claims manual recovery is needed. It says the write generation changed or could not be confirmed and that automatic rollback keeps the live database instead of that snapshot. * test(update): check live-owner progress across admission and shrink the idle fixture * fix(update): fall back to the snapshot when the last owner closes during a preserving read * fix(update): read the SQLite open failure code through its diagnostics owner The close-race fallback read errcode through an uncommented type assertion, which the assertion-safety ratchet rejects. Use sqlitePrimaryResultCode from sqlite-error-diagnostics instead.
…nt database (openclaw#201545) * fix(update): read live agent schemas without a stable copy Candidate admission inspects agent databases with artifact preservation, so every agent store went through a private full copy. A copy of a store the serving Gateway keeps writing never stabilizes, and `openclaw update` refused at database-schema-preflight (wal-copy-unstable) after up to 96 seconds. A complete WAL family is now read in the isolated reader through SQLite's read-only shared-memory index (`readonly_shm=1`): no reader mark, no index rebuild, no sidecar creation, so every source byte is preserved and the WAL-only committed schema is still seen. Any other family, or a read-only index SQLite cannot use, keeps the private snapshot path. The capture warning no longer claims manual recovery is needed. It says the write generation changed or could not be confirmed and that automatic rollback keeps the live database instead of that snapshot. * test(update): check live-owner progress across admission and shrink the idle fixture * fix(update): fall back to the snapshot when the last owner closes during a preserving read * fix(update): read the SQLite open failure code through its diagnostics owner The close-race fallback read errcode through an uncommented type assertion, which the assertion-safety ratchet rejects. Use sqlitePrimaryResultCode from sqlite-error-diagnostics instead. (cherry picked from commit 911e7c1) Release adaptation: Preserved baseline schema-version snapshot pinning and private fallback. Resolved comment/closed-WAL overlap with source read-only-SHM branch; all eleven source files retained. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
On a package install whose agent is busy,
openclaw update(CLI, orupdate.runthrough the Gateway) can refuse atdatabase-schema-preflightafter 60 to 96 seconds: "could not inspect agent database ... SQLite source did not stabilize (reason=wal-copy-unstable) ... Wait a moment for write activity to settle". A retry refuses the same way. The only advice printed isopenclaw triage, or a manual npm install that bypasses the guard. Nothing is changed and the Gateway keeps serving, but the update cannot start while the Gateway is writing.The cause: the schema check reads each agent database through a private full copy of the live file, and a copy of a file the Gateway keeps writing never holds still. The same runs also printed "Database changed during capture; its snapshot requires manual recovery", which was false. Nothing had changed and nothing needed recovery.
User Impact
User impact: the update's schema check reads a live agent database where it is, without copying it, while the Gateway serves and writes. The check's time and disk use no longer grow with the database's size. Users on the published
2026.11.5get this with no manual step once a release containing this commit is published, because the candidate package runs the check (see "Update behavior for published updaters").Why This Change Was Made
Root cause: candidate admission (
update-command-admit.ts) inspects state under artifact-preserving reads. Under those reads,preflightOpenClawDatabaseSchemasskipped the native read for every agent store and always prepared a private full copy (prepareSqliteReadOnlyLocation).v2026.11.5, and on main before fix: let updates proceed while a busy agent database keeps writing #201327, the copy gives up after 10 attempts when the WAL restarts during each one (wal-copy-unstable).Every pre-update schema read funnels through one owner:
checkTargetDatabaseSchemasForContexts→preflightOpenClawDatabaseSchemas. Its callers:update-command-admit.ts), used by the CLI and byupdate.run, because the Gateway starts the same updater;update-command-database-context.ts);update-command-schema.ts);update-command-original-service.ts).Without artifact preservation, the owner already read a live store in place. With artifact preservation, it now does too. The activation baseline (
captureUpdateActivationSchemas→readUpdateStateSchemaVersions) does not preserve artifacts and already reads a complete WAL family in place (inspectSqliteSchemaHeaderInProcess), so it is unchanged.What the copy protected (89217d3): admission must not change any source byte. A plain read-only open can claim a WAL-index reader mark in
-shm, rebuild the index, or create-wal/-shmfor a closed store. That protection is real, and this change keeps it.Fix: the isolated schema reader opens a store with a complete WAL family (
-waland-shmpresent, WAL mode, no rollback journal) through SQLite's read-only shared-memory index (file:...?mode=ro&readonly_shm=1).SQLITE_READONLYresult), the store falls back to the existing private snapshot. On main, that path also has fix: let updates proceed while a busy agent database keeps writing #201327's online-backup fallback.Warning text: the per-database capture warning now reads "Database write generation changed or could not be confirmed during capture (the running Gateway may have written to it); automatic rollback keeps the live database instead of this snapshot: ". That is what happens: automatic restoration is turned off for that capture, and the live database is kept. It no longer claims manual recovery is needed. One sentence covers both cases, so the change cherry-picks to the release line with no code differences.
No new config key, stored field, schema, protocol, dependency, retention or permission.
Relation to #201463: independent, and in other files. Once both land, #201463's post-activation reader can use this read-only-index path for live stores. Neither PR needs that unification.
Update behavior for published updaters
openclaw update admit), and the installed updater skips revalidating any context the candidate covered. So a published2026.11.5updater reads schemas through this code once the target release contains it. Proven end to end below: installed published2026.11.5, candidatev2026.11.5plus this commit, busy writer, update succeeded.2026.11.5: the installed updater's best-effort original-state capture still cannot copy a busy store. Its existing warning says the update continues without the capture, and that rollback uses the pre-migration snapshots taken after the Gateway stops. The update completes. That capture is a real backup taken by the installed updater, which cannot be patched, so this PR does not change it.update.runreply saysskipped, with a Doctor hint, when the run actually failed;Evidence
Owner level (
src/state/openclaw-database-preflight.artifacts.test.ts; real child-process owners and real WAL files):admits a live agent store's schema without a stable copy while it keeps checkpointing. Setup: a 32 MiB store whose owner process commits 128 KiB batches with SQLite's default auto-checkpoint. Admission must report the store's newer schema and make no private copy of it, and the owner must keep committing across the check.v2026.11.5here (before fix: let updates proceed while a busy agent database keeps writing #201327): a copy is made. An earlier version of this test also failed withwal-copy-unstablein 3 of 3 runs on an idle host.refuses a newer schema committed only to an open WAL without changing a source byte. Setup: the owner holds the WAL open after committing a neweruser_versiononly to the WAL. Admission must refuse it, and every byte of the main file,-waland-shmmust stay the same, with no reader-mark masking. Base passes through the copy and fails only the no-copy assertion. Head passes through the read-only index. This guards what the copy protected.update-command-admit.test.ts, from 89217d3).Cost of the admission schema check on one host, measured with the same script on both builds (script not committed; one run each). Setup: a 512 MiB agent store, writer at 8 MiB/s with default auto-checkpoint.
End to end (installed package, real Gateway, real
openclaw update --yes --json):scripts/e2e/update-matrix-docker.sh(branchtest/update-matrix-e2e). It uses a bare E2E image with a systemd-shim user service, and a loopback fixture registry that serves the candidate relabeled2026.11.6.2026.11.5database-schema-preflight(wal-copy-unstable); repeat refuses the same wayupdate.run(update matrix)2026.11.5database-schema-preflight2026.11.52026.11.5relabeled2026.11.5v2026.11.5+ this commitsucceeded, Gateway serves2026.11.6, repeatalready-currentThe copy race depends on timing: on this host, two of the three red runs refused and the counterpart passed. So the deterministic proof sits at the owner level (whether a copy is made). The end-to-end green shows that the release-line package updates a published
2026.11.5install under load. The Gateway downtime and peak disk in these cells come from the package swap, Doctor and the installed updater's own captures, which this PR does not change. The idle baseline from the update matrix is 233 s in the updater, with one 108 s outage.Recordings of the owner test (RED: base production code with the PR test; GREEN: PR head):
RED, base 3eee09d:
owner-red.mp4
GREEN, PR head:
owner-green.mp4
Full raw logs are not attached because the artifact store rejected uploads from this machine (
crabbox artifacts publishreturned http 401). Decisive excerpts:RED: update result (published 2026.11.5 updater, candidate main b400e8d)
GREEN: update result (published 2026.11.5 updater, candidate v2026.11.5 + this commit)
The revised capture warning comes from the backup owner.
update-database-backup.test.tsasserts its exact rendered text, and three engine tests assert it for the write case and the unavailable-generation case. The cells cannot show it, because the installed2026.11.5updater prints its own copy of the warning.CI on head f443ea8: two failing shards, both inherited and unrelated to this diff.
checks-node-changedfails ontest/gateway-restart-handoff.e2e.test.ts(a sessionresumeAfterRestartentry shape, from restart-resume code this diff does not touch; the test is Linux-only and could not be run locally).checks-node-changed-compact-large-30-1hangs onsrc/config/sessions/session-accessor.sqlite-reclamation-wal.test.ts(reclaim); it also hangs locally for 300 s with this PR's production files reverted to main.Checks run on head:
update-candidate-state.result.test.tscases that fail withENAMETOOLONGon this macOS host; they fail the same way on the base.tsgo:core,tsgo:core:test, oxlint on the touched files,check:baseline-ratchets, andgit diff --check.autoreviewdoes not run on this machine.Not proven:
2026.11.5update check asks public npm, and the stable channel waits 6 hours plus jitter.Independent review findings and resolutions
SQLITE_CANTOPEN(found by the landing review: 60 to 65 of 400 reads in a close-race probe, plus 2 in a long stress run; never a wrong, torn or stale version). Before the fix, that throw escaped the read's handler, so the preflight refused with "could not inspect agent database". Fixed: under artifact preservation,SQLITE_CANTOPENnow returns no result, and the store goes to the private snapshot path. That path rereads the closed store, which has no live writer, and reports any lasting open failure itself, so a fallback can never admit on its own. No other open error is converted. Regression:falls back to the private snapshot when the last owner closes during a preserving readruns 300 reads against an owner that opens, commits and closes as the last connection. It failed 3 of 3 runs before the fix (unable to open database file) and passed 3 of 3 after; the probe went from 60 errors in 400 reads to 0 (233 in-place reads, 167 snapshot fallbacks), with no sidecar left behind.SQLITE_READONLYfallback. Not added: SQLite returns that code only when it cannot use a read-only index, and that cannot be forced on SQLite 3.54 without mocking the native layer. The fallback is the existing snapshot path, which is covered.ClawSweeper (one local round): overall D, proof D, patch C, "patch is correct".
sqlite-checkpoint-writer.test-support.ts. Rejected: that helper arrived with fix: let updates proceed while a busy agent database keeps writing #201327 and does not exist atv2026.11.5, so the test would not cherry-pick. As it also asked, the owner fixture now checks that the owner kept committing across the check, and the idle case uses a small fixture.Cherry-pick for the release line
fix(update): read live agent schemas without a stable copy,test(update): check live-owner progress across admission and shrink the idle fixtureandfix(update): fall back to the snapshot when the last owner closes during a preserving read.v2026.11.5(e13cf15).git cherry-pick -nof the fix commit gives three mechanical textual conflicts:src/state/openclaw-database-preflight.ts: the tag also reads cleanly closed runtime stores natively. Take the PR's block, and keep that path non-preserving by adding&& !(purpose === "runtime" && readSqliteDatabaseCleanClose(realAgentPath))to thepreserveSourceArtifactsexpression.src/infra/sqlite-readonly-inspection.ts: comment wording only. Take the PR'spreserve/closedWal/early-return block, and keep the PR'stry/catcharound the finalwithSqliteSourceReadDatabasecall, together with theisSqliteCantOpenErrorhelper (the close-race fallback).src/infra/update-database-backup.test.ts: the PR's surrounding test does not exist at the tag. Keep the tag's side, and update the tag's one existing assertion of the old warning text to the new sentence.fix(update): fall back to the snapshot when the last owner closes during a preserving read) cherry-picks cleanly on top of the resolved pick at the tag. I did not rerun the tests at the tag for it: the machine is being kept quiet.tsgo:corepasses, and 292 focused tests pass at the tag: the preflight artifacts and main suites, schema-inspection worker, node-sqlite, backup, backup engine, status, candidate admission and schema preflight. The package built from the tag plus the pick is the GREEN cell above.07baab52b41) by itself also removes the refusal. Its cherry-pick ontov2026.11.5has one conflict insrc/infra/sqlite-readonly-location.ts: take the incoming side, which adds theLIVE_WRITER_CHANGESset and the async online-backup fallback. After that,tsgo:corepasses and its ownsqlite-readonly-location.test.tspasses there (26 passed, 1 skipped). Its Docker cell (installed published2026.11.5, candidatev2026.11.5+ fix: let updates proceed while a busy agent database keeps writing #201327, same load) exits 0 and the Gateway serves2026.11.6: 224 s wall, one 93 s outage, peak extra disk 3.7 GiB. It still copies the live store during admission, which is the cost in the table above. The two commits compose: this PR reads live WAL stores in place, and fix: let updates proceed while a busy agent database keeps writing #201327's fallback covers whatever still takes the copy path.Landing follow-up
aaf5c777a45reads the open failure code throughsqlitePrimaryResultCode(src/infra/sqlite-error-diagnostics.ts) instead of a type assertion, which theassertion-safetyratchet rejected on712b9684bf7. Behavior is unchanged: on that head the assertion-safety ratchet passes,openclaw-database-preflight.artifacts.test.tspasses (9/9, including the close-race fallback test), and a 400-read open/commit/close probe returns no errors (180 in place, 220 via the snapshot).