Repository navigation
perf(sqlite): reuse database validation after clean shutdown - #169649
Conversation
|
🦞👀 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. |
|
Codex review: blocked before merge. What this changesThis PR persists file-bound validation seals so clean Gateway restarts can reuse completed SQLite checks. Example: Restart six unchanged synthetic databases totaling about 1.01 GiB.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep this owner-directed performance PR open: it provides distinct restart optimization absent from main, and no concrete introduced code defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherPhysical database admission supplies shared validation facts to Gateway startup and workers; native-close owners persist eligible facts, and writers invalidate seals before mutation. flowchart TD
A[Gateway startup] --> B[Physical database admission]
C[Database and seal] --> B
B --> D[Shared validation facts]
B --> E[Full validation on miss]
E --> D
D --> F[Database workers]
F --> G[Checkpoint and native close]
G --> C
Technical reviewBest possible solution: Keep restart reuse in the existing physical admission owner while preserving independent maintenance, quarantine, and live write-authority checks. Do we have a high-confidence way to reproduce the issue? Current-main source retains repeated restart validation, and the supplied shipped-Gateway comparison exercises the avoided work; this read-only review performed no independent runtime reproduction. Is this the best way to solve the issue? Extending physical admission and removing superseded receipt and deferral paths is coherent, with the changed failure model explicitly recorded by the feature owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 001e13bc4f7d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
LabelsLabel changes: No label 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 HistoryReview history (8 earlier review cycles)
Reviewed October 12, 2026, 11:46 PM ET / October 13, 2026, 03:46 UTC (Revision 9). |
70cb7fd to
96dd98d
Compare
1fca91c to
b869cdc
Compare
dff0701 to
398b25e
Compare
398b25e to
f785e84
Compare
c8933dc to
524c1f8
Compare
|
Landed as CI run The final controlled synthetic benchmark measured readiness at 12.9406 → 11.3794 seconds and child CPU at 52.137376 → 40.989323 seconds, with startup inspections/integrity checks 5 → 0. This is one controlled pair; the 6.5-second target was missed. |
The raw-corruption fixture kept the successful admission and clean-close seal introduced by f787a89 (#169649). Revoke those facts before changing the schema marker, matching the neighboring corruption fixtures. Keep both schema rejection and database-byte preservation assertions. Production admission behavior is unchanged. Diagnosed in scheduled main run 38423359339, compact-small19.
…w#169649) * perf(sqlite): reuse clean-close validation from adjacent seals Publish checksummed file seals after TRUNCATE and native close. Restore physical admission facts once, revoke before writes, and retain explicit host refusals across worker handoff. Remove quarantine-backed runtime receipts and deferred admission while preserving the released quarantine schema. * refactor(sqlite): separate seal persistence and native close lifecycle * fix(sqlite): seal cached state after final lease release * fix(sqlite): bind reused integrity proof to the opened file * test(sqlite): use the exported restart seal identity * fix(state): preserve sealed reads and revoked worker admission * docs(sqlite): align seal recovery with native update ownership * fix(qa): use the SDK record coercion boundary * test(sqlite): isolate Bun cache from ownership snapshots * test(sessions): exercise cold worker revocation and retirement * fix(sqlite): preserve seals across final metadata retirement * fix(sqlite): align seal reuse with worker startup and native close Share commit-bound seal fingerprints across source and compiled workers. Preserve healthy delegated close publication, await requester startup before restored delivery claims, and update the affected ownership fixtures. * fix(sqlite): preserve clean-close proof through owner handoffs * refactor(sqlite): share admission lookup and seal disposal state * fix(sqlite): check file generation before reusing startup seals * fix(sqlite): retain current validation facts during readonly adoption * fix(sqlite): preserve canonical revocation in clean-close seals * test(qa): keep native settlement fixture unchanged * test(state): make cold seal admission fixtures explicit * refactor(sqlite): tidy execution authority rebase * test(sqlite): invalidate raw fixtures and await owner cleanup * test(sqlite): join cleanup before removing fixture state * test(sqlite): assert seals in native close checkpoint cases * test(sqlite): align idle and drain assertions with clean seals * test(sqlite): retire owners before raw fixture mutation
The raw-corruption fixture kept the successful admission and clean-close seal introduced by 2cb03c2 (openclaw#169649). Revoke those facts before changing the schema marker, matching the neighboring corruption fixtures. Keep both schema rejection and database-byte preservation assertions. Production admission behavior is unchanged. Diagnosed in scheduled main run 38423359339, compact-small19.
What Problem This Solves
Clean Gateway restarts repeat database snapshot, readiness, schema, and integrity inspection after the previous owner cleanly closed unchanged files.
User Impact
A matching clean-close seal reuses completed validation at startup. Missing, torn, stale, or nonmatching seals retain full validation. Doctor and explicit verification keep their checks. No configuration option, database schema migration, or operator action is required.
Why This Change Was Made
Database admission owns a small checksummed
<database>.sealfile. A successful TRUNCATE checkpoint and native close publish only completed validation facts; the first subsequent write unlinks the seal. Reuse requires matching device, inode, stable birthtime, size, nanosecond mtime, empty journals, schema/version and loaded-commit identity, and a full verification no more than seven days old. Clean close and worker adoption never advance that timestamp.The same lifecycle covers cached shared-state release, disposable startup-checkpoint connections, native close and lease cleanup. Retaining the admission generation through final-reference retirement prevents an idle close from creating a successor generation that permanently caches a miss. Worker handoffs carry current revocation and physical-file identity. Source and compiled workers use the loaded commit in the fingerprint, so equivalent builds can share proof; build ID remains the conservative fallback without commit provenance.
Restored requester wakes join their known agent's startup preparation before reading or reserving delivery, then recheck source and abort authority. Canonical invalidation republishes current receipts only when the owner already holds physical integrity proof; a canonical-only handoff cannot acquire integrity admission. These cutovers replace the former quarantine-backed runtime receipts and deferred unverified-admission path.
Doctor, migration, repair, backup, restore, and deployment/update owners retain their checks. Replaced or restored files cannot reuse predecessor seals. Both database reference pages document the ownership and maintenance behavior.
A plain seal write is sufficient: torn writes fail parsing/checksum; a database write surviving a lost unlink changes metadata or leaves WAL. If both unlink and writes are lost, the database remains at the sealed state. Silent corruption preserving all checked metadata is the accepted limit, caught by normal access or periodic full verification.
Evidence
Current head is
524c1f8299da6321242512e1a46f281f6b80c4c5, rebased onto6dbbb5925efd24e61d7b44637afc12f79eb0ace2to resolve a concrete conflict after main independently landed the same reader-order fixture repair. All 25 lane commits remain; production patches are preserved and the final conflict resolution changes one explanatory comment. Fresh reclamation proof passes 17/17 (245.32 s wall), with scoped format and diff checks passing. Independent production and fixture reviews are clean through P2; the mechanical rebase retains their reviewed patches.Exact-head CI run
38379496638, attempt 1, completed: 133 successful jobs, 20 skipped, eight failed test jobs plus the aggregate. Actual tested mergec80bfd525794f8a2db98a5d66d4c982f88a517fahas ordered parents main04c459451a8b10074ddcae554a09e23e1c570a45and the PR head. Retained checkout logs, Git objects and independently derived merge tree agree. Every failed log was fetched once. All failed jobs are independently attributed to inherited defects or deadlines; failed CI is not claimed green.[null, "SIGKILL"]rather than[0, null]at the same exit assertion.38378024699, job115231440064, reproduces all four missingassistant.stopReasonassertions at line 218. Test and projection blobs match actual CI main and tested merge.mainRestartRecoveryon both revisions—the same missing field as CI line 373. No assertion or production code was changed; original files were restored. This does not establish a clean exit or successor recovery in the sandbox.The hook and handoff cases share one failed job. The aggregate fails only the group containing these eight root jobs; security and every other selected group pass. The native inherited-failure packet binds all jobs, source inputs and hashed evidence to the exact head and tested merge. Upstream-fixed membership and older failures that no longer recur are not carried as exceptions.
The three requested files ran individually on both exact revisions in the authorized isolated Linux sandbox. Node 24.19.0 and pnpm 12.9.0 were used, with CPUs 64–127 and 64 GiB memory limit, low CPU/I/O priority and synthetic state only. Frozen installs pass in 3.342 / 3.361 s; canonical private-QA runtime preparation passes in approximately 75 s each. Runtime artifact hashes and clean tracked checkouts are preserved. No Testbox/Crabbox lease or CI rerun was used.
Focused tests and review
pnpm test src/state/openclaw-agent-db.integrity-lease.test.ts --maxWorkers=1after correcting the assertionsThe initial four-file run had four failures, all from the three remaining calls to the removed test helper. Those failures were fixed, not classified as inherited. The other three files completed successfully and were not rerun without a changed input.
Final CI fixture repairs: idle-reopen reproduced its obsolete one-catalog-scan assertion locally (10 pass / 1 fail, 112.943 s), while unchanged base passed all 11. The corrected file asserts a valid seal after idle close and zero validation SQL on reopening: 11 passed, 124.765 s. The reclamation fixture now checks joined native retirement and its clean seal before admitting its extra retained reader; the deleted-row assertion is preserved. It passes all 17 cases in 299.41 s. The original reclamation file also passed locally, so the precise CI timing cause remains unverified; this is a bounded fixture-order correction, not a claimed deterministic product fix. Focused format/lint and independent review of both corrections pass through P2.
The final raw-database fixture repair awaits owner retirement and revokes the exact database admission before each external schema mutation. All existing assertions remain: 25 passed in 226.51 s (Vitest 182.94 s), with format, focused lint, and independent review clean through P2. Both original candidate and unchanged base passed locally, so the precise CI timing was not reproduced; the change repairs the fixture's invalid lifecycle instead of weakening its assertion.
Final-head restart measurement
One matched no-seal/clean-hit pair on the isolated Linux rig used exact pushed head
524c1f8299da6321242512e1a46f281f6b80c4c5, six synthetic databases totaling 1,086,480,384 bytes (1.01 GiB), and the same ten-second post-ready observation and joined clean shutdown. Canonical schema/version contracts were unchanged from the already-warmed v22 fixture, so no additional migration warm-up was needed. Frozen install passed in 3 s, canonical CLI preparation in 95 s, and the measured pair in 46 s.This pair saved 1,561.2 ms / 12.06% to ready and 11.148 s / 21.38% of child CPU. It misses the estimated 6.5-second boot reduction. This is one controlled pair, not a statistical estimate or pure attribution of all CPU savings. Earlier pairs varied in wall savings (the e2c pair was only 0.22% faster to ready while using 18.98% less CPU), so this is not a stable wall-time guarantee. Phase durations overlap and must not be summed.
Both children ran
pnpm openclaw gateway run --bind loopback --port 19578 --tailscale offwith task-owned synthetic state and TMPDIR, and exited 0. All six seals were valid after close; full-verification timestamps stayed unchanged on the hit. No post-ready verifier was observed. Runtime artifact SHA256, size and nanosecond mtime were preserved, the instrumented driver was restored, and the rig has no owned runtime processes. Earlier lifecycle proof covers kill-9 restart, torn seal, external modification, schema-identity change and stale interval. Production services and data were untouched.Linux failure attribution and historical CI
Fresh exact-revision Linux controls compare
e2c5937with unchanged basec146b99c. The two test files are byte-identical between them:src/gateway/gateway-auth-recovery.test.tsGatewayStateOwnerContentionErrorat credential replacement, line 286: the fixture writes credentials outside the running Gateway ownertest/gateway-session-end-shutdown.e2e.test.ts[null, "SIGKILL"]instead of[0, null]after SIGTERM during the synthetic session-end hookThese controls establish inherited failures on the cited revisions, not passing tests. They used Node 24.19.0, pnpm 12.9.0, CPUs 64–127 and a 64 GiB limit in an explicitly authorized isolated Linux sandbox. Frozen install passed in 5.490/5.511 s; canonical private-QA runtime preparation passed in 126.455/124.614 s. A disposable network-isolated container prepared the runtimes; tests ran directly on the host with
OPENCLAW_E2E_USE_PREBUILT_DIST=1, CI portable compile-cache settings and an 8 GiB Node heap. Exact head/tree, clean tracked checkout, and runtime artifact hashes were preserved; final scope was inactive and runtimes idle. No Testbox/Crabbox lease was used.Production-size exception: the requested non-test/non-doc filter is +239 lines (1,113 added / 874 deleted); runtime source excluding test support is +132. The seal codec, worker physical-identity custody, and repair/restore invalidation preserve the required integrity contracts. The old receipt store and deferred-unverified path are removed; one admission lifecycle owns reuse and invalidation.