Skip to content

Commit 0fc2740

Browse files
committed
fix: preserve direct subagent dispatch failures on abort
1 parent 687ce31 commit 0fc2740

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/agents/subagent-announce-dispatch.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ describe("runSubagentAnnounceDispatch", () => {
135135
]);
136136
});
137137

138+
it("preserves direct failure when completion dispatch aborts before fallback queue", async () => {
139+
const controller = new AbortController();
140+
const queue = vi.fn(async () => "queued" as const);
141+
const direct = vi.fn(async () => {
142+
controller.abort();
143+
return {
144+
delivered: false,
145+
path: "direct" as const,
146+
error: "direct failed before abort",
147+
};
148+
});
149+
150+
const result = await runSubagentAnnounceDispatch({
151+
expectsCompletionMessage: true,
152+
signal: controller.signal,
153+
queue,
154+
direct,
155+
});
156+
157+
expect(direct).toHaveBeenCalledTimes(1);
158+
expect(queue).not.toHaveBeenCalled();
159+
expect(result).toMatchObject({
160+
delivered: false,
161+
path: "direct",
162+
error: "direct failed before abort",
163+
});
164+
expect(result.phases).toEqual([
165+
{
166+
phase: "direct-primary",
167+
delivered: false,
168+
path: "direct",
169+
error: "direct failed before abort",
170+
},
171+
]);
172+
});
173+
138174
it("returns none immediately when signal is already aborted", async () => {
139175
const queue = vi.fn(async () => "none" as const);
140176
const direct = vi.fn(async () => ({ delivered: true, path: "direct" as const }));

src/agents/subagent-announce-dispatch.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ export async function runSubagentAnnounceDispatch(params: {
8888
}
8989

9090
if (params.signal?.aborted) {
91-
return withPhases({
92-
delivered: false,
93-
path: "none",
94-
});
91+
return withPhases(primaryDirect);
9592
}
9693

9794
const fallbackQueue = mapQueueOutcomeToDeliveryResult(await params.queue());

0 commit comments

Comments
 (0)