Repository navigation
perf(plugins): make every plugin closure statically kysely-free and guard it transitively - #120876
Conversation
98bbf81 to
09cd9c0
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 12:44 AM ET / 04:44 UTC. ClawSweeper reviewWhat this changesThis PR splits light plugin doctor/setup helpers from database-heavy modules and adds a static test preventing Kysely from entering those import closures. Merge readinessKeep open for maintainer review: no concrete code regression was found, but this adds a public SDK callable and the required direct Codex compatibility inspection is unavailable. Priority: P3 Review scores
Verification
How this fits togetherPlugin doctor and channel setup load manifest-declared closures before performing migrations. This change keeps those control-plane paths on light SDK helpers while deferring database-backed runtime work until it is needed. flowchart LR
A[Plugin manifests] --> B[Doctor and setup closures]
B --> C[Static import guard]
C --> D[Light SDK helpers]
D --> E[Doctor migrations]
E --> F[Plugin and channel state]
Decision needed
Why: This is a permanent plugin SDK contract decision, and repository policy requires direct Codex-source inspection for the compatibility claim. Before merge
Agent review detailsSecurityNone. PR surfaceSource +203, Tests +70, Docs +1, Config +7, Generated 0, Other +4. Total +285 across 40 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the light control-plane boundary, but confirm the public Do we have a high-confidence way to reproduce the issue? Not applicable as an issue reproduction; the PR supplies performance measurements, while source review confirms the affected doctor/setup closure paths. Is this the best way to solve the issue? Unclear: the light-boundary refactor is coherent, but direct Codex contract evidence and public SDK intent are required before calling it the best solution. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7f3cc6995bc6. 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
|
d94b19c to
84ea99e
Compare
|
Pre-merge verification (head
|
…ility transitively Follow-up to #120698/#120811/#120882: the closure guard's enumerated barrel bans cannot catch new heavy edges, and two closures still statically reached kysely on main. - guard: add a transitive kysely-reachability test that walks static value imports from every doctor-contract and legacy-setup closure through plugin, plugin-sdk, and relative core graphs, failing with the full import chain; type-only and lazy dynamic imports stay allowed - llm-task/model refs: manifest-model-id-normalization reads snapshots through a registration-slot runtime bridge (snapshot modules register at eval; require fallback covers cold processes) and current-plugin-metadata-state moves its process-scoped facts onto a globalThis singleton so dual module instances share published state - telegram: split thread-bindings-store.ts (pure record shapes + legacy-file readers) out of the acp-runtime-heavy manager, delete the consumer-less testing export, move the pure bot-user-id token parse to token-fingerprint.ts, and lazy-import token.js in the async update-offset detector llm-task enumeration drops to ~0.8s/157 modules cold; every closure is now statically kysely-free and stays that way by construction.
84ea99e to
a5f546e
Compare
|
Merged via squash.
|
…uard it transitively (openclaw#120876) * perf(plugins): close the last kysely closure chains and guard reachability transitively Follow-up to openclaw#120698/openclaw#120811/openclaw#120882: the closure guard's enumerated barrel bans cannot catch new heavy edges, and two closures still statically reached kysely on main. - guard: add a transitive kysely-reachability test that walks static value imports from every doctor-contract and legacy-setup closure through plugin, plugin-sdk, and relative core graphs, failing with the full import chain; type-only and lazy dynamic imports stay allowed - llm-task/model refs: manifest-model-id-normalization reads snapshots through a registration-slot runtime bridge (snapshot modules register at eval; require fallback covers cold processes) and current-plugin-metadata-state moves its process-scoped facts onto a globalThis singleton so dual module instances share published state - telegram: split thread-bindings-store.ts (pure record shapes + legacy-file readers) out of the acp-runtime-heavy manager, delete the consumer-less testing export, move the pure bot-user-id token parse to token-fingerprint.ts, and lazy-import token.js in the async update-offset detector llm-task enumeration drops to ~0.8s/157 modules cold; every closure is now statically kysely-free and stays that way by construction. * fix(telegram): repoint the native-command menu state at the token-fingerprint parser
What Problem This Solves
Follow-up to #120698, #120811, and #120882. Two gaps remained after the heavy doctor barrel was deleted: (1) the closure guard only bans an enumerated list of heavy barrels, so a new heavy edge through any unlisted barrel ships silently — exactly how the remaining regressions below survived; (2) two closures still statically reach kysely on current
main: llm-task viamodel-ref-parse→model-selection-normalize→model-ref-shared→manifest-model-id-normalization→ plugin metadata snapshot → installed-plugin index, and telegram viastate-migrations→thread-bindings.ts→acp-runtime(plustoken.js→provider-auth→ config graph).Why This Change Was Made
The transitive backstop.
doctor-contract-closure-guard.test.tsgains a kysely-reachability test: from every doctor-contract and legacy-setup closure it walks static value imports through plugin code,openclaw/plugin-sdk/*subpaths, and relative core/package graphs, and fails with the full import chain when any path reaches thekyselypackage (the leaf every measured heavy chain ends in). Type-only and lazy dynamic imports stay allowed. This is behavior-level enforcement: no future barrel rename, new subpath, or second-hop edge can dodge it. It found both remaining chains onmainimmediately.llm-task / manifest normalization.
manifest-model-id-normalizationnow reads snapshots through a registration-slot runtime bridge (plugin-metadata-snapshot.runtime.ts): the snapshot modules register their readers at eval time (any process that publishes or scopes a snapshot has loaded them), with acreateRequirefallback for cold processes (built.jsviarequire(esm), jiti-hooked.tsfor doctor closures) — the same shape as the existingprovider-model-normalization.runtime.tsbridge beside it.current-plugin-metadata-statemoves its process-scoped facts onto a globalThis singleton, matching the scoped-snapshot ALS that already lives there, so a require-loaded second module instance shares published state. Call-time behavior is identical;model-ref-sharedkeeps its direct import. Named tradeoff: vitest workers that never load the metadata system resolve ambient manifest policies as empty — which is also the true state in such workers; the one disk-fallback test arranges registration with an explicit commented side-effect import.Telegram closure.
thread-bindings-store.tssplits the pure record shapes, key builders, and legacy-file readers out of the acp-runtime-heavy manager module (whose consumer-lesstestingexport is deleted);state-migrationsuses the store module andresolveTelegramThreadBindingsPathdirectly. The pure bot-user-id token parse moves totoken-fingerprint.ts(repointing the four send funnels andupdate-offset-store), and the update-offset detector lazy-importstoken.jsinside its async body so the provider-auth/config graph loads only when the migration runs.User Impact
openclaw doctorand channel setup no longer cold-load the kysely graph for any bundled plugin closure: llm-task enumeration drops to ~0.8s cold (~157 modules), telegram loses its acp/session and provider-auth/config cold-loads. Any future closure regression fails CI with the full offending import chain. No behavior change to migrations, model-ref normalization, or token resolution.Evidence
node scripts/run-vitest.mjs src/plugins/doctor-contract-closure-guard.test.ts— 4 tests green; the new backstop reproducibly flags both chains on unpatchedmain(full chains in the test output).pnpm tsgo:core,pnpm tsgo:extensions,pnpm check:test-types,pnpm check:import-cycles(0 cycles),pnpm plugin-sdk:surface:check(no SDK surface change — the bridge is core-internal),pnpm deadcode:full, oxfmt/oxlint clean; fullpnpm buildexit 0 with no[INEFFECTIVE_DYNAMIC_IMPORT].require.cachefree ofnode_modules/kyselyfor every closure.