Skip to content

perf(update): shorten stopped database capture and Doctor work - #170087

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-update-outage-minimize-20260919
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-update-outage-minimize-20260919

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native update migration spends minutes backing up and rechecking unchanged multi-GiB agent databases during a shared-state-only schema upgrade. The recovery capture performs multiple full-file passes, and Doctor invalidates existing integrity evidence and opens a writer even when there is nothing to change.

User Impact

Shorter stopped time during native updates. Every discovered database remains backed up, including unchanged agent schemas, because Doctor can still write bookkeeping. Existing receipt fields, SHA-256 verification during restore, row identities, and rollback ownership remain unchanged. No schema or configuration changes.

Why This Change Was Made

The native migration entrypoint already owns a stopped Gateway. Its checkpointed files now use the existing native filesystem clone/byte-copy owner, inspect the cloned SQLite header/schema, hash the final image once, and check source identity and mutation metadata. Retained WAL/journal families keep the coherent verified-snapshot path. Native rollback uses the supervisor fence, so capture no longer calculates live-writer generations twice; the mutable updater and standalone Doctor recovery captures retain those checks.

During update, current agent schemas with no pending repair or recorded corruption defer media body/archive maintenance to explicit Doctor and keep their clean-close evidence. Canonical-session repair reads the stored main key before opening a writer; actual changes still use the existing setter and admission checks. Startup integrity validation remains owned by startup, including the independent clean-close seal work.

Production LOC: +118 (155 added, 37 removed; tests/docs excluded). The increase is intentional: the existing live-writer/coherent-snapshot contract cannot be replaced by stopped-file capture. This adds the narrower stopped capture and removes its unnecessary full-file work without weakening the live path or changing persisted recovery metadata.

Evidence

Linux/Node 26 on a task-owned btrfs loopback, 3.01 GiB synthetic agent database plus a small shared-state database. One before/after pair per inode policy, measuring the production backup owner plus update-time media maintenance:

Source policy Backup before → after Media before → after Combined before → after
CoW/reflink 75.07 → 7.61 s 11.47 → 6.05 s 86.54 → 13.66 s (6.34×)
NOCOW/byte fallback 61.40 → 13.67 s 8.31 → 5.55 s 69.70 → 19.21 s (3.63×)

Shared btrfs extents independently confirm the clone path. These component timings exclude Gateway startup/readiness and the shared schema migration itself. No production state or services were changed, and no Testbox/Crabbox leases were allocated.

Focused proof: changed-file oxfmt and core oxlint passed; three independent P0–P2 reviews were clean, including the final snapshot-owner extraction. Doctor focused files passed 23 tests (352.89 s wrapper wall time including cold worker compilation). The backup and native migration/rollback files passed another 31 tests (374.38 s wrapper wall time; 145.90 s and 196.37 s Vitest durations, including cold preparation for backup). All 54 focused tests passed across four files; the new backup cases each ran under 0.6 s. The first attempt stopped before testing because a source edit invalidated worker compilation; the frozen retry passed. After CI caught misplaced raw SQL in the coordinator, capture moved into the existing snapshot owner and reused journal-policy normalization, without guard exceptions or baseline changes. Follow-up focused proof passed 36 backup/snapshot/native-migration tests (428.43 s wrapper) and 45 snapshot/journal tests (7 platform skips; 95.45 s wrapper). Full validation belongs to exact-head PR CI.

Limitations: a retained SHA-256 digest still requires one full read, and native cloning depends on the filesystem/inode flags. A byte copy remains available when reflink is unsupported. The 40-GiB end-to-end outage target has not been directly measured. A complete-command trial on the source rig encountered missing Control UI assets and began a build, so it was stopped and excluded rather than treated as installed-update timing. Startup validation remains separate from this change (related: #169649).

CI failure attribution

The first CI run exposed two lane-owned SQL ownership violations. Those are fixed by keeping stopped capture in the existing SQLite snapshot owner and sharing journal normalization through its existing PRAGMA owner; no guard allowlists or baselines were relaxed.

The remaining historical-transcript failure reproduces on unchanged main 8656a687160dbfdd95fd16ae1682e033747d2a07: src/commands/doctor-config-preflight.test.ts → “leaves historical transcript bytes at startup and normalizes them in later plain Doctor.” A single-test baseline run failed with the identical expected Historical answer versus actual [[reply_to_current]] Historical answer and missing openclawDelivery metadata (92.81 s). Baseline command: node scripts/run-vitest.mjs run --config test/vitest/vitest.commands.config.ts --project commands src/commands/doctor-config-preflight.test.ts --maxWorkers=1 -t 'leaves historical transcript bytes at startup and normalizes them in later plain Doctor'. The explicit project selects this focused source test without building runtime assets; existing workspace dependency directories were reused. No tracked baseline files changed.

This preflight does not reach either changed Doctor path. Source inspection traces the separate regression to historical migration opening a new unadmitted SQLite handle before transcript payload preparation, which now requires admitted schema facts. This lane does not change that migration.

The new-head checks-node-changed-compact-large-2 failure also reproduces on the same unchanged main: src/state/openclaw-agent-worker-store.test.ts → “pooled agent publication owner (captured source) > retains exact canonical lease cleanup after failure and releases it on retry.” It expects an aggregate containing controlled worker lease cleanup failure but receives that same ordinary Error. Baseline command: pnpm test src/state/openclaw-agent-worker-store.test.ts --maxWorkers=1 -t 'retains exact canonical lease cleanup after failure and releases it on retry' (54.42 s wrapper; 24.88 s Vitest; identical failure). The worker cleanup owner and test are unchanged by this PR.

Final CI: run 38293502498, attempt 1 tested head b3210bac376723086f7c48fd9aad449a559143d9 through merge 03fa034d6d77d25ec967fed0afd4199808cf0d88. Architecture, baseline ratchets, export/closure guards, lint, production types, builds, all seven UI E2E shards, and the other changed-code shards passed. The two test failures are the unchanged-main reproductions above. check-test-types-core-3 was marked cancelled at its 15-minute job limit during post-job cleanup: its log records successful completion of all six selected core graphs and the root-scripts graph (7/7, each exitCode 0), followed by the completed-step receipt before cleanup. No type error was reported. The CI aggregate remains red; no reruns were requested.

Review proof limit: the native production-entry tests cover successful migration, injected candidate failure, restoration of settings/includes and database contents, retry, and future-schema refusal. A complete v2026.10.2 binary-to-candidate upgrade/rollback campaign was not run.

Clone checkpointed databases in the native stopped-owner path and hash each image once while preserving the existing restore receipt. Keep coherent snapshot and write-generation checks for mutable update and standalone Doctor captures.

Defer current-schema media maintenance during updates and avoid a writable canonical-key open when the stored key already matches. Retain pending migration, corruption, and explicit Doctor repair behavior.
@steipete
steipete marked this pull request as ready for review October 12, 2026 18:25
@clawsweeper

clawsweeper Bot commented Oct 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 docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR speeds stopped-update database capture and skips unnecessary Doctor work on unchanged agent databases.

Example: A native update encounters a checkpointed 3.01 GiB agent database with a current schema.

  • Before: Backup performs repeated full-file verification, and Doctor runs media maintenance and opens an unchanged main-key contract for writing.
  • After: Backup clones or copies the database and hashes the image once, while Doctor defers optional media maintenance and reads the unchanged main key.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused performance work with meaningful production-owner coverage and no definite introduced defect; existing-state compatibility remains unverified.
Proof confidence 🦐 gold shrimp (3/6) Maintainer authorship exempts the ordinary contributor proof gate; reported Linux component benchmarks and production-owner tests exercise capture and Doctor behavior, but no latest-stable upgrade and restore evidence establishes existing-state compatibility for these changed recovery paths.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large unchanged agent databases extend the period when the Gateway is stopped during native updates.
Reason: The maintainer-authored direction has measured component value, retains every discovered database in the recovery capture, and explicitly records the maintenance tradeoff.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this useful, maintainer-directed performance PR open; the revised patch has no definite introduced correctness finding.

Priority: P2
Reviewed head: b3210bac376723086f7c48fd9aad449a559143d9

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: Record a v2026.10.2-to-candidate upgrade and failed-candidate restore through the changed stopped-capture path, preserving settings, session content, and row identities; redact credentials, IPs, and private endpoints.
Agent review details

How this fits together

The native migration command acquires stopped-Gateway ownership, captures database and configuration preimages, runs candidate Doctor, and retains recovery receipts for restoration or cleanup.

flowchart TD
  A[Native supervisor] --> B[Stopped migration command]
  B --> C[Database backup owner]
  C --> D[SQLite snapshot owner]
  D --> E[Recovery receipt]
  B --> F[Doctor maintenance]
  E --> G[Database restore owner]
  F --> H[Candidate activation]
Loading

Technical review

Best possible solution:

Retain the stopped-capture optimization within the existing snapshot owner while preserving coherent live capture, required Doctor repairs, and verified rollback.

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

Current main unconditionally performs verified capture and media maintenance and opens canonical-key contracts for writing; the body reports comparable Linux component measurements, and this read-only review executed no target code.

Is this the best way to solve the issue?

The patch reuses the guarded filesystem copy and snapshot owners, preserves the mutable capture path, and limits maintenance deferral to current schemas without pending repair or recorded corruption.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit aee12b6 adds src/cli/update-cli/update-command-migrate.ts:155 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: aee12b63234c; files: src/cli/update-cli/update-command-migrate.ts)
  • Vincent Koc: Raw commit f1afaa3 adds src/infra/sqlite-snapshot.ts:847 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f1afaa3d0ecd; files: src/infra/sqlite-snapshot.ts)

PR surface

Source +118, Tests +125, Docs +17. Total +260 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 155 37 +118
Tests 3 126 1 +125
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 298 38 +260

Review metrics

Metric Value Why it matters
Production versus test LOC Production +155/-37; tests +126/-1 Production growth supplies the justified stopped-capture contract inside existing owners; tests cover snapshot independence, retained WAL content, pending schema repair, maintenance deferral, and unchanged main-key behavior.

Labels

Label changes:

  • remove status: ⏳ waiting on author: Current PR status no longer selects a status label.

Label justifications:

  • P2: Reduces stopped-update work for large databases without establishing an urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

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-10-12T18:33:08.224Z sha abaf1e3 :: blocked before merge. :: none

Reviewed October 12, 2026, 3:06 PM ET / 19:06 UTC (Revision 2).

@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the SQL-ownership checks in b3210bac376723086f7c48fd9aad449a559143d9: stopped capture now lives in the existing SQLite snapshot owner and journal normalization uses the existing PRAGMA owner. The new-head architecture and baseline-ratchet jobs passed; no allowlist or baseline was relaxed. The final independent review found no actionable P0–P2 findings.

For recovery compatibility, the candidate-owned update migrate command sets the new internal stopped-capture option. The installed supervisor command/receipt protocol, receipt schema version, SHA-256 fields, and restore owner are unchanged. Focused production-entry tests exercised native migrate → candidate mutation/failure → restore, preserving settings/include bytes, database contents, recovery identities, retry behavior, and future-schema refusal. Backup-owner tests separately preserve explicit rowid 42 and verify snapshot digests and independence for native-auto and byte-copy modes; dirty WAL retains coherent capture.

A complete v2026.10.2 binary-to-candidate upgrade/rollback campaign was not run. It remains a stated proof limit, rather than a claimed result. There is no stored-shape change or identified introduced compatibility defect to justify expanding this performance lane into release validation. The requested validation scope is focused local checks plus full PR CI, and the component benchmark does not claim end-to-end update timing.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing under the lane's authorized inherited/unrelated-CI exception for head b3210bac376723086f7c48fd9aad449a559143d9, after three clean independent reviews and completed CI run 38293502498 (attempt 1).

  • checks-node-changed-compact-large-18: historical transcript normalization failure reproduces unchanged on main 8656a687160dbfdd95fd16ae1682e033747d2a07 (single-test baseline, 92.81 s).
  • checks-node-changed-compact-large-2: canonical worker-lease cleanup error-shape assertion reproduces unchanged on the same main (single-test baseline, 54.42 s wrapper).
  • check-test-types-core-3: all six selected type graphs plus root-scripts completed with exit code 0. The job reached post-job cleanup before cancellation at its 15-minute limit. This is a runner cleanup cancellation, not an observed type error; the cancelled job is not being relabeled green.

The baseline failure sources are also unchanged between that main revision and CI's main parent 1f7f1e9d7aed7d3e7e7ea74cf2316bceb6262779. The exact tested merge was 03fa034d6d77d25ec967fed0afd4199808cf0d88. Architecture, baseline ratchets, export/closure guards, lint, production types, builds, all seven UI E2E shards, and remaining changed-code checks passed. No rerun, update-branch, or dispatch was requested to chase green.

Using the explicitly authorized exact-head REST fallback: this lane's scripts/pr resolves its working-tree root through the shared Git directory to ~/Projects/openclaw, which this task expressly prohibits touching. The fallback keeps publication confined to this lane's PR. Security and required review state are checked separately before merge.

@steipete
steipete merged commit 21aa351 into main Oct 12, 2026
151 of 156 checks passed
@steipete
steipete deleted the steipete/perf-micro-update-outage-minimize-20260919 branch October 12, 2026 19:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…law#170087)

* perf(update): reduce stopped database capture and Doctor work

Clone checkpointed databases in the native stopped-owner path and hash each image once while preserving the existing restore receipt. Keep coherent snapshot and write-generation checks for mutable update and standalone Doctor captures.

Defer current-schema media maintenance during updates and avoid a writable canonical-key open when the stored key already matches. Retain pending migration, corruption, and explicit Doctor repair behavior.

* refactor(update): keep stopped capture in SQLite snapshot owner
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant