Skip to content

fix(state): explain startup integrity checks after clean close - #197008

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-state-integrity-check-55s-20260919
Nov 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-state-integrity-check-55s-20260919

Conversation

@steipete

@steipete steipete commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A clean shared-state database can require a full startup integrity check after an additive schema update, but the database-readiness log reports only the cost and gives no reason.

User Impact

Startup now includes stateIntegrityReason=schema-mismatch (or the admission owner's other refusal) alongside stateIntegrityCheckCount and stateIntegrityMs. Integrity checks, schema versions, sealing, and data remain unchanged.

Why This Change Was Made

Clean-close proof includes the database family's canonical SQL fingerprint, not just its numeric schema version. Adding the first-use workspace_setup_state.bootstrap_deferred column in #196392 therefore invalidates prior state seals at version 39. A successful current-runtime open and clean close restores compatible proof for later restarts; repeating read-only preflight alone does not reseal.

The seal loader already records the refusal. This change carries that fact through the existing preflight result and startup trace, retaining numeric accumulation while preserving text diagnostics. It does not remove the required scan or add a new cache, configuration option, schema, or admission policy. Production growth is 15 lines for the requested diagnostic and its typed transport.

Evidence

  • The prior-schema regression creates and seals real state under the earlier canonical SQL, then inspects in fresh child processes. It fails on the parent because the schema-mismatch reason is missing; the scan count is one both before and after. Current-schema seals retain zero scans, and corruption retains foreign-key rejection.
  • Real CPU profiling and heap capture preserve seal bytes; a fresh startup inspector then reports zero checks and one seal. Separately, real CLI calls for both diagnostic RPC methods, online and offline against the transport fixture, open no source database. This composes the CLI and native capture boundaries; it is not a full Gateway deployment test.
  • Startup log tests cover immediate output and buffered replay, preserving the reason as text and summing numeric metrics. Maintenance preflight reports maintenance.
  • The committed readiness benchmark now supports genuine prior-schema seeding, before/after owner CPU and sampled allocation, A/A controls, and real runtime resealing. Acceptance for this diagnostic-only change is unchanged scan counts and no attributable performance regression, with first-touch controls recorded separately and filesystem caches not reset. The 8 GiB synthetic fixture passed all work-count and reason assertions: 26 prior-schema reads scanned once, all 15 candidate/control reads named schema-mismatch, and four fresh readers after a real current-runtime clean close scanned zero times. Timing equivalence is inconclusive under shared-host cache pressure (A/A: 17,459/1,594 ms); no speedup is claimed. Median sampled V8 allocation was 42,465,208 → 42,349,504 bytes (−0.27%, within 2.07% A/A spread). Native SQLite allocation is not measured.
  • All 64 focused cases pass across cold schema inspection, preflight lifecycle, CLI/Gateway startup traces, native diagnostics, CLI diagnostic transport, and the shared CLI-exit fixture consumer. pnpm check:changed completed: 36/38 categories passed initially. Formatting was corrected by the commit formatter and its full changed-file replay passes. The remaining dead-export failure reproduces identically on the untouched main parent (56 production / 30 full-tree findings); it is a main regression, not ignored noise. The remaining five provider aliases were attributed with an isolated inverse-patch probe: restoring only the broad import removed by refactor(plugins): forward auth and catalog to their owners #190205 removes exactly all 11 provider-facade findings (56 → 45), with no new findings; the other 45 remain unchanged. This is a current-parent causal reachability probe, not a historical full-gate run. Codex autoreview is scoped-clean through P1 against the local candidate on c9caa4c; no accepted/actionable findings. The CI diagnostics fixture repair also passed a fresh scoped Codex autoreview through P1. The review is static and makes no production-scale performance claim.

The full requested large-database Linux fixture is unavailable on the current host; the configured private remote runner could not allocate without its organization setting. Smaller local measurements do not establish production latency or btrfs performance. No production data was used or deployment performed.

Test-line allocation covers the prior-schema diagnostic regression, read-only profiling safety, and text-metric transport. Existing fixture coverage is extended rather than adding new production test seams.

Synthetic owner measurements and reproduction

macOS/APFS, Node 26.12.1; 8,613,965,824-byte state database with 8,192 synthetic blob rows. Five counterbalanced timing pairs and five separate allocation pairs, plus A/A controls and CPU profiles. Filesystem caches were not reset; host load ranged 27.4–87.3. These are mixed-cache measurements, so differences below are not attributable to this diagnostic change.

Metric Before After
Full/FK checks per prior-schema inspection 1 / 1 1 / 1
Owner wall median / p95 25,756 / 74,462 ms 1,830 / 22,676 ms
Owner wall range 1,670–74,462 ms 1,653–22,676 ms
Owner CPU median / p95 7,634 / 8,581 ms 1,792 / 6,784 ms
Process CPU median 18,820 ms 14,850 ms
Sampled V8 allocation median 42,465,208 B 42,349,504 B

After a real current-runtime close, the existing seal fast path took 5.188/5.861 ms owner time and 5.83/6.31 ms CPU; allocation controls were 465,264/464,000 bytes. This demonstrates the existing one-time invalidation/reseal behavior, not a new optimization.

git show c9caa4c75ca2:src/state/openclaw-state-schema-preflight.ts > /path/to/baseline-preflight.ts
git show 6d811790:src/state/openclaw-state-schema.sql > /path/to/prior-state-schema.sql
nice -n 19 node --import ./scripts/tsx.mjs scripts/perf/startup-state-readiness-measure.ts \
  --state-dir /path/to/fresh-synthetic-state \
  --baseline-source /path/to/baseline-preflight.ts \
  --prior-schema-source /path/to/prior-state-schema.sql --sizes 8 --samples 5

Remaining proof and main regression

The exact-parent dead-export replay used c9caa4c and produced identical 56 production / 30 full-tree finding sets. Source attribution covers #196767, #192552, #196207, #196252, #196380, #191326, #190205, #190544 and 2c4e34a. A targeted inverse patch restores the provider-runtime.runtime.ts blob from #190205's parent and removes exactly all 11 provider-facade findings while preserving the other 45; the relevant exports all existed before #190205. No unrelated export fixes, ignores, or gate exceptions are included. This is a main regression to repair.

CI on d7aca05 found a PR-caused fixture defect: the native diagnostics subprocess mixed compiled diagnostic entrypoints with raw state TypeScript. Under Node it failed module resolution before the seal assertions; Bun had accepted it locally. The same Node/compiled-worker failure reproduced locally. The repaired fixture creates and cleanly closes real state in the normal test runtime, then retains the cold native capture child and fresh inspection worker. All nine native cases pass under both Node and Bun with compiled workers.

CI also exposed an inherited UI fixture regression: screen-requester-routing.e2e.test.ts:201 waits for tools.github.status after navigation, but the mock does not advertise any capability that enables the Tools panel. The same focused test fails on untouched c9caa4c (same assertion; local 10s versus CI 30s timeout). #196457 / 086d257 introduced the Tools capability gate. Adding only the missing config.get capability to that parent's fixture makes the complete flow pass (1/1, 33.09s; baseline 1/1 failed, 91.41s). This was a main regression, not flaky noise. It was independently repaired on main by #197001 (the same config.get advertisement), with additional settings capabilities in #197016; final-head UI CI passed. No unrelated UI edits are included here.

Full-scale Linux benchmark proof remains unavailable. ClawSweeper reviewed the final head with zero open items; the numbered response records the fixture repair. Final-head CI passed on 6fc4e7c: 51 successful jobs and 27 skipped, including all three PostgreSQL conformance shards. Native pinned auto-merge landed as f700899 without an admin exception or CI rerun. Native completion verified the receipt and cleanup.

Report the admission owner's refusal on database-readiness traces, including same-version canonical schema changes. Preserve full integrity checks and clean-close reuse; cover prior-schema seals and read-only CPU/heap diagnostics.
@clawsweeper

clawsweeper Bot commented Nov 11, 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 cli CLI command changes scripts Repository scripts commands Command implementations size: M labels Nov 11, 2026
@steipete
steipete marked this pull request as ready for review November 11, 2026 03:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T04:13:00.571842Z 6fc4e7c 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.

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds the existing clean-close seal refusal reason to shared-state startup diagnostics.

Example: A clean schema-39 database predates the bootstrap_deferred column.

  • Before: Startup reports stateIntegrityCheckCount=1 without explaining the scan.
  • After: Startup also reports stateIntegrityReason=schema-mismatch.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported diagnostic repair with the prior defect resolved; available behavioral evidence remains at harness boundaries.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; reported synthetic preflight measurements exercise prior-schema refusal and resealing, while the inspected screenshots concern unrelated UI behavior and do not prove startup output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators see an expensive integrity scan after a clean shutdown without knowing why clean-close proof was refused.
Reason: The feature owner's narrow diagnostic change explains existing behavior without weakening checks or introducing runtime configuration.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: the diagnostic improvement is useful, the earlier subprocess defect is resolved, and no actionable patch or security defect remains.

Priority: P3
Reviewed head: 6fc4e7cbf1c2656e3f9ae3e86d4e644bfa3d6b08

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A real Gateway startup capture showing the new reason alongside the scan count is not supplied.
Agent review details

How this fits together

SQLite admission records seal refusals; shared-state inspection returns those facts through preflight metrics to immediate CLI output and buffered Gateway startup traces.

flowchart LR
  A[SQLite database and seal] --> B[Admission owner]
  B --> C[State inspection worker]
  C --> D[Database preflight metrics]
  D --> E[CLI startup output]
  E --> F[Gateway trace replay]
Loading

Technical review

Best possible solution:

Carry the admission owner's existing refusal through the existing metric transport while preserving all integrity and sealing decisions.

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

Current-main source exposes scan counts without the recorded refusal; the supplied prior-schema regression targets that omission, but no target code was executed during this review.

Is this the best way to solve the issue?

The patch uses the existing refusal getter and trace owners with no parallel policy or state; its two new flags control only the synthetic benchmark.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared-state clean-close reuse keeps the original intent (a1f1248: Reuse valid sealed catalog proof in cold inspection children while retaining full verification when seals are refused.)
  • Bootstrap metric accumulation keeps the original intent (3e8b396: Expose bootstrap substeps and accumulated fleet-work counts; this patch preserves numeric totals while carrying text diagnostics.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +15, Tests +88, Docs +12, Other +42. Total +157 across 15 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 24 9 +15
Tests 7 156 68 +88
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 2 48 6 +42
Total 15 240 83 +157

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Runtime versus regression coverage Runtime +24/−9; tests/support +156/−68 The 15 net runtime lines carry the diagnostic; 88 net test/support lines extend existing seal, native-capture, CLI, and trace boundaries.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This improves startup troubleshooting without changing startup admission or fixing an availability failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-11T03:58:18.810Z sha d7aca05 :: needs changes before merge. :: [P2] Enable the TypeScript loader for the added state-owner import

Reviewed November 10, 2026, 11:17 PM ET / November 11, 2026, 04:17 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the review's one open item on 6fc4e7cbf1c2656e3f9ae3e86d4e644bfa3d6b08:

  1. State-owner TypeScript import in the native child: fixed by removing that import. The normal test runtime now creates and awaits clean closure of real isolated state at lines 270–274. The cold child receives only the seal path and continues using the existing compiled diagnostic entrypoints at lines 281–302. Both captures still assert unchanged seal bytes; the fresh inspection still asserts zero checks and one seal. The V8 tracking branch is preserved. This removes the mixed source/compiled import rather than adding another child-loader dependency.

The CI module-resolution failure was reproduced locally under Node with compiled workers before the repair. All nine native cases pass afterward under both Node and Bun with compiled workers. Fresh Codex autoreview found no actionable P0/P1 issue; changed-file checks pass all 29 test typecheck groups, formatting, guards and lint. Only the identical exact-parent dead-export regression remains locally. Replacement Node 24 CI is pending.

The PR body retains the separate transport/native-boundary proof and full-Gateway/full-scale measurement gaps. It also records the UI timeout's exact-parent reproduction and introducing commit, #196457; a single missing advertised capability fixes that parent fixture. No unrelated UI repair is included.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Nov 11, 2026
@steipete
steipete enabled auto-merge (squash) November 11, 2026 04:20
@steipete
steipete merged commit f700899 into main Nov 11, 2026
156 of 158 checks passed
@steipete
steipete deleted the steipete/perf-micro-startup-state-integrity-check-55s-20260919 branch November 11, 2026 04:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…law#197008)

* fix(state): explain startup integrity checks after clean close

Report the admission owner's refusal on database-readiness traces, including same-version canonical schema changes. Preserve full integrity checks and clean-close reuse; cover prior-schema seals and read-only CPU/heap diagnostics.

* test: account for formatted startup diagnostic fixture

* test: seed diagnostic seals before compiled captures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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