Repository navigation
perf(state): defer integrity scans after proven process crashes - #164846
Conversation
Admit same-boot Linux WAL stores after an admitted lease owner dies, using header, journal and schema checks before the existing background verifier runs full integrity and foreign-key checks. Keep unknown provenance and interrupted mandatory admission on the full foreground gate. Bind provenance to host, boot, PID namespace, version and physical file; publish completed admission separately from clean-close certification. Use non-backfilling WAL observation, retain confirmation child custody, and ignore empty-WAL metadata churn during generation confirmation. Preserve quarantine and write refusal on confirmed damage. No schema or configuration migration is required; advisory success remains distinct from a writer-owned clean-close receipt.
|
🦞👀 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. Reviewed October 4, 2026, 9:33 AM ET / 13:33 UTC (Revision 8). ClawSweeper reviewWhat this changesThe PR lets narrowly verified Linux crash restarts resume agent database operations before a background integrity scan, while preserving conservative admission and corruption quarantine. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 3 items remain This remains useful work beyond current main, with sufficient native recovery evidence and no concrete introduced correctness finding. The prior corruption-recovery acceptance blocker remains unresolved. Priority: P2 Review scores
Verification
How this fits togetherAgent databases store OpenClaw sessions and transcripts. Their admission owner checks ownership and consistency before native workers serve operations; background verification can subsequently revoke access and quarantine damaged files. flowchart TD
A[Agent database restart] --> B[Lease and file provenance]
B --> C{Eligible process crash?}
C -->|No| D[Full admission scan]
C -->|Yes| E[Header and schema checks]
D --> F[Session operations]
E --> F
E --> G[Background full verification]
G -->|Confirmed damage| H[Drain actors and quarantine]
Decision needed
Why: The implementation and proof support the intended behavior, but repository policy reserves schema and corruption-recovery contract acceptance for a recorded maintainer decision. Before merge
Agent review detailsSecurityNone. PR surfaceSource +245, Tests +467, Docs +48, Other +1. Total +761 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one native admission owner with conservative fallback and generation-bound quarantine, under explicitly accepted recovery and lease-schema contracts. Do we have a high-confidence way to reproduce the issue? Not applicable as an existing-behavior bug reproduction: this is a performance proposal, and the captured native SIGKILL evidence demonstrates the changed recovery path. Is this the best way to solve the issue? Yes, conditionally: extending the existing admission and verifier owners is coherent, and the latest repair preserves established identifiers and legacy-state admission. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 306da58672fd. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
Restore UUID lease IDs and persist the process binding in the nullable, first-use agent_database_leases.provenance column. Legacy leases keep the full integrity gate, and admission revalidates the prepared file binding. Move header and WAL admission PRAGMAs into the existing SQLite integrity owner without adding an allowlist exception. Preserve the transcript reconciliation identifier assertions. Cover legacy-row preservation, additive-schema rollback, and independent UUID and provenance checks in the native crash regression. Keep pre-migration maintenance compatible with published lease tables that lack provenance, while retaining present-column drift checks. Name snapshot fixture columns so optional additions preserve its lease data.
…claw#164846) * perf(state): defer integrity scans after proven process crashes Admit same-boot Linux WAL stores after an admitted lease owner dies, using header, journal and schema checks before the existing background verifier runs full integrity and foreign-key checks. Keep unknown provenance and interrupted mandatory admission on the full foreground gate. Bind provenance to host, boot, PID namespace, version and physical file; publish completed admission separately from clean-close certification. Use non-backfilling WAL observation, retain confirmation child custody, and ignore empty-WAL metadata churn during generation confirmation. Preserve quarantine and write refusal on confirmed damage. No schema or configuration migration is required; advisory success remains distinct from a writer-owned clean-close receipt. * test(doctor): complete active agent lease fixture * fix(state): keep lease identifiers separate from crash provenance Restore UUID lease IDs and persist the process binding in the nullable, first-use agent_database_leases.provenance column. Legacy leases keep the full integrity gate, and admission revalidates the prepared file binding. Move header and WAL admission PRAGMAs into the existing SQLite integrity owner without adding an allowlist exception. Preserve the transcript reconciliation identifier assertions. Cover legacy-row preservation, additive-schema rollback, and independent UUID and provenance checks in the native crash regression. Keep pre-migration maintenance compatible with published lease tables that lack provenance, while retaining present-column drift checks. Name snapshot fixture columns so optional additions preserve its lease data.
What Problem This Solves
After an unclean process restart, agent sessions can wait minutes for a full-file integrity scan even when SQLite can recover the intact WAL normally. Related: #164670.
User Impact
A proven same-boot Linux process crash admits native agent workers after header, journal, ownership, and schema checks, while the existing background verifier performs the full integrity and foreign-key check. Unknown or foreign provenance, PID reuse, dirty receipts alone, migrations, older SQLite without non-backfilling WAL observation, and other openers retain the full gate.
This deliberately relies on SQLite WAL crash recovery for a narrowly classified process death. Unrelated storage damage can be discovered after admission. Confirmed damage drains existing actors, reconfirms the file, persists quarantine, and refuses retained actors and new opens.
Why This Change Was Made
The lease owner records host, boot, PID namespace, application version, and physical-file provenance. A lease stays
opened_at=0until admission succeeds, so killing an opener during a mandatory full scan cannot turn that unfinished scan into a deferred restart. The existing verifier queue supports quick/full requests, with full requests taking precedence; its checking and confirmation children share shutdown ownership.The repair preserves UUID lease IDs and stores the versioned binding separately in nullable
agent_database_leases.provenance, to preserve the existing identifier contract. The existing first-use additive-schema owner creates the column without a schema-version bump. Legacy rows receive NULL and retain full admission; older readers accept the compatible nullable column. Stopped-writer maintenance accepts the missing column before migration, through its exact schema-compatibility contract, without altering the old schema. Present-column drift and every other mismatch still fail admission. Cleanup deletes provenance with its owning lease. No configuration option, new store, or identifier compatibility shim is added.Admission PRAGMAs now live in the existing sanctioned
sqlite-integrity.tsowner. The provenance module has no raw SQLite access; no allowlist expansion or suppression was added. Admission retains version-qualifiedwal_checkpoint(NOOP)through the shared WAL observer. PASSIVE was rejected by measurement because it synchronously backfills pages.Empty and absent WALs are equivalent when confirming corruption: native readers can create or retouch an empty sidecar themselves. The main file, nonempty WAL, and rollback journal keep exact generation checks. Advisory success does not mint a writer-owned clean-close certificate; without separately established durable verification, a later graceful restart can still require a full gate.
Evidence
Measurement
Prior rig evidence, before this identifier/storage repair: Linux, 1,100,000 synthetic events, a 5,112,291,328-byte main database, and SIGKILL of the admitted owner during an open write transaction.
These measure native worker admission/session operations, not full Gateway/WebSocket readiness. The baseline was cold/contended with a small WAL; the final cell had a large WAL and different cache/load conditions. A warm baseline scan took 3.327 s. The architectural result is removal of the foreground scan, not a universal speedup ratio. An initial large-WAL cell had 1,622,254,152 WAL bytes; the final replay observed 1,399,782,392 bytes before remaining writes finished, so its exact final WAL size is unobserved.
The previous rig also proved full-gate corruption refusal and deferred corruption quarantine at +46.406 s, after which a retained actor and fresh open refused work. The corrected generation comparator changed a native empty-WAL corruption reproducer from inconclusive to confirmed terminal failure. All rig state was synthetic and its worktrees were removed.
Repair validation
Repair validation runs on Blacksmith Testbox (
blacksmith-testbox, profileopenclaw-check, Node 24.19.0, SQLite 3.53.3), leasetbx_01m43bhf84mftd158zh8s5pge5, based on59c5b0b9a5d6c2a7a4b8431a13d50c528605474dplus repair commit0892bfd85d6f4aa7bae99872b1ec1012f49d9569, final tree3eeeb0848ab9852c24497142d4b67aa71ae0d62a. Source hashes, physical checkout, HEAD, and the staged Git tree were verified remotely.CI run 37198741596 provided the original failure: 11 UUID-shape assertions in
session-transcript-reconcile.lifecycle.test.tsandsession-transcript-reconcile.lease.test.ts, plus three raw-SQL architecture diagnostics. Both transcript test files remain unchanged. The crash regression now independently checks UUID keys and provenance-column bindings. A new additive-schema test checks legacy-row preservation, NULL provenance, unchanged user_version, and rollback/retry.The original validation reported 210 tests across 13 focused files on lease
tbx_01m42yr00v8zqpdhwddx6an46r(workflow); its published evidence did not retain the exact 13 filenames. The repair reruns all changed runtime test files and relevant lease/WAL/preflight/schema siblings, with exact commands and counts recorded below.334 distinct tests passed, with one existing case-insensitive-filesystem case skipped on Linux. The 75 tests affected by the physical-file helper move passed again, and the final native/maintenance standalone replay passed another 41 tests. Independent review of the complete repair, including upgrade compatibility, is scoped-clean through P2.
The new schema regression fails against the original owner, then passes after restoring candidate bytes. It takes 2 ms; its full file takes 19.23 s wall and 357 ms test work, mostly spending wall time on worker compilation. The final native crash case takes 6.293 s, reusing one killed child across eight cases without adding a process or timer. It verifies UUID keys, separate provenance, conservative refusal cases, and no foreground scan/backfill on the supported SQLite version.
The upgrade repair also has failing-before/passing-after proof. Snapshot fixtures originally fail in both DELETE and WAL modes because seven columns receive six positional values. Existing-schema maintenance originally rejects a published lease table missing provenance. The corrected snapshot cases take 1.542/1.493 s; current/old-table maintenance takes 430/433 ms, proving actual ownership acquisition/release preserves the schema and version.
Exact commands and validation recovery notes
Exact focused commands (all on the lease above):
An initial staged gate found 709 counted lease-module lines against a 700-line cap. Moving the existing physical-file comparison into the provenance owner resolved it without suppression or a new module. The first complete gate reported only two size warnings in unchanged Gateway files.
The first staged-gate attempt stopped before validation because serialized Git diff hashes differed despite matching file bytes. Verifying the complete staged Git tree established identical source and allowed the gate to proceed; no source or check was bypassed. A diagnostic command also exited 1 because optional
core.abbrevwas unset; it ran no tests. Testbox portal indexing occasionally timed out after successful payloads; the command receipts retained exit 0.The known quarantine-test defect is tracked separately; it was not present in the captured failure log for run 37198741596, and its focused replay passed here without a repair. A passing replay does not establish a fix. The first Testbox workflow was cancelled after 65 minutes during the final-source gate, ending SSH with exit 255 and no compiler/test failure. Architecture, core types, and 21 of 27 test type graphs passed on that final tree. Replacement lease
tbx_01m43fexnyrpce08277v3j6136(workflow) completed the final architecture and staged gates successfully against tree3eeeb0848ab9852c24497142d4b67aa71ae0d62a. Exact-head CI passed: run 37205606069 on0892bfd85d6f4aa7bae99872b1ec1012f49d9569, including the architecture check, all selected Node and Windows shards, and the published-driver-to-candidate update. The published-driver job completed successfully in 10m59s. The 5.1 GB measurement was not repeated for this repair.The repair adds 23 production lines to separate stable identifiers from provenance and preserve maintenance admission for published tables missing that field. It deletes the provenance-bearing ID constructor and moves, rather than duplicates, the integrity primitive. The full PR retains the original growth required for crash provenance, deferred-check selection, and owned off-thread failure confirmation; the exclusion-based full-PR count is 387 additions / 141 deletions, net +246 lines (production TypeScript +244, plus one SQL line and one wrapper inventory entry).
Both task-owned Testbox leases have been stopped. No tests, typechecks, or builds ran on the Mac. No live Gateway or deployment is touched.