Skip to content

fix(update): reduce CPU time in repeated ownership checks - #156757

Merged
fuller-stack-dev merged 8 commits into
mainfrom
openclaw/updater-lease-reader-20260923
Sep 24, 2026
Merged

fuller-stack-dev merged 8 commits into
mainfrom
openclaw/updater-lease-reader-20260923

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Related: #155977, #156227.

What Problem This Solves

Fixes excessive CPU time in update preparation when large installations require hundreds of thousands of live ownership checks.

User Impact

Large updates spend less CPU time checking their current owner without weakening revocation, database integrity, or cleanup guarantees. No configuration, schema, permission, or retention changes. The improvement applies once the installed updater contains this fix; it cannot speed up an older updater installing it.

Why This Change Was Made

Keep one read-only SQLite connection and reusable query handles for the admitted executor lifetime instead of reopening and reconstructing them for every check. Each check still revalidates the physical store, schema, lease row, and process identity. Each snapshot ends before returning, so other writers are not excluded between checks; readers close after direct/delegated settlement and preflight handoff.

Only connection and query setup are reused, not authority, database pages, schema decisions, or trusted SQLite bytecode. Before each retained read, SQLite discards cached pages and resets its schema with schema writing disabled. This preserves fresh-reader refusal even when in-place corruption leaves the inode, file size, and SQLite change counters unchanged. The existing one-shot writer admission and recovery policies remain in place.

Evidence

  • Native macOS Node 24.20: 141 focused and affected tests passed, with one existing Bun-only skip because Bun is unavailable. Scoped reruns after the final cache/lifetime adjustments passed: 27 reader + 20 settlement tests, and 44 handoff-database + 4 package-journal tests. The affected executor suite also passed all 46 cases.
  • Fixture follow-up: 93/93 executor, reader, and settlement tests passed in 45.54s wall after Windows-native path canonicalization, file-URL child imports, disposal on instrumentation failure, and joining the existing state-database lifecycle before fixture removal. The hosted TS2532 test error was repaired by explicitly asserting the retained reader exists. Type-aware lint, line-cap, and diff checks pass; independent review approved the exact fixture-only changes. Production code is unchanged by this follow-up. Hosted test-type gates passed at 15bf31fa8186; the strict Windows rerun exposed a second native sharing fixture issue, corrected below.
  • Real regression proof: same-size, same-inode corruption of the file signature, lease table page, and schema originally left the warm fence valid. All three tests failed against that retained-reader implementation and pass with pager/schema reset. Expected fence errors are asserted after executor settlement so cleanup failures cannot hide failed assertions.
  • Native fixtures verify fresh row/process revocation; unchanged file bytes, identity, and permissions; schema writing disabled; no WAL/SHM sidecars or hot-journal recovery; an independent writer acquiring EXCLUSIVE between fences; and direct/delegated reader closure, including real child-process failure.
  • Local real-store microbenchmark: 4,000 reads took 1.211s one-shot vs 0.565s retained/reset on the repeat pair (about 2.1x faster). This was not isolated from compiler load and is not an end-to-end update measurement.
  • Matched-tree, isolated Crabbox measurement: lease reader alone 229.4s vs 250.6s baseline, with all 281,956 ownership checks, shared inodes, real dependency execution, and cleanup preserved. Together with fix(update): shorten preparation for large dependency trees #156748, 117.3s (53% faster). These are measured retained-runtime preparation hooks, not total update wall time. Crabbox also passed all 141 focused/affected cases.
  • Final-effect revocation already has real process-boundary coverage: withholds candidate input when the original owner changes before process binding warms the admitted reader, replaces its owner before subprocess input, proves the real child never writes its effect, preserves the replacement owner, and releases the candidate owner. This passed in Windows run 35918366544; that overall run failed separate fixture cases, not this behavior.
  • Final fixture correction ffe22849076 preserves all cases: Windows SQLite denies renaming an open file, so replacement attempts must prove their exact native sharing code (EBUSY for source rename; EPERM for replacement), unchanged bytes, and still-current original authority; platforms permitting replacement must still reject the changed authority. Admission uses a real hard-link violation on every platform. Leak assertions remain mandatory, with cleanup afterward to prevent contaminating later tests. 27/27 reader tests pass on macOS, plus type-aware lint, line-cap, max-lines, assertion-safety and diff checks. Full-file independent API review is scoped-clean P0–P2.
  • Candidate 28e154b611b2c6af05676b72d05d6070d1e1504a incorporates main d3e8af2843c2, including the delivered Workshop clock and Factory-disposal test prerequisites. Production, dependency inputs, and reviewed behavior are unchanged by the merge. At that exact head, native macOS passed 157/157 cases across five files in 69.15s. Strict Windows run 35930572881 passed 150 cases, with six existing platform skips and one remaining missing-file rename fixture failure. Reader-only Windows diagnosis proved the one remaining failure was the fixture expecting EPERM while source rename correctly returned EBUSY. Reviewed fixture head f214d48d9b79f32390bc47a1df378e366727c2be asserts exact per-operation codes and preserves original assertion failures instead of masking them. The full-file API review remains scoped-clean P0–P2; Final strict Windows qualification passed all five files: 151 passed, six existing platform skips, 127.60s on native Windows 10.0.26100 x64 / Node 24.18.1 / pinned pnpm 12.4.2. The workflow verifies exact source/dependency binding and ordered project completion. The warm-owner real-child no-effect test passed again at this exact final head. Ephemeral runner teardown owns the retained temp namespaces; the harness did not separately attest non-group descendant cleanup. Ordinary CI has a Codex settlement hook failure, tracked separately below.
  • Published updater → exact candidate passed: Package Acceptance run 35939129755, published-upgrade-survivor job completed successfully using the actual published [email protected] updater and a package built from f214d48d9b79f32390bc47a1df378e366727c2be. The package SHA-256 is f8dfd8456696b932e2c30508081656b1e60486c3d2213ba36b109cebbfd58c5c; trusted workflow 0bdab89c20155 was called by the temporary, unmerged proof carrier 7a8d3c885427. Frozen admission receipts and the authenticated consumer artifact 10785710938 bind these identities. The recorded build changed from published 2026.9.5-release-ec9c1a13db89 to candidate 2026.9.5-f214d48d9b79. The base scenario passed through the installed updater in 330.434 seconds, then verified migration, state survival, dependency cleanup, manual Gateway startup, /healthz, /readyz, and status. The complete lane took 640 seconds and recorded joined cleanup. These compatibility timings are separate from the matched-tree performance measurements above.
  • Credential boundary, limits, and remaining CI: The reviewed caller forwarded no provider secrets; all 47 provider/auth environment bindings observed in the retained job log were empty. This proves a successful Linux Docker upgrade followed by manual Gateway startup, not native service restart or failure recovery. Retained redacted update output is truncated at 16 KiB, and the optional first-hop post-core exit snapshot is unavailable. Ordinary CI run 35931870289 remains red in the Codex settlement suite: fourteen 180-second hook timeouts occurred across two attempts, including the runner’s automatic no-output retry; the final attempt ended with the existing 300-second no-output termination and exit 143. The original log and tested merge b2d942247040 are preserved. This failure now maps to the delivered fix in perf(state): remove schema probes from warm session reads #156817 (d1a3a33acc1ca10d2e8f4cb3bf4a24a3d104ab18): releasing the held writer with fake timers installed stranded a coordinator wait and blocked teardown. That prerequisite passed exact-head CI run 35935966059, including the same extension shard; no blind rerun was used.
  • Current candidate: 429b78030ad89bcff98c6e08118053afd4357a49 merges pinned main 5fca488821d4e5e9a5b5f754f9ccadb9a8eda60f. All eight PR-owned files and dependency inputs are byte-identical to the previous 8719a7fb candidate; the retained native Windows evidence remains source-bound, not relabeled as a new-head run. The refresh includes landed path-index fix(update): shorten preparation for large dependency trees #156748, ACP migration canonicalization, and the direct-main maintenance shutdown fixture repair 441c3df8. That fixture repair replaces polling with actual startup/disposal signals and prepares cleanup release before scheduling, preserving abort/disposal/lane assertions. Its recorded original-order shard passed 447 tests across 26 files and standalone file passed 22 cases. The old CI35953027851 remains a failed historical run; fresh exact-head CI35956677247 passed all145 jobs, including the aggregate gate. Current-head security and dependency checks also passed.
  • Previous exact package cell passed: Package Acceptance35953054031 passed at 8719a7fb8ea7991836b569a68709496842a7a843: published2026.9.5 first hop, candidate-driven second hop with legacy chunks removed, and original-candidate base survivor/manual restart, each on attempt1 with joined cleanup. Package SHA256 7681ce436cc5366eeb72dec5abb565a2fd812ed7303d9bba790df9b2f9e2253f. First-hop625s; survivor654s. This is systemctl-shim service control and mock model traffic, not native systemd, live inference, full rollback or newer-write preservation. The new composition passed fresh exact-head Package Acceptance 35957254000: source and workflow 429b78030ad89bcff98c6e08118053afd4357a49, package build 2026.9.5-429b78030ad8-2026-09-24T04-51-17.127Z, tarball SHA-256 15f450f37058ff693343fc9fb0f8a24b7424d72af9c47414b8109bb1edf2b7ea, artifact 10791067183. Package integrity, npm 12 installation, source admission and final verification passed. Published-upgrade survivor passed in 461 seconds; first/second-hop compatibility passed in 528 seconds. Both were attempt 1, without timeout, and recorded joined cleanup. Frozen admission and both report artifacts were independently read and their ZIP digests verified in memory. Survivor verified automatic migration before standalone Doctor, unavailable-plugin configuration preservation, selected state survival, dependency repair, and manual Gateway readiness. The systemctl-shim/mock-traffic and rollback/newer-write limits above remain; no native-systemd or live-inference claim is made. Historical proof is not relabeled as new-head execution.
  • Refreshed native/API evidence: Exact 429b7803 passed 147 tests across seven files with one existing Bun-only skip in 62.90 seconds, combining the five lease/authority suites with the landed path-index and scaled-tree suites. All handoff stores resolve to private fixture paths, including delegated helpers. Fresh API-only independent review against pinned main 5fca4888 is scoped-clean P0–P2. No PR-owned source/test files changed or tests were pruned; the existing whole-file audits and native Windows proof remain source-bound. The consumed 177 MiB compiler cache was removed after all runners joined. No operator Gateway was updated or restarted.
Focused commands, measured test cost, and whole-file audit
node scripts/run-vitest.mjs run \
  src/cli/update-cli/update-command-executor-reader.test.ts \
  src/cli/update-cli/update-command-executor-settlement.test.ts \
  src/cli/update-cli/update-command-executor.test.ts \
  src/infra/update-managed-service-handoff-database.test.ts \
  src/infra/package-update-activation-journal.test.ts \
  --maxWorkers=1

The five-file affected run took 45.78s wall. The final reader + settlement rerun took 35.17s wall, including 20.52s of shared native-fixture compilation; its native child/crash fixtures protect cross-process disposal and recovery-byte preservation that mocked SQLite cannot establish. CI timing will be added once available.

Audited all four touched test/support files in full: executor reader, executor settlement, executor behavior, and the registered roots helper, including setup, helpers, assertions, skipped cases, mocks, and cleanup. The reader file covers 512 real checks, bounded handle setup, competing writers, failure/handoff disposal, real delegated children, revocation, physical replacement, corruption, permission/link changes, WAL transitions, and hot journals. The settlement file preserves all 20 distinct direct/delegated lifecycle, timeout, cleanup, lineage, and error-provenance cases while checking reader disposal.

All 46 existing executor cases remain. The replaced-preflight-owner case moved into the existing roots registration to respect the source line cap; its refusal and the existing service-owner refusal are now captured and asserted after executor settlement so cleanup cannot swallow assertion failures. No cases were removed, skipped, weakened, or given longer timeouts. The earlier truncating-corruption case remains distinct from the three new nontruncating cases. Negative tests capture actual product errors and assert them outside executor settlement. Every real fixture and delegated helper uses an explicitly private handoff SQLite path; the deterministic settlement mock never opens a database. Temporary paths and child processes are owned and cleaned, and mocks/environment state are restored.

@clawsweeper

clawsweeper Bot commented Sep 23, 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.

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 23, 2026 20:34
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: L labels Sep 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 1:08 AM ET / 05:08 UTC (Revision 7).

ClawSweeper review

What this changes

The branch reuses a read-only SQLite connection and prepared lease queries during update ownership checks, with integrity and lifecycle tests.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open. Current main still has the repeated-reader cost, and the reviewed authority path has no actionable defect. The exact-head published-updater compatibility run remains in progress.

Priority: P2
Reviewed head: 429b78030ad89bcff98c6e08118053afd4357a49

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong native and upgrade evidence supports a sound authority-preserving patch; final package-composition qualification remains pending.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The changed update lease reader is exercised through the real executor and child-process boundary against a private SQLite store: replacing a warmed owner's lease prevents the child's effect, while linked native and published-updater runs show after-fix operation. The final exact-head package cell is pending. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The changed update lease reader is exercised through the real executor and child-process boundary against a private SQLite store: replacing a warmed owner's lease prevents the child's effect, while linked native and published-updater runs show after-fix operation. The final exact-head package cell is pending. No stored-data contract changes.
Evidence reviewed 10 items Introduced reader lifecycle: The pinned PR delta retains one read connection within the executor and disposes it on preflight release or scope settlement.
Fresh checks on retained connection: Each retained read rechecks physical identity, resets SQLite pager and schema state, validates the lease table, and ends its transaction before returning.
Lease and process authority: A lease read obtains a fresh row; ownership also requires the current lease and live process identity.
Findings None None.
Security None None.

How this fits together

The update executor checks a managed SQLite lease before continuing work or handing it to a child process. The lease store supplies current ownership facts, while the executor decides whether work may proceed.

flowchart LR
A[Update command] --> B[Executor admission]
B --> C[Managed lease database]
C --> D[Retained read connection]
D --> E{File lease and process current?}
E -->|Yes| F[Continue update work]
E -->|No| G[Refuse and settle]
F --> H[Close reader at settlement]
Loading

Before merge

  • Resolve merge risk (P1) - The fresh published-updater Package Acceptance run for this exact head is still in progress. Earlier successful cells cover source-identical reader behavior, but not the final merged package composition.
  • Complete next step (P2) - Verify the exact-head published-updater Package Acceptance result before merge.
Agent review details

Security

None.

PR surface

Source +121, Tests +608. Total +729 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 164 43 +121
Tests 4 625 17 +608
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 789 60 +729

Review metrics

Metric Value Why it matters
Production and test delta production +164/−43; tests +625/−17 The production growth is justified by reader lifecycle and integrity handling; the larger test delta exercises native corruption, revocation, and disposal.
Measured lease-reader workload 281,956 checks; 250.6s baseline → 229.4s candidate This isolates the reported improvement from the larger combined preparation gain attributed to the separately merged path-index change.

Merge-risk options

Maintainer options:

  1. Finish exact-head upgrade proof (recommended)
    Check the pending published-updater Package Acceptance run for the final candidate, including its survivor and second-hop results.

Technical review

Best possible solution:

Keep per-fence physical, lease, and process checks with bounded reader lifetime, then ship once the exact-head published-updater upgrade cell passes.

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

Yes. Current-main source opens a reader on each lease observation, and the captured PR evidence records a matched workload with 281,956 checks; this read-only review did not execute that workload.

Is this the best way to solve the issue?

Yes. Reusing connection and query setup while refreshing physical and lease authority on each check addresses the measured cost without changing the lease contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6c2ebd8cd4ce.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The installed updater and final candidate must complete the repository's published-driver upgrade proof on the exact package composition.

Label justifications:

  • P2: This is a bounded update-preparation performance improvement for large installations, without evidence of a current widespread outage.
  • merge-risk: 🚨 security-boundary: Retaining a SQLite handle across ownership checks makes stale file, row, or process authority the key merge boundary, covered by the reviewed checks and final-effect test.
  • merge-risk: 🚨 compatibility: The installed updater and final candidate must complete the repository's published-driver upgrade proof on the exact package composition.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The changed update lease reader is exercised through the real executor and child-process boundary against a private SQLite store: replacing a warmed owner's lease prevents the child's effect, while linked native and published-updater runs show after-fix operation. The final exact-head package cell is pending. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed update lease reader is exercised through the real executor and child-process boundary against a private SQLite store: replacing a warmed owner's lease prevents the child's effect, while linked native and published-updater runs show after-fix operation. The final exact-head package cell is pending. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 0185544 adds src/infra/sqlite-existing-database.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 01855443a451; files: src/infra/sqlite-existing-database.ts)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (6 earlier review cycles)
  • reviewed 2026-09-23T20:55:35.186Z sha 15bf31f :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-23T23:14:52.259Z sha f214d48 :: blocked before merge. :: none
  • reviewed 2026-09-24T01:33:16.543Z sha f214d48 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T03:59:47.758Z sha 8719a7f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T04:13:48.851Z sha 8719a7f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T04:51:32.549Z sha 429b780 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 24, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 24, 2026
@fuller-stack-dev
fuller-stack-dev merged commit 8bb889e into main Sep 24, 2026
254 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the openclaw/updater-lease-reader-20260923 branch September 24, 2026 05:29
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…56757)

* fix(update): reduce CPU time in repeated ownership checks

* test(update): repair native Windows executor fixtures

* test(update): respect Windows SQLite sharing in reader fixtures

* test(update): preserve reader fixture failure provenance

* test(update): assert exact Windows sharing failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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: L 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