Skip to content

Commit dc9eba2

Browse files
committed
fix(claude): preserve error frames on interrupted turns
1 parent 398ddcc commit dc9eba2

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,6 +5120,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {
51205120
apiErrorStatus: 429,
51215121
shown: true,
51225122
},
5123+
{
5124+
name: "keeps the CLI's API error frame when the turn is interrupted",
5125+
text: "API Error: rejected",
5126+
apiErrorStatus: 400,
5127+
terminalReason: "aborted_streaming" as const,
5128+
shown: true,
5129+
},
51235130
])("$name", (input) =>
51245131
Effect.gen(function* () {
51255132
const harness = yield* makeWakeHarness;
@@ -5144,14 +5151,17 @@ describe("ClaudeAdapterV2 background wake turns", () => {
51445151
result: input.text,
51455152
isError: true,
51465153
apiErrorStatus: input.apiErrorStatus,
5147-
terminalReason: "api_error",
5154+
terminalReason: "terminalReason" in input ? input.terminalReason : "api_error",
51485155
}),
51495156
]);
51505157

51515158
const terminal = yield* Queue.take(harness.terminalReceipts);
5152-
assert.equal(terminal.status, "failed");
5153-
if (terminal.status !== "failed") return;
5154-
assert.equal(terminal.failure.message === input.text.slice(0, 500).trim(), !input.shown);
5159+
assert.equal(terminal.status, "terminalReason" in input ? "interrupted" : "failed");
5160+
if (terminal.status === "failed") {
5161+
assert.equal(terminal.failure.message === input.text.slice(0, 500).trim(), !input.shown);
5162+
} else {
5163+
assert.equal(terminal.failure, null);
5164+
}
51555165
const assistantTexts = harness.events.flatMap((event) =>
51565166
event.type === "message.updated" && event.message.role === "assistant"
51575167
? [event.message.text]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7303,8 +7303,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
73037303
input.context.assistant.apiErrorFrame = null;
73047304
if (
73057305
apiErrorFrame !== null &&
7306-
input.failure?.message !==
7307-
makeProviderFailure({ message: apiErrorFrame.text }).message.slice(0, 500).trim()
7306+
(input.status !== "failed" ||
7307+
input.failure?.message !==
7308+
makeProviderFailure({ message: apiErrorFrame.text }).message.slice(0, 500).trim())
73087309
) {
73097310
yield* emitAssistantTextArtifacts({ context: input.context, ...apiErrorFrame });
73107311
}

0 commit comments

Comments
 (0)