Skip to content

Commit 92f1042

Browse files
fix(server): an idle-launched nested Claude subagent no longer stays running after a sibling's wake (#16355)
A nested subagent started while the root was idle has its task_started held for the next wake drain. If it finished during a later user turn, its live task_notification found no node and was dropped, so the drain replayed the held start alone and left the subagent running forever. Hold that outcome behind its start so the drain replays both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4debf19 commit 92f1042

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8187,10 +8187,32 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
81878187
}
81888188

81898189
if (message.type === "system" && message.subtype === "task_notification") {
8190-
if (
8191-
!appliedSubagentOutcomes.has(message) &&
8192-
(yield* Ref.get(sessionSubagentsByTaskId)).has(message.task_id)
8193-
) {
8190+
const isRegistered = (yield* Ref.get(sessionSubagentsByTaskId)).has(message.task_id);
8191+
// A task whose start is still held for the next wake drain has no
8192+
// node to finish yet; hold its outcome behind that start, or the
8193+
// drain replays the start alone and the task stays running.
8194+
if (!isRegistered) {
8195+
yield* Ref.update(wakeBuffers, (current) => {
8196+
const entry = current.get(liveQuery.nativeThreadId);
8197+
if (
8198+
entry === undefined ||
8199+
entry.messages.includes(message) ||
8200+
!entry.messages.some(
8201+
(buffered) =>
8202+
buffered.type === "system" &&
8203+
buffered.subtype === "task_started" &&
8204+
buffered.task_id === message.task_id,
8205+
)
8206+
) {
8207+
return current;
8208+
}
8209+
return new Map(current).set(liveQuery.nativeThreadId, {
8210+
...entry,
8211+
messages: [...entry.messages, message],
8212+
});
8213+
});
8214+
}
8215+
if (!appliedSubagentOutcomes.has(message) && isRegistered) {
81948216
yield* discardBufferedSubagentStarts(
81958217
liveQuery.nativeThreadId,
81968218
message.task_id,

0 commit comments

Comments
 (0)