Skip to content

Commit c9cedc4

Browse files
committed
fix(kiro): keep progress text nonterminal
1 parent fd7e97e commit c9cedc4

4 files changed

Lines changed: 28 additions & 37 deletions

File tree

‎src/adapters/kiro.ts‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -917,23 +917,9 @@ async function* parseKiroAttempt(
917917
terminal: { type: "done", usage: finalUsage, endTurn: false, ...(finalProviderState ? { providerState: finalProviderState } : {}) },
918918
};
919919
}
920-
// A clean Smithy EOF after ordinary assistant text is a complete answer even when the
921-
// private completion tool was advertised. Replaying that answer through a second Kiro
922-
// request adds latency and can hang an otherwise-finished Codex turn if the retry stalls.
923-
// Reasoning-only output still needs the bounded fallback because it has no user-facing text.
924-
if (mode === "required" && sawText) {
925-
return {
926-
assistantText,
927-
sawReasoning,
928-
terminal: {
929-
type: "done",
930-
usage: finalUsage,
931-
endTurn: true,
932-
...(finalProviderState ? { providerState: finalProviderState } : {}),
933-
},
934-
};
935-
}
936-
if (mode === "required" && sawReasoning) {
920+
// Kiro text has no trustworthy final/progress marker. When completion is required, ordinary
921+
// text and reasoning remain unfinished until the one bounded fallback validates the turn.
922+
if (mode === "required" && (sawText || sawReasoning)) {
937923
return { assistantText, sawReasoning, needsFallback: true, usage: finalUsage, providerState: finalProviderState };
938924
}
939925
if (!sawText && !sawReasoning) {

‎structure/04_transports-and-sidecars.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ the watchdog.
108108
The web-search loop requests `stream: true` for every routed-model iteration, but buffers the events
109109
needed to decide whether to intercept a synthetic search call. Text explicitly phased as
110110
`commentary` is safe to forward live because it cannot terminate the turn; this keeps Kiro's
111-
progress visible. A clean Kiro stream EOF after user-facing text completes directly; reasoning-only
112-
output still gets one bounded completion retry. Synthetic search calls, real tool calls,
111+
progress visible. A Kiro stream EOF after user-facing text or reasoning gets one bounded completion
112+
retry, because the upstream text event does not distinguish progress from a final answer. Synthetic search calls, real tool calls,
113113
and terminal events remain buffered until the iteration validates. Only the first iteration's final
114114
response headers/status and any 429 key rotations are handled eagerly. A failure before downstream
115115
SSE starts returns non-2xx JSON; once headers have started the final response, a generation failure

‎tests/kiro-stream.test.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,31 @@ describe("kiro adapter — parseStream", () => {
279279
}
280280
});
281281

282-
test("text-only required response completes without a second upstream request", async () => {
283-
let fetches = 0;
284-
globalThis.fetch = (async () => {
285-
fetches++;
286-
throw new Error("unexpected fallback");
282+
test("progress-only required response makes exactly one structural text fallback", async () => {
283+
const requests: Record<string, any>[] = [];
284+
globalThis.fetch = (async (_input, init) => {
285+
requests.push(JSON.parse(String(init?.body)));
286+
return new Response(streamOf(eventFrame({ content: "Final from fallback." })));
287287
}) as typeof fetch;
288288
const adapter = createKiroAdapter(provider);
289289
await adapter.buildRequest(parsedWith([{ role: "user", content: "do it" }], [bashTool]));
290290

291291
const events = await collectAdapterEvents(adapter.parseStream(new Response(streamOf(
292-
eventFrame({ content: "Task complete." }),
292+
eventFrame({ content: "I am checking." }),
293293
eventFrame({ conversationId: "returned-conversation-42" }),
294294
))));
295295

296-
expect(fetches).toBe(0);
296+
expect(requests).toHaveLength(1);
297+
const retry = requests[0].conversationState;
298+
expect(retry.conversationId).toBe("returned-conversation-42");
299+
expect(retry.history.at(-1).assistantResponseMessage).toEqual({ content: "I am checking." });
300+
expect(retry.currentMessage.userInputMessage.content).toBe(KIRO_COMPLETION_RETRY_MESSAGE);
301+
expect(retry.currentMessage.userInputMessage.userInputMessageContext.tools.map(
302+
(tool: { toolSpecification: { name: string } }) => tool.toolSpecification.name,
303+
)).toEqual(["bash", KIRO_COMPLETION_TOOL_NAME]);
297304
expect(events.filter(event => event.type === "text_delta")).toEqual([
298-
{ type: "text_delta", text: "Task complete.", phase: "commentary" },
305+
{ type: "text_delta", text: "I am checking.", phase: "commentary" },
306+
{ type: "text_delta", text: "Final from fallback.", phase: "final_answer" },
299307
]);
300308
expect(events.at(-1)).toMatchObject({
301309
type: "done",

‎tests/server-kiro-completion-e2e.test.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ function textFrame(text: string): Uint8Array {
4949
return eventFrame("assistantResponseEvent", { content: text });
5050
}
5151

52-
function reasoningFrame(text: string): Uint8Array {
53-
return eventFrame("reasoningContentEvent", { text });
54-
}
55-
5652
function completionFrames(answer: string, id = "completion-1"): Uint8Array[] {
5753
const input = JSON.stringify({ answer });
5854
return [
@@ -132,9 +128,9 @@ function anthropicEvents(sse: string): Array<{ name: string; data: Record<string
132128
}
133129

134130
describe("Kiro completion through public server endpoints", () => {
135-
test("/v1/responses lets the bounded fallback complete after reasoning-only output", async () => {
131+
test("/v1/responses keeps progress nonterminal and lets only the bounded fallback complete", async () => {
136132
const upstream = scriptedKiroUpstream([
137-
[reasoningFrame("Checking the workspace.")],
133+
[textFrame("Checking the workspace.")],
138134
completionFrames("The workspace is ready."),
139135
]);
140136
saveConfig(kiroConfig(upstream.server.url.toString()));
@@ -156,20 +152,21 @@ describe("Kiro completion through public server endpoints", () => {
156152
const events = responseEvents(wire);
157153
const text = events.filter(event => event.name === "response.output_text.delta");
158154
expect(text.map(event => [event.data.delta, event.data.phase])).toEqual([
155+
["Checking the workspace.", undefined],
159156
["The workspace is ready.", undefined],
160157
]);
161158
const completed = events.filter(event => event.name === "response.completed");
162159
expect(completed).toHaveLength(1);
163160
expect(events.at(-1)?.name).toBe("response.completed");
164161
const messages = completed[0].data.response.output.filter((item: { type: string }) => item.type === "message");
165-
expect(messages.map((item: { phase?: string }) => item.phase)).toEqual(["final_answer"]);
162+
expect(messages.map((item: { phase?: string }) => item.phase)).toEqual(["commentary", "final_answer"]);
166163
expect(wire).not.toContain(KIRO_COMPLETION_TOOL_NAME);
167164

168165
expect(upstream.requests).toHaveLength(2);
169166
expect(kiroToolNames(upstream.requests[0])).toEqual(["bash", KIRO_COMPLETION_TOOL_NAME]);
170167
expect(kiroToolNames(upstream.requests[1])).toEqual(["bash", KIRO_COMPLETION_TOOL_NAME]);
171168
expect(upstream.requests[1].conversationState.history.at(-1).assistantResponseMessage.content)
172-
.toBe("");
169+
.toBe("Checking the workspace.");
173170
} finally {
174171
proxy.stop(true);
175172
upstream.server.stop(true);
@@ -181,7 +178,7 @@ describe("Kiro completion through public server endpoints", () => {
181178
["accepted text fallback", [textFrame("The Claude task is complete.")]],
182179
])("/v1/messages hides the private tool and ends after %s", async (_label, fallbackFrames) => {
183180
const upstream = scriptedKiroUpstream([
184-
[reasoningFrame("I am checking the Claude task.")],
181+
[textFrame("I am checking the Claude task.")],
185182
fallbackFrames,
186183
]);
187184
saveConfig(kiroConfig(upstream.server.url.toString()));
@@ -205,7 +202,7 @@ describe("Kiro completion through public server endpoints", () => {
205202
const deltas = events
206203
.filter(event => event.name === "content_block_delta" && event.data.delta?.type === "text_delta")
207204
.map(event => event.data.delta.text);
208-
expect(deltas).toEqual(["The Claude task is complete."]);
205+
expect(deltas).toEqual(["I am checking the Claude task.", "The Claude task is complete."]);
209206
expect(events.filter(event => event.name === "message_delta")).toHaveLength(1);
210207
expect(events.find(event => event.name === "message_delta")?.data.delta.stop_reason).toBe("end_turn");
211208
expect(events.at(-1)?.name).toBe("message_stop");

0 commit comments

Comments
 (0)