Skip to content

fix(state): avoid payload copies during online schema preflight - #171984

Merged
vincentkoc merged 2 commits into
mainfrom
fix/sqlite-preflight-payload-io-20261014
Oct 14, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/sqlite-preflight-payload-io-20261014

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes excessive database I/O during ordinary online schema preflight: shared-state inspection copied and compared the entire database before reading schema metadata.

User Impact

Routine online maintenance can inspect shared-state and agent schemas without copying their payloads. Explicit artifact-preserving admission, startup integrity checks, and migration refusals retain their existing guarantees. Online reads may update SQLite SHM read marks; they do not promise byte-identical sidecars.

Why This Change Was Made

Reuse the existing isolated native schema reader for explicit online shared-state inspection. The child keeps a coherent read transaction and closes before cleanup, preserving parent-process SQLite locks. Only the existing recovery/incomplete-WAL result selects snapshot fallback; read and close errors remain failures.

Production delta: +26 lines to extend the existing reader owner to shared state; tests: +78; documentation: +8. No schema or config change.

Evidence

  • 10 CLI update cleanup tests passed in original order after correcting the fixture to exercise real closed-WAL recovery. Cleanup failure, close ordering, cancellation and precedence assertions remain intact; DELETE/live-WAL cases prove no unrelated snapshot custody is acquired. Targeted format/lint and CLI-update test types passed.
  • 56 focused sibling tests passed, covering DELETE/WAL committed visibility, pending writes, schema/version refusals, artifact preservation, startup integrity/prepared custody, snapshot cleanup, and WAL copy recovery.
  • Independent source review and fresh exact-head P0–P2 autoreview cleared the final head with no actionable finding.
  • Targeted formatting/lint, core and state/logging test-shard type checks, and runtime build passed.
  • Runtime build and six-case I/O proof were reused with unchanged production, dependency and runtime inputs; the final correction is test-only.
  • Native Linux file-I/O proof passed on allocated, noncompressible 16/256 MiB payloads in both state and agent DBs, with committed WAL content. Fresh processes used the actual preflight, tracked across parent and children. Fixture creation and whole-file verification were outside measurement.
Path DB reads, 16 MiB fixture DB reads, 256 MiB fixture Staging writes, 16 / 256 MiB
Baseline, strict artifact preservation 71,631,088 B 1,080,475,888 B 35,844,256 / 540,266,656 B
Baseline, explicit online inspection 18,379,032 B 270,590,232 B 18,337,348 / 270,548,548 B
Repaired, explicit online inspection 200,984 B 200,984 B 0 / 0 B

The repaired cases each read another 8,192 B of WAL: 209,176 B total, unchanged across payload sizes. Both had zero staging reads, zero payload mappings, unchanged source DB/WAL hashes, and joined child lifecycles. The trace census covers native read/write/copy operations and distinguishes SHM/epoll metadata from payload. This is logical syscall I/O proof, not a claim that production latency is cured.

@vincentkoc vincentkoc self-assigned this Oct 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 14, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review October 14, 2026 08:46
@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 14, 2026
@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR extends the existing isolated schema reader to inspect shared-state metadata without copying database payloads during explicitly online preflight.

Example: Online schema preflight against the supplied 256 MiB SQLite fixtures.

  • Before: The reported baseline reads 270,590,232 database bytes and writes 270,548,548 staging bytes.
  • After: The reported repaired path reads 209,176 bytes including WAL and writes no staging payload.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and corrected fallback coverage are sound; supplied evidence remains production-owner harness evidence rather than a shipped-entry-point demonstration.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied native Linux measurements exercise actual preflight with real SQLite and show constant payload-independent I/O, while the final test-only correction leaves production unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Online schema preflight performs database-sized reads and staging writes even when only metadata is needed.
Reason: The maintainer-authored direction delivers measurable I/O reduction through an existing reader and preserves the documented strict paths.

Merge readiness

✅ Ready for maintainer review

This PR provides a useful performance fix that current main still lacks; the corrected cleanup fixture exercises real fallback, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 3088c14a98f654c10feb5d6e57554f405befb6f4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied measurements exercise the production preflight owner rather than the shipped update CLI, and a before-fix failure run for the newly added tests is not shown.
Agent review details

How this fits together

Update compatibility checks pass database paths and supported versions to the shared preflight owner, which returns schema, registry, and retained-deletion facts from isolated SQLite readers.

flowchart TD
  A[Update compatibility check] --> B[Database preflight owner]
  B --> C[Isolated schema reader]
  C --> D[Coherent SQLite transaction]
  B --> E[Private snapshot fallback]
  E --> C
  D --> F[Compatibility and discovery facts]
Loading

Technical review

Best possible solution:

Use the existing isolated reader for explicitly online shared-state checks while preserving snapshot, recovery, and admission ownership.

Do we have a high-confidence way to reproduce the issue?

Fetched main unconditionally prepares a shared-state snapshot when no admitted location exists, including explicit online inspection; supplied comparative I/O measurements support the source path, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch removes unnecessary copying at the existing owner, reuses coherent native reads, and retains strict artifact-preserving and recovery paths without adding configuration or persistence.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0602d851d3b5.

Provenance checked

  • Shared-state snapshot selection changes intended behavior with a stated reason (7632eb3: Bootstrap admission must consume its enclosing shared-state generation; subsequent changes preserve snapshot custody and cleanup failures.)
  • Isolated state inspection and contract transfer keeps the original intent (53fd3d8: Move schema, registry, and retained-deletion inspection off the Gateway thread while retaining snapshot identity and child settlement.)
  • Online artifact assertions changes intended behavior with a stated reason (cacc2a0: Online SQLite readers may update SHM read marks while preserving database and WAL contents; the PR explicitly extends that contract to shared state.)
  • Cleanup failure regression fixture keeps the original intent (a976c5c: Stop update admission when owned snapshot cleanup fails and retain the original inspection or cancellation error.)
  • Private inspection response keeps the original intent (e2689b0: Remove speculative bookkeeping while preserving actual integrity and lifecycle boundaries; nullable state results follow the existing source-reader fallback convention.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 53fd3d8 adds src/state/openclaw-database-preflight.ts:244 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 53fd3d8054c8; files: src/state/openclaw-database-preflight.ts)
  • Vito Cappello: Raw commit 0f74803 adds src/state/openclaw-database-preflight.ts:625 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0f748036332e; files: src/state/openclaw-database-preflight.ts)
  • Vincent Koc: Raw commit ccc84ac adds docs/reference/database-schemas/integrity-and-recovery.md:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ccc84ac86f2b; files: docs/reference/database-schemas/integrity-and-recovery.md)

PR surface

Source +26, Tests +78, Docs +8. Total +112 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 90 64 +26
Tests 4 80 2 +78
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 178 66 +112

Review metrics

Metric Value Why it matters
Production versus test LOC Production +90/-64; tests +80/-2 The net 26 production lines extend the existing reader, while test growth protects committed visibility, snapshot fallback cleanup, and online admission.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Payload-sized online preflight I/O is a concrete performance problem with a focused remedy and no demonstrated urgent outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-14T08:53:56.559Z sha 8dd8c5d :: needs maintainer review before merge. :: none

Reviewed October 14, 2026, 5:42 AM ET / 09:42 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Oct 14, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head 3088c14a98f654c10feb5d6e57554f405befb6f4. The update corrects the cleanup fixture to exercise real closed-WAL fallback and adds ordinary DELETE/live-WAL no-snapshot coverage. All 10 tests, targeted lint/format and CLI-update test types pass. Production blobs and prior measured I/O proof are unchanged.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc
vincentkoc enabled auto-merge (squash) October 14, 2026 09:46
@vincentkoc
vincentkoc merged commit e902bed into main Oct 14, 2026
136 checks passed
@vincentkoc
vincentkoc deleted the fix/sqlite-preflight-payload-io-20261014 branch October 14, 2026 10:05
steipete added a commit that referenced this pull request Oct 14, 2026
Online shared-state schema preflight now reads committed metadata in an
isolated native transaction instead of copying all payloads. The busy
writer fixture still expected its node:sqlite.backup preload to create a
counter file, so scheduled main failed with ENOENT after admission passed.

Remove that obsolete preload and copy-count expectation. Retain successful
caller/service admission, caller environment preservation, live writer
progress and final source database integrity checks.

Culprit: e902bed (#171984).
Natural failure: CI 38550286127 / job 115806476493.

Proof: https://github.com/openclaw/openclaw/actions/runs/38552665607
Job 115814133885 passed the single diagnosed case on Node 24.19.0
(1 passed, 13 skipped; case 985 ms, Vitest 62.06 s, test step 68 s,
whole job 143 s), plus changed-file oxfmt, oxlint and diff check.
The reviewed test blob was proven on current main 218baa9 as
source f2dcae3.
One Codex P2 review was scoped-clean. Test-only change: +7/-35.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…claw#171984)

* fix(state): inspect online schemas without copying database payloads

* test(update): exercise real schema snapshot fallback cleanup
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
Online shared-state schema preflight now reads committed metadata in an
isolated native transaction instead of copying all payloads. The busy
writer fixture still expected its node:sqlite.backup preload to create a
counter file, so scheduled main failed with ENOENT after admission passed.

Remove that obsolete preload and copy-count expectation. Retain successful
caller/service admission, caller environment preservation, live writer
progress and final source database integrity checks.

Culprit: 4392e4a (openclaw#171984).
Natural failure: CI 38550286127 / job 115806476493.

Proof: https://github.com/openclaw/openclaw/actions/runs/38552665607
Job 115814133885 passed the single diagnosed case on Node 24.19.0
(1 passed, 13 skipped; case 985 ms, Vitest 62.06 s, test step 68 s,
whole job 143 s), plus changed-file oxfmt, oxlint and diff check.
The reviewed test blob was proven on current main 4552777 as
source f2dcae3.
One Codex P2 review was scoped-clean. Test-only change: +7/-35.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant