mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:58:26 +00:00
refactor(agents): dedupe subagent announce cleanup
This commit is contained in:
@@ -46,6 +46,31 @@ function persistSubagentRuns() {
|
|||||||
|
|
||||||
const resumedRuns = new Set<string>();
|
const resumedRuns = new Set<string>();
|
||||||
|
|
||||||
|
function startSubagentAnnounceCleanupFlow(runId: string, entry: SubagentRunRecord): boolean {
|
||||||
|
if (!beginSubagentCleanup(runId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const requesterOrigin = normalizeDeliveryContext(entry.requesterOrigin);
|
||||||
|
void runSubagentAnnounceFlow({
|
||||||
|
childSessionKey: entry.childSessionKey,
|
||||||
|
childRunId: entry.runId,
|
||||||
|
requesterSessionKey: entry.requesterSessionKey,
|
||||||
|
requesterOrigin,
|
||||||
|
requesterDisplayKey: entry.requesterDisplayKey,
|
||||||
|
task: entry.task,
|
||||||
|
timeoutMs: SUBAGENT_ANNOUNCE_TIMEOUT_MS,
|
||||||
|
cleanup: entry.cleanup,
|
||||||
|
waitForCompletion: false,
|
||||||
|
startedAt: entry.startedAt,
|
||||||
|
endedAt: entry.endedAt,
|
||||||
|
label: entry.label,
|
||||||
|
outcome: entry.outcome,
|
||||||
|
}).then((didAnnounce) => {
|
||||||
|
finalizeSubagentCleanup(runId, entry.cleanup, didAnnounce);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function resumeSubagentRun(runId: string) {
|
function resumeSubagentRun(runId: string) {
|
||||||
if (!runId || resumedRuns.has(runId)) {
|
if (!runId || resumedRuns.has(runId)) {
|
||||||
return;
|
return;
|
||||||
@@ -59,27 +84,9 @@ function resumeSubagentRun(runId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof entry.endedAt === "number" && entry.endedAt > 0) {
|
if (typeof entry.endedAt === "number" && entry.endedAt > 0) {
|
||||||
if (!beginSubagentCleanup(runId)) {
|
if (!startSubagentAnnounceCleanupFlow(runId, entry)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const requesterOrigin = normalizeDeliveryContext(entry.requesterOrigin);
|
|
||||||
void runSubagentAnnounceFlow({
|
|
||||||
childSessionKey: entry.childSessionKey,
|
|
||||||
childRunId: entry.runId,
|
|
||||||
requesterSessionKey: entry.requesterSessionKey,
|
|
||||||
requesterOrigin,
|
|
||||||
requesterDisplayKey: entry.requesterDisplayKey,
|
|
||||||
task: entry.task,
|
|
||||||
timeoutMs: SUBAGENT_ANNOUNCE_TIMEOUT_MS,
|
|
||||||
cleanup: entry.cleanup,
|
|
||||||
waitForCompletion: false,
|
|
||||||
startedAt: entry.startedAt,
|
|
||||||
endedAt: entry.endedAt,
|
|
||||||
label: entry.label,
|
|
||||||
outcome: entry.outcome,
|
|
||||||
}).then((didAnnounce) => {
|
|
||||||
finalizeSubagentCleanup(runId, entry.cleanup, didAnnounce);
|
|
||||||
});
|
|
||||||
resumedRuns.add(runId);
|
resumedRuns.add(runId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -222,27 +229,7 @@ function ensureListener() {
|
|||||||
}
|
}
|
||||||
persistSubagentRuns();
|
persistSubagentRuns();
|
||||||
|
|
||||||
if (!beginSubagentCleanup(evt.runId)) {
|
void startSubagentAnnounceCleanupFlow(evt.runId, entry);
|
||||||
return;
|
|
||||||
}
|
|
||||||
const requesterOrigin = normalizeDeliveryContext(entry.requesterOrigin);
|
|
||||||
void runSubagentAnnounceFlow({
|
|
||||||
childSessionKey: entry.childSessionKey,
|
|
||||||
childRunId: entry.runId,
|
|
||||||
requesterSessionKey: entry.requesterSessionKey,
|
|
||||||
requesterOrigin,
|
|
||||||
requesterDisplayKey: entry.requesterDisplayKey,
|
|
||||||
task: entry.task,
|
|
||||||
timeoutMs: SUBAGENT_ANNOUNCE_TIMEOUT_MS,
|
|
||||||
cleanup: entry.cleanup,
|
|
||||||
waitForCompletion: false,
|
|
||||||
startedAt: entry.startedAt,
|
|
||||||
endedAt: entry.endedAt,
|
|
||||||
label: entry.label,
|
|
||||||
outcome: entry.outcome,
|
|
||||||
}).then((didAnnounce) => {
|
|
||||||
finalizeSubagentCleanup(evt.runId, entry.cleanup, didAnnounce);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,27 +357,7 @@ async function waitForSubagentCompletion(runId: string, waitTimeoutMs: number) {
|
|||||||
if (mutated) {
|
if (mutated) {
|
||||||
persistSubagentRuns();
|
persistSubagentRuns();
|
||||||
}
|
}
|
||||||
if (!beginSubagentCleanup(runId)) {
|
void startSubagentAnnounceCleanupFlow(runId, entry);
|
||||||
return;
|
|
||||||
}
|
|
||||||
const requesterOrigin = normalizeDeliveryContext(entry.requesterOrigin);
|
|
||||||
void runSubagentAnnounceFlow({
|
|
||||||
childSessionKey: entry.childSessionKey,
|
|
||||||
childRunId: entry.runId,
|
|
||||||
requesterSessionKey: entry.requesterSessionKey,
|
|
||||||
requesterOrigin,
|
|
||||||
requesterDisplayKey: entry.requesterDisplayKey,
|
|
||||||
task: entry.task,
|
|
||||||
timeoutMs: SUBAGENT_ANNOUNCE_TIMEOUT_MS,
|
|
||||||
cleanup: entry.cleanup,
|
|
||||||
waitForCompletion: false,
|
|
||||||
startedAt: entry.startedAt,
|
|
||||||
endedAt: entry.endedAt,
|
|
||||||
label: entry.label,
|
|
||||||
outcome: entry.outcome,
|
|
||||||
}).then((didAnnounce) => {
|
|
||||||
finalizeSubagentCleanup(runId, entry.cleanup, didAnnounce);
|
|
||||||
});
|
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user