openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 1.96 kB
JavaScript
import { o as getLatestLiveSubagentRunByChildSessionKey, s as getLatestSubagentRunByChildSessionKey } from "./subagent-registry-read-DeFf_9Nz.js";
//#region src/gateway/session-subagent-reactivation.ts
async function loadSessionSubagentReactivationRuntime() {
return import("./subagent-registry-runtime-i7iLqHfk.js");
}
/**
* Reactivates a completed subagent session by swapping in the new run id.
*
* `task` is the canonical user-supplied prompt text that just dispatched the
* follow-up. When provided, it is persisted on the new run record so a later
* orphan recovery / gateway restart rewraps the follow-up prompt rather than
* the stale original task. Without this, sessions.send and agent.run callers
* could reactivate a completed run with the new run id but lose the new
* prompt text from restart redispatch.
*/
async function reactivateCompletedSubagentSession(params) {
const runId = params.runId?.trim();
if (!runId) return false;
const existing = getLatestSubagentRunByChildSessionKey(params.sessionKey);
if (!existing || typeof existing.execution.endedAt !== "number") return false;
const { replaceSubagentRunAfterSteer } = await loadSessionSubagentReactivationRuntime();
if (params.gatewayContextResolver && !params.gatewayContextResolver()) return false;
const task = params.task;
const hasTask = typeof task === "string" && task.trim().length > 0;
if (await replaceSubagentRunAfterSteer({
previousRunId: existing.runId,
nextRunId: runId,
fallback: existing,
runTimeoutSeconds: existing.runTimeoutSeconds ?? 0,
persistenceFailure: "throw",
...hasTask ? { task } : {},
...params.gatewayContextResolver ? { gatewayContextResolver: params.gatewayContextResolver } : {}
})) return true;
if (getLatestLiveSubagentRunByChildSessionKey(params.sessionKey)?.runId === runId) return true;
throw new Error("subagent follow-up owner replacement was rejected");
}
//#endregion
export { reactivateCompletedSubagentSession as t };