Repository navigation
perf(plugins): keep state-db write machinery out of metadata read paths - #131417
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Metadata-only CLI reads (openclaw plugins list --json and friends) loaded the full Kysely-backed state-db graph (~250 modules) through three read-path fusions. Split them, behavior-neutral (module layout and imports only): - installed-plugin-index-store.ts now only reads/parses; the write, restore, and refresh functions move verbatim to installed-plugin-index-store-write.ts (write transactions are sync per the SQLite commit doctrine, so this is a module split, not a dynamic import). Writer callers and test mocks route to the write module. - refreshPluginRegistry moves out of plugin-registry-snapshot.ts into plugin-registry-refresh.ts, and the plugin-registry.ts barrel no longer re-exports it: ESM evaluates every barrel re-export source, so that one writer re-export dragged the write graph into every barrel consumer on the metadata path. - openclaw-state-db-readonly.ts no longer imports the heavy openclaw-state-db.js module: cache-trio calls go straight to openClawStateDatabaseCache, constants come from openclaw-state-db-contract.js, and registerNodeSqliteKyselyQueryErrorHandler moves into kysely-sync-cache-state.ts (that module's stated charter). Doctor and gateway schema preflights read OPENCLAW_STATE_SCHEMA_VERSION from the contract module instead of value-loading the heavy module; the now-dead wrapper exports are deleted or un-exported. Module-load census on the built CLI (module.registerHooks recorder, isolated HOME): the installed-plugin-index / manifest-registry / store / readonly / snapshot chain no longer imports the openclaw-state-db chunk, and the write module does not load on plugins list --json. kysely itself still loads via the separately owned config-io fusions (io.health-state, legacy-config-migrations -> config-machine-state, sqlite-audit-record-store, cron store) - the remaining named follow-ups from #131181. Named follow-up from #131181 (f49d250).
b5b5554 to
8640e42
Compare
|
The earlier CI stop is resolved by 3a25fffd2f2, a separate two-file test-only commit. Both remaining consumers now use the contract/cache owners; assertions are unchanged. The 11 focused tests, full changed gate, isolated autoreview, and exact-head CI run 33138778640 passed. No CI rerun was needed. The latest published ClawSweeper review covers this exact head and reports no actionable code or security findings. Its remaining “Before merge” items are handled as follows: exact-head CI is now complete and green; the maintainer-requested native landing flow has validated review artifacts and completed hosted-gate preparation; refreshed CLI terminal proof is recorded in the PR body. The sole “Rank-up moves” item asks for after-fix proof from a real setup. An isolated, credential-free source-CLI run of All native review/prepare steps passed with prepared head |
|
Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 11:30 PM ET / August 28, 2026, 03:30 UTC. ClawSweeper reviewWhat this changesThis PR moves plugin-index writes and registry refreshes out of metadata-only read imports so plugin listing avoids loading state-database write machinery. Merge readiness⛔ Blocked until stronger real behavior proof is added - 3 items remain No blocking introduced defect was found. The two previous test-import failures are corrected on the exact head; this maintainer-associated, protected PR should remain open for exact-head CI and maintainer review. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherPlugin metadata commands assemble manifests and a persisted plugin index for CLI output. Doctor, installation, and refresh flows mutate that index through the shared SQLite state database. flowchart LR
A[Plugin metadata CLI] --> B[Manifest registry]
B --> C[Plugin index reader]
C --> D[Read-only state database]
E[Doctor and refresh flows] --> F[Plugin index writer]
F --> G[State database transaction]
B --> H[CLI metadata output]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +48, Tests +10, Other +1. Total +59 across 79 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the coherent reader/writer separation once the exact head has green required checks, preserving the metadata path’s lazy import boundary. Do we have a high-confidence way to reproduce the issue? Yes: the metadata CLI has a concrete module-load and JSON-output path, and the prior integration failures are directly corrected in the exact-head test imports. Is this the best way to solve the issue? Yes: retaining one read-only module and one explicit write module is the narrowest maintainable way to keep metadata discovery lazy without changing the state-index contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9458d8b18105. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
|
Merged via squash.
|
…hs (openclaw#131417) * perf(plugins): keep state-db write machinery out of metadata read paths Metadata-only CLI reads (openclaw plugins list --json and friends) loaded the full Kysely-backed state-db graph (~250 modules) through three read-path fusions. Split them, behavior-neutral (module layout and imports only): - installed-plugin-index-store.ts now only reads/parses; the write, restore, and refresh functions move verbatim to installed-plugin-index-store-write.ts (write transactions are sync per the SQLite commit doctrine, so this is a module split, not a dynamic import). Writer callers and test mocks route to the write module. - refreshPluginRegistry moves out of plugin-registry-snapshot.ts into plugin-registry-refresh.ts, and the plugin-registry.ts barrel no longer re-exports it: ESM evaluates every barrel re-export source, so that one writer re-export dragged the write graph into every barrel consumer on the metadata path. - openclaw-state-db-readonly.ts no longer imports the heavy openclaw-state-db.js module: cache-trio calls go straight to openClawStateDatabaseCache, constants come from openclaw-state-db-contract.js, and registerNodeSqliteKyselyQueryErrorHandler moves into kysely-sync-cache-state.ts (that module's stated charter). Doctor and gateway schema preflights read OPENCLAW_STATE_SCHEMA_VERSION from the contract module instead of value-loading the heavy module; the now-dead wrapper exports are deleted or un-exported. Module-load census on the built CLI (module.registerHooks recorder, isolated HOME): the installed-plugin-index / manifest-registry / store / readonly / snapshot chain no longer imports the openclaw-state-db chunk, and the write module does not load on plugins list --json. kysely itself still loads via the separately owned config-io fusions (io.health-state, legacy-config-migrations -> config-machine-state, sqlite-audit-record-store, cron store) - the remaining named follow-ups from openclaw#131181. Named follow-up from openclaw#131181 (aeedd7b). * test: reroute state-db test imports to contract and cache modules
What Problem This Solves
Metadata-only CLI reads (
openclaw plugins list --jsonand every path through config io → plugin-metadata-snapshot → manifest-registry → installed-plugin-index) load the full Kysely-backed state-db graph (~250 modules: theopenclaw-state-dbchunk,kysely, and its zod v4 baggage) that they never use. This is the named follow-up from #131181, which removed the other startup paths that loaded this graph.A module-load census on the pre-fix dist showed three distinct read-path fusions dragging the write machinery in:
src/plugins/installed-plugin-index-store.tsmixed readers (leanwithExistingOpenClawStateDatabaseReadOnly) with writers that statically importrunOpenClawStateWriteTransaction.src/plugins/plugin-registry-snapshot.ts— loaded on the metadata path — statically imported therefreshPersistedInstalledPluginIndexwriter for one 8-line function used only by mutation/doctor flows, and theplugin-registry.tsbarrel re-exported it. ESM evaluates every barrel re-export source, so that single writer re-export forced the write graph onto every barrel consumer.src/state/openclaw-state-db-readonly.tsimported the open-database cache trio and constants from the heavyopenclaw-state-db.jsmodule, andopenclaw-state-db-cache.tsimported two functions fromkysely-sync.js, whose module body instantiates a Kysely dialect.Why This Change Was Made
Write transactions are synchronous (SQLite sync-commit doctrine), so a dynamic import inside the sync writers is not an option — these are module splits, following the precedent stated in
src/infra/kysely-sync-cache-state.ts's own header ("split from kysely-sync so lifecycle owners can clear caches without value-loading kysely"). All three legs are behavior-neutral: identical function bodies and semantics, module layout and imports only.installed-plugin-index-store.tskeeps read/parse; write/restore/refresh functions move verbatim to a newinstalled-plugin-index-store-write.ts. Writer callers and test mocks route to the write module; the kysely-guardrails raw-SQLite allowlist gains the write module entry recording the 1:1 move of the existing INSERT/DELETE calls.refreshPluginRegistrymoves to a newplugin-registry-refresh.ts; the barrel no longer re-exports it and its three callers import it directly (the CLI now loads it only inside the--refreshbranch).openclaw-state-db-readonly.tscallsopenClawStateDatabaseCachedirectly and takes constants fromopenclaw-state-db-contract.js;registerNodeSqliteKyselyQueryErrorHandler(a pure WeakMap set) moves intokysely-sync-cache-state.ts. Doctor and gateway schema preflights readOPENCLAW_STATE_SCHEMA_VERSIONfrom the contract module instead of value-loading the heavy module. Now-dead wrapper exports are deleted or un-exported (bodies unchanged where internal callers remain).User Impact
Metadata-only CLI commands stop paying module-load and allocation cost for write machinery they never invoke. No behavior change: same exports/semantics, no config surface, no schema change, no migration. Groundwork for the remaining #131181 follow-ups (config io
io.health-state, legacy-config-migrations →config-machine-state, audit record store, cron store are now the only loaded importers of the heavy chunk).Evidence
module.registerHooksload/edge recorder via--import, isolated HOME,OPENCLAW_NO_RESPAWN=1,plugins list --json): before — the plugins chain loaded theopenclaw-state-dbchunk + 254 kysely modules viamanifest-registryand the store; after — theinstalled-plugin-index-store-writechunk does not load at all, and no chunk in the installed-plugin-index / manifest-registry / store / readonly / snapshot chain imports the heavy state-db chunk. kysely still loads through the separately-owned config-io fusions named above (the remaining perf(startup): measure default resolve path and gate debug-capture imports #131181 follow-ups, tracked as a spawned task).test/scripts/doctor-config-preflight-plugin-index.built-cli.e2e.test.tsgreen against fresh dist (doctor preflight lease-write through the new write module).node scripts/check-changed.mjsexit 0: format, all tsgo lanes, lint, kysely guardrails, Knip dead-export scan (zero entries), import cycles (zero runtime value cycles).gpt-5.6-sol, high): clean, no accepted/actionable findings.git diff --numstat, classified): production 20 files +437/−410 (net +27, module-boundary imports and shared-export comments only), tooling +1 (allowlist entry), tests/support 56 files +152/−126.Post-rebase integration proof
Head
3a25fffd2f2a01093684b5a7f47a2af0fbed9ac6adds only the two remaining test-consumer migrations in commit 3a25fffd2f2: the state-lifetime test imports the schema version from the contract module, and the transcript auto-start test uses the cache owner with the same resolved database path. Assertions are unchanged. Follow-up production LOC: +0/-0; tests: +9/-4.Fresh validation:
node scripts/run-vitest.mjs test/test-env.state-lifetime.test.ts src/agents/tools/transcripts-tool.auto-start.test.ts: 11 tests passed (4 state-lifetime, 7 transcript auto-stop).node scripts/check-changed.mjs: exit 0, including core/test/script/root-test typechecks, lint, formatting for all 79 changed files, zero dead exports, and zero runtime value import cycles.GREEN, with zero pending checks. No CI rerun was needed.node --import ./scripts/tsx.mjs src/entry.ts plugins list --json, with an isolated temporary HOME/state directory,OPENCLAW_NO_RESPAWN=1, and a credential-free environment, exited 0. JSON parsing succeeded and the result contained 151 plugins. This is source-CLI behavior proof, not a packaged-build replay or a new module-load census. An initial invocation outside the checkout could not resolve a workspace package; running from the checkout supplied the normal TypeScript path configuration.ClawSweeper follow-through for the published review of
8640e421fc9:A new-head ClawSweeper review is in progress. The latest completed review is less than 12 hours old; no redundant re-review request was posted.