Skip to content

perf: avoid redundant update Doctor close probes - #186251

Merged
steipete merged 4 commits into
mainfrom
dbasync/custodysql
Oct 27, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/custodysql

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Update Doctor repeats database-generation and custody checks when each migrated SQLite handle closes, even though its session already publishes the final state of every captured database it opened. A later companion migration can also reject that session's own changes.

User Impact

Updates perform fewer database probes. First-open validation, untouched-database refusal, migration exclusion, credential authority checks, and automatic rollback receipts remain intact.

Why This Change Was Made

Remove the migration-specific native-close observer and use the existing opened-path fact for companion admission, matching the session settlement introduced in #185789. Keep per-operation publication and credential provenance, native locks, created-file checks, and the separate handoff/lease store unchanged.

The accepted edge remains the one documented in #177831: raw outside writes to databases opened during the Doctor session may be included in its settled postimage. Captured databases the session never opened must still match.

Evidence

Acceptance rule, recorded before native measurement: one matched synthetic native-update count pair on macOS, using the same current-main installed driver for both arms and distinct baseline/candidate descendants. Each arm runs a cold update and a subsequent warm update through both finalization Doctor passes, exact target activation, and real loopback Gateway readiness. Report each full Doctor pass's SQL/requests and canary/final Gateway MAIN separately. Win requires zero close-triggered generation/authority work, fewer full-pass SQL statements, valid final receipts, and no added worker-request work or runtime Gateway MAIN. Any adverse count cell of 20% or more stops the change. This is n=1 count evidence; no latency or timing claim.

The maintainer-approved post-merge native count pair is complete. Both synthetic updates activated their exact target, preserved the plugin payload, completed retirement after deferral, and stopped all owned processes. Every full finalization Doctor pass executes fewer SQL statements, with identical requests and worker SQL. No compared cell worsened by 20% or more, and all Gateway MAIN counts are identical. This is one count sample per arm, with no latency or CPU claim.

Full Doctor pass SQL baseline → candidate Requests baseline → candidate SQL saved
Cold 1 53,414 → 52,424 283 → 283 990 (1.85%)
Cold 2 38,327 → 37,676 231 → 231 651 (1.70%)
Warm 1 41,835 → 41,184 247 → 247 651 (1.56%)
Warm 2 38,744 → 38,093 234 → 234 651 (1.68%)

The reductions are on process-main threads; full-pass worker SQL stays 799/684/716/706, and each request-operation count is unchanged. The separate preflight Doctors stay 2,748/2,460 SQL and 101/100 requests. Whole-update SQL is 110,940 → 109,176 cold and 98,735 → 96,874 warm; requests are 153,224 → 153,224 and 153,178 → 153,177. The small worker/request differences outside the full Doctors are not claimed as savings from this change.

Gateway MAIN stays cold canary/final 46/89 and warm canary/final 96/75. Whole Gateway lineage SQL/requests are cold canary 230/35 → 230/35, cold final 656/144 → 674/145, warm canary 256/32 → 256/32, and warm final 574/148 → 568/143. The cold final increase is 18 worker SQL (+3.56% worker SQL, +2.74% total SQL) and one request (+0.69%); it is disclosed without attributing it to this deletion.

Frozen observer/parser verification passed in both arms. Baseline OS process-ID reuse was normalized using recorded process starts and SQL manifests; global SQL/request/prepare/error counts stayed exactly unchanged, and an independent attribution audit passed. Both final analyses have complete source attribution reconciliation and zero duplicate request IDs. Raw captures and synthetic runtime copies are removed after retaining compact count evidence.

The owner regression is red on the baseline: native close performs an unwanted generation read, and a companion already opened by the session is rejected. The consolidated candidate cases pass: no close-triggered generation/authority work, valid final receipt, changed opened-companion admission, and changed untouched-companion refusal. All 18 non-retirement cases pass across the focused runs. The existing native-parent retirement/credential case passed; the worker-parent case hit the unchanged 120-second limit on both the candidate and exact base (reported 139/144 seconds versus 165 seconds). No timeout or retry changes are included. Prior-head CI job 122440037186 passed all 20 attribution-owner cases, including native and worker retirement, both no-close-probe modes, untouched-companion refusal, created-family and credential coverage. The containing group passed 2 files / 38 tests with exit 0; this resolves the local worker-parent proof gap without changing its deadline. Two isolated production reviews were clean; a further isolated review of the final test-only consolidation was also clean. All three completed source verification with no actionable P0–P2 findings.

Production: +2/−39 lines (net −37); tests: +168/−168 (net 0). All original boundary cases remain; consolidation removes redundant setup and combines the new assertions into existing custody cases. Formatting and whitespace checks pass. Production Knip has the exact same single unused-export finding on base and candidate (extensions/knowledge/src/scribes-catalog.ts: runPrompt); the reviewed-head all-exports scan also exactly matches base, with only ui/src/pages/activity/activity-page.test-support.ts: settleActivity reported. Neither scan adds a finding. Local type-aware lint cannot admit declarations from the required external virtual store (Declaration input escapes checkout); the exact-head CI lint/type/declaration jobs cover that environment gap.

Exact-head CI run 40593068545 passed for 516f07d006b6f40ecf20d296e479711f0d405e43: 43 checks passed, 26 skipped, zero failed/pending. All three PostgreSQL conformance shards actually executed and passed (1/3, 2/3, 3/3). The owner job again passed all 20 attribution cases (combined 2 files / 38 tests). Lint, production/test types, source contracts and architecture checks passed; Madge reports zero cycles, SQLite T1 is 168→168, compatibility 15→15, and the dialect ratchet has no growth. Earlier corrected-head run 40590282500 passed all three PostgreSQL shards and the test-cleanup lint correction; its only lint errors were five inherited UI diagnostics. Main's fix for those diagnostics was then merged cleanly. The integration changes neither file in this PR; no inherited-failure waiver is currently requested.

The matched native proof uses common installed driver 364c0d4ebcd400ee4285eb989ed60d2a8b000b93, identical-tree baseline descendant 5145cd649ba992e59e7b22caf24072548d36d5a2, and candidate target b6193a123a6676fc9f7a418061851de5e1412270. The changed production file is byte-identical at the reviewed, measured and integrated heads. Main integration also brought unrelated Doctor heartbeat and port-memory changes, so the measured target is reported separately; whole-tree equivalence to the integrated head is not claimed.

The test-only promise cleanup correction uses explicit nested try/finally, passes four focused regression cases, and has a clean isolated delta review. Open-PR overlap index currently finds no other PR touching either changed file.

@clawsweeper

clawsweeper Bot commented Oct 27, 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 Oct 27, 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-27T22:14:49.097368Z 516f07d 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-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR removes redundant SQLite close probes and permits companion migrations to reuse the Doctor session’s existing admission.

Example: Doctor previously admitted companion.sqlite, then its own work inserted retained.value = 9 before another companion migration.

  • Before: The later migration rejects the changed companion generation.
  • After: The session admits the companion and includes its final generation in the settled receipt.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source change is focused and coherent, but current evidence does not establish the declared native performance win or update/rollback compatibility.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence covers owner regressions, while native full-Doctor counts and product-path results remain pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Updates perform redundant database probes and can reject changes made by their own Doctor session.
Reason: The maintainer-authored direction removes duplicate work through an existing owner and preserves the documented attribution boundary.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it makes a focused improvement using the existing Doctor settlement owner, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 971a785518f338ae2d1c4ec28d621944271f2a5e

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: The promised baseline/candidate native update count comparison and latest-stable upgrade/rollback run with settings and data intact are not yet supplied.
Agent review details

How this fits together

Update Doctor receives captured database generations, performs migrations under maintenance custody, and returns settled write receipts used by subsequent Doctor passes and rollback.

flowchart LR
  A[Installed updater capture] --> B[Doctor maintenance custody]
  B --> C[SQLite migration admission]
  C --> D[Companion migration]
  D --> E[Resource closure]
  E --> F[Session settlement]
  F --> G[Update and rollback receipts]
Loading

Technical review

Best possible solution:

Use session settlement as the final receipt owner while retaining first-open validation, native exclusion, per-operation publication, and untouched-path refusal.

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

The baseline installs a generation-reading close observer and unconditionally rejects changed companions; the added owner cases exercise both paths, with baseline failures reported in the body, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete fix found: delete the redundant observer and reuse the existing session admission fact without adding state, wrappers, or another settlement path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Migration-native close observer changes intended behavior with a stated reason (8f62210: Attribute native SQLite journal and WAL cleanup to the migration owner; later session settlement in fix: complete post-plugin Doctor after update bookkeeping #185789 now publishes the final opened-database postimage.)
  • Companion generation comparison changes intended behavior with a stated reason (8f62210: Require captured companion contents to match before migration; this PR retains that check for first admission and applies the existing session-owned exception to previously admitted paths.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit db37496 adds src/infra/update-doctor-migration-attribution.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: db37496952a4; files: src/infra/update-doctor-migration-attribution.ts)

PR surface

Source -37, Tests +67. Total +30 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 39 -37
Tests 1 75 8 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 77 47 +30

Review metrics

Metric Value Why it matters
Production versus test LOC Production +2/-39; tests +75/-8 Production shrinks by removing the redundant observer; added coverage exercises close settlement and distinguishes admitted companions from untouched paths.

Labels

Label changes:

  • add P2: This is a bounded update-path improvement that removes repeated work and prevents rejection of session-owned companion changes.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded update-path improvement that removes repeated work and prevents rejection of session-owned companion changes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rank-up moves

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

  • Supply the declared native baseline/candidate count comparison, including both Doctor passes and Gateway MAIN.
  • Demonstrate upgrade and rollback from the latest stable release with existing settings and data 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 October 27, 2026, 4:01 PM ET / 20:01 UTC.

@steipete
steipete merged commit ba2c432 into main Oct 27, 2026
137 checks passed
@steipete
steipete deleted the dbasync/custodysql branch October 27, 2026 22:38
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
Remove migration-specific native-close generation and authority probes now that Doctor session settlement publishes the final postimage for every captured SQLite path it opened. Admit later companions on already-opened paths while preserving first-open and untouched-path validation, native exclusion, and credential authority checks.

Owner work-count regressions and exact-head CI, including all three PostgreSQL conformance shards, pass. Native count comparison remains a maintainer-approved post-merge follow-up.
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: 🦐 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