mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 00:40:23 +00:00
fix: allow follow-up sends to finished subagents
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user