Repository navigation
perf(state): preserve database witnesses across managed restarts - #159753
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 27, 2026, 5:46 PM ET / 21:46 UTC (Revision 9). ClawSweeper reviewWhat this changesThe branch preserves native stop time during supervised restarts, retains a dirty database verification receipt for later certification, bounds integrity timing logs, and updates related tests and docs. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: current main still has the reported restart behavior. The runtime repair is well supported, but its durable recovery contract lacks recorded maintainer acceptance and copied-state upgrade proof. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s Gateway drains active work and closes SQLite databases during a managed restart. On startup, database admission uses a persisted verification receipt to decide whether an expensive integrity gate is needed. flowchart LR
A[Managed restart] --> B[Active work drain]
B --> C[Close database writers]
C --> D{Checkpoint completed?}
D -->|Yes| E[Clean receipt]
D -->|No| F[Dirty receipt]
E --> G[Cached startup admission]
F --> H[Integrity scan]
Decision needed
Why: This changes durable retention and recovery semantics, which repository policy reserves for recorded maintainer acceptance; runtime benchmark results cannot decide that contract. Before merge
Agent review detailsSecurityNone. PR surfaceSource +58, Tests +206, Docs +11. Total +275 across 21 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the native supervisor deadline and bounded diagnostics, and retain dirty receipts under an accepted recovery contract proven against copied released state. Do we have a high-confidence way to reproduce the issue? Yes, as a controlled source-backed path: a managed SIGTERM restart with a 30-second drain and 90-second native deadline exposes the premature stop, while a reader-pinned checkpoint exposes lost certification. This read-only review did not execute current main. Is this the best way to solve the issue? Unclear overall. The owner-level shutdown and receipt changes fit the failure path, but retaining durable verification metadata needs an accepted recovery contract and released-state upgrade proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2c962c0d6701. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
dd1aa58 to
b37c404
Compare
4db5efd to
55fe1b7
Compare
Keep native SIGTERM stop time available for database cleanup and preserve dirty verification after reader-blocked checkpoints. Retain crash invalidation and log bounded table costs with explicit missing-proof reasons.
Reconcile the source-owned fixture changes in #159852 with the native cleanup mode correction in #159841. These fixtures run without sandbox process admission and must exercise native terminal cleanup, including joined settlement and RPC failure. Source-owned sandbox behavior remains covered by the unchanged real-child suite.
6102b74 to
b2c5097
Compare
…ecovery #159179 replaced the retired task-registry check (every unended run read as "running") with resolveSubagentSessionStatus, which correctly reports unended gateway-restart runs as "interrupted". Assert the session status matches the non-terminal expected state, restoring the four interrupted cases on main. (cherry picked from commit b459eb6)
Join the existing persisted-snapshot signal before the first bounded catalog request. Keep the native hydration, hot-path measurements, response deadline, and all performance assertions unchanged.
…nclaw#159753) * perf(state): preserve database witnesses across managed restarts Keep native SIGTERM stop time available for database cleanup and preserve dirty verification after reader-blocked checkpoints. Retain crash invalidation and log bounded table costs with explicit missing-proof reasons. * test(subagents): check expired scope rejection at row readers * test(state): verify dirty receipts through native writer close * test(codex): match cancellation proof to native execution mode Reconcile the source-owned fixture changes in openclaw#159852 with the native cleanup mode correction in openclaw#159841. These fixtures run without sandbox process admission and must exercise native terminal cleanup, including joined settlement and RPC failure. Source-owned sandbox behavior remains covered by the unchanged real-child suite. * fix: repair artifact and upgrade validation after Task retirement (openclaw#159819) * fix: complete Task retirement test and harness cleanup * test: finish retirement selector and async fixture cleanup (cherry picked from commit fad8e39) * fix(test): keep interrupted subagent restarts interrupted in orphan recovery openclaw#159179 replaced the retired task-registry check (every unended run read as "running") with resolveSubagentSessionStatus, which correctly reports unended gateway-restart runs as "interrupted". Assert the session status matches the non-terminal expected state, restoring the four interrupted cases on main. (cherry picked from commit ea2fe01) * test(gateway): await catalog hydration before resident benchmark Join the existing persisted-snapshot signal before the first bounded catalog request. Keep the native hydration, hot-path measurements, response deadline, and all performance assertions unchanged.
What Problem This Solves
Managed SIGTERM restarts could lose the clean agent-database witness and repeat an expensive admission scan. The full table-timing array also hid the slowest tables when console metadata was truncated.
User Impact
Same-version restarts can reuse the witness after successful checkpointing and final writer closure. The requested active-run drain stays unchanged; cleanup can use the remaining native service-stop budget. Crashes, failed closes, foreign ownership, and file/version replacement retain their admission checks. No configuration, schema, or stored user-data changes.
Why This Change Was Made
Two paths prevented certification: a supervised restart shortened its known stop deadline to the requested drain plus ten seconds, and a healthy reader-blocked checkpoint deleted the verification row that a later successful last writer needed to certify.
The stop-budget owner now keeps the native deadline for external SIGTERM restarts. The verification owner retains a dirty row after healthy incomplete checkpoints; only the existing last-lease checkpoint/close path marks it clean. Admission diagnostics distinguish stale leases, matching dirty receipts, and other invalidation. Deadline logs describe incomplete cleanup even when the supervisor requires exit status zero. Timing summaries report the ten slowest tables plus complete counts and elapsed totals per check kind. Production delta: +58 net lines.
Evidence
Blacksmith Testbox, profile
openclaw-check:tbx_01m3hjttenszx5d3cvr7n3gtct: same 64 MiB fixture, three cold admissions after pinned-reader eviction and final checkpointed close. Baseline validation 12.90–15.15 ms, median 13.86 ms, missing witness, table gate. Candidate 5.22–6.23 ms, median 6.11 ms, clean witness, cached admission (56% lower median). A real child killed with SIGKILL still ran the table gate: 14.89 ms, reasonstale-lease.tbx_01m3hknbrr4mq7q51rvzt7hrc6: real Gateway startup, persisted restart intent, SIGTERM handler, active reply cancellation, registered server close, resource drain, SQLite checkpoint/close, and cold cached reopen. With a 30-second drain and 90-second native timeout, the original code recordedforced_stopat 40 seconds; the repair completes cleanup at 45 seconds and records onlyplanned_restart.Primary validation on
tbx_01m3hnz8a3km41tvemd6befq06(workflow):node scripts/check-changed.mjs --base b1935b05e8814792587d26e5f1a770f38737ab9fpassed core types, all 25 selected test graphs, lint, formatting, and guards. 336 focused tests passed across Gateway close, run-loop, shutdown budget, integrity, integrity worker, admission cache/policy/timing, lease, and quarantine suites. Changed source inputs were hash-verified.Latest refreshed-base validation on
tbx_01m3j7tnr5b0n0a7qcgathg8kb: the original 12-file Codex group passed 89/89; the three corrected files passed individually; the Gateway close, native writer-close, integrity diagnostic, admission timing, and real-child process-ownership replay passed 65/65 in 69.21 s.node scripts/check-changed.mjs --base HEAD -- <three corrected Codex tests>passed the scoped static gate, including extension test types, formatting, guards, export checks, and lint. The combined command took 547.48 s; the lease is stopped. All 19 changed files plus the two relevant Codex production owners were hash-verified. Missing dependencies were installed once withpnpm install --frozen-lockfileon the lease.CI repairs and upstream reconciliation
CI exposed stale test expectations in addition to the witness change. The subagent regression now checks ended-scope rejection at the actual row readers; readiness probes intentionally return unavailable. On
tbx_01m3hvvfs5bq9ekh4nh7gg7010, the original 79-file shard reproduced 1 failed / 1,053 passed, then passed 1,054/1,054. Native-worker blocked-checkpoint cases now requireclean_close=0, with the final writer required to publishclean_close=1; all 22 cases passed ontbx_01m3hygy9krx7tdr7cdsa3fj7b.Main owns the malformed PNG correction in #159771 and the media/ACP type repairs in #159836; duplicate task commits were removed. Concurrent #159852 changed non-sandbox Codex fixtures to expect source-owned cleanup, while #159841 restored native terminal cleanup outside sandbox process admission. Their combination produced five failures in CI run 36345413499. This PR reconciles those three tests with the actual execution-mode contract: native list/terminate/confirmation outside the sandbox, concrete source-owned process cleanup inside it. It preserves exact-turn confirmation, joined cleanup, propagated failures, activation cleanup, and Computer Use cancellation. The unchanged real-child suite protects independent sandbox work. No additional Codex production change remains in this PR.
The next CI run exposed one artifact-selector case left behind by Task retirement. Upstream #159819 (
14ef6ab47832) removes only that retiredtaskIdexpectation; supported run/session selectors and disclosure checks remain covered. On Blacksmith Testboxtbx_01m3j9jksb9yccryfyh04ym788, the original Gateway-methods group reproduced 1 failed / 971 passed / 2 skipped, then passed 972 / 2 skipped, followed by 70/70 in its isolated configuration with the exact upstream patch. The focused file passed 10/10 in 23.04 s; explicit-file changed checks passed types, formatting, guards, export checks, and lint. The complete comparison/check command took 700.87 s; the lease is stopped, and fresh P2 review was scoped-clean.The full compact-large-6 bundle then exposed a stale restart-status assertion after its artifact group passed. Upstream
b459eb600f23restores the table-defined interrupted/running expectation after Task retirement changed the status reader. On Blacksmith Testboxtbx_01m3jbnam8zzr2mqp4cx4n9ye2, the original 77-file group reproduced 4 failed / 1,004 passed. With the exact upstream patch, the entire original four-group bundle passed 2,639 tests / 2 existing skips, including the two groups previously hidden by fail-fast. The focused restart file passed 27/27 in 45.65 s, and explicit-file changed checks passed types, lint, formatting, guards, and export checks. The comparison plus full proof took 926.20 s. Fresh P2 review was scoped-clean, and the lease is stopped. This adds no production behavior, cases, fixtures, or delays; the existing restart file includes real SQLite persistence, lifecycle rotation, and cold restoration, with 56% of its focused Vitest duration spent in transformation.The resident catalog benchmark exposed one timing-dependent CI failure (
catalog_pending) after the earlier groups passed. Its existing hydration-completion wait occurred after the first bounded requests. The test now joins that same persisted-snapshot signal before its first request and reuses the namespace later; production deadlines, measured hot calls, and all I/O/CPU assertions remain unchanged. The exact failing list call could not be identified from the redacted CI stack, and the original 19-file Testbox replay passed, so that replay alone is not claimed as a fix.On Blacksmith Testbox
tbx_01m3jdse4q3cjt9ttmq0rpddpq, a temporary cold-start fault accelerated the response deadline only while the actual hydration marker was pending: the original ordering failed with the samecatalog_pendingerror and the candidate passed. Instrumentation was then removed and production/test hashes verified. The uninstrumented candidate passed 20/20 focused runs (single-worker command median 29.82 s, range 26.59–34.16 s), 3/3 original 19-file shard runs with 259 tests each (148.93 / 151.67 / 156.87 s), 12 catalog-budget tests, and scoped changed checks. The final stability/check command took 1,400.58 s. Fresh P2 review was scoped-clean; the lease is stopped.The database-related commits are patch-identical across the final base refresh (
git range-diff). Independent Codex reviews were scoped-clean through P2 for the production change and earlier CI repairs; the final three-test reconciliation also passed fresh P2 review.Test cost
Single-worker command wall time (
pnpm test <file> --maxWorkers=1), measured remotely:src/gateway/server-close.agent-databases.test.tssrc/cli/gateway-cli/run-loop.test.tssrc/infra/sqlite-integrity.test.tssrc/state/openclaw-agent-db.integrity-cache.test.tssrc/state/openclaw-agent-db.integrity-policy.test.tssrc/state/openclaw-agent-db.open-timing.test.tssrc/agents/subagents/registry/subagent-registry-state.async.test.tssrc/state/openclaw-agent-execution.integrity.test.tsextensions/codex/src/app-server/run-attempt-thread-cleanup.test.tsextensions/codex/src/app-server/run-attempt.activation.test.tsextensions/codex/src/app-server/run-attempt.computer-use.test.tssrc/gateway/server-methods/artifacts-session-resolution.test.tssrc/agents/subagents/registry/subagent-orphan-recovery.restart-integration.test.tssrc/gateway/server-methods/session-catalog.performance.test.tsGateway and CLI coverage retain real lifecycle/process boundaries; command wall time includes worker/module transformation. The new managed-restart case replaces an existing case, uses a controlled clock, and took 1.66 s. A same-lease warm-cache comparison of the original and updated Gateway test file on identical final production code measured 17.68 → 17.11 s, with all four tests passing. Final CI run 36355972726 passed on exact head
ec600543ac321e90d4fe8f8e725f47936eae171d: 129 successful jobs, 19 skipped jobs, andopenclaw/ci-gategreen. Job wall times, including setup and all tests in each bundle: Linux compact-large-6 414 s, Codex bundle-13 255 s, Windows shard-4 272 s. These are job costs, not per-file estimates. The PR merged as0722b96fe87a7b03e4b089caacdfeaec175f9852after validation.Limits
The Gateway fixture controls time, the systemd timeout response, and the process-exit callback; it does not run a real systemd unit. The benchmark uses 1,024 synthetic 64 KiB rows. Production-scale restart latency, the live Gateway, and a published-package upgrade were not tested.
An earlier broader storage replay produced 1 failed / 1,274 passed / 1 skipped across 69 available files; two moving-base files were unavailable. Standalone
state-migrations.caller-mode.plugin-execution.test.tsproduced 2 failed / 21 passed. Diagnostic replay identifiedplugin lifecycle lease core:plugin-lifecycle/global was lostin indexed post-session-repair cells. No safe migration repair was established here, and no migration assertions or authority checks were relaxed. Completed unbrokered background-source revocation received no new OS-settlement proof in this lane.