Repository navigation
perf(state): reuse native verification in reclamation workers - #154662
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: needs maintainer review before merge. Reviewed September 21, 2026, 6:47 AM ET / 10:47 UTC (Revision 3). ClawSweeper reviewWhat this changesLets session cleanup workers reuse database integrity verification established by native execution workers, with revocation safeguards, regression coverage, and documentation. Merge readiness✅ Ready for maintainer review This remains a useful, distinct optimization absent from inspected main. The pinned patch preserves validation and admission safeguards, has relevant real-worker evidence, and introduces no actionable correctness finding. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw verifies agent SQLite databases before admitting writes. Native execution and session cleanup use separate workers; sharing current verification avoids repeated full scans while retaining database identity and write-admission checks. flowchart TD
A[Native execution worker] --> B[Verified agent database]
B --> C[Existing admission handshake]
C --> D{Identity and revocation checks}
D -->|Current proof| E[Host validation cache]
E --> F[Cleanup worker admission]
D -->|Rejected proof| G[Full database validation]
F --> H[Guarded session cleanup]
G --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +94, Tests +195, Docs +4. Total +293 across 6 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep verification reuse within the existing validation owner and admission handshake, preserving full validation whenever proof becomes ineligible. Do we have a high-confidence way to reproduce the issue? Yes: open the database only through a native execution worker, keep its lease live, then reclaim a session without a host writable handle. Inspected main lacks the return handoff, and the supplied before/after probe demonstrates the redundant scan; this review did not execute it. Is this the best way to solve the issue? Yes. Returning proof through the existing admission message fixes the missing direction without another cache, host SQLite open, or message round trip, while retaining the receiving opener's integrity gates. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3a0137c9394a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Return native worker validation through its first identity admission so reclamation can reuse proof without a host SQLite open. Bind adoption to current cache state and preserve agent, file, shared revocation, and durable verification checks. Synthetic 1.08 GB database on Testbox: reclamation open 186 ms to 18 ms, full scans 1 to 0. Focused regressions, complete selected changed-code checks, and independent review passed; production Gateway behavior remains unmeasured.
1391e9a to
c5578f1
Compare
…aw#154662) Return native worker validation through its first identity admission so reclamation can reuse proof without a host SQLite open. Bind adoption to current cache state and preserve agent, file, shared revocation, and durable verification checks. Synthetic 1.08 GB database on Testbox: reclamation open 186 ms to 18 ms, full scans 1 to 0. Focused regressions, complete selected changed-code checks, and independent review passed; production Gateway behavior remains unmeasured.
What Problem This Solves
Session reclamation can repeat a full integrity scan even while a native execution Worker already holds verified proof for the same agent database. This adds database-sized latency to deletions and maintenance.
Related: #153581, #154258, #153463.
User Impact
Cleanup reuses verification established inside native execution Workers, including when the host has no writable handle. Revoked proof still requires full validation. There are no schema, configuration, retention, durability, or update-contract changes; Doctor, migration, quarantine, and missing/mismatched durable verification retain their existing checks.
Why This Change Was Made
Reclamation already uses
runReclamationWorkerPort→withWorkerWriteAdmission→withOpenClawAgentDatabaseAdmission→ the canonical opener withpending.validation(admissionMode=async). Its parent already sends valid host proof throughrunSqliteMutationWorkerRequest. Archive materialization uses a fresh read-only connection.The missing direction was native Worker → host. Native execution calls
openOpenClawAgentDatabase(options, lease)synchronously, but previously retained newly established proof only in its own thread. Its live lease correctly prevents the persisted receipt from acting as a clean-close receipt, leaving a later reclamation Worker without reusable runtime proof.Return that proof with the first existing native identity admission. The existing validation owner accepts it only after current source/caller authority and physical identity checks, and only while its captured validation state remains current. Path, agent, cache, and shared-cell revocation reject delayed handoffs. Existing durable metadata and live-lease checks still decide whether the receiving opener may reuse proof. This adds 94 net production lines, no host SQLite open, no new message round trip, and no separate cache owner.
Evidence
On Blacksmith Testbox
tbx_01m31ep2d5rr8karh7t1d0xpg0(blacksmith-testbox,openclaw-check), a 1,080,115,200-byte synthetic database containing 8,192 × 128 KiB payload rows reproduced the native-only → reclamation flow:This is one before/after sample on the same lease with equivalent fixtures, not a production latency claim. Temporary timing instrumentation and the large fixture were removed; permanent regressions use small databases. The pre-fix real reclamation probe failed on the extra full scan; the fixed probe passed. Live-host and closed-host controls already avoided the scan before this change.
Validation used
crabbox run --id <id> --timing-json -- <command>throughout; no heavy checks ran on the development Mac.tbx_01m31e0hqx9s7ztzyass8s484r: focused reclamation probe passed live/closed/revoked controls; native-only probe failed as expected (1 scan instead of 0). The initial run stopped at missing remote dependencies, then passed after a frozen-lockfile install. Two later large-fixture attempts stopped at file-sync timeout before executing.tbx_01m31ep2d5rr8karh7t1d0xpg0:node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts -t 'lane 89 probe.*native-only' --maxWorkers=1produced the table above: baseline failed on scan count; candidate passed. A subsequent focused-suite attempt stopped at sync timeout before execution.tbx_01m31f96drw4vra76h7gfh3sxy:node scripts/run-vitest.mjswith reclamation reuse, validation cache, native execution integrity, integrity policy, and integrity-cache files,--maxWorkers=1: 76 passed. After the review fixes, the two edited files passed again: 46 passed, 44.96 s wrapper wall. File walls were 16.50 s for validation cache (25 tests, including compiler preparation) and 26.24 s for reclamation reuse (21 tests); the three added real-Worker cases took 3.61 s total. One intermediate replay stopped at a corrected source-marker preflight typo before tests.node scripts/check-changed.mjs --base 92f2fcfd1ad6c76b72dbddb1cd1619ae78b22f58 -- <six changed files>passed both type lanes (all 24 test graphs took 1,628.97 s), graph boundaries, lint, formatting, dead exports, and preceding guards. The wrapper later exited 1 at the database-first guard with anENOENTfor an unchanged Telegram file during lease retirement. Its earlier unpinned attempt had flagged unrelated CLI/UI growth against the hydration checkout's movingorigin/main; no ratchet baselines were changed.tbx_01m31hzj0sy8mrnpcvcqm6c51x: reran the database-first guard and all six remaining planned guards through their package-owned Node commands: media download helpers, runtime sidecar loaders, import cycles, webhook body order, pairing-store groups, and pairing account scope. All passed, command wall 139.12 s. Valid prior proof was retained; the completed 24-graph sweep was not repeated.The four initial task-owned leases were retired; replacement leases recovered dependency/sync/retirement failures without overlapping validation commands.
CI follow-up
The first PR CI run (35580042749, 24m31s) failed the native-process authority fixture in
checks-node-changed-extensions-bundle-20; its first shard passed 389 tests and failed one after cold preparation exhausted the fixture's five-second attempt budget. A controlled pre-fix clock probe reproduced the execution-timeout callback followed by the exact missing-relay error. The original two-shard bundle passed on replay (457 tests); that alone was not treated as a fix.Main has since landed the owning fixture repair in 9247701e7ae. This PR was rebased onto
ffb50bc0479d8a52b6f5b7575632c8726b6cff41to include it.git range-diffconfirms the optimization is patch-identical; its scope remains the original six files. A separately investigated fixture alternative is retained only as local evidence and is not part of this PR.The new head is
c5578f19d5eaf6206a6b17f52110ce1b15464b3e. A fresh Testbox request was rejected with HTTP429 while fetching the workflow, without an unambiguous lease receipt. The first attachment on this head had a GitHubstartup_failure; Security Review resolve separately failed with HTTP403 installation API rate exhaustion before checking code. After a newer Security Review run succeeded and this PR's merge ref became available, one documented close/reopen recovery requested CI again on the unchanged head. Auto-merge was requested immediately after PR creation and again after the CI repair, but the CLI refused withstring rewrite protection blocked unsafe input; auto-merge remains disabled.Gap: no live Gateway deployment or measurement against an operator database. The observed synchronous open logs cannot be attributed to reclamation solely from timing; the reproduced native-only proof gap is the basis for this change. The rebased CI run 35589838642 passed in 17m48s, and both forms of
openclaw/ci-gatereport success onc5578f19d5eaf6206a6b17f52110ce1b15464b3e.