Skip to content

Commit 77c6cf9

Browse files
fix(agent-invocations): End a stopped tree's child markers together
Refs #3060
1 parent c1ef9be commit 77c6cf9

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

  • packages/junior/src/chat/agent-invocations

‎packages/junior/src/chat/agent-invocations/stop.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { and, eq, gt, inArray, isNotNull, isNull, ne, or } from "drizzle-orm";
22
import type { StateAdapter } from "chat";
3+
import pLimit from "p-limit";
34
import {
45
getConversationStoppedAtMs,
56
markConversationsStopped,
67
} from "@/chat/conversations/session-stop";
78
import { getSqlExecutor } from "@/chat/db";
9+
import { FAN_OUT_CONCURRENCY } from "@/chat/fan-out";
810
import { cancelSignInWait } from "@/chat/task-execution/turn-cancel";
911
import {
1012
dropPendingMessages,
@@ -276,13 +278,18 @@ async function finishStoppedTree(
276278
await recordSubagentEnded(invocation);
277279
}
278280
// The stop skips the parent messages that still wait, so their work ends.
279-
for (const conversationId of conversationIdsToStop) {
280-
await recordChildAgentEnded(conversationId, "aborted", {
281-
includeWaiting: true,
282-
nowMs: options.nowMs,
283-
state: options.state,
284-
});
285-
}
281+
const limit = pLimit(FAN_OUT_CONCURRENCY);
282+
await Promise.all(
283+
conversationIdsToStop.map((conversationId) =>
284+
limit(() =>
285+
recordChildAgentEnded(conversationId, "aborted", {
286+
includeWaiting: true,
287+
nowMs: options.nowMs,
288+
state: options.state,
289+
}),
290+
),
291+
),
292+
);
286293
await markConversationsStopped(conversationIdsToStop, options);
287294
for (const conversationId of conversationIdsToStop) {
288295
await cancelSignInWait(conversationId);

0 commit comments

Comments
 (0)