Skip to content

perf(plugins): retain settled migration readiness - #178323

Merged
steipete merged 2 commits into
mainfrom
dbasync/pluginready
Oct 20, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/pluginready

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

#178165 correctly prevents plugins from registering before their retained-data migrations finish. Its readiness checks also sent ordinary runtime preparation through artifact-preserving database snapshots and discarded cached results after unrelated state writes or a new plugin metadata owner. That introduced repeated snapshot setup/copy/cleanup and main-thread SQL during runtime preparation.

Ordinary readiness now uses the existing live read worker and retains its result under the deferred-migration owner's process-lifetime admission receipt plus database-engine identity. Committed migration writes retire the receipt; unrelated state writes and ordinary database-handle closure do not. Receipt publication uses the existing commit/rollback and worker propagation owner. Pending migrations still block registration and direct operators to Doctor.

This replaces the metadata-owner/global-write-token cache and removes the snapshot path from ordinary readiness. No schema, SQL text, transaction ordering, or migration-gate change. Explicit artifact-preserving, maintenance and existing-schema inspections keep their separate read contract. A source-key comment documents why session-import recovery cannot write deferred-migration ledger rows.

Measurement

Frozen harness v3.1, three alternating base/candidate pairs (M,C,M,C,M,C), each with the full 300-second connected-idle interval and restart. Base 9f662f896dcf3a7dea8f4a01d198024acab75bff; measured implementation 5e673e7fe4b0587e9b9f50d61e2a347254fc8f8d. Final head 03fbc607cb302d6f926ca1a4855ffb7168249f1b adds only the source-key comment, so runtime measurement and update evidence are reused unchanged.

Counts are SQL / worker requests / MAIN, with median [min–max].

Scope Base Candidate
Readiness family 226 [226–226] / 42 [42–42] / 5 [5–5] 41 [41–41] / 10 [10–10] / 0 [0–0]
Whole workload 3204 [3170–3212] / 819 [818–825] / 103 [102–103] 3021 [2995–3021] / 791 [789–795] / 98 [97–98]
Warm causal turn 46 [46–46] / 11 [11–11] / 0 [0–0] 46 [46–46] / 11 [11–11] / 0 [0–0]
Phase Base Candidate
Boot 315 [315–316] / 89 [89–89] / 50 [50–50] 298 [298–298] / 86 [86–86] / 50 [50–50]
Connect 276 [275–282] / 43 [41–46] / 0 [0–0] 280 [277–282] / 42 [42–42] / 0 [0–0]
First turn 313 [313–348] / 88 [87–102] / 1 [1–1] 236 [235–241] / 77 [76–77] / 0 [0–0]
Second session 482 [482–482] / 115 [115–116] / 2 [2–2] 480 [480–481] / 116 [116–117] / 0 [0–0]
Cron 241 [241–241] / 61 [61–61] / 1 [1–1] 240 [240–240] / 61 [61–61] / 0 [0–0]
Restart boot 328 [327–334] / 105 [105–106] / 38 [37–38] 298 [297–299] / 101 [101–102] / 38 [37–38]
Restart connect 40 [33–40] / 26 [23–26] / 0 [0–0] 52 [50–53] / 26 [24–26] / 0 [0–0]
Restart first turn 269 [236–269] / 65 [65–66] / 1 [1–1] 198 [166–200] / 55 [54–56] / 0 [0–0]

Readiness saves 185 statements, 32 requests and all five runtime MAIN statements in every pair. Its operation breakdown is:

Operation Base SQL/requests Candidate SQL/requests
Deferred-migration worker reads 80/8 5/4
Snapshot staging create 40/10 8/2
Snapshot staging retire 70/10 18/2
Raw-copy admission 1/4 0/0
Snapshot preparation 0/6 0/2
Snapshot allocation 0/4 0/0
Native snapshot lifecycle 30/0 10/0
Synchronous readiness reads 5/0 0/0

The remaining 41/10/0 comprises the pre-existing metadata snapshot family (36/6/0), four cold ledger SELECTs and one ordinary quarantine-admission SELECT. The result cache is isolate-local: Gateway and catalog-worker each read once, then repeat after process restart. First turns, spawned sessions, cron and restart-first turns issue zero readiness SQL after initialization. The synchronous cold CLI/compute-worker adapter remains.

Shared read-family medians are unchanged: exact-entry 18 SELECTs, actor hydration 10, entry-cache snapshots 7, watermark 4, and row-facts operations 27 statements. All five families have zero warm causal statements in every arm. C1 alone had one extra exact-entry SELECT during spawn (19 versus 18); C2/C3 matched the baseline.

Outside readiness, each candidate recorded one extra maintenance preparation (21/4 → 24/5) and metadata maintenance operation (8/4 → 10/5): +5 SQL/+2 requests, outside warm turns. ACP metadata requests changed 1 → 2; scan requests had medians 5 → 6 (candidate range 4–6). Entry-patch SQL fell 173 → 171 and usage-cost SQL 22 → 21. These are disclosed workload differences, not additional savings claimed for this patch. The net measured workload still falls 183 SQL/28 requests/5 MAIN; the fixed readiness-family reduction is the causal claim.

Evidence

  • Original retained-data/Doctor registration test from fix(plugins): defer startup registration until data migrations finish #178165 stays green. Its extension proves zero deferred-migration requests and zero MAIN migration SQL after settlement across fresh async and sync preparations, including an unrelated state write. The same regression fails on the base at the expected extra readiness request.
  • Native and worker migration writes invalidate results; rollback, database/engine separation, explicit snapshots and ordinary close/reopen are covered. All 162 focused owner and affected mock-consumer tests passed using the pinned Bun runtime.
  • Final comment-only head CI 39409732873 passed, including all three PostgreSQL shards and required/static checks. Implementation CI 39404094995 passed, including all three PostgreSQL conformance shards, production/test types, lint and source/architecture checks. Local changed lint, 29 selected test type graphs, Knip (0 findings), Madge (0 cycles), export collisions, T1 (171→171), and dialect ratchet passed. Local core tsrs diagnostics were identical to the pinned base (809 UI DOM/JSX diagnostics); test-root limits were already exceeded, with one required new plugin test. No baseline was relaxed.
  • Published-driver update 39404108487 passed on the measured implementation in one attempt: update finished, readyz=200, running version verified, durable/incognito checks passed, service stopped. That fixture disables plugins; registration proof comes from the tests and live workload above.
  • Isolated Codex implementation review found no actionable P0–P2 findings. PostgreSQL owner review approved commit/rollback publication, live-read semantics, receipt identity and scope separation. The second and final isolated Codex review approved the comment-only follow-up; the PostgreSQL coordinator extended approval to final head 03fbc607cb30.

Accepted boundaries: process reuse relies on sole-live-writer/root custody. Explicit maintenance remains outside the live cache. A migration committed after a captured read retires that receipt for subsequent preparation; no new cross-thread handshake, generation counter or freshness probe is added. Whole-workload totals include background scheduling and conditional install-status work; the fixed readiness delta is the attributable claim. No latency claim.

Production +48/−19 (net +29, including the ownership comment); tests +131/−1; docs +2. The small receipt mechanism removes repeated database work while retaining the data-safety gate.

Thanks @RomneyDa for the retained-data migration gate and safety regression in #178165.

Read the live migration ledger through the shared-state read worker and reuse its readiness across plugin metadata owners. Invalidate only on committed deferred-migration writes, while preserving explicit snapshot inspection and the retained-data registration gate from #178165.

Co-authored-by: Dallin Romney <[email protected]>
@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.

@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-20T09:58:55.745639Z 5e673e7 PR opened
ℹ️ 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 docs Improvements or additions to documentation commands Command implementations size: S labels Oct 20, 2026
@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 changes before merge.

What this changes

This PR retains plugin migration readiness across metadata generations and unrelated writes using a migration-owner receipt.

Example: Doctor completes pending-data-fixture’s migration, then an unrelated machine-state setting changes.

  • Before: A fresh plugin preparation reads the migration ledger again.
  • After: Preparation reuses settled readiness until a migration write invalidates it.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful owner-boundary coverage supports the optimization, but interrupted receipt publication can bypass the retained-data migration gate.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises production owners in process, while the explicitly promised Gateway performance measurements remain pending.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Gateway plugin preparation repeats migration-ledger reads and snapshot work after unrelated state changes.
Reason: The maintainer-authored direction removes avoidable startup work through existing owners without new settings, schemas, or SDK contracts.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the optimization is useful, but interrupted migration commits can leave retained readiness stale and bypass the migration gate.

Priority: P2
Reviewed head: 5e673e7fe4b0587e9b9f50d61e2a347254fc8f8d

Before merge

  • Invalidate readiness when migration receipt publication is interrupted (P1) - After readiness has cached an empty ledger, a migration worker can commit a new pending obligation and terminate before this staged admission publication runs. publishSqliteDatabaseAdmission installs the replacement fact after physical COMMIT, while worker-exit recovery only advances writeRevision/unscopedWriteRevision; it does not revoke this process-lived fact. The new readiness cache no longer consumes either write revision, so subsequent cold plugin loads can keep returning the old empty result and evaluate replacement code against unmigrated data. Preserve invalidation across this lost-publication case through the existing admission/settlement owner, with a regression that retains the host cache while interrupting the writer after COMMIT.

Findings

  • [P1] Invalidate readiness when migration receipt publication is interrupted — src/infra/deferred-plugin-migrations.ts:532-533

Tests

  • Missing end-to-end proof: The planned real-Gateway before/after performance campaign, fresh-install and stable-upgrade validation, and an interrupted-commit regression are not supplied.
Agent review details

How this fits together

The plugin loader reads migration obligations before evaluating replacement plugins; Doctor owns migration completion, and database admission carries invalidation facts between workers.

flowchart TD
  A[Plugin preparation] --> B[Readiness cache]
  B --> C[Shared state read worker]
  C --> D[Migration ledger]
  E[Doctor migration writer] --> D
  E --> F[Admission receipt]
  F --> B
  B --> G[Plugin registration gate]
Loading

Technical review

Best possible solution:

Retain owner-scoped readiness while making migration receipts invalidate safely when a worker loses settlement after a durable commit.

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

Current-main source invalidates readiness after unrelated writes or metadata-owner changes, and the supplied regression reports a matching base failure; no target code was executed during this review.

Is this the best way to solve the issue?

Reusing the existing read worker and migration owner is a focused solution, but receipt invalidation must also cover interrupted settlement rather than only successful publication.

Full review comments:

  • [P1] Invalidate readiness when migration receipt publication is interrupted — src/infra/deferred-plugin-migrations.ts:532-533
    After readiness has cached an empty ledger, a migration worker can commit a new pending obligation and terminate before this staged admission publication runs. publishSqliteDatabaseAdmission installs the replacement fact after physical COMMIT, while worker-exit recovery only advances writeRevision/unscopedWriteRevision; it does not revoke this process-lived fact. The new readiness cache no longer consumes either write revision, so subsequent cold plugin loads can keep returning the old empty result and evaluate replacement code against unmigrated data. Preserve invalidation across this lost-publication case through the existing admission/settlement owner, with a regression that retains the host cache while interrupting the writer after COMMIT.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/plugins/plugin-state-migration-readiness.test.ts --maxWorkers=1
  • pnpm test src/commands/startup-config-preflight.plugin-migration.test.ts --maxWorkers=1
  • pnpm test src/infra/sqlite-database-admission.worker.test.ts --maxWorkers=1
  • Verify the interrupted-commit regression fails on the reviewed head and passes after repair.

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 36b28bb adds src/plugins/plugin-state-migration-readiness.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 36b28bb0f51d; files: src/plugins/plugin-state-migration-readiness.ts)
  • Peter Steinberger: Raw commit 443f0c2 adds src/infra/deferred-plugin-migrations.ts:267 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 443f0c23d437; files: src/infra/deferred-plugin-migrations.ts)

PR surface

Source +28, Tests +130, Docs +2. Total +160 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 47 19 +28
Tests 2 131 1 +130
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 180 20 +160

Labels

Label changes:

  • add P2: A focused startup-performance improvement with a migration-admission correctness defect limited to interrupted worker settlement.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: A focused startup-performance improvement with a migration-admission correctness defect limited to interrupted worker settlement.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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, 6:09 AM ET / 10:09 UTC.

@steipete
steipete merged commit 729f302 into main Oct 20, 2026
143 of 145 checks passed
@steipete
steipete deleted the dbasync/pluginready branch October 20, 2026 11:05
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
Read ordinary deferred-plugin readiness through the live state read worker and retain results under the migration owner's process receipt and database engine. Invalidate on committed ledger changes while preserving the pending-data registration gate and explicit snapshot scopes.

Three alternating baseline/candidate pairs reduce the readiness family from 226 SQL statements / 42 requests / 5 MAIN statements to 41 / 10 / 0. Warm causal work stays 46 / 11 / 0. Retain one cold read per Gateway/catalog isolate; unrelated state writes no longer discard settlement.

Preserve and extend the retained-data migration regression from openclaw#178165. 162 focused tests, PostgreSQL conformance, static CI, two isolated reviews and the published-driver update check pass. Record the source-key namespace guarantee for session-import recovery.

Co-authored-by: Dallin Romney <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant