Skip to content

perf: skip read-only Doctor preparation capture - #193241

Merged
steipete merged 8 commits into
mainfrom
dbasync/doctorgen
Nov 5, 2026
Merged

steipete merged 8 commits into
mainfrom
dbasync/doctorgen

Conversation

@steipete

@steipete steipete commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Captured Doctor wrapped initial shared-state Doctor/version preparation in a before/after generation envelope even when it only reads owner/schema facts before yielding. For a database without WAL or rollback journal, this launches two generation workers and two size workers unnecessarily.

Run that first synchronous preparation directly only for artifact-free Doctor/version paths. Retained WAL and journal keep the envelope because native reads can rebuild SHM or recover a journal. Every later resumption—including credential preparation and actual repairs—retains capture. Automatic, indexes and readability are unchanged.

The original baseline, first real mutation check, untouched-store final comparison, source custody, cancellation, awaited credentials/closure, and separate state/agent commits remain. Skipped preparation never accepts a new baseline or marks the path opened. No schema, dependency, SQL text, public API or configuration change.

Acceptance rule (declared before performance runs)

Use the committed scripts/perf/doctor-captured-pass.mts workload through production runPackageUpdateDoctor, with an adopted update run, original recovery capture and compiled delegated Doctor. Baseline and candidate use the same platform, Node 26.12.1 or newer, parent driver and identical already-migrated synthetic fixture (four agents, 4,096 sessions). First migration and repeat cohorts stay separate. Record the fixture's actual database bytes; no personal state or logs.

Counts first: generation/size workers, observations, copied bytes, SQL statements, requests, main-thread and total work per Doctor pass, plus source/refusal/cleanup outcomes. Win: exactly two generation and two size workers removed per eligible Doctor/version preparation, with no replacement elsewhere. Total SQL/requests and runtime MAIN must hold or improve. Preserve all migration, outside-write refusal and native update behavior.

For wall/CPU comparisons, acquire the PID-owned timing lock and require one-minute load <24. Interleave at least five samples per head, cold and warm separately; report median, p95 and min–max plus host load. Any adverse 20% cell stops the change. If lock/load waits exceed 60 minutes, use deterministic worker/SQL/copied-byte counts only, explicitly omit a speedup claim, and report the timing gap. Per-thread profiles and counts are diagnostic and lock-exempt. Frozen M/C census pairs are not required for this Doctor-only change.

Matched native update proof, red/green work-count regression, retained refusal tests, two isolated Codex reviews, PG checklist, exact-head CI including all three PostgreSQL shards and the published-driver update cell are required before landing.

Evidence

The real-capture attribution suite passes 39/39. The Doctor/version work-count regression is red on the base (four observations instead of two) and green with the change. Clean WAL-mode, retained WAL, retained journal, wrong mode, outside same/different-content writes, predecessor-stop receipts, empty-reader transitions, cancellation, credential custody, retirement and legacy credential/policy migration remain covered. The unopened clean-stop probe preserves the existing empty-reader equivalence and final receipt.

Two complete isolated Codex reviews plus the isolated production-correction review are scoped-clean. Later changes only repair committed benchmark instrumentation: propagate probe context to sanitized subprocesses and recognize native doctor --fix. Both have red/green subprocess smoke evidence. A final test-only correction restores the original canonical retained-reader operation on clean databases inside the existing matrix, while retaining artifact-preserving current reads for recovery-artifact shapes. This preserves both the admission-read and retained-reader regressions. The expanded PERSIST-journal + canonical-live-reader combination hit a lock and is not claimed as passing coverage; the original regression used a clean database. Exact-head PG approval is recorded for d25ea5b06527663c214d83bf8bb3e783165ee7cd; the coordinator also explicitly approved native/published-driver proof carry-forward from the production-identical earlier heads. The corrected eight-case matrix passes, and its isolated review with full reader/capture/lock owner context is scoped-clean. CI then caught the test passing a boolean to live?: true; the one-line correction preserves the literal clean-case live: true and omits the option elsewhere, with identical runtime behavior. Its full-context isolated review is scoped-clean. No production or workload bytes changed.

Production +2 LOC; tests net 0 LOC. The workload is committed in scripts/perf/doctor-captured-pass.mts and the native probe in scripts/perf/doctor-retirement-measure.mts. Local lint/format and worker/dialect ratchets pass (T1 168→168; deprecated-only 15→15). Local type-aware preparation refuses the mandated external virtual-store layout; exact-head CI covers types/static checks.

Corrected matched count pair

The baseline and candidate use the same migrated seven-database fixture, restored to the same absolute path. Both Control UI artifacts are ready with matching build identities; neither arm builds UI. All child processes are accounted for.

Per pass Baseline Candidate
Doctor generation workers 29 27
Doctor size workers 29 27
All process starts 188 184
Doctor SQL 43,052 42,354
Doctor requests 271 271
Doctor worker-thread SQL 582 582
Whole-flow SQL 44,475 43,777
Whole-flow requests 289 289
Whole-flow copied bytes 1,495,123,368 1,493,609,016

The four missing processes are exactly the two generation and two size workers. The two removed generation observations account for 22 SQL statements. The remaining SQL difference includes time-dependent maintenance-authority work and is not claimed as a fixed saving. Parent/other-flow SQL and requests remain 1,423/18. Process-main SQL across CLI/child processes is separate from Gateway runtime MAIN; no work moves onto the Gateway. This count pair makes no CPU or wall-time claim.

The explicit clean-stop probe starts Doctor and version with WAL-mode header [2,2], no WAL/SHM/journal, and the capture path unopened. The first read creates WAL=0 and SHM=32,768 while the connection stays open. At the next envelope, the path is still unopened: the committed fingerprint differs, while the existing empty-reader alternate matches the original expected fingerprint. Both real admissions and subsequent credential migration pass with no refusal/warning and an unchanged final receipt. This uses the shipped absent-versus-zero WAL-index equivalence; no skipped phase accepts or marks open the source.

Copied-byte attribution: the deleted observations each copied a 1,716,224-byte main database (3,432,448 bytes removed). The retained main image grew by 311,296 bytes, and five existing WAL-prefix copies grew by 321,360 bytes each (+32% for that component), leaving the measured whole-flow reduction at 1,514,352 bytes. The same 42 WAL-prefix writes remain. The omitted initial envelope previously checkpointed the source; preserving its absence changes later physical layout. The exact page-allocation mechanism is unproven, so the net copied-byte change is measured evidence, not a fixed per-pass saving. No replacement observation or extra request is introduced.

The coordinator explicitly accepted the +32% retained WAL-copy component as a physical-layout shift from the omitted checkpoint: 42 prefix writes remain, and whole-flow copied bytes decrease. The component increase is disclosed above; no copy-policy change or new acceptance mechanism is introduced.

Timing and remaining observations

No CPU or wall-time speedup is claimed. The optional alternating timing cohort stopped at 3 baseline / 2 candidate samples when one-minute load reached 48.06. The third baseline was 202.433s versus 104.204/108.239s earlier; this is an incomplete, loaded-host cohort.

The remaining 27 observations are inventory 3, quick-index 2, readability 2, shared-state/credential open 6, additive-agent schemas 8, legacy-schema/credential repair 6. A separately approved B2 targets only the two readability observations; index WAL/SHM makes its envelope necessary.

D copy investigation is a floor: private generation images copy main + committed WAL prefix (or whole-WAL fallback) + retained journal, never source SHM. Existing clone modes violate the established source-lock/shared-extent inspection contract. No copy-policy/dependency change is included.

Native update and exact-head CI

Exact-head normal CI 41994095575 passed, including all three PostgreSQL conformance shards, required gate, type-aware lint, source contracts and baseline ratchets.

The corrected same-snapshot native update pair passed on source-equivalent baseline target f12f35015e9c2ca3442f086e7a3a1ecda8e24929 and candidate 85dbcba051f054ae3ac1cc19f4f35f7b02ee26fe (explicit production-identical carry to this head). Both activated the exact source/build identity, retained plugin payloads, accepted migration attribution, recorded genuine deferred then completed retirement, served the final real-Gateway transport and confirmed process cleanup. CLI-entry WAL was 8,272 bytes in both; all three Doctor boundaries matched (zero WAL; SHM absent/present/absent).

Native scope Baseline SQL / requests / generation / size Candidate SQL / requests / generation / size
Preflight Doctor 2,800 / 119 / 0 / 0 2,800 / 119 / 0 / 0
Installed Doctor 1 53,360 / 350 / 34 / 34 52,787 / 350 / 32 / 32
Installed Doctor 2 27,517 / 166 / 23 / 23 26,944 / 166 / 21 / 21
Whole native update 105,692 / 155,606 / 72 / 69 106,111 / 155,603 / 68 / 65

Whole-flow SQL increases by 419: the installed Doctors remove 1,146 statements, while non-Doctor work adds 1,565. Source-attributed canary-readiness authority observations rise 315→515: seven SQL shapes each add 200 executions and BEGIN adds 199; the observed readiness authority subgroup itself increases 315→515 (+63.49%), and is not an independently observed HTTP-probe count; other outside-Doctor changes total −34. The existing readiness loop checks authority before and after each fetch, then sleeps up to 100 ms. Its recovery guard reads the exact config-machine-state key; that shape rises 600→800 (+33.3%), with the recovery-read function group rising 465→665. Those owners are byte-identical between arms. Two further adverse cells are pending/deferred migration reads 4→5 (+25%, service-installation reader), and cache_size 2→3 (+50%, an already-spawned integrity worker that emitted no SQL before baseline cleanup). These adverse cells are not proof of harmless noise. The coordinator explicitly accepted these native compatibility-cohort count movements for this exact head, with every cell disclosed here and no whole-update CPU, wall-time or count-improvement claim. Real Gateway thread-0 SQL is 96→89 across canary and final Gateways. Canary is 44→36; final startup is 47→48 and final shutdown 5→5. The extra final-startup canonical_ready SELECT comes from unchanged startup session-validation code; its admission-state difference is unexplained. The cold-only native script exits after readiness, so it does not measure sustained warm-runtime MAIN. The startup cell is disclosed here; no runtime-MAIN exception is claimed. No CPU or wall-time comparison is claimed; exit accounting is incomplete (21/20 missing exits). Earlier instrumentation attempts are invalid proof, not product failures: sanitized subprocesses lost probe context, and doctor --fix was initially not recognized. An initial dispatch from main was rejected before tests; it is not reused.

Prior production-equivalent head 85dbcba051f054ae3ac1cc19f4f35f7b02ee26fe: normal PR run https://github.com/openclaw/openclaw/actions/runs/41988354238 passed, including all three PG shards. Supplemental run https://github.com/openclaw/openclaw/actions/runs/41988583984 has all three PG shards passing; its actual published-driver update job127122603710 passed, including published2026.10.10 activation and native-systemd2026.10.9 update. The test-only parent 4eb3f6d88fddd82c2cb68928c92cb7e1ac8b3135 has one test type failure at https://github.com/openclaw/openclaw/actions/runs/41992656008, corrected in final head d25ea5b06527663c214d83bf8bb3e783165ee7cd; refreshed exact-head normal CI passed at https://github.com/openclaw/openclaw/actions/runs/41994095575 . A duplicate supplemental dispatch was canceled after explicit carry-forward approval; the superseded normal run was canceled after its known test-type failure once the corrected head was pushed. Neither is passing proof. Prior-head evidence is not labeled exact-head.

Earlier cleanup/discovery timeouts remain intermittent and unresolved: exact-base and current-head focused replays pass (discovery 21.037/17.459s; cleanup 76.080/56.583s). Passing replays are not fixes or inherited-failure proof. The earlier Bun restart-resume timeout also remains unresolved; final-head job127115368267 passes all five tests, including that case at50.004s. No timeout or related owner code changed.

Supplemental failures are disclosed under the coordinator's scoped disposition: cron F11 is the stale scheduled-event assertion repaired separately; plugin env-reference F4 is fixed by #193074 (absent from this base/head, present on main); Slack transcript loading is an unrelated normal-Gateway UI case; the Windows installer-shell timeout serves synthetic marker scripts and never runs OpenClaw/Doctor. The UI 2/7 run passes all 143 files/613 tests then exceeds its Actions step budget. The auth-controller fake-timer case fails its timer-count assertion on Node, then the following Bun execution passes 378/378; it mocks credential/runtime-auth exchange and does not invoke Doctor. Their failures are not described as passing or as matching-main execution where none was observed. Update/Doctor/state tests, required PR/security checks, 3PG and actual published-driver remain gates.

Open PR overlap

Exact-head d25ea5b0 audit: #192698c144b22, #192228b4f1f32 and #149882aca8f05 add no merge-tree conflict paths (2907→2907, 7→7 and92→92), as discovered through the campaign PR index. Current main also merges without conflicts.

@clawsweeper

clawsweeper Bot commented Nov 5, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-11-05T08:15:12.055200Z 4eb3f6d 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L labels Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR skips redundant database capture around Doctor’s initial read-only preparation while retaining capture around subsequent mutation phases.

Example: A captured update prepares an existing SQLite state database in Doctor mode.

  • Before: Preparation and the following mutation phase each perform before-and-after generation observations.
  • After: Preparation runs directly; the mutation phase retains its before-and-after observations.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source change is coherent and narrowly scoped, but its declared performance and native-update acceptance evidence is unfinished; latest-stable upgrade preservation is also unproven.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Captured updates and Doctor spend unnecessary copying and hashing work before shared-state repair can write.
Reason: The maintainer-directed change removes identifiable redundant work without adding runtime state, configuration, or a competing owner.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this is a focused, maintainer-directed optimization absent from current main, and source review found no definite introduced defect.

Priority: P2
Reviewed head: ae8f814d1808707e158c2133056151a9f2847fb3

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: Completed candidate workload output, candidate-green regression results, and the declared native update scenario are not supplied.
Agent review details

How this fits together

The shared-state repair owner receives Doctor or version-migration requests, prepares credentials and repairs, and publishes verified database changes through the updater’s existing capture owner.

flowchart TD
A[Update or Doctor] --> B[Shared-state repair owner]
B --> C[Read-only preparation]
C --> D[Await credential or repair preparation]
D --> E[Captured mutation phase]
E --> F[Generation publication]
F --> G[Final capture settlement]
Loading

Technical review

Best possible solution:

Retain the narrow initial-step bypass and the existing capture owner for every subsequent mutation.

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

Source shows the initial read-only step entering the same observation envelope as writes, and the PR reports a baseline regression observing four generation inspections rather than two; this review executed no target code.

Is this the best way to solve the issue?

This is the smallest complete production change: bypass only the proven read-only step and preserve the existing mutation, authority, custody, and settlement owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cf39400 adds src/infra/update-doctor-migration-attribution.test.ts:334 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cf3940004049; files: src/infra/update-doctor-migration-attribution.test.ts)
  • RoboClaw: Raw commit d894035 adds src/state/openclaw-state-db-repair.ts:192 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d894035c7829; files: src/state/openclaw-state-db-repair.ts)

PR surface

Source +1, Tests -16, Other +452. Total +437 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 62 78 -16
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 452 0 +452
Total 3 516 79 +437

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
Production versus test LOC Production +1 net line; tests −16 net lines The production change reuses existing owners, and the test consolidation retains approval migration and warm-reader coverage.

Labels

Label changes:

  • add P2: Avoiding redundant database copies during Doctor is a useful, bounded performance improvement without an established urgent outage.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: Avoiding redundant database copies during Doctor is a useful, bounded performance improvement without an established urgent outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

Rank-up moves

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

  • Supply completed baseline/candidate workload results meeting the declared acceptance rule.
  • Demonstrate a v2026.10.10 upgrade with settings, approval policy, socket credentials, and restoration attribution preserved.

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 November 5, 2026, 1:25 AM ET / 06:25 UTC.

@steipete
steipete merged commit ef81b25 into main Nov 5, 2026
189 of 193 checks passed
@steipete
steipete deleted the dbasync/doctorgen branch November 5, 2026 09:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
Skip the initial generation envelope for artifact-free shared-state Doctor/version preparation. Retain WAL/journal capture and every later write-phase admission, source custody and cleanup.

The matched repeat-Doctor fixture removes two generation workers, two size workers and 22 fixed inspection SQL statements per pass; requests remain unchanged. Preserve real admission/reader, outside-write refusal, cancellation and credential migration coverage. Counts only; no CPU or wall-time speedup claim.
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: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant