Skip to content

Commit ccc9500

Browse files
committed
fix(agents): preserve aborts without fallbacks
1 parent 2f9759d commit ccc9500

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/agents/embedded-agent-runner/run.prompt-timeout-fallback.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,47 @@ describe("runEmbeddedAgent prompt timeout fallback handoff", () => {
9494
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
9595
});
9696

97+
it("preserves provider aborts when no model fallback is configured", async () => {
98+
mockedClassifyFailoverReason.mockReturnValue("timeout");
99+
mockedRunEmbeddedAttempt.mockResolvedValueOnce(
100+
makeAttemptResult({
101+
aborted: true,
102+
externalAbort: false,
103+
assistantTexts: [],
104+
promptError: Object.assign(new Error("This operation was aborted"), {
105+
name: "AbortError",
106+
}),
107+
promptErrorSource: "prompt",
108+
}),
109+
);
110+
111+
const result = await runEmbeddedAgent({
112+
...overflowBaseRunParams,
113+
provider: "amazon-bedrock",
114+
model: "global.anthropic.claude-sonnet-4-6",
115+
runId: "run-bedrock-prompt-abort-without-fallback",
116+
config: makeModelFallbackCfg({
117+
agents: {
118+
defaults: {
119+
model: {
120+
primary: "amazon-bedrock/global.anthropic.claude-sonnet-4-6",
121+
fallbacks: [],
122+
},
123+
},
124+
},
125+
}),
126+
});
127+
128+
expect(result.payloads).toEqual([
129+
{
130+
text: "⚠️ Agent couldn't generate a response. Please try again.",
131+
isError: true,
132+
},
133+
]);
134+
expect(result.meta?.aborted).toBe(true);
135+
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
136+
});
137+
97138
it("preserves visible output from a provider abort instead of handing off fallback", async () => {
98139
mockedClassifyFailoverReason.mockReturnValue("timeout");
99140
mockedRunEmbeddedAttempt.mockResolvedValueOnce(

src/agents/embedded-agent-runner/run/attempt-recovery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export async function recoverEmbeddedRunAttempt(input: {
268268
// Some provider SDK stream aborts mark the attempt aborted without an external stop.
269269
// Only replay the model call when no visible output, timeout, or side effect made it unsafe.
270270
const replaySafePromptAbortFallback =
271+
runInput.fallbackConfigured &&
271272
aborted &&
272273
!externalAbort &&
273274
!signalOwnedInterruption &&

0 commit comments

Comments
 (0)