mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-02 21:01:51 +00:00
refactor(tasks): route subagents through executor (#57481)
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor
This commit is contained in:
@@ -2,9 +2,10 @@ import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { emitSessionLifecycleEvent } from "../sessions/session-lifecycle-events.js";
|
||||
import {
|
||||
markTaskTerminalByRunId,
|
||||
setTaskRunDeliveryStatusByRunId,
|
||||
} from "../tasks/task-registry.js";
|
||||
completeTaskRunByRunId,
|
||||
failTaskRunByRunId,
|
||||
setDetachedTaskDeliveryStatusByRunId,
|
||||
} from "../tasks/task-executor.js";
|
||||
import { normalizeDeliveryContext } from "../utils/delivery-context.js";
|
||||
import {
|
||||
captureSubagentCompletionReply,
|
||||
@@ -157,7 +158,7 @@ export function createSubagentRegistryLifecycleController(params: {
|
||||
entry: SubagentRunRecord;
|
||||
reason: "retry-limit" | "expiry";
|
||||
}) => {
|
||||
setTaskRunDeliveryStatusByRunId({
|
||||
setDetachedTaskDeliveryStatusByRunId({
|
||||
runId: giveUpParams.runId,
|
||||
deliveryStatus: "failed",
|
||||
});
|
||||
@@ -273,7 +274,7 @@ export function createSubagentRegistryLifecycleController(params: {
|
||||
return;
|
||||
}
|
||||
if (didAnnounce) {
|
||||
setTaskRunDeliveryStatusByRunId({
|
||||
setDetachedTaskDeliveryStatusByRunId({
|
||||
runId,
|
||||
deliveryStatus: "delivered",
|
||||
});
|
||||
@@ -329,7 +330,7 @@ export function createSubagentRegistryLifecycleController(params: {
|
||||
}
|
||||
|
||||
if (deferredDecision.kind === "give-up") {
|
||||
setTaskRunDeliveryStatusByRunId({
|
||||
setDetachedTaskDeliveryStatusByRunId({
|
||||
runId,
|
||||
deliveryStatus: "failed",
|
||||
});
|
||||
@@ -462,21 +463,25 @@ export function createSubagentRegistryLifecycleController(params: {
|
||||
if (mutated) {
|
||||
params.persist();
|
||||
}
|
||||
markTaskTerminalByRunId({
|
||||
runId: entry.runId,
|
||||
status:
|
||||
completeParams.outcome.status === "ok"
|
||||
? "succeeded"
|
||||
: completeParams.outcome.status === "timeout"
|
||||
? "timed_out"
|
||||
: "failed",
|
||||
startedAt: entry.startedAt,
|
||||
endedAt: entry.endedAt,
|
||||
lastEventAt: entry.endedAt ?? Date.now(),
|
||||
error: completeParams.outcome.status === "error" ? completeParams.outcome.error : undefined,
|
||||
progressSummary: entry.frozenResultText ?? undefined,
|
||||
terminalSummary: null,
|
||||
});
|
||||
if (completeParams.outcome.status === "ok") {
|
||||
completeTaskRunByRunId({
|
||||
runId: entry.runId,
|
||||
endedAt: entry.endedAt,
|
||||
lastEventAt: entry.endedAt ?? Date.now(),
|
||||
progressSummary: entry.frozenResultText ?? undefined,
|
||||
terminalSummary: null,
|
||||
});
|
||||
} else {
|
||||
failTaskRunByRunId({
|
||||
runId: entry.runId,
|
||||
status: completeParams.outcome.status === "timeout" ? "timed_out" : "failed",
|
||||
endedAt: entry.endedAt,
|
||||
lastEventAt: entry.endedAt ?? Date.now(),
|
||||
error: completeParams.outcome.status === "error" ? completeParams.outcome.error : undefined,
|
||||
progressSummary: entry.frozenResultText ?? undefined,
|
||||
terminalSummary: null,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await persistSubagentSessionTiming(entry);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { createTaskRecord } from "../tasks/task-registry.js";
|
||||
import { createRunningTaskRun } from "../tasks/task-executor.js";
|
||||
import { type DeliveryContext, normalizeDeliveryContext } from "../utils/delivery-context.js";
|
||||
import { ensureRuntimePluginsLoaded } from "./runtime-plugins.js";
|
||||
import type { SubagentRunOutcome } from "./subagent-announce.js";
|
||||
@@ -320,7 +320,7 @@ export function createSubagentRunManager(params: {
|
||||
retainAttachmentsOnKeep: registerParams.retainAttachmentsOnKeep,
|
||||
});
|
||||
try {
|
||||
createTaskRecord({
|
||||
createRunningTaskRun({
|
||||
runtime: "subagent",
|
||||
sourceId: registerParams.runId,
|
||||
requesterSessionKey: registerParams.requesterSessionKey,
|
||||
@@ -329,7 +329,6 @@ export function createSubagentRunManager(params: {
|
||||
runId: registerParams.runId,
|
||||
label: registerParams.label,
|
||||
task: registerParams.task,
|
||||
status: "running",
|
||||
deliveryStatus:
|
||||
registerParams.expectsCompletionMessage === false ? "not_applicable" : "pending",
|
||||
startedAt: now,
|
||||
|
||||
Reference in New Issue
Block a user