Skip to content

perf(doctor): delete the heavy doctor barrel and finish slimming enumeration - #120882

Merged
steipete merged 4 commits into
mainfrom
claude/doctor-closure-slimming
Aug 9, 2026
Merged

steipete merged 4 commits into
mainfrom
claude/doctor-closure-slimming

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor enumeration cold-loads every declaring plugin's contract closure, so one
heavy import inside a closure is paid by the whole openclaw doctor sweep and by
the startup migration scan. #120678 removed the worst offenders; this finishes the
job and deletes the barrel that made the problem possible.

It also repairs two things that are broken on main today:

  • The closure guard landed in perf(doctor): slim remaining heavy doctor contract closures #120811 fails on main — three closures import a
    heavy barrel for one symbol each.
  • Discord's built doctor contract fails to load in packaged builds and silently
    loses its repairs (an ESM-only transitive dependency reached through dist
    chunking), so 12 of its legacy config rules never run.

Why This Change Was Made

plugin-sdk/runtime-doctor is deleted. Its heavy exports move to narrow
private-local subpaths, each with one purpose, so no caller can pull the
state-database graph through a doctor barrel again:

Subpath Owns Used by
doctor-repair-runtime install-path diagnosis, plugin config removal, state-db schema repair matrix doctor, voice-call (lazy)
plugin-state-store-runtime sync keyed-store factory qa-lab, matrix
model-ref-parse parseModelRef, normalizeProviderId llm-task, discord
session-store-paths resolveStorePath telegram
outbound-echo-runtime recordOutboundMessageIdentity discord

The store factory deliberately does not go in plugin-state-runtime: hot
channel entrypoints import that at module load, and opening a store pulls the
state-database graph.

Four more closures were pulling whole graphs for trivial helpers. Each is repaired
at the leaf rather than by caching downstream:

  • Legacy private-network config migration only reshapes records but lived beside
    the SSRF runtime (DNS, proxy state, logging). Moved to a config leaf; ssrf-policy
    re-exports it. Cost mattermost ~2.7s.
  • Streaming config readers read two config keys, but streaming.ts also formats
    tool aggregates, pulling tool-display → logging → acp-core. Cost slack ~2.3s.
  • signal took the channel-secret barrel for isRecord; the canonical plugin
    record guard is string-coerce-runtime (root AGENTS.md).
  • llm-task took the provider-model barrel for parseModelRef.

The guard gains a rule per repaired barrel, and stops walking artifacts of plugins
whose manifest declares no doctor surface — such a declaration gates the artifact off
every enumeration path exactly as resolvePluginDoctorContracts does, so its closure
cost cannot be incurred. Absent declarations still load eagerly and stay enforced.

User Impact

openclaw doctor and the startup migration scan get materially faster, and Discord
operators get back doctor repairs that silently did nothing in packaged builds. No
plugin API was removed: every touched SDK subpath keeps a byte-identical runtime
export surface.

Evidence

Full enumeration of all declaring plugins, built mode, same machine, three runs each:

main this branch
legacy config rules 10436 ms 4864 ms
rules actually enumerated 87 99 (discord restored)
state migrations 445 ms 361 ms

On a base without the pre-existing telegram build defect (measured before rebasing
onto current main), the same sweep went 6668 ms → 1265 ms, and no plugin
remained an outlier: worst ~380 ms against a ~200 ms floor, down from mattermost
2724 ms and slack 2289 ms.

Surface safety: built module exports were diffed before/after for all seven affected
SDK subpaths (ssrf-policy, ssrf-runtime, channel-streaming-config,
channel-outbound, channel-streaming, channel-message, infra-runtime) —
identical in every case. The API baseline hashes move only because re-exported
declarations emit differently.

Checks: closure guard (green — it fails on main), plugin contracts (44 files/1056
tests), telegram/discord/matrix/slack/signal/mattermost/anthropic/llm-task suites,
plugin-sdk surface + export + API baseline gates, release pretag pack check (91
plugins), import cycles, tsgo core + extensions, full pnpm build, and a clean
structured pre-land review.

Two failures reproduce identically on clean main and are not touched here:
npm-install-security-scan.release.test.ts (performs real installs) and
bot-message-dispatch.draft-failures-progress.test.ts.

Known Follow-up

Telegram's built doctor artifact still reaches execa through dist chunking and
fails to require in packaged builds, losing its repairs. Its source closure is clean
(the guard passes); the artifact pulls telegram's runtime stores — bot-info-cache,
sticker-cache-store, update-offset-store, sent-message-cache,
topic-name-cache — whose chunks carry runtime code. That is a build-level defect
with a different owner and is pre-existing on main; it dominates the remaining
4.8 s and is filed separately rather than bolted onto this change.

@steipete
steipete marked this pull request as ready for review August 9, 2026 04:32
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: nextcloud-talk Channel integration: nextcloud-talk channel: signal Channel integration: signal channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call extensions: llm-task Extension: llm-task scripts Repository scripts extensions: qa-lab extensions: xai size: L maintainer Maintainer-authored PR labels Aug 9, 2026
Nothing may pull the state-db/kysely graph through a doctor barrel anymore.
The barrel's remaining heavy exports move to two narrow private-local
subpaths, each with a single purpose:

- doctor-repair-runtime: install-path diagnosis, plugin config removal, and
  state-database schema detect/repair (matrix doctor, voice-call lazy import)
- plugin-state-store-runtime: the sync keyed-store factory. It stays out of
  plugin-state-runtime because hot channel entrypoints import that at module
  load and opening a store pulls the state-database graph.

Doctor closures also stop pulling ssrf-runtime (fetch-guard + gateway net)
for two legacy private-network helpers that live in the lighter ssrf-policy
subpath: mattermost, nextcloud-talk, tlon, matrix.

The closure guard now forbids the two new heavy subpaths instead of the
deleted barrel, so the invariant keeps being enforced where it still applies.
Doctor enumeration cold-loads each declaring plugin's contract closure, so
one heavy import in a closure is paid by the whole sweep. Four barrels were
still dragging unrelated graphs in for trivial helpers; each is repaired at
the leaf rather than by caching downstream:

- Legacy private-network config migration moves to a config leaf. It only
  reshapes records, but lived beside the SSRF runtime (DNS, proxy, logging),
  costing mattermost ~2.7s. ssrf-policy re-exports it, surface unchanged.
- Streaming config readers move to a leaf. They read two config keys, but
  streaming.ts also formats tool aggregates, pulling tool-display/logging/
  acp-core; that cost slack ~2.3s.
- signal took the channel-secret barrel for isRecord; the canonical plugin
  record guard is string-coerce-runtime (root AGENTS.md).
- llm-task took the provider-model barrel for parseModelRef, now a narrow
  model-ref-parse subpath.

Full doctor enumeration of all 42 declaring plugins, built mode:
legacy config rules 6668ms -> 1265ms, state migrations 184ms -> 127ms.
No plugin remains an outlier; the slowest is now ~380ms against a ~200ms floor.

Public export surfaces of every touched SDK subpath are byte-identical
(verified by diffing built module exports before/after); the API baseline
hashes move only because re-exported declarations emit differently.

The closure guard gains rules for each repaired barrel so the invariant
holds for future closures.
…ed package

Same pack-path rule as c41da37: private-local subpaths ship without d.ts.
@steipete
steipete force-pushed the claude/doctor-closure-slimming branch from 2cad3eb to fa86c6d Compare August 9, 2026 04:34
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. 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: found issues before merge. Reviewed August 9, 2026, 12:42 AM ET / 04:42 UTC.

ClawSweeper review

What this changes

This PR replaces the broad doctor runtime SDK entrypoint with narrow internal subpaths and leaf helpers so doctor contract enumeration avoids loading heavyweight runtime graphs.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the new model-ref leaf still statically loads the manifest/state-database path, so the llm-task doctor closure retains the expensive dependency graph this PR is meant to remove. The patch also removes a current documented SDK import without updating its migration guide; the facade is main-only rather than shipped, so this is a pre-release contract decision rather than a released-user regression.

Priority: P2
Reviewed head: fa86c6d4f5057b404603a341c84077d1a412f933
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The stated measurements are useful, but two concrete correctness and compatibility blockers remain.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR includes built-mode enumeration measurements in its body; the external-contributor proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR includes built-mode enumeration measurements in its body; the external-contributor proof gate does not apply.
Evidence reviewed 5 items Current external-plugin guidance: The migration guide directs channel-plugin authors to import definePluginDoctorMigrationFromPlans from runtime-doctor, while that builder is already available from runtime-doctor-migrations.
Model parser remains heavyweight: Current parseModelRef imports model-ref-shared, which imports manifest model normalization; that path resolves plugin metadata and its installed-index reader imports the state database. The supplied PR diff re-exports this parser from the new model-ref leaf.
Doctor closure consumes the parser: The llm-task doctor contract calls parseModelRef while preserving legacy model references, so loading the contract takes the parser dependency closure during enumeration.
Findings 2 actionable findings [P2] Keep model parsing off the doctor closure
[P2] Update the documented doctor migration import
Security None None.

How this fits together

OpenClaw doctor loads plugin migration contracts during CLI checks and startup migration scans. Those contracts read legacy configuration or state and produce repair rules and operator diagnostics.

flowchart LR
  A[Doctor CLI and startup scan] --> B[Plugin manifest discovery]
  B --> C[Doctor contract enumeration]
  C --> D[Focused SDK helper imports]
  D --> E[Config and state migration rules]
  E --> F[Operator diagnostics and repairs]
Loading

Decision needed

Question Recommendation
Should runtime-doctor be removed before its first release with the documentation moved to runtime-doctor-migrations, or should it remain as a deprecated external facade for a migration window? Remove before release and update the guide: Keep the removal, change the migration guide to runtime-doctor-migrations, and repair the parser closure before merge.

Why: Current docs and the workspace SDK facade describe an external plugin import, but release history shows the exact path is main-only; that compatibility direction requires maintainer intent.

Before merge

  • Keep model parsing off the doctor closure (P2) - This new leaf re-exports parseModelRef from model-selection-normalize, whose static path reaches manifest normalization and the installed-plugin state-database reader. The llm-task doctor contract imports it during enumeration, so the claimed slimming does not occur; split or use a parser with no manifest/plugin-runtime imports and extend the closure proof for this transitive edge.
  • Update the documented doctor migration import (P2) - The plugin migration guide still tells external authors to import definePluginDoctorMigrationFromPlans from runtime-doctor. Removing this facade makes that documented import fail resolution; point the guide to runtime-doctor-migrations or retain a deprecated facade if the existing contract is meant to survive.
  • Resolve merge risk (P1) - Removing a currently documented external SDK subpath needs an explicit pre-release compatibility decision: update the migration guide before removal, or retain a deprecated facade through a migration window.

Findings

  • [P2] Keep model parsing off the doctor closure — src/plugin-sdk/model-ref-parse.ts:9
  • [P2] Update the documented doctor migration import — packages/plugin-sdk/package.json:195-198
Agent review details

Security

None.

PR surface

Source +49, Tests -108, Config +25, Generated 0, Other +8. Total -26 across 41 files.

View PR surface stats
Area Files Added Removed Net
Source 32 300 251 +49
Tests 3 48 156 -108
Docs 0 0 0 0
Config 3 34 9 +25
Generated 1 7 7 0
Other 2 12 4 +8
Total 41 401 427 -26

Review metrics

Metric Value Why it matters
Doctor SDK subpaths 1 removed, 5 added The change replaces a documented SDK import with private runtime entrypoints, making the intended external-plugin compatibility direction important before merge.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/matrix/auth-presence.ts, migration/backfill/repair: extensions/matrix/src/doctor-contract.ts, migration/backfill/repair: extensions/matrix/src/doctor.ts, migration/backfill/repair: extensions/matrix/src/matrix/credentials-read.ts, migration/backfill/repair: extensions/mattermost/src/doctor-contract.ts, migration/backfill/repair: extensions/nextcloud-talk/src/doctor-contract.ts, and 20 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #120882
Summary: This PR is the current canonical follow-up for doctor-contract closure slimming; the two merged PRs established the same enumeration-performance invariant but do not contain this remaining fix.

Members:

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

Merge-risk options

Maintainer options:

  1. Repair the leaf and document the removal (recommended)
    Split the parser away from manifest/state imports and update the external migration guide if maintainers confirm pre-release removal of the old facade.
  2. Preserve a migration facade
    Keep runtime-doctor as a deprecated re-export until maintainers set and document a compatibility window.

Technical review

Best possible solution:

Use a genuinely dependency-light model-reference parser for the llm-task migration and extend the closure proof to catch its transitive graph, then document the supported doctor-migration import before removing the old facade.

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

Yes, from source: loading the new model-ref leaf reaches model-ref-shared, manifest normalization, plugin metadata, and the state-database reader before the llm-task doctor contract can enumerate.

Is this the best way to solve the issue?

No: re-exporting parseModelRef through a new leaf does not make it lightweight because its existing static dependency chain remains; a genuinely isolated parser plus a transitive closure check is the maintainable repair.

Full review comments:

  • [P2] Keep model parsing off the doctor closure — src/plugin-sdk/model-ref-parse.ts:9
    This new leaf re-exports parseModelRef from model-selection-normalize, whose static path reaches manifest normalization and the installed-plugin state-database reader. The llm-task doctor contract imports it during enumeration, so the claimed slimming does not occur; split or use a parser with no manifest/plugin-runtime imports and extend the closure proof for this transitive edge.
    Confidence: 0.95
  • [P2] Update the documented doctor migration import — packages/plugin-sdk/package.json:195-198
    The plugin migration guide still tells external authors to import definePluginDoctorMigrationFromPlans from runtime-doctor. Removing this facade makes that documented import fail resolution; point the guide to runtime-doctor-migrations or retain a deprecated facade if the existing contract is meant to survive.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7f3cc6995bc6.

Labels

Label changes:

  • add P2: The patch leaves a doctor-enumeration performance defect and a documented plugin import mismatch, with bounded operator and plugin-author impact.
  • add merge-risk: 🚨 compatibility: The PR removes the current runtime-doctor package subpath while documentation still directs external plugin authors to it.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR includes built-mode enumeration measurements in its body; the external-contributor proof gate does not apply.

Label justifications:

  • P2: The patch leaves a doctor-enumeration performance defect and a documented plugin import mismatch, with bounded operator and plugin-author impact.
  • merge-risk: 🚨 compatibility: The PR removes the current runtime-doctor package subpath while documentation still directs external plugin authors to it.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR includes built-mode enumeration measurements in its body; the external-contributor proof gate does not apply.

Evidence

What I checked:

  • Current external-plugin guidance: The migration guide directs channel-plugin authors to import definePluginDoctorMigrationFromPlans from runtime-doctor, while that builder is already available from runtime-doctor-migrations. Public docs: docs/plugins/sdk-migration.md. (docs/plugins/sdk-migration.md:92, 7f3cc6995bc6)
  • Model parser remains heavyweight: Current parseModelRef imports model-ref-shared, which imports manifest model normalization; that path resolves plugin metadata and its installed-index reader imports the state database. The supplied PR diff re-exports this parser from the new model-ref leaf. (src/agents/model-selection-normalize.ts:7, 7f3cc6995bc6)
  • Doctor closure consumes the parser: The llm-task doctor contract calls parseModelRef while preserving legacy model references, so loading the contract takes the parser dependency closure during enumeration. (extensions/llm-task/doctor-contract-api.ts:13, 7f3cc6995bc6)
  • Release and ownership provenance: runtime-doctor was introduced by steipete on current main after the supplied latest-release commit, so no tagged release evidence establishes an existing shipped consumer of this exact facade. (src/plugin-sdk/runtime-doctor.ts:1, 75dbe52e3e40)
  • Patch availability: The local partial clone did not materialize the PR-head objects and attempted to fetch them over unavailable DNS; changed-line assessment therefore uses the supplied PR diff, while current-main source above was read locally. (fa86c6d4f505)

Likely related people:

  • steipete: Peter Steinberger introduced the current runtime-doctor path and is the author of the related doctor-enumeration work and this PR. (role: introduced current behavior and recent area contributor; confidence: high; commits: 75dbe52e3e40, c2e7c819f570; files: src/plugin-sdk/runtime-doctor.ts, src/plugins/doctor-contract-registry.ts, packages/plugin-sdk/package.json)

Rank-up moves

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

  • Use a parser whose module closure excludes manifest and state-database loading, and prove that transitive invariant.
  • Update the documented plugin migration import after confirming the intended fate of runtime-doctor.

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.

The landed guard fails on main: three closures import heavy barrels for one
symbol each. Two more surfaced once the guard learned about the provider-model
barrel. Each gets a narrow subpath at the leaf:

- telegram sent-message-cache + state-migrations took the session-store barrel
  (session accessor + state-db) for resolveStorePath -> session-store-paths
- discord thread-bindings.state took the channel-outbound barrel (reply
  pipeline + channel registry) for one identity write -> outbound-echo-runtime
- discord model-picker took the provider-model barrel for normalizeProviderId,
  which model-ref-parse now exposes beside parseModelRef

The guard also stops walking artifacts of plugins whose manifest declares no
doctor surface. Such a declaration gates the artifact off every enumeration
path exactly as resolvePluginDoctorContracts does, so its closure cost is never
paid; anthropic ("doctorContract": {}) was being held to a cost it cannot
incur. Absent declarations still load eagerly and stay enforced.

Side effect worth naming: discord's built doctor contract now loads again.
On main both discord and telegram fail to require in packaged builds (an
ESM-only transitive dep) and silently lose their repairs; this restores
discord and takes enumerated legacy config rules from 87 to 99. Telegram's
built artifact still pulls execa through dist chunking - a build-level defect
with a different owner, filed as follow-up.
@steipete
steipete force-pushed the claude/doctor-closure-slimming branch from fa86c6d to 62bbdc7 Compare August 9, 2026 04:47
@steipete
steipete merged commit 6192673 into main Aug 9, 2026
124 checks passed
@steipete
steipete deleted the claude/doctor-closure-slimming branch August 9, 2026 05:01
steipete added a commit that referenced this pull request Aug 9, 2026
…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 added a commit that referenced this pull request Aug 9, 2026
…uard it transitively (#120876)

* perf(plugins): close the last kysely closure chains and guard reachability 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.

* fix(telegram): repoint the native-command menu state at the token-fingerprint parser
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…eration (openclaw#120882)

* refactor(plugin-sdk): delete the heavy runtime-doctor barrel

Nothing may pull the state-db/kysely graph through a doctor barrel anymore.
The barrel's remaining heavy exports move to two narrow private-local
subpaths, each with a single purpose:

- doctor-repair-runtime: install-path diagnosis, plugin config removal, and
  state-database schema detect/repair (matrix doctor, voice-call lazy import)
- plugin-state-store-runtime: the sync keyed-store factory. It stays out of
  plugin-state-runtime because hot channel entrypoints import that at module
  load and opening a store pulls the state-database graph.

Doctor closures also stop pulling ssrf-runtime (fetch-guard + gateway net)
for two legacy private-network helpers that live in the lighter ssrf-policy
subpath: mattermost, nextcloud-talk, tlon, matrix.

The closure guard now forbids the two new heavy subpaths instead of the
deleted barrel, so the invariant keeps being enforced where it still applies.

* perf(doctor): keep heavy graphs out of every doctor closure

Doctor enumeration cold-loads each declaring plugin's contract closure, so
one heavy import in a closure is paid by the whole sweep. Four barrels were
still dragging unrelated graphs in for trivial helpers; each is repaired at
the leaf rather than by caching downstream:

- Legacy private-network config migration moves to a config leaf. It only
  reshapes records, but lived beside the SSRF runtime (DNS, proxy, logging),
  costing mattermost ~2.7s. ssrf-policy re-exports it, surface unchanged.
- Streaming config readers move to a leaf. They read two config keys, but
  streaming.ts also formats tool aggregates, pulling tool-display/logging/
  acp-core; that cost slack ~2.3s.
- signal took the channel-secret barrel for isRecord; the canonical plugin
  record guard is string-coerce-runtime (root AGENTS.md).
- llm-task took the provider-model barrel for parseModelRef, now a narrow
  model-ref-parse subpath.

Full doctor enumeration of all 42 declaring plugins, built mode:
legacy config rules 6668ms -> 1265ms, state migrations 184ms -> 127ms.
No plugin remains an outlier; the slowest is now ~380ms against a ~200ms floor.

Public export surfaces of every touched SDK subpath are byte-identical
(verified by diffing built module exports before/after); the API baseline
hashes move only because re-exported declarations emit differently.

The closure guard gains rules for each repaired barrel so the invariant
holds for future closures.

* fix(release): exclude new private-local declarations from the published package

Same pack-path rule as c41da37: private-local subpaths ship without d.ts.

* fix(doctor): repair the closure guard violations that break main

The landed guard fails on main: three closures import heavy barrels for one
symbol each. Two more surfaced once the guard learned about the provider-model
barrel. Each gets a narrow subpath at the leaf:

- telegram sent-message-cache + state-migrations took the session-store barrel
  (session accessor + state-db) for resolveStorePath -> session-store-paths
- discord thread-bindings.state took the channel-outbound barrel (reply
  pipeline + channel registry) for one identity write -> outbound-echo-runtime
- discord model-picker took the provider-model barrel for normalizeProviderId,
  which model-ref-parse now exposes beside parseModelRef

The guard also stops walking artifacts of plugins whose manifest declares no
doctor surface. Such a declaration gates the artifact off every enumeration
path exactly as resolvePluginDoctorContracts does, so its closure cost is never
paid; anthropic ("doctorContract": {}) was being held to a cost it cannot
incur. Absent declarations still load eagerly and stay enforced.

Side effect worth naming: discord's built doctor contract now loads again.
On main both discord and telegram fail to require in packaged builds (an
ESM-only transitive dep) and silently lose their repairs; this restores
discord and takes enumerated legacy config rules from 87 to 99. Telegram's
built artifact still pulls execa through dist chunking - a build-level defect
with a different owner, filed as follow-up.
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: discord Channel integration: discord channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: nextcloud-talk Channel integration: nextcloud-talk channel: signal Channel integration: signal channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call docs Improvements or additions to documentation extensions: llm-task Extension: llm-task extensions: qa-lab extensions: xai maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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