Repository navigation
perf(state): trust a live Gateway owner of the shared-state file - #183379
Conversation
Every separate process that admitted the shared-state database while the Gateway held it ran a whole-database integrity scan in the fast path. On Team's 8.4 GB state database that was 143 processes in about 21 hours at 6.4-7.3 s each (957 s), the shared-state sibling of #182984. The Gateway now publishes Linux file provenance in its owner lease when it marks itself listening while holding a completed verification receipt. A different process skips only the integrity scan when the owner is live with a matching PID start time and the provenance matches its own view of the file. Schema, version and legacy-repair checks still run, and the borrower records no verification, so it can never write a clean-close seal.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR lets Linux processes reuse a live Gateway’s completed shared-state integrity verification while retaining schema and ownership checks. Example: A separate CLI process opens an 8.4 GB shared-state database held by a Linux Gateway.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a concrete shared-state performance cost that remains on main, and no definite introduced code defect was found. The failing CI checks remain unattributed. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherShared-state admission sits between native SQLite opening and usable database handles; it validates schema and integrity before callers perform state operations. flowchart TD
A[Gateway verifies SQLite] --> B[Owner lease publishes provenance]
C[Separate process opens SQLite] --> D[Validate schema and version]
B --> E[Match live owner and file]
D --> E
E --> F[Reuse integrity admission]
E --> G[Otherwise run full scan]
Technical reviewBest possible solution: Reuse the existing Gateway lease and physical-verification owner while preserving full checks for unmatched peers and preventing borrowers from sealing unverified state. Do we have a high-confidence way to reproduce the issue? Current-main source shows the redundant integrity call for a cold process without shared admission, and the report identifies the matching operation in production; this read-only review did not execute a reproduction. Is this the best way to solve the issue? The patch is a focused implementation using existing owners: publish completed verification through the current lease, borrow only for a matching live peer, and leave schema validation and fallback verification intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f3c34dcad092. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +22, Tests +114, Docs +8. Total +144 across 8 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 25, 2026, 3:25 AM ET / 07:25 UTC. |
|
Converting to draft: a real-product Linux end-to-end run shows this does not remove the scan yet. Run on the Team perf sandbox: a synthetic 2.16 GB shared-state DB, an isolated Gateway, and a separate
Every scan comes from Root cause, from a follow-up probe of a real programmatic Gateway startup: at Making this work needs a design decision first. Either the Gateway records a live-file proof it can share, or a live Gateway owning the exact file becomes enough for a CLI process to skip its own scan. Until then this stays a draft. CI note: |
The Linux end-to-end run showed the receipt condition never fired: at listening the Gateway holds no completed integrity proof for the live state file, because startup verifies a private snapshot. Publish the owner's exact-file provenance at listening instead, after startup admission, and let a different process with matching provenance and a live owner PID/start time skip only its whole-file integrity scan. Borrowers still record no verification and never seal.
|
Merged via squash auto-merge.
|
…nclaw#183379) * perf(state): reuse a live Gateway's shared-state integrity admission Every separate process that admitted the shared-state database while the Gateway held it ran a whole-database integrity scan in the fast path. On Team's 8.4 GB state database that was 143 processes in about 21 hours at 6.4-7.3 s each (957 s), the shared-state sibling of openclaw#182984. The Gateway now publishes Linux file provenance in its owner lease when it marks itself listening while holding a completed verification receipt. A different process skips only the integrity scan when the owner is live with a matching PID start time and the provenance matches its own view of the file. Schema, version and legacy-repair checks still run, and the borrower records no verification, so it can never write a clean-close seal. * perf(state): trust a live Gateway owner of the exact shared-state file The Linux end-to-end run showed the receipt condition never fired: at listening the Gateway holds no completed integrity proof for the live state file, because startup verifies a private snapshot. Publish the owner's exact-file provenance at listening instead, after startup admission, and let a different process with matching provenance and a live owner PID/start time skip only its whole-file integrity scan. Borrowers still record no verification and never seal.
What Problem This Solves
Fixes: every separate OpenClaw process that opens the shared-state database while the Gateway is running re-verifies the whole file. On Team (read-only, 2026-10-24/25) the 8.4 GB
state/openclaw.sqlitepaid this in 143 distinct processes in about 21 hours (slow SQLite transaction hold,operation: "state.admission.fast-path"): 6.4–7.3 s each, 957 s total, all SQL time. #182984 fixed the same problem for agent databases.User Impact
User impact: on Linux, CLI commands and other processes that open the shared state database while the Gateway runs no longer pay a whole-file integrity scan; on large installs that is several seconds per process. macOS and Windows behave as before.
Why This Change Was Made
The first revision tried to borrow the Gateway's completed integrity receipt. A Linux end-to-end run showed it never fired: at listening, the Gateway holds no completed proof for the live state file, because its startup inspection verifies a private snapshot copy. The maintainer chose to trust a live owner instead.
markListening(), after startup admission, the Gateway publishesstateDatabaseProvenancein its existing owner-lease payload update. The value comes from the existingreadAgentDatabaseLeaseProvenancehelper, which binds host, boot id, PID namespace, build, and dev:inode, and is null off Linux.apps/and native code).Production TypeScript: net −4 lines versus the first revision (the receipt condition and its imports are removed).
Evidence
Linux end-to-end on the Team perf sandbox (isolated Gateway on a loopback port, synthetic 2.16 GB state DB, separate
pnpm openclaw agents list --json, 3 runs per cell, statement observer with stacks):integrity_checkin the CLI processopenclaw-state-db-fast-path.ts→sqlite-integrity.ts:332. The existing-schema and existing-write paths did not scan.Tests:
src/state/openclaw-state-db.integrity-lease.test.ts(8) runs through the realopenOpenClawStateDatabasepath. A live matching peer gives 0 scans. Each of these still scans once: no lease, dead peer, changed start time, different inode, same process, missing provenance. The borrower leaves no receipt and no seal.src/infra/gateway-owner-lease.test.ts(41) now publishes from the real startup order (preflight → lease → listening). It is red with the old receipt condition and green here.openclaw-state-db-fast-path.test.ts(6) andopenclaw-state-db-checkonce.test.ts(11) pass.pnpm tsgo:core, changed-file oxlint,oxfmt --check,git diff --check: pass.CI note:
src/cli/gateway-diagnostics-opens.process.test.ts(an extra:memory:open from #183120'sprobeSqlite) andtest/canonical-descendant.integration.test.tsfail identically on unchanged origin/main 3db36fc.Not changed
Migrations, repair, Doctor, explicit verification, quarantine and seal policy. Other cold whole-scan entry points (existing-schema readers, one-shot writers, startup checkpoint/bootstrap) are separate borrowing points and keep their behavior.
Release note context: on Linux, CLI and other processes that open the shared state database while the Gateway runs no longer re-verify the whole file.