Skip to content

improve(config): keep recovery responsive during health snapshots - #145965

Merged
steipete merged 1 commit into
mainfrom
codex/perf-sep12-config-health-async
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-sep12-config-health-async

Conversation

@steipete

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

What Problem This Solves

Config recovery can pause unrelated Gateway work while it checks the health of saved configuration, even though recovery preparation runs asynchronously.

Why This Change Was Made

Use the existing asynchronous artifact-preserving snapshot reader in the async recovery effect, sharing the existing ordered health-row query with the synchronous reader. Keep synchronous recovery, ordinary live reads, snapshot/artifact ownership, error handling and final config/backup/lease commit guards unchanged; no schema, configuration, cancellation API, snapshot coalescing or new storage owner is introduced.

User Impact

The event loop can remain responsive while the existing snapshot worker runs. This reduces blocking, not snapshot work, and does not establish a throughput or end-to-end Gateway speedup. Ordinary async recovery gains one Promise yield. The final change adds 33 production lines, compared with 34 in the measured unformatted candidate.

Evidence

Matching Oxfmt 0.66, git diff --check, and fresh managed Codex review through P2 passed on the final source. Darwin/Node 26.8.1 validation passed 106 existing assertions across io.health-state.test.ts, io.observe-recovery.test.ts, io.snapshot.recovery.test.ts, and openclaw-state-db-readonly.test.ts; all 25 small guards selected by the actual changed-check owner passed under unchanged per-child 300s/6 GiB/64-process limits. No dependency install or new permanent implementation-mirroring test was added.

The first small-guard phase stopped at assertion safety: the new generator-result cast raised undocumented assertions from 7 to 8. The original failure remains retained. An inline SAFETY comment documents the existing runner invariant; no assertion type, baseline, test or executable behavior changed. Fresh P2 and the selected guards passed afterward; the 106 behavioral assertions were retained without rerunning for the comment-only change. Hosted CI remains pending for tsgo:core, tsgo:core:test, and changed core type-aware lint because of the established local capacity limit; none is claimed passed.

One isolated Linux/Node 24.19.0 B1/C1/C2/B2 pilot at 7292689e7f78026060491fc94923cafdec48733f exercised actual prepareConfigRecovery with real SQLite snapshots, plus ordinary-async and synchronous controls. Each case/phase had one warmup and two measured calls. Relative to the measured candidate, author changes are formatting and the comment-only SAFETY annotation; executable code is unchanged. Relevant owners, callers and tests were verified unchanged at 93a5d822750d726481ab2998e53b404d04e58b27; no retiming was performed.

For the four cold snapshot cases, median maximum callback gaps dropped from 422–557 ms to 5.4–7.5 ms in both comparisons. The real 5 ms sampler starts before the call and drains after completion; performance clocks and timers remain live. Snapshot count stays one per cold call. All 32 case/phase graphs, warnings, health rows, config/backup artifacts and 144 decoded SQLite artifact images passed parity/preservation checks; four additional freshness checks passed.

The tradeoffs remain explicit: cold parent CPU increases 9.7–71.6%, including callbacks that can now run during the call. Transaction call wall time worsens +1.51/+2.21%, warm call wall is −7.93/+15.68%, and ordinary-async call wall is +19.63/−4.70%. Ordinary-async whole-child wall worsens +4.70/+4.98%, CPU +0.74/+4.26%, and observed tree peak RSS +1.03/+0.99%. Whole-child clocks include imports, setup and verification; they are separate from call clocks.

Complete eight-case paired measurements and resource observations

Each pair is B1→C1 / B2→C2. Times are median milliseconds per call; positive percentage changes in wall, CPU or gaps are adverse. These are two-sample pilot medians, not a throughput distribution. Every raw sample and both comparison orders are retained.

Case Wall ms, both pairs Parent CPU change Maximum callback gap ms, both pairs Snapshots per call
missing 0.203→0.197 / 0.200→0.185 +3.32% / -7.67% 5.312→5.303 / 5.315→4.825 0
cold-healthy 557.343→430.149 / 424.469→426.420 +17.69% / +55.55% 557.457→6.113 / 424.560→7.484 1
cold-suspicious 442.798→414.407 / 429.619→446.835 +9.70% / +18.43% 433.981→7.295 / 421.852→7.094 1
cold-wal 433.194→435.113 / 435.904→414.934 +71.57% / +70.64% 433.275→5.424 / 435.976→6.718 1
warm 0.321→0.295 / 0.311→0.360 -0.14% / +16.46% 4.928→4.966 / 5.006→5.523 0
transaction 421.948→428.335 / 421.792→431.119 +57.23% / +67.97% 422.027→6.885 / 421.881→5.803 1
ordinary-async 0.256→0.306 / 0.332→0.316 +17.89% / -7.11% 4.445→4.935 / 5.552→4.413 0
sync 0.225→0.247 / 0.239→0.220 +4.58% / +0.32% 4.894→4.929 / 5.437→4.895 0

Whole-child metrics include imports, fixtures, verification, compression and timer draining. RSS is process high-water/observed tree peak, not exact per-call allocation.

Case Whole-child CPU change Whole-child wall change Kernel child max RSS change Observed tree peak RSS change
missing +1.25% / -0.21% -0.39% / -1.78% +1.69% / -0.04% +1.45% / +3.80%
cold-healthy -12.52% / -0.55% -11.69% / +3.31% -0.33% / -0.30% +1.43% / -1.24%
cold-suspicious -11.94% / +3.73% -11.80% / +6.79% -0.26% / +0.25% -0.91% / +0.71%
cold-wal -0.63% / +1.00% -1.08% / +1.03% -0.28% / -0.46% +1.05% / -1.61%
warm +4.29% / -0.50% +5.47% / +1.42% +0.30% / +0.26% -2.57% / -0.87%
transaction +2.04% / +0.22% +2.16% / +1.56% -0.24% / -0.72% +0.52% / +1.55%
ordinary-async +0.74% / +4.26% +4.70% / +4.98% -0.10% / +0.12% +1.03% / +0.99%
sync +0.88% / +1.75% +0.36% / +0.62% -1.33% / -0.30% -3.81% / -0.30%

No benchmark retry, cap increase or acceptance-threshold adjustment was used. Measurement closure verified 38 successful native commands, 190 distinct PIDs and 38 groups, source/worktree cleanup and exact Testbox lease closure. Local validation and reviewer children also closed.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 12:38
@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 Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 8:45 AM ET / 12:45 UTC.

ClawSweeper review

What this changes

Config recovery now awaits the existing private SQLite snapshot worker when reading saved health information, allowing unrelated Gateway work to continue.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused responsiveness improvement absent from fetched main. No introduced correctness or security defect was found, and the supplied production-path measurements support the stated benefit.

Priority: P2
Reviewed head: c5edeb71ea1d81b3dfa79fe8ce82868ffee2e5fd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with directly relevant before/after measurements and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.
Evidence reviewed 7 items Pinned patch and current-main comparison: The complete introduced patch changes only the health reader and its recovery effect. Comparing fetched main with the pinned head shows the same focused changes in these files; fetched main still uses the synchronous health read. The host-verified test merge likewise changes only these two files relative to its main parent.
Existing snapshot owner reused: The async reader preserves warm-handle reuse, skips active transactions, handles absent databases, awaits the existing artifact-preserving snapshot worker, and rechecks fresh-open admission afterward. The extracted health query remains synchronous and retains ordering and decoding. This path depends on OpenClaw's SQLite owner, not the Codex harness.
Recovery safeguards preserved: Preparation enters the existing artifact-preserving scope. Applying its plan checks config and backup bytes and file identity, and the atomic rename invokes the final guard again. The patch changes neither these checks nor recovery eligibility, configuration defaults, schema, or write transactions.
Findings None None.
Security None None.

How this fits together

Config recovery compares the current configuration with saved health fingerprints and backup contents before preparing a restoration. The shared-state reader supplies those fingerprints while preserving the source database and its sidecar files.

flowchart TD
  A[Current config and backup] --> B[Recovery preparation]
  B --> C{Artifact-preserving read?}
  C -->|Yes| D[Await existing snapshot worker]
  C -->|No| E[Existing live reader]
  D --> F[Read saved health fingerprints]
  E --> F
  F --> G[Prepare recovery candidate]
  G --> H[Recheck sources before restoration]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +33. Total +33 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 64 31 +33
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 64 31 +33

Review metrics

Metric Value Why it matters
Reported cold snapshot responsiveness Maximum callback gaps: 422–557 ms → 5.4–7.5 ms Paired production-path pilot measurements support improved event-loop responsiveness without claiming overall throughput gains.
Production versus test growth Production net +33 lines; tests unchanged Growth provides the async adapter and shared query extraction while retaining the existing storage owner and behavioral coverage.

Technical review

Best possible solution:

Keep snapshot preparation with the existing SQLite owner while preserving synchronous row reads, ordinary live-read behavior, and final recovery commit checks.

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

Yes: fetched main's asynchronous recovery preparation reaches the synchronous snapshot reader on a cold artifact-preserving read. The supplied real SQLite pilot measures that blocking; this review verified the source path without executing it.

Is this the best way to solve the issue?

Yes: selecting the existing async snapshot reader at the recovery effect is a narrow repair that preserves the query, storage lifecycle, and commit safeguards.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This addresses bounded event-loop blocking during config recovery without evidence of an urgent user-facing outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.

Label justifications:

  • P2: This addresses bounded event-loop blocking during config recovery without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux/Node pilot exercises actual prepareConfigRecovery through the existing SQLite snapshot worker, showing lower callback gaps with matching recovery results and preserved artifacts; synchronous and ordinary-async controls bound the claim.

Evidence

What I checked:

  • Pinned patch and current-main comparison: The complete introduced patch changes only the health reader and its recovery effect. Comparing fetched main with the pinned head shows the same focused changes in these files; fetched main still uses the synchronous health read. The host-verified test merge likewise changes only these two files relative to its main parent. (src/config/io.health-state.ts:126, c5edeb71ea1d)
  • Existing snapshot owner reused: The async reader preserves warm-handle reuse, skips active transactions, handles absent databases, awaits the existing artifact-preserving snapshot worker, and rechecks fresh-open admission afterward. The extracted health query remains synchronous and retains ordering and decoding. This path depends on OpenClaw's SQLite owner, not the Codex harness. (src/state/openclaw-state-db-readonly.ts:239, c5edeb71ea1d)
  • Recovery safeguards preserved: Preparation enters the existing artifact-preserving scope. Applying its plan checks config and backup bytes and file identity, and the atomic rename invokes the final guard again. The patch changes neither these checks nor recovery eligibility, configuration defaults, schema, or write transactions. (src/config/io.observe-recovery.ts:325, c5edeb71ea1d)
  • Production-path measurement evidence: The fully supplied PR body, captured under sourceRevision d36db30c9091c26b55f36940f25131cce4ff9dcd67740c31a012c06fccb8b838, reports an isolated Linux/Node 24.19.0 B1/C1/C2/B2 run through actual prepareConfigRecovery with real SQLite snapshots. Cold-case maximum callback gaps fell from 422–557 ms to 5.4–7.5 ms, retaining one snapshot per cold call. It records parity across 32 case/phase results, preservation of 144 decoded artifact images, four freshness checks, and explicit CPU and wall-time tradeoffs. These are small pilot measurements, not throughput evidence; the measured candidate differs from final source only by reported formatting and a comment. (c5edeb71ea1d)
  • Existing boundary coverage: Read the complete health-state, prepared-recovery, and shared-state reader tests. They cover absent-store reads, source artifact preservation, committed-row isolation, warm reuse, cleanup after rejection, config/backup drift, and lease loss before replacement. The PR reports 106 passing existing assertions and 25 passing small guards; this read-only review did not execute tests. The pinned diff passes git diff --check. (src/config/io.snapshot.recovery.test.ts:132, c5edeb71ea1d)
  • Release comparison: The latest supplied release, v2026.9.4, retains the synchronous health-store implementation and does not contain this async adapter. (src/config/io.health-state.ts:74, 3a9d69db306c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit d640aef into main Sep 12, 2026
254 checks passed
@steipete
steipete deleted the codex/perf-sep12-config-health-async branch September 12, 2026 13:29
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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: 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