Skip to content

fix(state): retain startup integrity proof through idle retirement - #166412

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-integrity-proof-store-closed-20260919
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-integrity-proof-store-closed-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes lost startup integrity proof when an agent executor retires while its background full check is queued or publishing. A successful scan previously reached a closed SQLite worker store, leaving the next orderly restart without reusable clean-close proof.

Related: #166112, #165993.

User Impact

A deferred full check retains its original writer across idle expiry and warm-pool eviction. Its normal final checkpoint and close can then make the verification reusable at restart. Explicit close, revoked admission, foreign commits, and file replacement still prevent stale publication. No schema, configuration, update, or rollback contract changes.

Why This Change Was Made

Full checks now borrow the existing executor at enqueue time. The verifier queue releases that borrow after result application, scan failure, cancellation, or supersession, and preserves it across verifier handoff. Shutdown joins asynchronous cleanup. The existing shared-state identity check moves into the execution-scope module to keep the executor within its line cap; its physical-store and Windows environment-casing checks are unchanged.

Production LOC delta: +47 (65 added, 18 removed). The missing queue ownership and cleanup contract requires retaining the same admitted writer through asynchronous verification. The small scope extraction preserves the existing admission contract and file cap. This uses one borrower/retirement owner, with no second proof path, cache, or retry loop.

Evidence

All heavy validation uses Blacksmith Testbox (blacksmith-testbox, profile openclaw-check). Behavior proof and review used 07e9a2519420, which includes the four-slot warm executor pool. Publication was rebased onto 2beca62e67b1 with an identical stable patch ID; only this lane's commit remains on top.

  • Before: on that base, the real killed-process/WAL regression fails with background-idle-swap: expected undefined for the verification record after five sibling agents create eviction pressure. Testbox tbx_01m4a207gmf2bt324zp81fnzm7, node scripts/run-vitest.mjs src/state/openclaw-agent-execution.integrity.test.ts --maxWorkers=1 -t 'classifies dead-owner': expected failure, 13.67 s wall.
  • After: the integrity, verifier, shutdown, and idle-pool suites pass 79 tests on that lease. node scripts/run-vitest.mjs src/state/openclaw-agent-execution.integrity.test.ts src/state/openclaw-database-verify.shutdown.test.ts src/state/openclaw-database-verify.test.ts src/state/openclaw-agent-execution.idle.test.ts --maxWorkers=1: 40.82 s wrapper time; integrity file 27.57 s wall, unit files 8.79 s. The regression retains proof through eviction and expiry, completes clean close, and reopens with zero integrity/foreign-key scans. Its real process-death provenance and native lease lifetime require the existing worker fixture.
  • Final integrated gate and identity-contract tests: Testbox tbx_01m4a32k1zv3bqsb2kg27ax6m5; exact hashes of all seven files are checked before node scripts/check-changed.mjs --staged and node scripts/run-vitest.mjs src/state/openclaw-agent-execution.integrity.test.ts src/state/openclaw-database-verify.shutdown.test.ts src/state/openclaw-database-verify.test.ts src/state/openclaw-agent-execution.idle.test.ts src/state/openclaw-agent-execution.creation-witness.test.ts --maxWorkers=1. Gate passed; 110 tests passed. The combined remote command took 26m58.7s; focused wrapper time was 74.84s. Final reported test time: integrity 26.868s, verifier shutdown 0.025s, creation-witness 14.930s. All owned leases were stopped.
  • Review: final independent review is scoped-clean, with no actionable P0–P2 findings.
  • CI: exact-head run 37565241487 failed in eight Node test shards (plus the aggregate gate). The 40 executed Node shard jobs consumed 11,496 summed runner-seconds. See the clean-main reproduction below.

Some reused-lease checksum syncs timed out before commands started. Fresh, normally synced leases supplied the passing validation above.

Gap: no live Gateway deployment or production latency measurement. This repair is measured by retained proof and avoided repeat integrity scans.

Inherited CI failures reproduced without this patch

On Blacksmith Testbox tbx_01m4a5xc7gfhw7kf7kkzvmkvhm, a separate clean worktree at main 3a085ea5dee4c704c6df4e972ae84335177aed09 ran each file below with node scripts/run-vitest.mjs <file> --maxWorkers=1, preserving each file's test order. No lane patch was applied. All ten files failed, with 36 failures in 394.6 seconds of remote command time. Each of the eight failed CI shards has an exact matching baseline case (22 matching cases overall). Configuration lifecycle failure case identities also vary during isolated replay, so the remaining individual case differences are not claimed as proven fixes or exact reproductions.

  • src/auto-reply/reply/reply-turn-admission.worker.test.ts
  • src/config/sessions/session-transcript-reconcile.lifecycle.test.ts
  • src/config/sessions/session-transcript-reconcile-pool.test.ts
  • src/gateway/server.chat.gateway-server-chat-b.test.ts
  • src/gateway/server.sessions.create.authority.test.ts
  • src/gateway/server.sessions.create.lifecycle.test.ts
  • src/gateway/board-store.test.ts
  • src/cron/session-registry-maintenance.test.ts
  • src/gateway/worker-environments/live-events.test.ts
  • src/gateway/server-methods/chat-send-global-identity.test.ts

The failures include expectations of one idle executor where four can now remain warm, admission closed after config publication, and related existing lifecycle assertions. The baseline lease is stopped. These inherited failures remain unresolved; main repairs are still needed for green CI. Independent inherited-failure qualification and the verified merge are recorded in the landing comment.

Keep a logical executor borrow from enqueue through full-check result
publication. Release it when verification completes, fails, is superseded,
or is canceled, and preserve custody across verifier handoff.

This prevents idle expiry and warm-pool eviction from closing the original
writer before its integrity receipt is retained. Explicit close, revoked
admission, foreign commits, and physical-file replacement still refuse proof.
Move the unchanged shared-state identity check into the execution scope
owner to preserve the executor's file-size limit.
@clawsweeper

clawsweeper Bot commented Oct 7, 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 labels Oct 7, 2026
@steipete
steipete enabled auto-merge (squash) October 7, 2026 03:10
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 11:49 PM ET / October 7, 2026, 03:49 UTC (Revision 2).

ClawSweeper review

What this changes

The PR keeps an agent’s SQLite executor alive until background integrity verification settles, preserving reusable restart proof through idle expiry and eviction.

Merge readiness

✅ Ready for maintainer review

This repair remains necessary on current main. No actionable introduced defects were found, and the recorded production-boundary validation supports the change.

Priority: P2
Reviewed head: bc09ab787d47a9ff7b9d8066c1e94632686ca81d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful production-boundary evidence and no blocking review findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.
Evidence reviewed 7 items Pinned introduced patch: The merge-base-to-head patch adds executor retention at full-check enqueue, idempotent queue-owned release, and shutdown cleanup joins. The shared-state identity check is extracted without changing its physical-store or Windows environment semantics.
Current main still lacks retention: Fetched main retains the background publication callback but has neither the queued release contract nor the executor borrow. The central repair is therefore still missing; the related merged changes do not supersede it.
Publication authority remains live: The retained borrow affects resource lifetime. Publication still checks verifier lifetime, shared admission, and logical/native ownership. The worker admits transaction and commit, while the existing lifecycle owner checks revocation, physical identity, and connection-local data_version under BEGIN IMMEDIATE.
Findings None None.
Security None None.

How this fits together

Agent database admission can defer a full integrity scan after a proven process crash. The background verifier returns successful results to the original writer, whose orderly checkpoint and close can certify proof for the next restart.

flowchart TD
  A[Agent database admission] --> B[Queued full integrity check]
  B --> C[Retained executor borrow]
  B --> D[Verifier child scans SQLite]
  D --> E[Original writer checks current admission and continuity]
  E --> F[Durable verification]
  E --> G[Release executor borrow]
  F --> H[Clean close enables restart reuse]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +47, Tests +128, Docs +4. Total +179 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 65 18 +47
Tests 2 140 12 +128
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 209 30 +179

Review metrics

Metric Value Why it matters
Production versus regression growth production +47 net lines; tests +128 net lines The PR explains the production growth as missing asynchronous custody and cleanup, while tests cover retirement and settlement behavior.

Technical review

Best possible solution:

Keep verification custody within the existing executor and queue owners while preserving live publication checks and clean-close certification.

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

Yes: current main queues publication against the original writer without retaining its executor, allowing idle retirement to close it first. The PR records a failing real SQLite eviction regression; this review did not execute tests.

Is this the best way to solve the issue?

Yes: borrowing the existing executor through verification settlement repairs the missing lifetime contract without adding a second proof owner or relaxing publication safeguards.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 30d563e262aa.

Labels

Label changes:

  • add P2: Lost reusable verification causes unnecessary restart scans within a bounded database lifecycle path.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.
  • 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 (terminal): Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.

Label justifications:

  • P2: Lost reusable verification causes unnecessary restart scans within a bounded database lifecycle path.
  • 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 (terminal): Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Testbox runs exercise the production executor, real SQLite worker, and verifier child after process death: expiry and eviction retain verification, normal close certifies it, and reopening performs zero repeat full scans. Negative controls preserve stale-publication rejection. Shutdown unit tests are supplemental; no stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced patch: The merge-base-to-head patch adds executor retention at full-check enqueue, idempotent queue-owned release, and shutdown cleanup joins. The shared-state identity check is extracted without changing its physical-store or Windows environment semantics. (src/state/openclaw-database-verify.ts:59, bc09ab787d47)
  • Current main still lacks retention: Fetched main retains the background publication callback but has neither the queued release contract nor the executor borrow. The central repair is therefore still missing; the related merged changes do not supersede it. (src/state/openclaw-database-verify.ts:11, 30d563e262aa)
  • Publication authority remains live: The retained borrow affects resource lifetime. Publication still checks verifier lifetime, shared admission, and logical/native ownership. The worker admits transaction and commit, while the existing lifecycle owner checks revocation, physical identity, and connection-local data_version under BEGIN IMMEDIATE. (src/state/openclaw-agent-execution-native.ts:548, bc09ab787d47)
  • Real SQLite lifecycle regression: The complete regression uses SIGKILL provenance, real native SQLite workers, and a real verifier child. Added scenarios release the foreground borrower, advance idle expiry or open five sibling agents, publish verification, close normally, and assert zero integrity/foreign-key scans on reopening. Existing foreign-write, revoked-admission, explicit-close, and file-replacement controls remain. (src/state/openclaw-agent-execution.integrity.test.ts:584, bc09ab787d47)
  • Recorded after-fix validation and inherited CI failures: The captured PR body records a failing before-fix idle-eviction case, passing after-fix recovery with zero repeat scans, and a final file-hash-verified Testbox gate with 110 passing tests. It separately records clean-main failures matching all eight failed CI shards. These are contributor-recorded results, not checks executed during this read-only review; no live Gateway or production latency claim is made. (bc09ab787d47)
  • Merged feature history and routing: The warm-executor owner was changed by merged perf(state): switching between agents reopens agent database executors on every request #165993; background verification publication was added by merged perf(state): reuse background integrity checks on clean restarts #166112. Local path history connects both to Peter Steinberger. The exact warm-pool source line was compared against the commit's raw recorded parent. (src/state/openclaw-agent-execution.ts:67, 1240759624a5)

Likely related people:

  • Peter Steinberger: Raw commit 1240759 adds src/state/openclaw-agent-execution.ts:71 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1240759624a5; files: src/state/openclaw-agent-execution.ts)

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 (1 earlier review cycle)
  • reviewed 2026-10-07T03:10:57.917Z sha bc09ab7 :: needs maintainer review before merge. :: none

@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 Oct 7, 2026
@steipete

steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Verified inherited-failure landing qualification for exact head bc09ab787d47a9ff7b9d8066c1e94632686ca81d.

I inspected all eight failed Node job logs from CI run 37565241487, including 40 reported cases across 12 files. The checkout was merge 57d5a6cb0800449a3377bd64046be05ba67b3ef2, whose first parent is unchanged main 2beca62e67b1fb3bc1f55ad3025f2eb5d50d4c3d. Independent main runs 37563803327 and 37567947157 reproduce 22 exact cases, with a matching baseline failure for every failed job. These cover reply-turn release, transcript reconciliation, board reopening, Gateway chat/session lifecycle, history HTTP, worker live events, and config changes after chat.send ACK.

The distinct cron failures were independently reproduced on an isolated Linux rig at that exact unchanged first parent: node scripts/run-vitest.mjs src/cron/session-registry-maintenance.test.ts --maxWorkers=1 failed both “preserves stores held by missing deletion history” and “preserves stores held by reconstructed deletion history” byte comparisons; 8 other tests passed (249.49 s wrapper). Thus 24 case identities have exact baseline matches. The remaining 16 admission-closed case identities vary with lifecycle ordering; their unchanged config-retirement/capture producer and matching baseline fixture stacks establish the same inherited cause, but I am not claiming exact case-for-case reproduction. All 36 named failure inputs are unchanged between the inspected main baselines and the tested merge. The PR's retained borrow is reached only for deferred full verification; it does not alter those existing rejection conditions, warm-pool policy, or the cron fixture's asynchronous checkpoint race.

Exact-head validation on Blacksmith Testbox tbx_01m4aawaqnkmnxcq85dx283yej passed: export-name collision guard; eager-import and PR-wrapper source-closure tests (20 passed, 18.81 s); and the 135 state sibling files absent from CI (1,205 tests passed, 7 skipped, 259.36 s). Two Windows-only files were skipped on Linux, not claimed as Windows proof. The other 87 direct state siblings have passing CI evidence. The combined remote command exited 0 and the lease was stopped. Fresh independent review found no actionable P0–P2 findings; current security checks pass.

The PR CI run was not rerun, and the branch was not updated or given an unrelated fix. The native merge route refused before submission because its review worktree was unavailable; initialization in the isolated landing checkout is blocked by missing tooling dependencies on this restricted host. The authorized REST fallback pinned the exact reviewed head and landed squash commit a6092b141bc2ce77f78f45d51107d6259ef1a816. Fresh remote verification confirms MERGED, the commit is on main, and its tree exactly matches merging the pinned PR head into the actual landed parent. Historical CI remains red with the inherited failures described above.

@steipete
steipete merged commit a6092b1 into main Oct 7, 2026
154 of 164 checks passed
@steipete
steipete deleted the steipete/perf-micro-integrity-proof-store-closed-20260919 branch October 7, 2026 05:07
steipete added a commit that referenced this pull request Oct 7, 2026
Merge current main to include the warm schema-admission fix from #166253 and startup integrity-proof retention from #166412. The profile cutover delta is unchanged; repeat its integration gates and matched measurements on this baseline before landing.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…penclaw#166412)

Retain the originally admitted SQLite executor while a deferred full integrity check is queued, scanning, or publishing, and release it after verification and cleanup settle. This preserves clean-close proof through idle expiry and eviction without relaxing stale-publication checks or changing stored schemas.

Validated with exact-head export/closure guards and 1,205 additional state sibling tests on Blacksmith Testbox. Inherited CI failures independently qualified against main; see the PR landing evidence. No live deployment was performed.
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 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