fix: allow follow-up sends to finished subagents

This commit is contained in:
Tak Hoffman
2026-03-24 14:50:27 -05:00
parent 7d6d112656
commit e99c270684
2 changed files with 64 additions and 1 deletions

View File

@@ -154,6 +154,69 @@ describe("sendControlledSubagentMessage", () => {
text: "stale task is already finished.",
});
});
it("sends follow-up messages to the exact finished current run", async () => {
addSubagentRunForTests({
runId: "run-finished-send",
childSessionKey: "agent:main:subagent:finished-worker",
controllerSessionKey: "agent:main:main",
requesterSessionKey: "agent:main:main",
requesterDisplayKey: "main",
task: "finished task",
cleanup: "keep",
createdAt: Date.now() - 5_000,
startedAt: Date.now() - 4_000,
endedAt: Date.now() - 1_000,
outcome: { status: "ok" },
});
__testing.setDepsForTest({
callGateway: async <T = Record<string, unknown>>(request: CallGatewayOptions) => {
if (request.method === "agent") {
return { runId: "run-followup-send" } as T;
}
if (request.method === "agent.wait") {
return { status: "done" } as T;
}
if (request.method === "chat.history") {
return { messages: [] } as T;
}
throw new Error(`unexpected method: ${request.method}`);
},
});
const result = await sendControlledSubagentMessage({
cfg: {
channels: { whatsapp: { allowFrom: ["*"] } },
} as OpenClawConfig,
controller: {
controllerSessionKey: "agent:main:main",
callerSessionKey: "agent:main:main",
callerIsSubagent: false,
controlScope: "children",
},
entry: {
runId: "run-finished-send",
childSessionKey: "agent:main:subagent:finished-worker",
requesterSessionKey: "agent:main:main",
requesterDisplayKey: "main",
controllerSessionKey: "agent:main:main",
task: "finished task",
cleanup: "keep",
createdAt: Date.now() - 5_000,
startedAt: Date.now() - 4_000,
endedAt: Date.now() - 1_000,
outcome: { status: "ok" },
},
message: "continue",
});
expect(result).toEqual({
status: "ok",
runId: "run-followup-send",
replyText: undefined,
});
});
});
describe("killSubagentRunAdmin", () => {

View File

@@ -799,7 +799,7 @@ export async function sendControlledSubagentMessage(params: {
};
}
const currentEntry = getSubagentRunByChildSessionKey(params.entry.childSessionKey);
if (!currentEntry || currentEntry.runId !== params.entry.runId || currentEntry.endedAt) {
if (!currentEntry || currentEntry.runId !== params.entry.runId) {
return {
status: "done" as const,
runId: params.entry.runId,