Skip to content

perf(plugins): make every plugin closure statically kysely-free and guard it transitively - #120876

Merged
steipete merged 2 commits into
mainfrom
claude/doctor-closure-guard-hardening
Aug 9, 2026
Merged

steipete merged 2 commits into
mainfrom
claude/doctor-closure-guard-hardening

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

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 via model-ref-parse → model-selection-normalize → model-ref-shared → manifest-model-id-normalization → plugin metadata snapshot → installed-plugin index, and telegram via state-migrations → thread-bindings.ts → acp-runtime (plus token.js → provider-auth → config graph).

Why This Change Was Made

The transitive backstop. doctor-contract-closure-guard.test.ts gains 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 the kysely package (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 on main immediately.

llm-task / manifest normalization. manifest-model-id-normalization now 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 a createRequire fallback for cold processes (built .js via require(esm), jiti-hooked .ts for doctor closures) — the same shape as the existing provider-model-normalization.runtime.ts bridge beside it. current-plugin-metadata-state moves 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-shared keeps 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.ts splits the pure record shapes, key builders, and legacy-file readers out of the acp-runtime-heavy manager module (whose consumer-less testing export is deleted); state-migrations uses the store module and resolveTelegramThreadBindingsPath directly. The pure bot-user-id token parse moves to token-fingerprint.ts (repointing the four send funnels and update-offset-store), and the update-offset detector lazy-imports token.js inside its async body so the provider-auth/config graph loads only when the migration runs.

User Impact

openclaw doctor and 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

  • Guard: node scripts/run-vitest.mjs src/plugins/doctor-contract-closure-guard.test.ts — 4 tests green; the new backstop reproducibly flags both chains on unpatched main (full chains in the test output).
  • Suites green: model-ref-shared, manifest-model-id-normalization (including the ambient current-snapshot-by-default test that proves bridge semantics), provider-attribution, current-plugin-metadata-snapshot, telegram thread-bindings/state-migrations/token/update-offset-store, llm-task.
  • 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; full pnpm build exit 0 with no [INEFFECTIVE_DYNAMIC_IMPORT].
  • Fresh-process jiti timing: llm-task 768ms/157 modules, telegram kysely-free; require.cache free of node_modules/kysely for every closure.
  • Codex autoreview (gpt-5.6-sol, high): clean.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 04:24
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram extensions: llm-task Extension: llm-task scripts Repository scripts extensions: xai size: XL maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete force-pushed the claude/doctor-closure-guard-hardening branch from 98bbf81 to 09cd9c0 Compare August 9, 2026 04:30
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 12:44 AM ET / 04:44 UTC.

ClawSweeper review

What this changes

This PR splits light plugin doctor/setup helpers from database-heavy modules and adds a static test preventing Kysely from entering those import closures.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep 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
Reviewed head: 81e09851361b1fb91c8c0afefbeac3d8c05ffc22
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent, but merge confidence is limited by the unverified Codex compatibility claim and public SDK expansion.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal performance refactor is exempt from the external contributor proof gate; the PR body supplies claimed focused timing and validation evidence.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal performance refactor is exempt from the external contributor proof gate; the PR body supplies claimed focused timing and validation evidence.
Evidence reviewed 6 items Transitive closure guard: The new guard walks static relative and Plugin SDK imports from each declared doctor/setup closure and fails on a Kysely chain.
Metadata behavior retained: The normalizer still prefers a compatible current snapshot and otherwise resolves metadata; only the reader boundary became lazy.
SDK surface change: state-paths now publicly re-exports resolveStorePath, creating an additional supported import location for an existing compatibility-sensitive helper.
Findings None None.
Security None None.

How this fits together

Plugin 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]
Loading

Decision needed

Question Recommendation
Should state-paths.resolveStorePath become a supported public SDK import after the Beta.5 Codex compatibility assumption is directly verified? Verify and retain the alias: Inspect the sibling Codex runtime’s resolve-to-load/update sequence, then accept the documented light public alias if that contract matches.

Why: This is a permanent plugin SDK contract decision, and repository policy requires direct Codex-source inspection for the compatibility claim.

Before merge

  • Resolve merge risk (P1) - state-paths.resolveStorePath is a new public SDK callable, so third-party plugins could rely on this compatibility-sensitive alias permanently.
  • Resolve merge risk (P1) - The refactor preserves a Beta.5 Codex session-store assumption, but the mandatory direct ../codex source check could not be completed.
  • Complete next step (P2) - A maintainer must confirm the public SDK commitment and obtain the required Codex-source compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +203, Tests +70, Docs +1, Config +7, Generated 0, Other +4. Total +285 across 40 files.

View PR surface stats
Area Files Added Removed Net
Source 29 567 364 +203
Tests 4 144 74 +70
Docs 1 2 1 +1
Config 2 7 0 +7
Generated 1 2 2 0
Other 3 6 2 +4
Total 40 728 443 +285

Review metrics

Metric Value Why it matters
Production versus test LOC production +580/-366, tests +144/-74, docs/generated +4/-3 The net production growth is tied to splitting control-plane ownership and preserving a static import invariant.
Public SDK callable 1 added on state-paths The additional resolveStorePath import location is a compatibility commitment beyond this performance repair.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/plugins/doctor-contract-closure-guard.test.ts, serialized state: extensions/telegram/src/state-migrations.ts, serialized state: src/plugin-sdk/session-store-path-state.ts, serialized state: src/plugin-sdk/session-store-runtime.ts, serialized state: src/plugin-sdk/state-paths.ts, unknown-data-model-change: extensions/telegram/src/state-migrations.ts, and 12 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #120876
Summary: This PR is the remaining closure-lightening follow-up after two merged predecessor PRs.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify the compatibility contract (recommended)
    Before merge, inspect the Beta.5 Codex caller sequence and explicitly confirm that the new public state-paths alias is intended to remain supported.
  2. Avoid the new public alias
    If that contract is not intended to be permanent, keep the lightweight path on a private-local SDK seam instead.

Technical review

Best possible solution:

Keep the light control-plane boundary, but confirm the public state-paths contract and the Codex synchronous path-selection behavior before merging.

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.

Labels

Label changes:

  • add P3: This is a bounded performance and maintainability cleanup without evidence of a current user-facing outage.
  • add merge-risk: 🚨 compatibility: The PR adds a public SDK callable and carries forward a compatibility bridge whose external Codex contract was not directly inspected.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal performance refactor is exempt from the external contributor proof gate; the PR body supplies claimed focused timing and validation evidence.

Label justifications:

  • P3: This is a bounded performance and maintainability cleanup without evidence of a current user-facing outage.
  • merge-risk: 🚨 compatibility: The PR adds a public SDK callable and carries forward a compatibility bridge whose external Codex contract was not directly inspected.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal performance refactor is exempt from the external contributor proof gate; the PR body supplies claimed focused timing and validation evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this branch and the related merged doctor-closure work that established the affected control-plane boundary. (role: recent closure-lightening owner; confidence: high; commits: c2e7c819f570, 8a620a9b5073; files: src/plugins/doctor-contract-closure-guard.test.ts, src/plugin-sdk/session-store-path-state.ts)

Rank-up moves

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

  • Inspect and cite the sibling Codex resolve-to-load/update behavior.
  • Record maintainer acceptance of the new public state-paths callable.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete steipete closed this Aug 9, 2026
@steipete steipete reopened this Aug 9, 2026
@steipete
steipete force-pushed the claude/doctor-closure-guard-hardening branch 2 times, most recently from d94b19c to 84ea99e Compare August 9, 2026 05:22
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed docs Improvements or additions to documentation channel: discord Channel integration: discord extensions: llm-task Extension: llm-task scripts Repository scripts extensions: xai size: XL labels Aug 9, 2026
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Pre-merge verification (head 84ea99ea9d80af62c5fb95093cf1c64fefad82ab):

  • Exact-head CI green. After perf(doctor): delete the heavy doctor barrel and finish slimming enumeration #120882 landed (the parallel session's version of the closure slimming), this branch was rebuilt minimally on top of it: the earlier heads' overlap was dropped and only what main lacks remains — the transitive kysely-reachability guard, the manifest-normalization snapshot bridge, and the telegram thread-bindings/token splits.
  • ClawSweeper's review of 81e09851361 raised two P1s that are both resolved by removal in the rebuild: the new public state-paths.resolveStorePath alias no longer exists in this PR (main's perf(doctor): delete the heavy doctor barrel and finish slimming enumeration #120882 ships session-store-paths instead, and this PR adds no SDK surface at all), and the Beta.5 session-store side-map move it flagged was dropped (session-store-runtime is untouched here). The rebuilt PR touches no codex-extension files; the earlier sibling ../codex inspection (3b36665, codex-rs/app-server-protocol/src/protocol/common.rs ThreadId plain-string serialization) still stands for the record and no Codex protocol surface is involved.
  • Local proof on this head: closure guard (4 tests incl. the transitive backstop, which reproducibly flags the two remaining chains on unpatched main), model-ref-shared / manifest-model-id-normalization / provider-attribution / current-plugin-metadata-snapshot / telegram thread-bindings, state-migrations, token, update-offset-store / llm-task suites; pnpm tsgo:core + tsgo:extensions + check:test-types, check:import-cycles (0), plugin-sdk:surface:check (no surface change), deadcode:full, full pnpm build with no [INEFFECTIVE_DYNAMIC_IMPORT]; Codex autoreview (high) clean.
  • Timing: llm-task doctor closure 768ms/157 modules cold (was ~22s pre-program); every doctor and legacy-setup closure statically kysely-free, now enforced by construction.

…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.
@steipete
steipete force-pushed the claude/doctor-closure-guard-hardening branch from 84ea99e to a5f546e Compare August 9, 2026 06:30
@steipete
steipete merged commit 499d81c into main Aug 9, 2026
120 checks passed
@steipete
steipete deleted the claude/doctor-closure-guard-hardening branch August 9, 2026 07:39
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant