Skip to content

perf(config): avoid a sealed-state copy during startup health reads - #178592

Closed
steipete wants to merge 1 commit into
mainfrom
steipete/perf-micro-production-boot-profile-analysis-20260919
Closed

steipete wants to merge 1 commit into
mainfrom
steipete/perf-micro-production-boot-profile-analysis-20260919

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Outcome

Not selected for landing: the prewritten performance acceptance criterion was not met. Two valid concurrent, swapped-core comparisons showed no material startup improvement. This proposed change is not shipped.

What Problem This Solves

A Gateway with a retained config backup copies the shared-state database during its first config-health read, even when a valid clean-close seal already permits a safe read without a copy.

User Impact

The proposal avoids one unnecessary whole-database snapshot for cleanly closed state. Unsealed state retains its private-copy path. Config recovery, stored data, permissions, and normal runtime reads are unchanged; no migration or new configuration is required.

Why This Change Was Made

The config-health owner now uses the existing retained snapshot owner after an artifact-preserving cache miss, allowing that owner to reuse its clean-close proof. Receipt cache hits remain before snapshot preparation; maintenance/schema contexts keep their existing path. The production change is net +12 lines (plus 3 benchmark lines) because it selects the existing snapshot lifecycle without removing the required unsealed fallback or duplicating seal validation. There is no new cache or snapshot implementation.

The existing teamBoot benchmark now retains an identical config backup so it exercises this otherwise-missed startup read. It still seeds eight synthetic agents, 4,096 sessions, 44 synthetic startup-active plugins, and 128 MiB of incompressible shared-state payload.

Evidence

  • Regression reproduced on the base: a valid clean-close seal still caused one private snapshot preparation. Candidate: zero preparations and the correct health row; the next observation remains cached.
  • Unsealed control: one private copy, correct health row, unchanged source bytes, and no newly created WAL/SHM sidecars.
  • node scripts/run-vitest.mjs src/config/io.health-state-scope.test.ts --maxWorkers=1: 15 passed. Wrapper wall time 46.67 s including worker compilation; tests approximately 10 s. Base regression failed for the intended extra copy; the other 13 existing cases passed.
  • Changed-file oxfmt and targeted oxlint passed. pnpm tsgo:core (tsrs) passed.
  • Independent autoreview: scoped clean through P2; no accepted/actionable findings.
  • Broad gates are delegated to PR CI. No Testbox lease was allocated.

Paired startup measurements

Both comparisons ran concurrently under an exclusive measurement lock, using separate state directories and 16 cores per side; the second pair swapped CPU halves. Each fresh fixture had eight agents, 4,096 sessions, a matching config backup, 135,950,336 allocated shared-state database bytes, and 44 loaded plugins (43 synthetic plugins plus explicitly selected memory-core). Outside CPU load was recorded with mpstat for context.

Pair Baseline ready Candidate ready Candidate − baseline Change
1 20.412 s 20.399 s -13.5 ms -0.07%
2 22.407 s 22.714 s +306.8 ms +1.37%

Median paired spawn-to-ready difference: +146.6 ms (+0.65%). The gate required at least 5% improvement; it was not met. First seeded-session RPC was +44.1 ms (+0.19%), sampled CPU showed no difference at its sampling resolution, peak Gateway RSS was +50.0 MiB (+0.75%), and shutdown was −59.2 ms (−2.00%). These are neutral/noisy results, not a demonstrated performance benefit.

All four measured processes passed /healthz, /readyz, the seeded sessions.list requirement, the exact 44-plugin inventory check, and clean shutdown without forced termination. All 59 PR checks passed; independent review and both automated reviews found no actionable code defect.

Setup failures are excluded: an initial pair exited before startup because the artifact layout omitted root launcher companions. After correcting the layout, a functional smoke exposed the default fixture's 44 synthetic plugins plus default-slot memory-core (45 total). The supported --bundled-plugin-fixture option supplied the explicit 44-plugin inventory above before any valid A/B result. A separate corrected smoke passed; its timings are excluded.

Runtime compilation, asset preparation, bootstrap checks, 55 native plugin control-plane module loads, postbuild, and runtime stamps passed. The broader build's UI tail attempted dependency reconciliation and was refused; UI was disabled for this benchmark. Both sides reused the same external dependencies and current workspace-package outputs; this was controlled A/B evidence, not an exact frozen-lock installation reproduction. No production-ready improvement is claimed.

@clawsweeper

clawsweeper Bot commented Oct 20, 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.

@steipete
steipete marked this pull request as ready for review October 20, 2026 17:23
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Oct 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T17:26:44.160996Z 5d6b81e Draft marked ready
ℹ️ 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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets config-health startup reads reuse clean-close seals and adds a retained config backup to the startup benchmark.

Example: Start a Gateway with a retained openclaw.json.bak and cleanly closed shared-state SQLite database.

  • Before: The first config-health read prepares one private database copy.
  • After: The read uses the existing sealed-source path without preparing a private copy; unsealed state still uses a copy.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified defect, but its explicitly required real-startup performance evidence is still pending.
Proof confidence 🧂 unranked krab (1/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: Gateway startup with a retained config backup copies the shared-state database even when clean-close proof permits reading it directly.
Reason: The maintainer-authored direction removes concrete redundant work through an existing owner without adding settings or changing recovery policy.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a concrete redundant startup copy using the existing snapshot owner, and review found no actionable code defect.

Priority: P2
Reviewed head: 5d6b81ec94735556bed1223ef588a78fec41f36e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Real Gateway baseline/candidate startup results for the retained-backup teamBoot workload have not been supplied.
Agent review details

How this fits together

Gateway config recovery reads saved health rows through the shared-state reader; the snapshot owner selects sealed-source reuse or an artifact-preserving private copy and returns the health snapshot.

flowchart TD
  A[Gateway startup] --> B[Config recovery]
  B --> C[Config health owner]
  C --> D[Receipt cache]
  C --> E[Existing snapshot owner]
  E --> F[Sealed database read]
  E --> G[Private snapshot read]
Loading

Technical review

Best possible solution:

Use the existing snapshot owner to eliminate the sealed-state copy while preserving receipt invalidation, unsealed artifact preservation, and recovery write guards.

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

Source traces a retained backup to the health read and an artifact-preserving copy on main; the PR reports the regression failing on base, but this read-only review ran no target code.

Is this the best way to solve the issue?

The change is a focused reuse of existing lifecycle machinery, with no duplicate seal validation, cache, or storage owner; its end-to-end performance value remains subject to the recorded acceptance rule.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d151219 adds src/config/io.health-state.ts:158 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d15121968a19; files: src/config/io.health-state.ts)

PR surface

Source +12, Tests +25, Docs +1, Other +3. Total +41 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 17 5 +12
Tests 1 26 1 +25
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 0 +3
Total 4 48 7 +41

Labels

Label changes:

  • add P2: Avoiding a whole-database startup copy is a useful performance improvement with a limited affected path and no established urgent outage.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Avoiding a whole-database startup copy is a useful performance improvement with a limited affected path and no established urgent outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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.

Reviewed October 20, 2026, 1:39 PM ET / 17:39 UTC.

@steipete steipete closed this Oct 20, 2026
@RomneyDa
RomneyDa deleted the steipete/perf-micro-production-boot-profile-analysis-20260919 branch October 22, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S 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