Skip to content

perf(state): reuse native verification in reclamation workers - #154662

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-reclamation-worker-open-reuse-20260919
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-reclamation-worker-open-reuse-20260919

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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 with pending.validation (admissionMode=async). Its parent already sends valid host proof through runSqliteMutationWorkerRequest. 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:

Measurement Before After
Reclamation Worker database open 186 ms 18 ms
Validation phase 169 ms 17 ms
Full integrity pragma executions 1 0
Integrity verdict healthy cached
End-to-end reclamation 692.4 ms 492.2 ms
Native open, already cached (control) 34 ms 36 ms

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=1 produced 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.mjs with 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.
  • Changed-code checks: all selected checks passed across the final run and recovery below. 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 an ENOENT for an unchanged Telegram file during lease retirement. Its earlier unpinned attempt had flagged unrelated CLI/UI growth against the hydration checkout's moving origin/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.
  • Codex autoreview: final P0–P2 scope clean after fixing two agent-wide revocation edge cases and extending the regression.

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 ffb50bc0479d8a52b6f5b7575632c8726b6cff41 to include it. git range-diff confirms 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 GitHub startup_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 with string 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-gate report success on c5578f19d5eaf6206a6b17f52110ce1b15464b3e.

@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 6:47 AM ET / 10:47 UTC (Revision 3).

ClawSweeper review

What this changes

Lets 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
Reviewed head: c5578f19d5eaf6206a6b17f52110ce1b15464b3e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful worker-boundary proof, targeted revocation coverage, and no actionable review findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Testbox before/after measurements exercise native execution followed by real SQLite reclamation without a host writable handle, showing one full scan reduced to zero; real-worker regressions additionally demonstrate full validation after revocation during or after opening.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Testbox before/after measurements exercise native execution followed by real SQLite reclamation without a host writable handle, showing one full scan reduced to zero; real-worker regressions additionally demonstrate full validation after revocation during or after opening.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta, rather than endpoint drift. Production changes are confined to the validation cache and native worker handoff; no dependencies, schema definitions, settings, or workflow permissions change.
Current main still lacks the return handoff: The pinned main source sends retained host proof to native workers but has no receiveValidation callback or native-to-host adoption. Local retrieval of this blob failed; the exact revision was successfully inspected through GitHub's contents API.
Revocation remains authoritative: Adoption checks the captured cache entry, shared revocation state, agent identity, admitted physical identity, and shared-buffer shape. Path, cache, and agent invalidation replace the captured entry, rejecting delayed handoffs. Existing native source/caller checks precede adoption.
Findings None None.
Security None None.

How this fits together

OpenClaw 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +94, Tests +195, Docs +4. Total +293 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 108 14 +94
Tests 2 195 0 +195
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 307 14 +293

Review metrics

Metric Value Why it matters
Production versus test growth Production +94 net lines; tests +195 lines Production growth implements the reverse handoff and revocation fencing within the existing cache owner.
Added real-worker coverage cost 3 cases; 3.61 seconds reported The cases exercise actual cross-worker reuse and invalidation that isolated cache tests cannot establish.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This is a bounded database-cleanup performance improvement with a demonstrated redundant-scan trigger.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Testbox before/after measurements exercise native execution followed by real SQLite reclamation without a host writable handle, showing one full scan reduced to zero; real-worker regressions additionally demonstrate full validation after revocation during or after opening.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox before/after measurements exercise native execution followed by real SQLite reclamation without a host writable handle, showing one full scan reduced to zero; real-worker regressions additionally demonstrate full validation after revocation during or after opening.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta, rather than endpoint drift. Production changes are confined to the validation cache and native worker handoff; no dependencies, schema definitions, settings, or workflow permissions change. (src/state/openclaw-agent-execution-native.ts:194, c5578f19d5ea)
  • Current main still lacks the return handoff: The pinned main source sends retained host proof to native workers but has no receiveValidation callback or native-to-host adoption. Local retrieval of this blob failed; the exact revision was successfully inspected through GitHub's contents API. (src/state/openclaw-agent-execution-native.ts:187, 3a0137c9394a)
  • Revocation remains authoritative: Adoption checks the captured cache entry, shared revocation state, agent identity, admitted physical identity, and shared-buffer shape. Path, cache, and agent invalidation replace the captured entry, rejecting delayed handoffs. Existing native source/caller checks precede adoption. (src/state/openclaw-agent-db-validation-cache.ts:122, c5578f19d5ea)
  • Receiving opener retains integrity policy: The canonical opener adopts proof against its physical database identity and still applies owner, schema, durable-verification, and live-lease gates. Pending migrations retain full validation; proof reuse does not grant permission to delete sessions. (src/state/openclaw-agent-db.ts:361, c5578f19d5ea)
  • Production-boundary regression coverage: Three cases run the actual native generation and reclamation worker against SQLite: current proof avoids the scan, while revocation during or after native opening requires a full scan. They also verify the requested session deletion. Instrumentation counts real integrity PRAGMA execution rather than substituting a mock database. (src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts:158, c5578f19d5ea)
  • Supplied after-fix runtime evidence: The captured PR body reports a real native-only-to-reclamation run on Blacksmith Testbox using a 1,080,115,200-byte synthetic SQLite database: full scans fell from one to zero and reclamation open time from 186 ms to 18 ms. It links https://github.com/openclaw/openclaw/actions/runs/35574271517 and reports 46 passing focused cases after the revocation fixes. These are supplied observations, not tests executed during this read-only review; production deployment timing is not claimed.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-21T08:58:27.978Z sha 1391e9a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T10:34:52.653Z sha c5578f1 :: needs maintainer review before merge. :: none

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.
@steipete
steipete force-pushed the steipete/perf-micro-reclamation-worker-open-reuse-20260919 branch from 1391e9a to c5578f1 Compare September 21, 2026 10:23
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 21, 2026
@steipete steipete closed this Sep 21, 2026
@steipete steipete reopened this Sep 21, 2026
@steipete
steipete merged commit 50d26ab into main Sep 21, 2026
241 of 242 checks passed
@steipete
steipete deleted the steipete/perf-micro-reclamation-worker-open-reuse-20260919 branch September 21, 2026 11:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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