Skip to content

perf(sqlite): reuse clean-close proof across app versions - #176909

Merged
steipete merged 5 commits into
mainfrom
steipete/perf-micro-integrity-seal-version-binding-20260919
Oct 19, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/perf-micro-integrity-seal-version-binding-20260919

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A release-number-only upgrade discards clean-close integrity proof and scans every page of large agent databases again, even when their storage stack is unchanged.

User Impact

Compatible application upgrades reuse clean-close proof. SQLite/runtime changes, family schema changes, policy changes, unknown identity, malformed seals, and legacy app-version-bound seals still require full validation. Existing seals incur one full scan on the first upgrade to this policy. No database schema, retention, configuration, quarantine, or write-authority contract changes.

Why This Change Was Made

The old app version was a broad compatibility fence. The existing policy already requires a revision for code-only migrations, validation rules, or serialized facts. Bind that policy and the family SQL/schema version to the actual loaded SQLite version, source ID, compile options, and Node/Bun runtime versions instead. The native runtime owner collects the additional identity in its existing one-time in-memory probe, including shared-library builds; unknown identity disables seal reuse/publication.

The seven-day full-verification limit, physical file metadata, empty journals, additive-column prerequisites, and quarantine checks remain intact. The old version argument and artifact-version expectation are removed. Runtime production change is +52 lines across seven files: the growth records the actual storage contract and fails closed when it is unavailable. There is no additional cache layer or alternate admission path. Native library loading/probing now lives in a leaf module, so file admission can consume its identity without importing the file-opening adapter. The existing node-sqlite facade retains its public exports, backed by that single implementation.

Evidence

  • Regression was red before the fix: an app-version-only change produced a different seal identity. It now passes.
  • Focused identity/runtime/transcript/admission files: 100 tests pass. The admission tests observe real PRAGMA integrity_check execution for legacy, malformed, and unknown-policy seals. The identity tests cover SQLite and family schema/version changes and preserve unrelated-family reuse.
  • Targeted pnpm tsgo:core, changed-file oxfmt and lint pass. Export-name collision guard and both closure files pass (22 tests).
  • Independent Codex autoreview: clean at P0–P2 on the complete final branch, including the corrected test fixtures and shrink-only assertion baseline update. Broad and Linux Gateway restart proof belong to PR CI; no Testbox/Crabbox lease was allocated.
  • CI caught an import cycle in the first implementation and an overly broad test-fixture type. The repair extracts the native-runtime owner, narrows the fixture type, and updates the PR wrapper source inventory; all 100 focused application tests and 22 closure tests pass after the repair. A second static cycle through database types is removed by moving the unchanged version constants to the existing schema-version leaf; the native constructor registration and relocated assertion contracts are updated as well. The repair received a fresh clean P0–P2 review. The retired node-sqlite assertion allowance is removed; the actual checker reports zero undocumented assertions in both the file-opening adapter and native-runtime owner.
  • Additional repair proof: 6 seal-policy, 11 startup-admission, 22 closure, 2 native-version consistency, and 68 native SQLite tests pass. Updater test mocks now target the schema-version owner. Their local run was stopped when the test runner attempted a full build; those two files are left to PR CI under the local compute limit.
  • Test wall time: identity file 4.18 s; final admission file 24.68 s; runtime/transcript files passed in the focused infra run. Closure files 51.15 s combined. Broad proof is recorded in PR CI run 39202314802 for final head 05c51d63f6e6741fe481ed261faa9ef0368118af.

Measurement acceptance rule (recorded before A/B measurement)

Use the committed scripts/perf/seal-version-restart.ts with two separately generated synthetic agent databases of at least 2 GiB. In each checkout, fully verify/clean-close under app version 2026.10.4, change only package version to 2026.10.5, then measure the next cold-process owner open. Run two concurrent A/B pairs under the exclusive benchmark lock, swapping the 16-core CPU halves between pairs, and record outside CPU load. Seeding is sequential, paced, and stops at 2 GiB Linux Dirty memory; databases are never copied or vacuumed.

Acceptance: baseline performs one full scan per version-only bump; candidate performs zero and preserves the seal fast path. Compare paired candidate-minus-baseline gate and owner-open latency; no regression beyond noise. This measures the real database admission owner, not full Gateway readiness or cold OS page cache. Results (each database 2,169,942,016 bytes, Node 26.8.2, synthetic canonical-schema cache rows):

Concurrent pair Baseline gate / scans Candidate gate / scans Baseline admission Candidate admission Paired admission difference
1: A 96–111, B 112–127 7,520 ms / 1 no scan / 0 7,625.72 ms 31.93 ms −7,593.78 ms
2: A 112–127, B 96–111 7,818 ms / 1 no scan / 0 7,963.65 ms 38.44 ms −7,925.21 ms

The paired results meet the acceptance rule: every version-only baseline restart scans; neither candidate restart scans; admission improves in both pairs. Starts differed by 0 ms and 1 ms. Sampled CPU busy time across CPUs 96–127 was 5.62% and 6.10%; load/page-cache variation explains why absolute times are not a stable service-latency prediction. Two pairs establish the scan-removal result, not a latency distribution. Candidate seal lookup was 5.10 ms and 6.09 ms. These final pairs were repeated after the native-runtime extraction, using the original synthetic databases.

Seeding took 113.1 s and 117.0 s sequentially. Peak observed Dirty memory was 1,096,839,168 bytes, below the 2 GiB limit. No production data, database copies, or Gateway restarts were used. Measurement ran against base 049f5f9 with the final native-runtime and seal-identity implementation; the subsequent main rebases add no seal/schema/SQLite changes.

The first attempted pair stopped during reseal setup: deleting a seal intentionally retains process-local validation facts. The benchmark now uses the existing admission-revocation API for --refresh-proof; that one-line correction received a separate clean P0–P2 review. The reported pairs were rerun after the correction.

The isolated benchmark sandbox was removed after retaining its results.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 19, 2026 04:22
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts labels Oct 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T05:05:19.677501Z 05c51d6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete force-pushed the steipete/perf-micro-integrity-seal-version-binding-20260919 branch from 611dbd5 to 9478deb Compare October 19, 2026 04:27
@steipete
steipete force-pushed the steipete/perf-micro-integrity-seal-version-binding-20260919 branch 2 times, most recently from d464819 to 95eca36 Compare October 19, 2026 04:49
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Oct 19, 2026
Bind restart proof to the loaded SQLite build, Node/Bun runtime, family schema version and SQL, and explicit integrity policy instead of the app version. Legacy seals require one full verification; file, journal, expiry, quarantine, and write invalidation checks remain unchanged.
@steipete
steipete force-pushed the steipete/perf-micro-integrity-seal-version-binding-20260919 branch from 95eca36 to 05c51d6 Compare October 19, 2026 05:00
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@steipete
steipete merged commit b0055b6 into main Oct 19, 2026
170 checks passed
@steipete
steipete deleted the steipete/perf-micro-integrity-seal-version-binding-20260919 branch October 19, 2026 05:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…76909)

* perf(sqlite): reuse clean-close proof across app versions

Bind restart proof to the loaded SQLite build, Node/Bun runtime, family schema version and SQL, and explicit integrity policy instead of the app version. Legacy seals require one full verification; file, journal, expiry, quarantine, and write invalidation checks remain unchanged.

* fix(bench): revoke admitted facts when refreshing integrity proof

* fix(sqlite): separate native runtime from file admission

* fix(sqlite): keep seal schema versions dependency-free

* chore(sqlite): prune retired assertion allowance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. cli CLI command changes docs Improvements or additions to documentation scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant