Skip to content

perf(config): stop blocking plugin-update config writes on repeated migration checks - #170695

Merged
steipete merged 1 commit into
mainfrom
perf/config-write-pending-migrations-once
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/config-write-pending-migrations-once

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A plugin update that completes a deferred plugin migration wrote config while reading the migration ledger twice before publication, once in replaceConfigFile and once in the underlying file write. Outside the Gateway, each read was a synchronous SQLite snapshot child that blocked the CLI main thread (about 0.5 s on a built CLI and 1-3 s under heavy load). Both reads only repeated a generation check that publication already performs.

User Impact

No user-visible behavior change. openclaw plugins update and plugin installs that finish a pending plugin migration no longer spend two blocking SQLite snapshot reads per config write. Retained plugin inputs stay protected, and a migration obligation that changes before publication still refuses the write with the same conflict error.

Why This Change Was Made

Inside an unpublished withDeferredPluginConfigCompletion scope, the pre-publication read could only return the scope's admitted generation minus the resolved plugins, or throw. withDeferredPluginMigrationsCurrent already re-reads the pending rows inside the publication write transaction and asserts that exact generation before publishing, for both root and include-owned writes. readConfigWritePendingMigrations now returns the admitted facts directly and leaves the generation check to that point of effect. Scope filtering (resolved owners released, unresolved owners retained) is unchanged.

After publication in the same scope, the function still reads fresh rows, now through the async state-worker read (readDeferredPluginMigrationsAsync) instead of the synchronous main-thread read. readConfigWritePendingMigrations and readConfigWriteMigrationFacts became async; both callers were already async.

Ordinary config writes are unaffected: since #170230 they do not read migration state at all. No write option was added, so plugin code reaching replaceConfigFile/mutateConfigFile through the SDK gains no new way to influence migration protection.

Accepted edge case: a migration obligation that changes between write preparation and publication is now reported at publication rather than at the start of the write. Nothing is published either way; the write only does its validation work before refusing.

Related: #160682, #170230.

Evidence

  • New focused test in src/config/io.deferred-plugin-migrations.test.ts: drives a completion-scoped replaceConfigFile through the real config IO and state database, counting pending-ledger queries executed outside a write transaction. On origin/main it fails with 2 such reads (the publication transaction itself reads 3 more times, unchanged); with this change it records 0. The same test proves a migration obligation recorded in beforeCommit still rejects with DeferredPluginMigrationConflictError and leaves the file unchanged, and that a successful completion keeps the unresolved owner's session.store, releases the resolved owner's plugin config, and records only the unresolved obligations as pending.
  • pnpm test src/config/io.deferred-plugin-migrations.test.ts --maxWorkers=1: 9/9 pass at the PR head. The new test takes 2.9 s; the whole file took 207 s wall (179 s Vitest duration, 74% cold transform) on a host at load ~52 on 32 cores, where its pre-existing tests take 6-11 s each. CI seconds: see the PR CI run.
  • node scripts/check-changed.mjs --staged: every lane green for the changed files, including format, line-cap (io.write.ts stays at its 700-line cap), mock-export, SQLite worker (T1 455 -> 455, no growth), typecheck core, oxlint on the changed files, and import cycles. Two lanes failed only on files this PR does not touch, both inherited from the base commit 33a438a and already fixed on main (the PR merge ref includes both): TS2724 in src/commands/config-preflight-snapshot.test.ts (fixed by test(config): migrate preflight snapshot reader ownership #170619) and the Knip unused export renderBoardWidgetError (fixed by fix(ui): remove obsolete board error adapter #170609).
  • Codex autoreview: scoped-clean at P0, and scoped-clean again at P1 with withDeferredPluginMigrationsCurrent, both publishers, and the completion-scope caller supplied as evidence.
  • Doctor context: a profile of openclaw doctor --fix that showed two pending-migration snapshot children per config write predates perf(config): keep deferred plugin migrations out of normal runs #170230. Since perf(config): keep deferred plugin migrations out of normal runs #170230, ordinary and Doctor legacy-key writes perform no ledger read at all (covered by the existing "normal reads and writes never inspect deferred migration records" test), so this PR targets the remaining completion-scope path.
  • Gap: no built-CLI re-profile of openclaw plugins update; the read count is proven at the config write owner against the real state database.

A config write inside a deferred plugin migration completion scope (plugin
update or install finishing a pending migration) read the pending-migration
ledger twice before publication: once in replaceConfigFile and again in the
file write. Outside the Gateway each read was a synchronous SQLite snapshot
child on the main thread.

Before publication those reads could only return the scope's admitted
generation minus the resolved plugins, or throw. The publication write
transaction (withDeferredPluginMigrationsCurrent) already re-reads the rows
and asserts that exact generation for root and include-owned writes, so the
pre-publication path now returns the admitted facts directly. After
publication in the same scope the fresh read stays, moved to the async
state-worker read. Scope filtering is unchanged, and no write option or
plugin SDK surface is added.

Related: #160682, #170230.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 13, 2026 05:48
@chatgpt-codex-connector

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-13T05:53:51.012208Z c51dbeb Draft marked ready
ℹ️ 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.

@steipete
steipete merged commit 7b73007 into main Oct 13, 2026
203 of 204 checks passed
@steipete
steipete deleted the perf/config-write-pending-migrations-once branch October 13, 2026 06:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…claw#170695)

A config write inside a deferred plugin migration completion scope (plugin
update or install finishing a pending migration) read the pending-migration
ledger twice before publication: once in replaceConfigFile and again in the
file write. Outside the Gateway each read was a synchronous SQLite snapshot
child on the main thread.

Before publication those reads could only return the scope's admitted
generation minus the resolved plugins, or throw. The publication write
transaction (withDeferredPluginMigrationsCurrent) already re-reads the rows
and asserts that exact generation for root and include-owned writes, so the
pre-publication path now returns the admitted facts directly. After
publication in the same scope the fresh read stays, moved to the async
state-worker read. Scope filtering is unchanged, and no write option or
plugin SDK surface is added.

Related: openclaw#160682, openclaw#170230.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant