mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
perf(status): lazy-load harness selection
This commit is contained in:
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { withTempHome } from "openclaw/plugin-sdk/test-env";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { normalizeTestText } from "../../../test/helpers/normalize-text.js";
|
||||
import { clearAgentHarnesses, registerAgentHarness } from "../../agents/harness/registry.js";
|
||||
import type { AgentHarness } from "../../agents/harness/types.js";
|
||||
@@ -25,6 +25,17 @@ import {
|
||||
configureInMemoryTaskRegistryStoreForTests,
|
||||
} from "./commands.test-harness.js";
|
||||
|
||||
vi.mock("../../agents/harness/builtin-pi.js", () => ({
|
||||
createPiAgentHarness: () => ({
|
||||
id: "pi",
|
||||
label: "OpenClaw Pi",
|
||||
supports: () => ({ supported: true, priority: 0 }),
|
||||
runAttempt: async () => {
|
||||
throw new Error("not used in status tests");
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
const baseCfg = baseCommandTestConfig;
|
||||
|
||||
async function buildStatusReplyForTest(params: { sessionKey?: string; verbose?: boolean }) {
|
||||
|
||||
@@ -218,6 +218,7 @@ describe("gateway shared auth rotation with unchanged SecretRefs", () => {
|
||||
const ws = await openSecretRefAuthenticatedWs();
|
||||
try {
|
||||
const closed = waitForGatewayWsClose(ws);
|
||||
process.env[SECRET_REF_TOKEN_ID] = NEW_TOKEN;
|
||||
const res = await applyCurrentConfig(ws);
|
||||
expect(res.ok).toBe(true);
|
||||
await expect(closed).resolves.toEqual({
|
||||
|
||||
@@ -12,11 +12,18 @@ export async function openAuthenticatedGatewayWs(port: number, token: string): P
|
||||
|
||||
export async function waitForGatewayWsClose(
|
||||
ws: WebSocket,
|
||||
timeoutMs = 10_000,
|
||||
): Promise<{ code: number; reason: string }> {
|
||||
return await new Promise((resolve) => {
|
||||
ws.once("close", (code, reason) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
ws.off("close", onClose);
|
||||
reject(new Error(`gateway websocket did not close within ${timeoutMs}ms`));
|
||||
}, timeoutMs);
|
||||
const onClose = (code: number, reason: Buffer) => {
|
||||
clearTimeout(timer);
|
||||
resolve({ code, reason: reason.toString() });
|
||||
});
|
||||
};
|
||||
ws.once("close", onClose);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
resolveAgentModelFallbacksOverride,
|
||||
} from "../agents/agent-scope.js";
|
||||
import { resolveFastModeState } from "../agents/fast-mode.js";
|
||||
import { selectAgentHarness } from "../agents/harness/selection.js";
|
||||
import { resolveModelAuthLabel } from "../agents/model-auth-label.js";
|
||||
import {
|
||||
resolveInternalSessionKey,
|
||||
@@ -46,6 +45,9 @@ const USAGE_OAUTH_ONLY_PROVIDERS = new Set([
|
||||
|
||||
let statusMessageRuntimePromise: Promise<typeof import("../auto-reply/status.runtime.js")> | null =
|
||||
null;
|
||||
let agentHarnessSelectionRuntimePromise: Promise<
|
||||
typeof import("../agents/harness/selection.js")
|
||||
> | null = null;
|
||||
let statusQueueRuntimePromise: Promise<typeof import("./status-queue.runtime.js")> | null = null;
|
||||
let statusSubagentsRuntimePromise: Promise<typeof import("./status-subagents.runtime.js")> | null =
|
||||
null;
|
||||
@@ -58,6 +60,14 @@ function loadStatusMessageRuntime(): Promise<typeof import("../auto-reply/status
|
||||
return runtimePromise;
|
||||
}
|
||||
|
||||
function loadAgentHarnessSelectionRuntime(): Promise<
|
||||
typeof import("../agents/harness/selection.js")
|
||||
> {
|
||||
const runtimePromise = (agentHarnessSelectionRuntimePromise ??=
|
||||
import("../agents/harness/selection.js"));
|
||||
return runtimePromise;
|
||||
}
|
||||
|
||||
function loadStatusSubagentsRuntime(): Promise<typeof import("./status-subagents.runtime.js")> {
|
||||
const runtimePromise = (statusSubagentsRuntimePromise ??=
|
||||
import("./status-subagents.runtime.js"));
|
||||
@@ -101,15 +111,16 @@ function formatSessionTaskLine(sessionKey: string): string | undefined {
|
||||
return parts.length ? `📌 Tasks: ${parts.join(" · ")}` : undefined;
|
||||
}
|
||||
|
||||
function resolveStatusHarnessId(params: {
|
||||
async function resolveStatusHarnessId(params: {
|
||||
cfg: OpenClawConfig;
|
||||
provider: string;
|
||||
model: string;
|
||||
agentId: string;
|
||||
sessionKey: string;
|
||||
sessionEntry?: SessionEntry;
|
||||
}): string | undefined {
|
||||
}): Promise<string | undefined> {
|
||||
try {
|
||||
const { selectAgentHarness } = await loadAgentHarnessSelectionRuntime();
|
||||
const selected = selectAgentHarness({
|
||||
provider: params.provider,
|
||||
modelId: params.model,
|
||||
@@ -288,14 +299,14 @@ export async function buildStatusText(params: BuildStatusTextParams): Promise<st
|
||||
}).enabled;
|
||||
const effectiveHarness =
|
||||
params.resolvedHarness ??
|
||||
resolveStatusHarnessId({
|
||||
(await resolveStatusHarnessId({
|
||||
cfg,
|
||||
provider,
|
||||
model,
|
||||
agentId: statusAgentId,
|
||||
sessionKey,
|
||||
sessionEntry,
|
||||
});
|
||||
}));
|
||||
const agentFallbacksOverride = resolveAgentModelFallbacksOverride(cfg, statusAgentId);
|
||||
const { buildStatusMessage } = await loadStatusMessageRuntime();
|
||||
const explicitThinkingDefault =
|
||||
|
||||
Reference in New Issue
Block a user