Skip to content

perf(state): keep agent startup inspection proportionate - #188459

Merged
steipete merged 8 commits into
mainfrom
steipete/perf-micro-proportionate-startup-inspection-20260919
Oct 30, 2026
Merged

steipete merged 8 commits into
mainfrom
steipete/perf-micro-proportionate-startup-inspection-20260919

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large agent databases can leave sessions unavailable for minutes after a restart because writable admission scans the entire database. Graceful shutdown can also lose its clean-close seal when an idle writer closes before a retained reader.

Related: #186783. That fix is already present in both reported affected builds; this addresses residual close ordering and startup scan cost.

User Impact

Exact current-schema agent databases recover through SQLite and bounded structural checks before readiness; full integrity and foreign-key verification continues in a cancellable background child. A matching clean-close seal skips that scan. Existing schema/index repair and migration gates remain foreground.

Integrity policy for maintainer review: ordinary reads and writes may run before the background verdict, so untouched damaged pages can exist during that interval. Proven corruption revokes admission and persists quarantine, makes the agent unavailable in readiness/status, and directs the operator to Doctor. Cancelled or inconclusive verification never supplies a seal. Background-discovered FTS damage also requires Doctor; automatic backed-up FTS repair remains on the foreground repair path. No schema or stored-data format changes.

Why This Change Was Made

Keep dependent readers in the existing ordered drain before the last writer closes. A native SQLite reproduction shows that even an idle read-only connection can strand the WAL after the last writer closes; no active reader transaction is required. The production reader responsible for the reported receipt was not directly observed.

Use the existing startup owner, native execution owner, and quarantine store for the new provisional-admission lifecycle. At most two full scans run at once. Provisional admission publishes no integrity receipt; only a successful full scan supplies this path's full-verification timestamp. The existing ordinary-open crash-recovery QUICK receipt remains distinct.

Runtime production delta is +507 lines (+546/-39); the benchmark adds 302 lines and tests/support add 301 net lines. The growth is required by the delegated integrity policy: provisional admission must remain distinct from completed verification across native workers, the asynchronous scan needs bounded/cancellable ownership, and corruption must remain durably refused after its agent writer is retired. It reuses the existing integrity worker and quarantine database rather than adding a second validator or a new store.

Evidence

Synthetic fixture: 10,000 sessions, 9.82 GiB initially (9.87 GiB after ordinary Gateway usage-projection maintenance). Fresh-process owner measurements on base 885e57e9f9d1 and the candidate patch, with a committed 12,392-byte WAL left by SIGKILL:

Owner measurement Base Candidate
Unclean admission ready 200.29 s 16.55 s
Full verification complete 200.29 s 152.12 s
Main-thread CPU (untraced pass) 205.9 ms 222.6 ms
Sampled allocations (separate pass) 48.67 MiB 52.04 MiB
Parent RSS after verification 435.17 MiB 471.32 MiB
Parent heap used after verification 63.97 MiB 64.49 MiB

Clean owner admission reused its seal: 4.53 s base, 1.56 s candidate. Every healthy owner run finished with a valid seal. The improvement is reduced blocking time, not less full-scan work or a CPU/allocation reduction. Native scan CPU and child RSS are excluded from these owner counters; these are single startup observations on a shared Mac, not controlled throughput or tail measurements. End-of-arm 1/5/15-minute host load: base 48.8/56.4/55.5, candidate 33.3/43.9/52.3. Allocation passes use 32 KiB sampling including collected objects.

Built Gateway proof uses the same database and real HTTP readiness plus WebSocket sessions.list (10 returned, 10,000 total), with isolated loopback ports and state. Base build is 885e57e9f9d1; candidate build is f7e1032c80183546431ae61fc7208050b227485a (before the later shutdown refinements below).

Built Gateway observation Base Candidate
Clean restart readiness 30.11 s 14.25 s
Small-WAL SIGKILL recovery readiness 186.39 s 18.14 s
Full background verdict after launch foreground 158.28 s
Clean-run graceful shutdown 558 ms 233 ms
Recovered-run graceful shutdown 333 ms 301 ms
Recovered-run single sessions.list response 1,014 ms 613 ms
Recovered-run parent RSS at readiness 1,386.58 MiB 1,744.66 MiB

All four healthy runs acknowledged graceful shutdown, exited 0, and wrote the clean-close seal. The candidate served the session list before its full integrity verdict. RSS is a point observation at different phases of startup, not a peak or retained-memory comparison. These are single shared-host observations, not p99s. Start/end 1/5/15-minute host load: base clean 56.4/61.9/59.4 → 70.4/64.1/60.5; candidate clean 32.7/27.2/28.8 → 39.3/30.1/29.7; base unclean 46.9/51.9/54.2 → 61.2/56.1/55.4; candidate unclean 65.4/41.3/34.0 → 55.9/45.5/36.9. No throughput, tail-latency, GC-rate, or CPU-reduction claim is made.

Two immediate-after-readiness baseline stops exceeded the harness's 120 s deadline while startup usage projection drained; both wrote a database seal. The steady-state clean-stop protocol allows the same 60 s post-readiness settling window in both arms. Physical-corruption proof passed on the built candidate: after damaging the cache_entries root page in the same 9.87 GiB database, the background integrity check reported corruption at 120.42 s, HTTP readiness returned 503, and a real WebSocket sessions.create was refused with UNAVAILABLE. The Gateway acknowledged shutdown and exited 0 in 339 ms, with no clean-close seal. Native integration tests separately prove the durable quarantine refusal across reopening.

Focused proof: the clean-close regression fails on the base and passes with the fix; integrity/quarantine, native execution/restart recovery, reader-resource, and startup-index tests pass. All 26 Gateway preparation tests pass, including two regressions that first reproduced stale config-change quarantine. Import-closure checks found one missing wrapper inventory path; it is fixed and the affected six checks pass (remaining closure checks had already passed). Changed-file lint, format, export-name collision checks, and the core typecheck pass. No schema or budget/baseline changes.

This startup admission policy is not a turn-processing hot-path optimization. The lane's FAST PATH exception applies; no multi-pair ten-minute load campaign was run. No live service or production database was touched.

Independent subagent review (autoreview route unavailable): no actionable findings. The configured helper rejected the selected provider route before starting; operator configuration was not changed.

The initial candidate runtime build passed on f7e1032c80183546431ae61fc7208050b227485a, which is also the built-Gateway measurement head above. Build preparation first exposed stale installed dependencies after rebasing (resolved by the frozen install), then a strict import-boundary warning introduced here (fixed by keeping quarantine dispatch in the existing lazy verification module).

CI found and this PR repaired import cycles, a test connection-type mismatch, native-header query ownership, and an early-shutdown lease handoff regression. Resource retirement now notifies the writable lifecycle through a registered callback, keeping the resource registry independent of its caller. The existing idle timer closes the deferred writer after readers and workers settle. It never starts path-wide revocation: a new native-worker regression first failed against that discarded approach, then passed with the final passive callback while committing accepted writes during shutdown. The portable seal test requires reader retirement itself to close/seal the writer without global drainage. The managed-shutdown test still requires zero leases while an independent sidecar remains held, with a bounded wait for asynchronous retirement. A startup cancellation fixture now requires an actual missing-index repair, preserving foreground integrity-child cancellation and exact database bytes under the new policy. No budgets were raised.

The next Linux CI pass exposed the remaining reader owner: an idle session-history pool retained its database through its normal 90-second/five-minute warm deadline. The exact managed-SIGTERM scenario reproduced the same held lease locally. Reader pools now use their existing idle retirement operation when shutdown cleanup starts; pending reads retain custody and retire only after settlement. A portable idle-versus-busy regression was red before this change and green afterward. The managed scenario then released all agent leases while its independent sidecar remained held, completed shutdown, and wrote a valid clean-close seal. Its Linux-only selection was temporarily removed only for local reproduction and restored before committing. Three setup failures shared one intentionally isolated resource-registry mock; adding the new callback-registration export repaired all three consumers without importing real lifecycle state.

Final reader repair validation: 57 tests passed across the three reader/usage consumers and native worker-store file, including the accepted-native-write regression. The original managed scenario passed locally; focused lint, format, runtime-cycle and Madge-cycle guards pass. The previously recorded typecheck, closure, and integrity results below remain supporting evidence. CI is the final Linux and broad validation.

Earlier repair validation: 47 focused shutdown/native-worker tests passed with one Linux-only skip; 27 import-sensitive Bun tests passed with one Linux-only skip, and 20 worker-consumer Bun tests passed. Both runtime and Madge cycle checks report zero cycles; focused lint, the persisted-catalog closure check, and export-name guard pass. Earlier repair validation also passed the failed state-test typecheck leaf, database dialect ratchet, startup shutdown-preparation case, and 55 native execution/integrity tests (one Linux-only skip).

The eight-commit stack is based on main 83064b3ae115, including #188462's provider-refusal notice fix, #188409's separate Linux quick-recovery receipt policy, and the auxiliary quarantine-file identity refresh. Independent integration review confirmed the QUICK/FULL distinction, quarantine ordering, and retained-reader lifetime. Following the earlier quarantine identity-refresh integration on base bd4d2c76a583, all 28 quarantine and database-verification tests passed. Final head is 4c0be2cb9b0dbdb39a32abcef756971f20c0b584; exact-head CI results and inherited failures are recorded below. The multi-GiB built-Gateway measurements above predate the final shutdown refinements, which are covered by native owner/Gateway tests.

A later CI failure exposed a fixture overlap in server.sessions.store-paths.test.ts: the configured-store case rebound the process state root beneath the suite Gateway. Five ordinary fresh-process runs on each of the pinned base and candidate did not reproduce it, so passing replays were not used to dismiss the failure. A temporary controlled interleaving selected the real suite registry after the real case-registry read, reproducing the exact registry-witness failure on base 8f1ef6c97eff. Removing only the state-root override passed the same interleaving, and the final uninstrumented file passed all five tests. Absolute configured stores, parent-child lineage, exact returned keys, and the no-directory-discovery assertion are unchanged; no diagnostic hook remains.

Final integration also includes main's #188402 marker-before-cleanup boundary and #188496 snapshot/shared-state retirement ordering. All 28 native-idle/worker-store tests and the now-portable managed-SIGTERM scenario pass with the marker boundary; independent source review confirms the later shared-state ordering preserves asynchronous quarantine and accepted native writes. On the preceding head, Linux CI passed all four agent-database shutdown cases, including the managed lease-release and written-seal proof. On exact final head 4c0be2cb9b0d, all 28 quarantine and database-verification tests pass with the new shared-state close ordering. Exact-final-head Linux CI passed all five configured-store discovery cases and the actual managed-SIGTERM lease-release/seal case, together with the agent-database shutdown siblings.

Known baseline evidence: doctor-usage-cost-cache.test.ts / unreadable temp entry reports two warnings instead of one on both the prior candidate and unchanged main ba6cfcd58df47a3037507362e45ed95757fae41c (main job). This is inherited evidence, not a passing result. A focused auth-product replay passed its original CI timeout case, then hit a different retryable catalog-generation-superseded error in the second case; that observation remains investigated but unclassified, and a passing replay alone is not claimed as a fix.

Final exact-head CI attribution (4c0be2cb9b0dbdb39a32abcef756971f20c0b584, run 41101511557): three jobs failed, all with unchanged-base evidence. The Doctor warning-count failure matches the main job linked above. The other two files were run individually on unchanged base 83064b3ae1155f0c6c96081c863e7db4bd4451f4 using OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs <file> --maxWorkers=1:

  • src/gateway/server-close.auth-usage.test.ts: 2 failed, 1 passed on both candidate and base. The failures expect an owner-closed error instead of the scheduler abort error, and expect the provider signal already aborted at the earlier request-admission boundary. Upstream fix: resume running channel threads after graceful restarts #188402 moved auth/model-account cleanup after restart-marker persistence; these unchanged tests still observe the earlier phase.
  • src/auto-reply/reply/reply-turn-admission.worker.test.ts: the same 4 full-idle-cache variants fail at line 440 on CI and base (base: 4 failed, 3 passed). The fixture signals restart drain without starting shutdown cleanup; fix: resume running channel threads after graceful restarts #188402 intentionally retains idle executors until that later cleanup signal, leaving one lease. The predecessor/successor settlement assertions pass. The owner, worker store, admission implementation, and test are unchanged by this PR.

These are recorded failures, not green replays. No CI rerun, budget increase, or unrelated source repair was used to obtain a passing result. The configured-store and actual Linux managed-shutdown cases pass on this exact head. Enforced exact-head review, dependency review, security-sensitive review, security-fast, all six Security High checks, and Opengrep pass. All three PostgreSQL conformance shards and the remaining execution jobs completed successfully. Landing uses the explicitly authorized inherited-failure exception for the three attributed jobs above; the CI aggregate remains failed.

Compatibility scope: the built-Gateway proof reopens the existing multi-GiB current-schema fixture, with retained sessions and normal writes. No latest-stable upgrade campaign was run; schema/index repair and migration admission remain on the existing foreground path, and no schema or stored-format change is introduced. The earlier advisory review requested Gateway/corruption proof when those scenarios were still pending; the completed results and this remaining upgrade-proof limit are recorded above.

@clawsweeper

clawsweeper Bot commented Oct 30, 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 gateway Gateway runtime scripts Repository scripts size: XL labels Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR drains dependent readers before writers close and moves full integrity verification behind bounded startup admission for current-schema agent databases.

Example: Restarting an agent with a 9.82 GiB database and a 12,392-byte committed WAL.

  • Before: The reported owner measurement took 200.29 seconds to admit writes.
  • After: The candidate admitted writes in 16.55 seconds while full verification continued until 152.12 seconds.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent owner-level implementation with focused behavioral coverage; shipped-entry-point and existing-state validation remain incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large agent databases leave sessions unavailable for minutes after restart, and lost clean-close seals force additional verification.
Reason: The reported reduction in blocked startup time is substantial, and maintainer authorship establishes direction for the explicitly documented integrity-policy tradeoff.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it addresses substantial restart delays and a clean-close ordering defect, with no definite introduced bug found in the pinned diff.

Priority: P2
Reviewed head: e34d51dc98b7629ba014455da72d03d56b8e6af0

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Complete the pending candidate built-Gateway recovery and physical-corruption scenarios, including cancellation and restart quarantine, and an upgrade from the latest stable release with retained settings and data.
Agent review details

How this fits together

Gateway startup inspects agent databases, prepares their native execution owners, and publishes readiness; background verification then supplies completed integrity receipts or revokes admission and records quarantine.

flowchart TD
  A[Gateway startup] --> B[Schema and ownership inspection]
  B --> C[Bounded native admission]
  C --> D[Agent reads and writes]
  C --> E[Background integrity child]
  E --> F[Verification receipt]
  E --> G[Admission revocation and quarantine]
  F --> H[Clean close seal]
Loading

Technical review

Best possible solution:

Retain the existing startup, execution, quarantine, and ordered-drain owners, and complete candidate Gateway and upgrade validation before landing.

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

Source traces the foreground full-scan and premature idle-close paths, and the body records native-owner measurements plus a base-failing clean-close regression; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The implementation separates provisional admission from completed verification while reusing established owners; its added lifecycle machinery serves cancellation, revocation, persistence, and seal eligibility rather than introducing a competing validator.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Deferred startup admission changes intended behavior with a stated reason (ec9de37: Retain slow database preparation under the Gateway lifetime while keeping affected agents unavailable until guarded preparation completes.)
  • Clean-close and idle-retirement lifecycle keeps the original intent (perf(sqlite): reuse database validation after clean shutdown #169649: Reuse completed validation only after a successful checkpoint and native close; retained readers can prevent that close from producing a seal.)
  • Automatic startup FTS repair changes intended behavior with a stated reason (fix(state): rebuild stale FTS indexes during agent database admission #176833: Back up and rebuild eligible stale canonical FTS indexes before admission; this PR explains why background detection no longer has exclusive pre-admission repair custody.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned change and clean checkout: Reviewed the introduced merge-base-to-head diff rather than endpoint drift; git status remained clean. (e34d51dc98b7)
  • Bounded admission preserves required schema gates: Provisional admission applies only to the current schema without pending same-version migration or an explicit integrity-check request; other paths retain existing verification and repair. (src/state/openclaw-agent-db-schema.ts:196, e34d51dc98b7)
  • Verification settlement: The verifier rechecks its lifetime and configured paths before accepting results, revokes admission before asynchronous quarantine persistence, and publishes a verification timestamp only after a successful full check. (src/state/agent-database-startup-verification.ts:40, e34d51dc98b7)
  • Reader-before-writer shutdown: Post-grace idle eviction yields to existing resource drainage when resources remain for the database path; the extended regression checks reader closure and seal publication. (src/state/openclaw-agent-db-lifecycle.ts:236, e34d51dc98b7)
  • Recorded integrity tradeoff: The maintainer-authored body explicitly accepts ordinary access before the background verdict and Doctor recovery for background-discovered FTS damage; these are intentional policy changes rather than unexplained reversions. Public docs: docs/reference/database-schemas/integrity-and-recovery.md. (docs/reference/database-schemas/integrity-and-recovery.md:177, e34d51dc98b7)
  • Proof supplied and acknowledged gaps: The complete body supplies synthetic native-owner measurements and regression results, but explicitly marks candidate built-Gateway and physical-corruption proof pending; discussion adds no completed proof. (e34d51dc98b7)

Likely related people:

  • Peter Steinberger: Raw commit ec9de37 adds src/state/agent-database-startup.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ec9de3781828; files: src/state/agent-database-startup.ts)
  • Shakker: Raw commit 9bf3231 adds src/state/agent-database-startup.ts:343 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9bf3231d2535; files: src/state/agent-database-startup.ts)

PR surface

Source +465, Tests +251, Docs +36, Other +303. Total +1055 across 27 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 18 495 30 +465
Tests 6 277 26 +251
Docs 1 56 20 +36
Config 0 0 0 0
Generated 0 0 0 0
Other 2 303 0 +303
Total 27 1131 76 +1055

Labels

Label changes:

  • add P2: The change improves restart availability for large databases and clean-close reliability without establishing a widespread emergency.
  • add merge-risk: 🚨 compatibility: Current-schema databases with background-discovered FTS damage now require Doctor instead of automatic startup repair; the maintainer-authored body explicitly records this tradeoff.
  • add merge-risk: 🚨 session-state: Ordinary session access can precede full integrity verification, an explicitly accepted interval in which untouched damaged pages may remain.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: The change improves restart availability for large databases and clean-close reliability without establishing a widespread emergency.
  • merge-risk: 🚨 compatibility: Current-schema databases with background-discovered FTS damage now require Doctor instead of automatic startup repair; the maintainer-authored body explicitly records this tradeoff.
  • merge-risk: 🚨 session-state: Ordinary session access can precede full integrity verification, an explicitly accepted interval in which untouched damaged pages may remain.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Finish the candidate Gateway scenarios already identified as pending.
  • Show a latest-stable upgrade preserving settings, sessions, and quarantine recovery.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 11:31 AM ET / 15:31 UTC.

@steipete
steipete force-pushed the steipete/perf-micro-proportionate-startup-inspection-20260919 branch from e34d51d to f7e1032 Compare October 30, 2026 15:36
@steipete
steipete marked this pull request as ready for review October 30, 2026 15:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T17:50:30.839184Z 4c0be2c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete force-pushed the steipete/perf-micro-proportionate-startup-inspection-20260919 branch from f7e1032 to 43c8a06 Compare October 30, 2026 16:20
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Production startup observation for the existing proportionate-inspection lane: Team build 562772b4945f (contains #188409) logged agent admission as integrityGateReason=process-death, integrityGateMode=quick, healthy, with 258,678 ms in the check. Gateway readiness was about 472 seconds after startup. Bootstrap was 191,007 ms and post-bind plugin loading 255,757 ms; these measurements overlap and should not be summed as independent costs.

A separate, directly attributed main-thread stall consumed 201,391 ms: cua-computer registration itself reported 201,369 ms. Its synchronous registration calls verifyInstalledCuaDriverArtifacts(), whose Linux libc detection builds a complete process.report.getReport(). The Team reliability loop is handling that registration path separately; it will not duplicate this PR’s database inspection or checkpoint/seal scope.

The preceding stop also logged a hard-exit watchdog kill after the shutdown deadline with pending close steps: none; this is an observation, not evidence that this PR fixes it. No production service or state was modified by the reliability investigation.

@steipete
steipete force-pushed the steipete/perf-micro-proportionate-startup-inspection-20260919 branch 2 times, most recently from b59abb4 to 8d83fc1 Compare October 30, 2026 17:15
Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after #186783.

Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change.
Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof.
@steipete
steipete force-pushed the steipete/perf-micro-proportionate-startup-inspection-20260919 branch from 8d83fc1 to 4c0be2c Compare October 30, 2026 17:47
@steipete

Copy link
Copy Markdown
Contributor Author

Landing evidence for exact head 4c0be2cb9b0dbdb39a32abcef756971f20c0b584, CI run 41101511557: all three failed test jobs are inherited.

  • Doctor: doctor-usage-cost-cache.test.ts / unreadable temp entry expects one warning and receives two. The same assertion fails on unchanged main ba6cfcd58df47a3037507362e45ed95757fae41c in main job 124149134725, and on the candidate.
  • Auth shutdown: job 124221857967 has two failures in server-close.auth-usage.test.ts. Running that exact file on unchanged base 83064b3ae1155f0c6c96081c863e7db4bd4451f4 reproduces both (2 failed, 1 passed), matching the local candidate. The assertions inspect owner-closed wording and provider cancellation before fix: resume running channel threads after graceful restarts #188402's later cleanup boundary.
  • Reply admission: job 124221858079 has four full-idle-cache variants in reply-turn-admission.worker.test.ts, each expecting zero leases at line 440. The unchanged base reproduces all four (4 failed, 3 passed). The fixture signals drain only; fix: resume running channel threads after graceful restarts #188402 retains idle executors until shutdown cleanup. The owner, worker store, admission code, and test are unchanged by this PR.

Both baseline files ran separately with OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs <file> --maxWorkers=1; the lane branch was restored clean afterward. No failing assertion was weakened or skipped, and CI was not rerun. The correct follow-up is to align these inherited test fixtures with the marker-before-cleanup phase, preserving their accepted-write and zero-lease assertions.

On the exact PR head, all configured-store discovery tests and the real Linux managed-SIGTERM lease-release/seal proof pass. Independent review is clean; enforced exact-head review and all applicable security checks pass. This PR uses the standing authorization to land with attributed inherited failures; CI remains truthfully recorded as failed.

@steipete
steipete merged commit 4464e6f into main Oct 30, 2026
175 of 184 checks passed
@steipete
steipete deleted the steipete/perf-micro-proportionate-startup-inspection-20260919 branch October 30, 2026 18:22
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…8459)

* perf(state): keep agent startup inspection proportionate

Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after openclaw#186783.

Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change.

* refactor(state): keep quarantine dispatch behind verification boundary

* fix(state): settle deferred writers when readers retire

Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof.

* docs(state): distinguish startup admission from crash recovery receipts

* fix(state): let resource owners settle before idle writer cleanup

* fix(sessions): retire idle readers during shutdown cleanup

* test(gateway): keep configured stores in the suite registry

* docs(state): align idle retirement with restart marker persistence
steipete added a commit that referenced this pull request Oct 31, 2026
Team's r253 update crossing scanned the 65 GiB roboclaw agent database twice after the schema migration had already finished: Doctor's 'Session transcripts' reopen found no clean-close seal and ran a 584 s whole-file quick_check on the main thread; its close was checkpoint-incomplete, so 'Config audit' reopened with no proof and scanned again (~13 min). The Gateway was down throughout.

Agent-database opens without a seal now use the bounded structure admission already used at Gateway startup (#188459), keep this process's proof across checkpoint-incomplete closes, and run any required scan in the integrity worker. Bounded admission mints neither a verification timestamp nor a seal, so full verification stays owed and the next Gateway start runs it in the background. A lease-less unclean close now takes this bounded path; closes whose lease survives keep their synchronous full check, and a corrupt page is still rejected. Pre-migration checks are unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…189247)

Team's r253 update crossing scanned the 65 GiB roboclaw agent database twice after the schema migration had already finished: Doctor's 'Session transcripts' reopen found no clean-close seal and ran a 584 s whole-file quick_check on the main thread; its close was checkpoint-incomplete, so 'Config audit' reopened with no proof and scanned again (~13 min). The Gateway was down throughout.

Agent-database opens without a seal now use the bounded structure admission already used at Gateway startup (openclaw#188459), keep this process's proof across checkpoint-incomplete closes, and run any required scan in the integrity worker. Bounded admission mints neither a verification timestamp nor a seal, so full verification stays owed and the next Gateway start runs it in the background. A lease-less unclean close now takes this bounded path; closes whose lease survives keep their synchronous full check, and a corrupt page is still rejected. Pre-migration checks are unchanged.
RomneyDa added a commit that referenced this pull request Nov 13, 2026
Backport the assertion synchronization from 4464e6f (#188459, Peter Steinberger). Keep the sidecar held until independently retired readers release their leases, preserving the existing shutdown assertions.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit c05b7491b912c5b0599c43590c3db1d5666cb9d7)
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants