Skip to content

perf(state): reuse retained proof for native worker opens - #154258

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

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-sync-open-validation-20260919

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #153581, #153463.

What Problem This Solves

Native agent database Workers repeat full integrity scans after the host's verified database handle closes or is evicted, delaying their first operation while another database lease is still live.

User Impact

Already-verified native Worker opens reuse retained proof without scanning the file again. Revoked proof, replacement files, missing or mismatched durable records, migrations, and Doctor retain their existing checks. There are no schema, configuration, durability, retention, or update-behavior changes.

Why This Change Was Made

The validation owner intentionally retains revocable, file-bound proof after an ordinary handle close. The native admission handoff previously required an open host handle to retrieve that proof. With a live sibling lease, the durable clean-close receipt also cannot substitute. The handoff now reads transferable proof from the same validation owner; the receiving opener still checks its physical identity and shared revocation flag before the existing durable-record and lease gates. Net production change: +9 lines; no new cache or lifecycle.

Evidence

Synthetic warm-cache benchmark on a 1,076,822,016-byte SQLite database, with a closed host handle and a live sibling lease. Three fresh native opens per version, on the same Blacksmith Testbox lease. The fixture adds 128 × 8 MiB zero-filled BLOBs; the measured interval is the existing agent-database open timer, excluding Worker startup and lease acquisition. A temporary probe printed the existing opener phase timings and counted actual integrity PRAGMA executions; the probe and large fixture are not included in the PR.

Measurement Before After
Worker open, three samples 102 / 96 / 94 ms 13 / 11 / 12 ms
Median Worker open 96 ms 12 ms (87.5% lower, 8× faster)
Validation phase, median 84 ms 12 ms
Integrity outcome healthy cached
integrity_check / foreign_key_check, per open 1 / 1 0 / 0

The committed regression failed on the original code specifically for the closed-host case ([1, 1] PRAGMA counts instead of [0, 0]); the eight other cases passed. New cases also cover revoked retained proof and a replaced file.

All heavy validation used provider blacksmith-testbox, profile openclaw-check. No local tests, builds, or typechecks ran.

  • tbx_01m30ppyjtrwq257y9gcs96ymg: node scripts/run-vitest.mjs src/state/openclaw-agent-execution.integrity.test.ts --maxWorkers=1 reproduced the regression (1 expected failure / 8 passes). Testbox run. Lease stopped after a subsequent file-sync timeout.
  • tbx_01m30qd53kwp4zy26bfj4bvk16: the same command with the temporary benchmark fixture passed three samples before and three after. Testbox run.
  • tbx_01m30r0d93ydx1qf544t1vk2vz: node scripts/run-vitest.mjs src/state/openclaw-agent-execution.integrity.test.ts src/state/openclaw-agent-db-validation-cache.test.ts src/state/openclaw-agent-db.integrity-policy.test.ts --maxWorkers=1 passed all 45 tests. The changed native Worker test file passed all 9 cases in 7.46 s wall time (one worker); the other two files passed 36 cases in 15.01 s including worker compilation. Final validation Testbox run.
  • tbx_01m30r0d93ydx1qf544t1vk2vz: node scripts/check-changed.mjs --base HEAD passed (23m 03s command time). HEAD was the unchanged pre-commit lane base 21688de06da; this covered core and test types, ratchets, formatting, lint, export scans, runtime import cycles, and ownership guards. All three task-owned leases were stopped.
  • Independent Codex autoreview: scoped-clean, no actionable P0–P2 findings. Local formatting and git diff --check passed.
Validation setup and recovered infrastructure failures

Validation setup encountered missing dependencies in the synchronized checkout, resolved with pnpm install --frozen-lockfile there. An initial login-shell invocation ran six unchanged tests in the hydration checkout and was excluded from candidate proof. A temporary benchmark filename selected the thread pool and hit the host-only admission guard; moving the probe into the existing fork-based integrity test route fixed that harness issue. Two later incremental-sync timeouts required replacing the first and second leases. The default changed gate compared against a newer origin/main and reported line-cap growth in untouched files: src/agents/agent-tools.ts and src/gateway/config-reload.test.ts. Upstream commits ddc25180e5c and 052d26eec0b explain those differences; the gate was corrected to the unchanged lane base. No failed product test was retried without a diagnosed change.

Gap: this proves the native execution Worker path and synthetic performance. Production journal correlation and production-scale timing remain unverified; no live deployment was performed.

Landing CI investigation

The initial exact-head CI run failed only checks-node-compact-small-45 and its aggregate gate. The failing case was test/scripts/crabbox-staging.test.ts → “keeps preparation callbacks and additional Git workspaces held without disabling them”: its child command exceeded 30 seconds. The fixture does not retain the specific child arguments/output on timeout, so the precise stalled operation remains unknown. The staging owner and helper code are identical on this PR and the inspected main revision; the fixture does not execute the changed native database validation path.

The original three-group shard plan was replayed in order on pure main 894fb140a22246bc1574d5b29fe61e10f77036de, using Blacksmith Testbox tbx_01m30xbwn1bdd19661xvqdbjh5 and node --import tsx scripts/ci-run-node-test-shard.mts with the original shard groups and two workers. All 74 files passed: 1,769 tests passed and seven were skipped. Command time was 413.155 seconds; the previously failing case passed in 12.743 seconds. The lease was stopped. This passing replay does not establish a fix for the original timeout. No source changes, test retries, timeout changes, local tests, builds, or typechecks were introduced during landing.

The single operator-authorized job-specific rerun passed on unchanged head 29bc4a0c6d743884f1d6559b12e7718dd1f04a22: CI run 35551629220, attempt 2. The successful shard job was 106197640653; the CI gate job was 106199710586. The CLI rerun shim refused before dispatch, so the equivalent job-specific REST endpoint was used once.

Transfer revocable host integrity proof after ordinary handle close through the existing native admission port. Keep receiver identity validation and durable verification gates intact. A synthetic 1 GiB database opens in 12 ms median versus 96 ms; Testbox regression, sibling tests, changed checks, and independent review pass.
@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: S maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 01:39
@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
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 9:54 PM ET / September 21, 2026, 01:54 UTC.

ClawSweeper review

What this changes

Native database Workers reuse retained integrity validation after the host connection closes, avoiding redundant scans while preserving existing admission checks.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused performance fix: current main still requires an open host handle to transfer validation. No actionable correctness or security defect was found.

Priority: P2
Reviewed head: 29bc4a0c6d743884f1d6559b12e7718dd1f04a22

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level fix with relevant before/after measurements and meaningful regression coverage; no blocking defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Testbox measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.
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 measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.
Evidence reviewed 8 items Introduced change and merge result: The pinned introduction changes only validation transfer, its native Worker caller, regression cases, and documentation. Raw test-merge parents match the supplied main and PR head; comparison against that main parent preserves the same focused change.
Existing validation owner: Ordinary close already retains validation. The new transfer accessor requires integrity-verified evidence, matching agent identity, and a live shared revocation flag; adoption still checks the receiving connection's physical identity.
Independent admission and durable gates: The opener adopts transferred evidence against its registered physical connection, then requires live-lease eligibility and the existing durable verification policy. Missing metadata, version mismatch, replacement, and pending migrations retain full verification. Worker lease claiming separately rechecks maintenance and deletion authority.
Findings None None.
Security None None.

How this fits together

Native Workers open agent SQLite databases to perform session and agent operations. The validation owner supplies reusable integrity evidence, while the database opener independently checks identity, durable metadata, schema, and leases.

flowchart TD
  A[Agent database operation] --> B[Worker admission]
  C[Retained host validation] --> B
  B --> D[Check identity and revocation]
  D --> E[Check durable record and lease]
  E --> F[Reuse validation or scan database]
  F --> G[Admitted database operation]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +20, Docs +3. Total +32 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 17 8 +9
Tests 1 28 8 +20
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 48 16 +32

Review metrics

Metric Value Why it matters
Reported Worker open benchmark 96 ms → 12 ms median; 3 samples per version The synthetic benchmark measures the changed database-open path, excluding Worker startup and lease acquisition.

Technical review

Best possible solution:

Keep retained validation in its existing owner and reuse it through native admission while preserving receiver-side identity, revocation, durable-record, and migration checks.

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

Yes, source establishes the trigger: close a verified host handle while a sibling lease remains live, then open a native Worker; current main cannot transfer the retained evidence. The supplied regression reports this failure, but this review did not execute it.

Is this the best way to solve the issue?

Yes. The patch accesses the existing validation owner directly and preserves the canonical opener's checks, avoiding a competing cache or broader lifecycle change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 20eebbd5c7bf.

Labels

Label changes:

  • add P2: This bounded optimization reduces repeated database scans during native Worker opening without changing user configuration or persisted state.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Testbox measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.

Label justifications:

  • P2: This bounded optimization reduces repeated database scans during native Worker opening without changing user configuration or persisted state.
  • 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 measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox measurements exercise native Worker database opening with a closed host and live sibling lease, reporting cached validation, zero full scans, and lower opening time after the fix. Real Worker regression cases cover revoked and replaced evidence; production-scale timing remains outside the claim, and linked raw logs were inaccessible to this reviewer.

Evidence

What I checked:

  • Introduced change and merge result: The pinned introduction changes only validation transfer, its native Worker caller, regression cases, and documentation. Raw test-merge parents match the supplied main and PR head; comparison against that main parent preserves the same focused change. (src/state/openclaw-agent-execution-native.ts:188, 7c34be280750)
  • Existing validation owner: Ordinary close already retains validation. The new transfer accessor requires integrity-verified evidence, matching agent identity, and a live shared revocation flag; adoption still checks the receiving connection's physical identity. (src/state/openclaw-agent-db-validation-cache.ts:96, 29bc4a0c6d74)
  • Independent admission and durable gates: The opener adopts transferred evidence against its registered physical connection, then requires live-lease eligibility and the existing durable verification policy. Missing metadata, version mismatch, replacement, and pending migrations retain full verification. Worker lease claiming separately rechecks maintenance and deletion authority. (src/state/openclaw-agent-db.ts:360, 29bc4a0c6d74)
  • Meaningful Worker regression coverage: The extended fixture invokes the real native Worker and SQLite implementation, counting executed integrity PRAGMAs. Closed-host proof avoids both scans; revoked retained proof and file replacement require both scans. Existing cases cover revocation after transfer, failed source authority, and missing or mismatched durable metadata. (src/state/openclaw-agent-execution.integrity.test.ts:99, 29bc4a0c6d74)
  • Still necessary on main: Fetched main retrieves transferable evidence only through an open host database handle, so it does not cover the closed-host scenario. The latest supplied release does not contain this native execution module; no released implementation of this optimization was established. (src/state/openclaw-agent-execution-native.ts:189, 20eebbd5c7bf)
  • Supplied production-path performance evidence: The captured body, sourceRevision 54d60de0a3cd8b7db7ebed2cfa32c16f68f43960c219c057de433fca16969d1d, reports three real native Worker opens per version on a synthetic 1,076,822,016-byte SQLite database with a closed host and live sibling lease: median open time falls from 96 ms to 12 ms, with integrity/foreign-key scan counts falling from 1/1 to 0/0. It also reports the original-code regression failure and 45 passing focused tests. Linked Testbox logs could not be independently inspected because their redirected storage host was blocked; no reviewer-side execution is 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.

@steipete
steipete merged commit ba2fc97 into main Sep 21, 2026
454 of 456 checks passed
@steipete
steipete deleted the steipete/perf-micro-worker-sync-open-validation-20260919 branch September 21, 2026 03:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…54258)

Transfer revocable host integrity proof after ordinary handle close through the existing native admission port. Keep receiver identity validation and durable verification gates intact. A synthetic 1 GiB database opens in 12 ms median versus 96 ms; Testbox regression, sibling tests, changed checks, and independent review pass.
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: S 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