Repository navigation
fix: avoid repeated agent database integrity scans - #146512
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. Reviewed September 12, 2026, 7:59 PM ET / 23:59 UTC (Revision 5). ClawSweeper reviewWhat this changesReuse successful agent-database integrity checks across connection reopens and cleanup workers, update regression coverage and documentation, and consolidate undersized Control UI startup bundles. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this remains useful work absent from current main, with convincing recorded runtime evidence and no blocking correctness finding. The previous blanket migration-proof blocker is unsupported by the actual diff; the integrity-policy tradeoff already has explicit maintainer acceptance. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s agent databases hold sessions, transcripts, and other agent state. Database admission prepares connections for session operations and cleanup workers while checking ownership, schema compatibility, and database health. flowchart TD
A[Session operations and cleanup] --> B[Database admission]
B --> C[Current ownership and schema checks]
C --> D{Reusable integrity verification?}
D -->|No or migration pending| E[Full integrity verification]
D -->|Yes| F[Admitted database operations]
E --> F
F --> G[Session results and preserved archives]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +137, Tests +233, Docs +18. Total +388 across 34 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep verification reuse in the existing database owner, with independent migration, maintenance, schema, and current-authority checks under the accepted detection policy. Do we have a high-confidence way to reproduce the issue? Yes: current-main physical writable reopens unconditionally reach full integrity verification, and the discussion supplies measured affected workloads. This review established the mechanism from source without executing it. Is this the best way to solve the issue? Yes: extending the existing validation owner avoids repeated full-file work without a competing cache or persistent format. The accepted same-file corruption detection window is explicit, and pending migrations retain full checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a0792d71e5b4. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
Maintainer decision: accept the documented longer detection window for same-file corruption after successful verification. Checking once per Gateway lifetime, including reuse across eviction and cleanup workers, is the explicitly requested behavior. First-use verification, fresh-process verification, replacement/disposal/quarantine invalidation, migrations, repair validation, and independent maintenance checks remain in place. The follow-up fixes lint issues and preserves deliberate cold-admission test coverage. The PR body now includes completed live restart and final-candidate evidence; 380 focused tests pass. No correctness finding remains from the review. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Reuse the first successful verification across physical reopens and admitted cleanup workers during the Gateway lifetime. Bind remembered health to the agent and physical database identity, share revocation with workers, and keep fresh ownership, schema, migration, repair, and quarantine checks. Related: #145909, #118885. Maintainer-requested verification policy; no persistent marker or durability change.
Explicitly invalidate verification only where fixtures exercise cold integrity admission, and retain ordinary close and revocation paths. Move the unchanged session-project schema probe to its migration owner, extract native scan instrumentation, and remove callback shadowing.
Settle the canonical validity projection for healthy raw fixture rows and invalidate verification only for tests that exercise first-scan admission. Preserve existing history protection, warm-parent, and refusal assertions.
Keep undersized measured boot tails with their consumers through automatic chunking. This removes inherited dependency-layout-sensitive startup overhead while preserving the generated boot manifest, route boundaries, maximum chunk sizes, and all compressed-size budgets.
4f71fa6 to
55e1d13
Compare
|
Merged via squash.
|
* fix: avoid repeated agent database integrity scans Reuse the first successful verification across physical reopens and admitted cleanup workers during the Gateway lifetime. Bind remembered health to the agent and physical database identity, share revocation with workers, and keep fresh ownership, schema, migration, repair, and quarantine checks. Related: openclaw#145909, openclaw#118885. Maintainer-requested verification policy; no persistent marker or durability change. * test: preserve cold admission coverage with remembered integrity Explicitly invalidate verification only where fixtures exercise cold integrity admission, and retain ordinary close and revocation paths. Move the unchanged session-project schema probe to its migration owner, extract native scan instrumentation, and remove callback shadowing. * test: complete fixtures before reusing database verification Settle the canonical validity projection for healthy raw fixture rows and invalidate verification only for tests that exercise first-scan admission. Preserve existing history protection, warm-parent, and refusal assertions. * build: coalesce tiny Control UI boot chunks Keep undersized measured boot tails with their consumers through automatic chunking. This removes inherited dependency-layout-sensitive startup overhead while preserving the generated boot manifest, route boundaries, maximum chunk sizes, and all compressed-size budgets.
|
Related follow-up #146597 has merged. This PR's ordinary runtime-open verification reuse and #146597's Doctor import-finalization optimization address complementary paths. The latter avoids redundant cleanup and a second full integrity/foreign-key check when an imported database is already in incremental auto-vacuum mode, has zero free pages, and has no WAL. Initial validation remains intact. This is a follow-up, not a replacement for this PR. |
Related: #145909, #118885.
What Problem This Solves
Large agent databases repeatedly stall session operations because every physical writable reopen performs a full SQLite integrity scan, including reopens after cache eviction and short-lived cleanup workers.
User Impact
Ordinary reopens now reuse the first successful integrity and foreign-key verification for the Gateway lifetime. A fresh Gateway process checks again. No configuration, database schema, persistent marker, retention, or durability setting changes.
This is the maintainer-requested policy: damage introduced into the same file after verification is detected by SQLite operations, the daily verifier, or explicit maintenance instead of a full scan on every reopen. Doctor, backup verification, migration checks, and repair validation remain intact.
Why This Change Was Made
Extend the existing validation owner with physical file identity and shared revocation. Reclamation and cold-storage workers borrow verified health under their existing live writer admission and return newly established proof only after cleanup. File replacement, disposal, registry invalidation, quarantine, and failed admission discard remembered health; current ownership, schema, and write authority are still checked independently.
CI also exposed an inherited Control UI build failure on unmodified main: dependency layout could split a tiny shared module into its own boot bundle. A two-line correction gives the existing measured boot groups a 16 KiB minimum so small tails stay with their consumers through automatic chunking. Maximum chunk sizes, generated manifests, route boundaries, and compressed-size budgets are unchanged.
Thanks to @najef1979-code for the detailed large-database report.
Evidence
442 focused storage and admission tests passed, with four existing skips, covering all open modes, eviction, first-open corruption and foreign keys, replacement, migrations, cancellation, reclamation, and cold storage.
New regressions fail on pre-fix main: repeated synchronous/admitted/async opens rescan; a second fresh reclamation worker performs a second native integrity check. The fixed worker regression observes one scan across two workers, then another after owner invalidation, with persisted survivors verified.
Real isolated Gateway before/after comparison on macOS with Node 24.21.0: 70 agents, including one healthy 316 MB database. Two 70-agent session RPC sweeps reduced full canonical integrity scans from 140 to zero after startup and elapsed time from 38.86 seconds to 9.21 seconds. Hundreds of physical opens still occurred. These are single-run synthetic workload timings, not a production latency guarantee.
Two real chat-inject/session-delete flows succeeded and preserved their archived transcripts. Fresh cleanup workers added one full scan each before the fix and zero afterward.
A fresh Gateway process against the same completed-migration state checked all 70 databases again, then performed zero checks during subsequent sweeps. Pending one-time migrations retain their own independent full verification.
The final production follow-up was rebuilt and live-tested: another 70-agent sweep and two transcript deletions added zero integrity checks; session/archive contents, all 300 payload hashes, and final full integrity/foreign-key checks passed.
Supported runtime builds, the full changed-code check, and targeted lint passed. Independent reviews found no actionable P0–P2 issues. Cold-admission fixtures explicitly clear remembered verification where they need to exercise scan cancellation and FIFO ordering.
The inherited UI failure was reproduced on unmodified main and with this PR, producing byte-identical artifacts. With the grouping correction, the normal production build passes at 354,912 startup gzip bytes against the unchanged 355,116-byte limit. Five chunking tests, the existing production startup-recovery E2E, and served-production
/newand/chatchecks pass; both routes report zero page errors and chat send/final rendering succeeds.Required CI passed on rebased head
55e1d13a7cb5302dbcbdf7e3b4446317c7c12374: https://github.com/openclaw/openclaw/actions/runs/34725497360. The clean rebase preserves all four patches and incorporates upstream fix: restore core test shard headroom #146538 to restore type-shard headroom without changing limits.