Repository navigation
fix: CLI runs stall for minutes scanning an agent database the Gateway already opened - #182984
Conversation
A second process that opens an agent database the Gateway already holds no longer runs a full integrity_check. When another lease on the exact path has completed admission and its PID start time still matches, the claimant reuses that admission and keeps schema and index validation. Migrations, alias paths, unfinished admissions, and stale or revoked leases still take the full check. The borrower records no verification, so closing last leaves the next opener to verify instead of sealing. On Team, autoreview's agent exec runs hit this on the 43 GB roboclaw store: 97 lease-class scans totaling 7,465 s on 2026-10-24 (max 321 s per open), and kills mid-scan forced Gateway-side full rescans.
|
🦞👀 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 changes before merge. What this changesReuse a live peer process’s completed agent-database admission instead of repeating an integrity scan. Example: A separate agent exec process opens a 1.98 GB database already held by an isolated Gateway.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR addresses a measured CLI stall, but borrowed admission is not bound to the physical file the peer verified. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe agent database opener claims a shared-state lease, validates SQLite storage, and exposes an admitted connection; lease and validation owners govern reuse and clean-close certification. flowchart TD
A[Gateway or CLI] --> B[Agent database opener]
B --> C[Shared-state lease owner]
C --> D[Peer admission decision]
D --> E[Schema and integrity gate]
E --> F[Admitted database connection]
F --> G[Close and seal owner]
Technical reviewBest possible solution: Reuse peer admission only when existing identity or provenance owners establish that it covers the claimant’s physical file, retaining full verification otherwise. Do we have a high-confidence way to reproduce the issue? Current-main source forces fresh foreign-process opens through integrity verification, matching the supplied real-entry-point comparison; no target code was executed during this review. Is this the best way to solve the issue? Removing redundant scans through the existing lease owner is appropriately scoped, but path equality cannot substitute for the physical-file binding already required by admission. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ab7631a25601. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +14, Tests +65, Docs +8. Total +87 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
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 24, 2026, 6:55 PM ET / 22:55 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
|
The P2 finding (borrowed admission not bound to the peer's physical file) is valid and is fixed forward in #183052: borrowing now also requires matching lease provenance (boot, PID namespace, build, file inode), re-checked after the native open, with a replaced-file regression that fails on current main. |
…e while the Gateway holds it (#183052) * fix(state): bind borrowed agent database admission to the peer's file A process reusing a live peer's admission (#182984) matched the peer by path, completed admission and PID start time only. If a different file was renamed over the path while the peer stayed alive, a fresh process could borrow the peer's admission and skip integrity_check for a file nobody verified. Borrowing now also requires the peer's lease provenance (boot, PID namespace, build, file inode) to equal the claimant's, and the opener re-reads provenance after the native open so a file swapped between claim and open still gets the full check. Provenance exists only on Linux, so other platforms fall back to the full check. * test(state): let a separate process create the borrowed database * test(state): prove borrowing without the creator's clean-close seal
…82984) A second process that opens an agent database the Gateway already holds no longer runs a full integrity_check. When another lease on the exact path has completed admission and its PID start time still matches, the claimant reuses that admission and keeps schema and index validation. Migrations, alias paths, unfinished admissions, and stale or revoked leases still take the full check. The borrower records no verification, so closing last leaves the next opener to verify instead of sealing. On Team, autoreview's agent exec runs hit this on the 43 GB roboclaw store: 97 lease-class scans totaling 7,465 s on 2026-10-24 (max 321 s per open), and kills mid-scan forced Gateway-side full rescans.
…e while the Gateway holds it (openclaw#183052) * fix(state): bind borrowed agent database admission to the peer's file A process reusing a live peer's admission (openclaw#182984) matched the peer by path, completed admission and PID start time only. If a different file was renamed over the path while the peer stayed alive, a fresh process could borrow the peer's admission and skip integrity_check for a file nobody verified. Borrowing now also requires the peer's lease provenance (boot, PID namespace, build, file inode) to equal the claimant's, and the opener re-reads provenance after the native open so a file swapped between claim and open still gets the full check. Provenance exists only on Linux, so other platforms fall back to the full check. * test(state): let a separate process create the borrowed database * test(state): prove borrowing without the creator's clean-close seal
…3379) * 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 #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.
…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: CLI processes such as
openclaw agent exec(used by the Auto Review tool for every pass) spend up to several minutes in a full SQLiteintegrity_checkwhen they open an agent database that the running Gateway already holds.User Impact
Auto Review passes and other CLI commands that open a large, Gateway-held agent database start in seconds instead of waiting minutes, and the Gateway no longer stalls on its own rescans after one of those processes is killed mid-open.
Why This Change Was Made
When the Gateway holds a lease on an agent database, any second process opening the same file was refused reuse of integrity proof (
integrityGateReason=lease-class) and ran a full scan. A live process that already finished admitting that exact file has verified it, and a second process rescanning a file the Gateway is actively writing adds no protection.Now a claimant reuses that admission when another lease on the exact same path has completed admission and its PID start time still matches. Schema and canonical-index validation still run. Migrations, alias paths, unfinished admissions, and stale or revoked leases keep the full check. Doctor and updater quick-check handles hold the maintenance lease, which refuses all lease claims, so they cannot lend admission.
Named edge case: the borrowing process never verified the file itself, so if it is the last process to close it does not publish a clean-close seal, and the next opener runs one full check. That is still strictly fewer scans than before, where every borrower scanned at open. Documented in
docs/reference/database-schemas/integrity-and-recovery.md.Evidence
Production (OpenClaw Team Gateway, 2026.10.7, read-only log analysis, 2026-10-24): the main agent database is 43 GB. Auto Review's
agent execpasses produced 97lease-classfull scans totaling 7,465 s that day (about 2.1 hours), 50–321 s per open. Two of those processes were killed mid-scan; their unfinished leases then forced Gateway-sidestale-lease-fullrescans (4 scans, 280 s total, one 89 s scan that stalled all of that agent's sessions for about 55 s).Local reproduction through the real entry point: isolated dev Gateway on this branch's base, main agent database grown to 1.98 GB with synthetic rows, a synthetic API-key profile so
agent execreads the agent database the same way production does.agent execopen of the Gateway-held agent DB52068cf86d6)integrityGateReason=lease-class,mode=full, 967 ms integrity scanlsof), no integrity gate event, no slow-open warningScan time scales with file size, which matches the minutes observed at 43 GB.
Tests:
reuses a live peer process admission instead of rescanning the file(real child process holds the database): fails on main withintegrityGateOutcome: "healthy"(a full scan ran), passes with the fix. It also asserts that a borrower closing last publishes no seal.openclaw-agent-db.integrity-lease,openclaw-agent-db-lease,openclaw-agent-db.integrity-cache,openclaw-agent-db.open-timing,server-close.agent-databases, andsqlite-integritysuites pass. The existing clean-close test now has its last closer verify the file itself, since a borrower intentionally cannot certify it.tsgo:coreand the core oxlint shard pass; independent Codex review (P0–P2) was scoped-clean.Not covered: the effect on the production Gateway itself, which needs this change deployed and the same log query repeated.