mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-04-30 22:12:32 +08:00
perf(cron): lazy-load delivery subagent registry
This commit is contained in:
@@ -15,13 +15,21 @@ import { SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
|
||||
|
||||
// --- Module mocks (must be hoisted before imports) ---
|
||||
|
||||
const { countActiveDescendantRunsMock } = vi.hoisted(() => ({
|
||||
countActiveDescendantRunsMock: vi.fn().mockReturnValue(0),
|
||||
}));
|
||||
|
||||
vi.mock("../../config/sessions.js", () => ({
|
||||
resolveAgentMainSessionKey: vi.fn(({ agentId }: { agentId: string }) => `agent:${agentId}:main`),
|
||||
resolveMainSessionKey: vi.fn(() => "global"),
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/subagent-registry-read.js", () => ({
|
||||
countActiveDescendantRuns: vi.fn().mockReturnValue(0),
|
||||
countActiveDescendantRuns: countActiveDescendantRunsMock,
|
||||
}));
|
||||
|
||||
vi.mock("./delivery-subagent-registry.runtime.js", () => ({
|
||||
countActiveDescendantRuns: countActiveDescendantRunsMock,
|
||||
}));
|
||||
|
||||
vi.mock("../../infra/outbound/deliver.js", () => ({
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { countActiveDescendantRuns } from "../../agents/subagent-registry-read.js";
|
||||
import type { ReplyPayload } from "../../auto-reply/reply-payload.js";
|
||||
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
|
||||
import type { CliDeps } from "../../cli/outbound-send-deps.js";
|
||||
@@ -131,6 +130,9 @@ let gatewayCallRuntimePromise: Promise<typeof import("../../gateway/call.runtime
|
||||
let deliveryOutboundRuntimePromise:
|
||||
| Promise<typeof import("./delivery-outbound.runtime.js")>
|
||||
| undefined;
|
||||
let deliverySubagentRegistryRuntimePromise:
|
||||
| Promise<typeof import("./delivery-subagent-registry.runtime.js")>
|
||||
| undefined;
|
||||
let subagentFollowupRuntimePromise:
|
||||
| Promise<typeof import("./subagent-followup.runtime.js")>
|
||||
| undefined;
|
||||
@@ -149,6 +151,13 @@ async function loadDeliveryOutboundRuntime(): Promise<
|
||||
return await deliveryOutboundRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadDeliverySubagentRegistryRuntime(): Promise<
|
||||
typeof import("./delivery-subagent-registry.runtime.js")
|
||||
> {
|
||||
deliverySubagentRegistryRuntimePromise ??= import("./delivery-subagent-registry.runtime.js");
|
||||
return await deliverySubagentRegistryRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadSubagentFollowupRuntime(): Promise<
|
||||
typeof import("./subagent-followup.runtime.js")
|
||||
> {
|
||||
@@ -569,8 +578,11 @@ export async function dispatchCronDelivery(
|
||||
return null;
|
||||
}
|
||||
const initialSynthesizedText = synthesizedText.trim();
|
||||
let activeSubagentRuns = countActiveDescendantRuns(params.agentSessionKey);
|
||||
const expectedSubagentFollowup = expectsSubagentFollowup(initialSynthesizedText);
|
||||
const subagentRegistryRuntime = await loadDeliverySubagentRegistryRuntime();
|
||||
let activeSubagentRuns = subagentRegistryRuntime.countActiveDescendantRuns(
|
||||
params.agentSessionKey,
|
||||
);
|
||||
const shouldCheckCompletedDescendants =
|
||||
activeSubagentRuns === 0 && isLikelyInterimCronMessage(initialSynthesizedText);
|
||||
const needsSubagentFollowupRuntime =
|
||||
@@ -597,7 +609,9 @@ export async function dispatchCronDelivery(
|
||||
timeoutMs: params.timeoutMs,
|
||||
observedActiveDescendants: activeSubagentRuns > 0 || expectedSubagentFollowup,
|
||||
});
|
||||
activeSubagentRuns = countActiveDescendantRuns(params.agentSessionKey);
|
||||
activeSubagentRuns = subagentRegistryRuntime.countActiveDescendantRuns(
|
||||
params.agentSessionKey,
|
||||
);
|
||||
if (!finalReply && activeSubagentRuns === 0) {
|
||||
finalReply = await subagentFollowupRuntime?.readDescendantSubagentFallbackReply({
|
||||
sessionKey: params.agentSessionKey,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { countActiveDescendantRuns } from "../../agents/subagent-registry-read.js";
|
||||
Reference in New Issue
Block a user