Skip to content

Commit c2e7c81

Browse files
authored
perf(doctor): slim remaining heavy doctor contract closures (#120811)
* perf(doctor): slim remaining heavy doctor contract closures Follow-up to #120698: several doctor closures still cold-loaded multi-second kysely-bearing graphs through other broad barrels (session-store-runtime, realtime-voice, channel-outbound, logging-core, memory-host-core/-events, sqlite-runtime, persistent-dedupe, and plugin-local barrels). - lazy-import heavy helpers inside async migration bodies (codex, msteams, zalouser, workboard, matrix inbound-dedupe, memory-core migrations) - bypass plugin-local barrels to defining modules (reef protocol, memory-core short-term-promotion) - move to lighter existing subpaths (slack -> channel-streaming, matrix logger -> security-runtime, memory-wiki -> agent-scope-runtime, which now also exports resolveSessionAgentId) - add narrow openclaw/plugin-sdk/realtime-voice-activation for discord's sync wake-name doctor rules - split src/infra/kysely-sync-cache-state.ts so sqlite-transaction clears Kysely caches without value-loading kysely; split the memory-host-sdk kysely bridge off the schema/transaction bridge - guard: forbid the heavy barrels in doctor closures with per-kind scoping Cold enumeration per plugin: discord 52.6s->0.3s, msteams 30.9s->0.5s, codex 29.6s->2.6s, zalouser 28.8s->2.3s, matrix 27.2s->3.2s, slack 17.5s->1.5s, reef 9.9s->0.7s, memory-core 6.4s->3.6s, workboard 3.4s->0.25s; all kysely-free except llm-task (named follow-up). * fix(plugins): route slack streaming compat through a focused streaming-config subpath The channel-streaming compat barrel is deprecated for extension production code (deprecated-api-usage guard + SDK package contract). Add the narrow non-deprecated openclaw/plugin-sdk/channel-streaming-config subpath for the pure streaming config readers, and drop the now consumer-less short-term-promotion barrel re-exports knip flagged. * test(plugins): register memory-host-sdk kysely bridge in package boundary inventory * fix(plugins): classify realtime-voice-activation as private-local ClawSweeper P2: the subpath exports only a default target, which is the private-local shape; register it in plugin-sdk-private-local-only-subpaths, the package-boundary d.ts alias maps, and correct the public surface budgets (realtime-voice-activation no longer counts as public). * fix(release): exclude realtime-voice-activation declarations from the published package Private-local subpaths ship without d.ts; register the files negation the release pack-path check requires.
1 parent b7add0b commit c2e7c81

39 files changed

Lines changed: 289 additions & 121 deletions

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ e5e67ddf3cab38fcbf9220bc3160715897e2709d9a9ff6ff36f1ecc9453c2367 module/agent-c
77
a43840ff36833daef61050fd801e825ec3ba806348b4fbe6c613f20a8807a5e7 module/agent-harness-runtime
88
5168648cd946abad8a92822889f13ceacc87ed502314a66190d0b1eb8ebe76ea module/agent-media-payload
99
e82bf122ca0787ec0bcdd12b669cfe24f07da16be1f4090e84c7d645b07ac79f module/agent-runtime
10-
770bcb35221a019c70eace0200233a3a7985b24a6df48625f3e67b478d071ed1 module/agent-scope-runtime
10+
6d12eed0833b9f63b5cea9a763c470487c85c5a722a3a35ec1f5ce07dc8715a9 module/agent-scope-runtime
1111
56b6d5fb6af3d95af1200065aca2e7d4f59e5fa59740505fe6ff433077ef6646 module/allow-from
1212
55cea5390d68839ca7768b4a0cc570b17b65fa0fa3bc4d76130ef0f16cb79ede module/allowlist-config-edit
1313
7ddd81bd5f55de9adf64bf4d92d012f24b37b6da0a72805a3a220d8feff24ca3 module/approval-auth-runtime
@@ -48,6 +48,7 @@ f3cee48527f5cddde81912a588e72947d40443322b716871a8d9e5dc0c37c542 module/channel
4848
fb123c1b557ed2527e335f13c3d6de41ab0c3305151001cf2b1075d1da8034c5 module/channel-setup
4949
aeac9bb8127faf636dde79772a577d9cb003660ef3d1df03ddf606101020c402 module/channel-status
5050
f008d1d9ea73cd17e9833143bd117436599438523041fd157b6b6cb17500ac06 module/channel-streaming
51+
d1ff8728d99acf8130b94db7ba75ad7050a549c96365f56b8d4f601a533ca947 module/channel-streaming-config
5152
14f0103adb14627b662fbe9fdd5ed08596ed702a250853e8beb8bb8dd1361588 module/cli-argv
5253
c89ec1b194b76f67a6f4dd108dccf460da6065646cba31374c8aa748f23a39e4 module/collection-runtime
5354
391e6f0c77da2e17a058fc5aea87fd193830b2a14e12fae77c7f63b0226f0bb5 module/command-auth

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ deprecated for new code; see the per-row notes below.
124124
| `plugin-sdk/channel-inbound-debounce` | Narrow inbound debounce helpers |
125125
| `plugin-sdk/channel-mention-gating` | Private-local after July 2026; Narrow mention-policy, mention marker, and mention text helpers without the broader inbound runtime surface |
126126
| `plugin-sdk/channel-streaming` | Deprecated compatibility facade. Use `plugin-sdk/channel-outbound`. |
127+
| `plugin-sdk/channel-streaming-config` | Dependency-light channel streaming config readers (`getChannelStreamingConfigObject`, `resolveChannelStreamingNativeTransport`) for doctor contract closures and other control-plane paths that must not load the reply pipeline |
127128
| `plugin-sdk/channel-send-result` | Reply result types |
128129
| `plugin-sdk/channel-actions` | Channel message-action helpers, plus deprecated native schema helpers kept for plugin compatibility |
129130
| `plugin-sdk/channel-route` | Private-local after July 2026; Shared route normalization, parser-driven target resolution, thread-id stringification, dedupe/compact route keys, parsed-target types, and route/target comparison helpers |
@@ -340,6 +341,7 @@ Use `isLoopbackHost(host)` when a plugin must accept only the local machine. It
340341
| `plugin-sdk/realtime-transcription` | Private-local after July 2026; Realtime transcription provider types, registry helpers, and shared WebSocket session helper |
341342
| `plugin-sdk/realtime-bootstrap-context` | Private-local after July 2026; Realtime profile bootstrap helper for bounded `IDENTITY.md`, `USER.md`, and `SOUL.md` context injection |
342343
| `plugin-sdk/realtime-voice-audio-queue` | Private-local JavaScript-only host runtime for bundled or separately published official plugins; narrow bounded audio queue seam for lazy realtime voice provider facades without importing the broader realtime voice runtime; not for third-party plugins |
344+
| `plugin-sdk/realtime-voice-activation` | Private-local; dependency-light realtime-voice activation-name helpers (normalize, match, word-count, sort) for doctor contract closures and other control-plane paths that must not load the realtime voice runtime |
343345
| `plugin-sdk/realtime-voice` | Private-local after July 2026; Realtime voice provider types, registry helpers, shared audio-energy/speech-onset gates, and realtime voice behavior helpers, including the transport-independent session harness and output activity tracking. For official runtime consumers, sender-auth contract revision 1 forwards ingress-authenticated `senderId` and `senderIsOwner` unchanged; ingress owns authentication, and consumers requiring the handoff must fail closed on other revisions. |
344346
| `plugin-sdk/meeting-runtime` | Browser-meeting session runtime, realtime audio engines/transports, `MeetingPlatformAdapter`, browser/node control, agent-consult, voice-call delegation, setup checks, and SoX command helpers |
345347
| `plugin-sdk/image-generation` | Private-local after July 2026; Image generation provider types plus image asset/data URL helpers and the OpenAI-compatible image provider builder |

‎extensions/codex/src/migration/session-binding-sidecars.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
isPathInside,
1919
pathExists,
2020
} from "openclaw/plugin-sdk/security-runtime";
21-
import { patchSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
2221
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
2322
import {
2423
CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
@@ -97,6 +96,9 @@ type MigratedBindingRow =
9796
};
9897

9998
async function collectSessionSurfaces(params: MigrationEnvironment): Promise<SessionSurface[]> {
99+
// Doctor enumeration cold-loads this closure; session-store-runtime pulls the
100+
// session-accessor/kysely graph, so it stays behind lazy imports in async bodies.
101+
const { resolveStorePath } = await import("openclaw/plugin-sdk/session-store-runtime");
100102
const surfaces = new Map<string, SessionSurface>();
101103
const stateRoot = await canonicalPathFromExistingAncestor(params.stateDir);
102104
const add = async (root: string, storePath: string, agentId: string, scan: boolean) => {
@@ -305,6 +307,7 @@ async function collectBindingOwners(
305307
surfaces: SessionSurface[],
306308
params: MigrationEnvironment,
307309
): Promise<BindingOwnerCollection> {
310+
const { resolveStorePath } = await import("openclaw/plugin-sdk/session-store-runtime");
308311
const sourcePaths = new Set(
309312
await Promise.all(
310313
sources.map((source) => canonicalPathFromExistingAncestor(source.transcriptPath)),
@@ -679,6 +682,7 @@ async function recordSessionOwner(
679682
owner: LegacyBindingOwner,
680683
env: NodeJS.ProcessEnv,
681684
): Promise<string | undefined> {
685+
const { patchSessionEntry } = await import("openclaw/plugin-sdk/session-store-runtime");
682686
const currentIndex = await readLegacySessionIndex(owner.storePath);
683687
if ("failure" in currentIndex) {
684688
return "its legacy session owner could not be revalidated";

‎extensions/discord/src/doctor-contract.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import type {
44
ChannelDoctorLegacyConfigRule,
55
} from "openclaw/plugin-sdk/channel-contract";
66
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
7+
// The narrow activation subpath avoids realtime-voice's agent-consult/session
8+
// graph, which doctor enumeration must not cold-load.
79
import {
810
isSupportedRealtimeVoiceActivationName,
911
normalizeRealtimeVoiceActivationNamePrefix,
10-
} from "openclaw/plugin-sdk/realtime-voice";
12+
} from "openclaw/plugin-sdk/realtime-voice-activation";
1113
import {
1214
asObjectRecord,
1315
defineChannelAliasMigration,

‎extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,12 @@ import type { Dirent } from "node:fs";
1515
import fs from "node:fs/promises";
1616
import path from "node:path";
1717
import type { DatabaseSync } from "node:sqlite";
18-
import {
19-
createPersistentDedupeImportEntry,
20-
type PersistentDedupeEntry,
21-
} from "openclaw/plugin-sdk/persistent-dedupe";
18+
// Doctor enumeration cold-loads this closure; persistent-dedupe pulls the
19+
// plugin-state-store/kysely graph, so the value import stays lazy below.
20+
import type { PersistentDedupeEntry } from "openclaw/plugin-sdk/persistent-dedupe";
2221
import type { PluginDoctorStateMigrationContext } from "openclaw/plugin-sdk/runtime-doctor-migrations";
23-
import {
24-
openNodeSqliteDatabase,
25-
runSqliteImmediateTransactionSync,
26-
} from "openclaw/plugin-sdk/sqlite-runtime";
2722
import { isRecord } from "../../record-shared.js";
2823
import { normalizeMatrixStorageMetadata } from "../client/storage.js";
29-
import {
30-
buildMatrixInboundDedupeEventKey,
31-
MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES,
32-
MATRIX_INBOUND_DEDUPE_TTL_MS,
33-
resolveMatrixInboundDedupeStateNamespace,
34-
} from "./inbound-dedupe.js";
3524

3625
const LEGACY_SQLITE_NAMESPACE = "inbound-dedupe";
3726
const LEGACY_MARKERS_NAMESPACE = "inbound-dedupe-migrations";
@@ -249,6 +238,9 @@ function parseLegacySqliteRow(row: {
249238
export async function readLegacyInboundDedupeSqliteSource(
250239
storageRootDir: string,
251240
): Promise<{ markers: LegacyInboundDedupeMarker[]; legacyRowCount: number }> {
241+
// sqlite-runtime re-exports the agent-db/kysely graph; keep it lazy so doctor
242+
// enumeration does not cold-load it with this closure.
243+
const { openNodeSqliteDatabase } = await import("openclaw/plugin-sdk/sqlite-runtime");
252244
const databasePath = path.join(storageRootDir, STATE_DATABASE_RELATIVE_PATH);
253245
const db = openNodeSqliteDatabase(databasePath, { readOnly: true });
254246
try {
@@ -282,6 +274,8 @@ export async function readLegacyInboundDedupeSqliteSource(
282274

283275
/** Deletes only the two retired Matrix namespaces after a successful import. */
284276
export async function retireLegacyInboundDedupeSqliteRows(storageRootDir: string): Promise<void> {
277+
const { openNodeSqliteDatabase, runSqliteImmediateTransactionSync } =
278+
await import("openclaw/plugin-sdk/sqlite-runtime");
285279
const databasePath = path.join(storageRootDir, STATE_DATABASE_RELATIVE_PATH);
286280
const db = openNodeSqliteDatabase(databasePath);
287281
try {
@@ -406,6 +400,16 @@ export async function importNewestInboundDedupeMarkers(params: {
406400
now?: number;
407401
stateMaxEntries?: number;
408402
}): Promise<{ imported: number; total: number }> {
403+
const { createPersistentDedupeImportEntry } =
404+
await import("openclaw/plugin-sdk/persistent-dedupe");
405+
// inbound-dedupe.js value-imports persistent-dedupe's replay guard, so the
406+
// runtime module also stays out of this closure's static import graph.
407+
const {
408+
buildMatrixInboundDedupeEventKey,
409+
MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES,
410+
MATRIX_INBOUND_DEDUPE_TTL_MS,
411+
resolveMatrixInboundDedupeStateNamespace,
412+
} = await import("./inbound-dedupe.js");
409413
const now = params.now ?? Date.now();
410414
const stateMaxEntries = params.stateMaxEntries ?? MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES;
411415
const newestByKey = new Map<string, LegacyInboundDedupeMarker & { key: string }>();

‎extensions/matrix/src/matrix/sdk/logger.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Matrix plugin module implements logger behavior.
22
import { format } from "node:util";
3-
import { redactSensitiveText } from "openclaw/plugin-sdk/logging-core";
43
import type { RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
4+
// security-runtime exports the same redaction helper without logging-core's
5+
// diagnostic/config graph, which doctor enumeration must not cold-load.
6+
import { redactSensitiveText } from "openclaw/plugin-sdk/security-runtime";
57
import { getMatrixRuntime } from "../../runtime.js";
68

79
type Logger = {

‎extensions/memory-core/src/migration/doctor-dreaming-state.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import {
2121
writeMemoryCoreWorkspaceEntries,
2222
writeMemoryCoreWorkspaceEntry,
2323
} from "../dreaming-state.js";
24+
// Import from the defining modules, not the short-term-promotion barrel: the
25+
// barrel pulls memory-host-events/kysely, which doctor enumeration cold-loads.
26+
import { normalizeShortTermPhaseSignalStore } from "../short-term-promotion-store.js";
2427
import {
2528
SHORT_TERM_PHASE_SIGNAL_RELATIVE_PATH,
2629
SHORT_TERM_STORE_RELATIVE_PATH,
27-
normalizeShortTermPhaseSignalStore,
28-
normalizeShortTermRecallStore,
29-
} from "../short-term-promotion.js";
30+
} from "../short-term-promotion-types.js";
31+
import { normalizeShortTermRecallStore } from "../short-term-promotion-utils.js";
3032
import { resolveConfiguredWorkspaces } from "./doctor-workspaces.js";
3133
import { dreamingStateComparison } from "./dreaming-state-comparison.js";
3234

‎extensions/memory-core/src/migration/doctor-host-event-sources.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import crypto from "node:crypto";
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import { root } from "openclaw/plugin-sdk/memory-core-host-engine-fs";
5-
import { resolveMemoryHostEventLogPath } from "openclaw/plugin-sdk/memory-host-events";
5+
// Doctor enumeration cold-loads this closure; memory-host-events pulls the
6+
// event-store/kysely graph, so the path resolver loads lazily in async bodies.
67
import { resolveConfiguredWorkspaces } from "./doctor-workspaces.js";
78

89
export type LegacyMemoryHostEventSource =
@@ -45,6 +46,7 @@ export async function collectLegacyMemoryHostEventSources(
4546
config: unknown,
4647
env: NodeJS.ProcessEnv,
4748
): Promise<LegacyMemoryHostEventSource[]> {
49+
const { resolveMemoryHostEventLogPath } = await import("openclaw/plugin-sdk/memory-host-events");
4850
const sources: LegacyMemoryHostEventSource[] = [];
4951
const seenWorkspaces = new Set<string>();
5052
for (const workspaceDir of resolveConfiguredWorkspaces(config, env)) {
@@ -154,6 +156,7 @@ export async function collectLegacyMemoryHostEventSources(
154156
export async function resolveMemoryHostEventArchivePath(
155157
source: ReadyLegacyMemoryHostEventSource,
156158
): Promise<{ archiveRelativePath: string; claimRelativePath: string; generationKey: string }> {
159+
const { resolveMemoryHostEventLogPath } = await import("openclaw/plugin-sdk/memory-host-events");
157160
const activeRelativePath = path.relative(
158161
source.workspaceDir,
159162
resolveMemoryHostEventLogPath(source.workspaceDir),

‎extensions/memory-core/src/migration/doctor-host-events.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import crypto from "node:crypto";
22
import path from "node:path";
3-
import {
4-
normalizeMemoryHostEventRecordForStorage,
5-
resolveMemoryHostEventLogPath,
6-
} from "openclaw/plugin-sdk/memory-host-events";
3+
// Doctor enumeration cold-loads this closure; memory-host-events pulls the
4+
// event-store/kysely graph, so values load lazily inside the async migration.
5+
import type { normalizeMemoryHostEventRecordForStorage } from "openclaw/plugin-sdk/memory-host-events";
76
import type {
87
PluginDoctorStateMigration,
98
PluginDoctorStateMigrationContext,
@@ -157,6 +156,8 @@ async function migrateLegacyMemoryHostEventSource(params: {
157156
changes: string[];
158157
warnings: string[];
159158
}): Promise<"completed" | "blocked"> {
159+
const { normalizeMemoryHostEventRecordForStorage, resolveMemoryHostEventLogPath } =
160+
await import("openclaw/plugin-sdk/memory-host-events");
160161
const activeRelativePath = path.relative(
161162
params.source.workspaceDir,
162163
resolveMemoryHostEventLogPath(params.source.workspaceDir),

‎extensions/memory-core/src/migration/doctor-memory-sidecar.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ import fs from "node:fs/promises";
44
import path from "node:path";
55
import { reclaimDefinitelyStaleFileLock } from "openclaw/plugin-sdk/file-lock";
66
import { resolveUserPath } from "openclaw/plugin-sdk/memory-core-host-engine-fs";
7-
import {
8-
ensureMemoryIndexSchema,
9-
loadSqliteVecExtension,
10-
} from "openclaw/plugin-sdk/memory-core-host-engine-schema";
7+
// Doctor enumeration cold-loads this closure; the host engine schema pulls the
8+
// runtime-sqlite/kysely graph, so its helpers load lazily in the async migration.
119
import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
1210
import {
1311
legacyStateFileExists,
1412
type PluginDoctorStateMigration,
1513
} from "openclaw/plugin-sdk/runtime-doctor-migrations";
16-
import {
17-
ensureOpenClawAgentDatabaseSchema,
18-
openNodeSqliteDatabase,
19-
resolveOpenClawAgentSqlitePath,
20-
} from "openclaw/plugin-sdk/sqlite-runtime";
14+
// sqlite-runtime re-exports the agent-db/kysely graph; keep it lazy so doctor
15+
// enumeration does not cold-load it with this closure.
2116
import {
2217
importLegacyMemorySidecarIndex,
2318
LEGACY_MEMORY_SIDECAR_SUFFIXES,
@@ -144,6 +139,7 @@ async function collectLegacyMemorySidecarSources(params: {
144139
env: NodeJS.ProcessEnv;
145140
stateDir: string;
146141
}): Promise<LegacyMemorySidecarSource[]> {
142+
const { resolveOpenClawAgentSqlitePath } = await import("openclaw/plugin-sdk/sqlite-runtime");
147143
const agentIds = new Set(resolveConfiguredAgentIds(params.config));
148144
const legacyDir = path.join(params.stateDir, "memory");
149145
const retrySidecars: Array<{ agentId: string; legacyPath: string }> = [];
@@ -373,6 +369,10 @@ async function migrateLegacyMemorySidecarSource(params: {
373369
changes: string[];
374370
warnings: string[];
375371
}): Promise<{ archiveReady: boolean }> {
372+
const { ensureMemoryIndexSchema, loadSqliteVecExtension } =
373+
await import("openclaw/plugin-sdk/memory-core-host-engine-schema");
374+
const { ensureOpenClawAgentDatabaseSchema, openNodeSqliteDatabase } =
375+
await import("openclaw/plugin-sdk/sqlite-runtime");
376376
// OpenClaw itself can leave a zero-byte placeholder at the legacy sidecar
377377
// path while the live index is the per-agent SQLite database. An empty file
378378
// holds no legacy rows, so remove it quietly instead of emitting a permanent

0 commit comments

Comments
 (0)