fix(commandcode): retry on transient stream error and avoid fake stop chunks

This commit is contained in:
Christian Gennari
2026-09-18 17:07:32 +07:00
committed by decolua
parent b3d6e089c6
commit 092c84eac9
4 changed files with 65 additions and 8 deletions

View File

@@ -165,12 +165,11 @@ export function commandCodeToOpenAIResponse(chunk, state) {
break;
}
case "error": {
state.finishReason = OPENAI_FINISH.STOP;
const errVal = event.error ?? event.message ?? "unknown";
const errStr = typeof errVal === "string" ? errVal : JSON.stringify(errVal);
out.push(makeChunk(state, { content: `\n\n[CommandCode error: ${errStr}]` }));
out.push(makeChunk(state, {}, OPENAI_FINISH.STOP));
break;
// Mid-stream error: throw rather than emitting as fake content with finish_reason: "stop"
// This ensures the downstream stream handler marks the stream as errored/aborted.
throw new Error(`[CommandCode error: ${errStr}]`);
}
// Silently ignore: start, start-step, reasoning-start, reasoning-end, text-start, text-end,
// provider-metadata, message-metadata, etc. They carry no client-visible content.