diff --git a/CHANGELOG.md b/CHANGELOG.md index 3762ecb84bd..836a56e8f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Docs: https://docs.openclaw.ai ### Changes +- Gateway/startup: keep model-catalog test helpers and run-session lookup code out of the hot `server.impl` import graph, reducing default gateway benchmark readiness latency. - Channels/streaming: add unified `streaming.mode: "progress"` drafts with auto single-word status labels and shared progress configuration across Discord, Telegram, Matrix, Slack, and Microsoft Teams. - Slack/streaming: add `streaming.progress.render: "rich"` for Block Kit progress drafts backed by structured progress line data. - Slack/streaming: keep the newest rich progress lines when Block Kit limits trim long progress drafts. Thanks @vincentkoc. diff --git a/src/gateway/server-import-boundary.test.ts b/src/gateway/server-import-boundary.test.ts index 0f986c03950..f7654e745af 100644 --- a/src/gateway/server-import-boundary.test.ts +++ b/src/gateway/server-import-boundary.test.ts @@ -17,6 +17,15 @@ describe("gateway startup import boundaries", () => { expect(serverImpl).toContain('from "./server-cron-lazy.js"'); expect(serverImpl).not.toContain('from "./server-methods.js"'); expect(serverImpl).not.toContain('from "./config-reload.js"'); + expect(serverImpl).not.toMatch( + /import\s+\{[^}]*resolveSessionKeyForRun[^}]*\}\s+from "\.\/server-session-key\.js"/s, + ); + expect(serverImpl).not.toMatch( + /export\s+\{[^}]*__resetModelCatalogCacheForTest[^}]*\}\s+from "\.\/server-model-catalog\.js"/s, + ); + expect(readSource("src/gateway/server-runtime-subscriptions.ts")).toContain( + 'import("./server-session-key.js")', + ); expect(readSource("src/gateway/server-shared-auth-generation.ts")).not.toContain( 'from "./config-reload.js"', ); diff --git a/src/gateway/server-runtime-subscriptions.ts b/src/gateway/server-runtime-subscriptions.ts index eaeb74d0b42..23c84de8d64 100644 --- a/src/gateway/server-runtime-subscriptions.ts +++ b/src/gateway/server-runtime-subscriptions.ts @@ -1,4 +1,4 @@ -import { onAgentEvent } from "../infra/agent-events.js"; +import { clearAgentRunContext, onAgentEvent } from "../infra/agent-events.js"; import { onHeartbeatEvent } from "../infra/heartbeat-events.js"; import { onSessionLifecycleEvent } from "../sessions/session-lifecycle-events.js"; import { onSessionTranscriptUpdate } from "../sessions/transcript-events.js"; @@ -21,8 +21,6 @@ export function startGatewayEventSubscriptions(params: { nodeSendToSession: (sessionKey: string, event: string, payload: unknown) => void; agentRunSeq: Map; chatRunState: ChatRunState; - resolveSessionKeyForRun: (runId: string) => string | undefined; - clearAgentRunContext: (runId: string) => void; toolEventRecipients: ToolEventRecipientRegistry; sessionEventSubscribers: SessionEventSubscriberRegistry; sessionMessageSubscribers: SessionMessageSubscriberRegistry; @@ -32,15 +30,18 @@ export function startGatewayEventSubscriptions(params: { ReturnType > | null = null; const getAgentEventHandler = () => { - agentEventHandlerPromise ??= import("./server-chat.js").then(({ createAgentEventHandler }) => + agentEventHandlerPromise ??= Promise.all([ + import("./server-chat.js"), + import("./server-session-key.js"), + ]).then(([{ createAgentEventHandler }, { resolveSessionKeyForRun }]) => createAgentEventHandler({ broadcast: params.broadcast, broadcastToConnIds: params.broadcastToConnIds, nodeSendToSession: params.nodeSendToSession, agentRunSeq: params.agentRunSeq, chatRunState: params.chatRunState, - resolveSessionKeyForRun: params.resolveSessionKeyForRun, - clearAgentRunContext: params.clearAgentRunContext, + resolveSessionKeyForRun, + clearAgentRunContext, toolEventRecipients: params.toolEventRecipients, sessionEventSubscribers: params.sessionEventSubscribers, isChatSendRunActive: (runId) => { diff --git a/src/gateway/server.impl.ts b/src/gateway/server.impl.ts index e29f2d20f5c..5f5104208fc 100644 --- a/src/gateway/server.impl.ts +++ b/src/gateway/server.impl.ts @@ -23,7 +23,6 @@ import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js"; import { applyConfigOverrides } from "../config/runtime-overrides.js"; import { resolveMainSessionKey } from "../config/sessions.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; -import { clearAgentRunContext } from "../infra/agent-events.js"; import { isDiagnosticsEnabled, setDiagnosticsEnabledForProcess, @@ -70,7 +69,6 @@ import type { GatewayRequestHandlers } from "./server-methods/types.js"; import { setFallbackGatewayContextResolver } from "./server-plugins.js"; import type { GatewayPluginReloadResult } from "./server-reload-handlers.js"; import { createGatewayRuntimeState } from "./server-runtime-state.js"; -import { resolveSessionKeyForRun } from "./server-session-key.js"; import { enforceSharedGatewaySessionGenerationForConfigWrite, getRequiredSharedGatewaySessionGeneration, @@ -92,7 +90,11 @@ import { loadGatewayTlsRuntime } from "./server/tls.js"; import { resolveSharedGatewaySessionGeneration } from "./server/ws-shared-generation.js"; import { maybeSeedControlUiAllowedOriginsAtStartup } from "./startup-control-ui-origins.js"; -export { __resetModelCatalogCacheForTest } from "./server-model-catalog.js"; +export async function __resetModelCatalogCacheForTest(): Promise { + const { __resetModelCatalogCacheForTest: resetModelCatalogCacheForTest } = + await import("./server-model-catalog.js"); + await resetModelCatalogCacheForTest(); +} ensureOpenClawCliOnPath(); @@ -1028,8 +1030,6 @@ export async function startGatewayServer( nodeSendToSession, agentRunSeq, chatRunState, - resolveSessionKeyForRun, - clearAgentRunContext, toolEventRecipients, sessionEventSubscribers, sessionMessageSubscribers,