xonecas.io
64875
Mc

mini-coder / commit 471f269

fix: remove tool input start deduplication logic

xonecas2026-03-14 471f26962675759f3c800dbf2d12c169ff150366 parent a97e2c9

2 files changed

src/llm-api/turn.test.ts+0−73
@@ -4,7 +4,6 @@ import {
44 annotateAnthropicCacheBreakpoints,
55 applyContextPruning,
66 compactToolResultPayloads,
7- consumePendingToolInputStart,
87 getMessageDiagnostics,
98 getReasoningDeltaFromStreamChunk,
109 isOpenAIGPT,
@@ -122,78 +121,6 @@ describe("getReasoningDeltaFromStreamChunk", () => {
122121 });
123122 });
124123
125-describe("consumePendingToolInputStart", () => {
126- test("consumes one queued start by id", () => {
127- const pendingById = new Set<string>(["call_1"]);
128- const pendingByName = new Map<string, number>([["read", 2]]);
129-
130- expect(
131- consumePendingToolInputStart(
132- pendingById,
133- pendingByName,
134- "call_1",
135- "read",
136- ),
137- ).toBe(true);
138- expect(pendingById.has("call_1")).toBe(false);
139- expect(pendingByName.get("read")).toBe(2);
140- });
141-
142- test("falls back to name only when id is missing", () => {
143- const pendingById = new Set<string>();
144- const pendingByName = new Map<string, number>([["read", 2]]);
145-
146- expect(
147- consumePendingToolInputStart(pendingById, pendingByName, "", "read"),
148- ).toBe(true);
149- expect(pendingByName.get("read")).toBe(1);
150- expect(
151- consumePendingToolInputStart(pendingById, pendingByName, "", "read"),
152- ).toBe(true);
153- expect(pendingByName.has("read")).toBe(false);
154- });
155-
156- test("does not consume by name when an id is present but unmatched", () => {
157- const pendingById = new Set<string>(["call_a", "call_b"]);
158- const pendingByName = new Map<string, number>([["read", 2]]);
159-
160- expect(
161- consumePendingToolInputStart(
162- pendingById,
163- pendingByName,
164- "call_missing",
165- "read",
166- ),
167- ).toBe(false);
168- expect(pendingById.size).toBe(2);
169- expect(pendingByName.get("read")).toBe(2);
170- });
171-
172- test("handles interleaved same-name calls without cross-consuming", () => {
173- const pendingById = new Set<string>(["call_a", "call_b"]);
174- const pendingByName = new Map<string, number>();
175-
176- // tool-call for B arrives before A; both should dedupe correctly by id.
177- expect(
178- consumePendingToolInputStart(
179- pendingById,
180- pendingByName,
181- "call_b",
182- "read",
183- ),
184- ).toBe(true);
185- expect(
186- consumePendingToolInputStart(
187- pendingById,
188- pendingByName,
189- "call_a",
190- "read",
191- ),
192- ).toBe(true);
193- expect(pendingById.size).toBe(0);
194- });
195-});
196-
197124 describe("sanitizeGeminiToolMessages", () => {
198125 const healthyGeminiToolTurn = (userContent: string): CoreMessage[] =>
199126 [
src/llm-api/turn.ts+3−55
@@ -275,29 +275,6 @@ export function getReasoningDeltaFromStreamChunk(
275275 return "";
276276 }
277277
278-export function consumePendingToolInputStart(
279- pendingToolStartsById: Set<string>,
280- pendingToolStartsByName: Map<string, number>,
281- toolCallId: string,
282- toolName: string,
283-): boolean {
284- if (toolCallId.length > 0) {
285- if (!pendingToolStartsById.has(toolCallId)) return false;
286- pendingToolStartsById.delete(toolCallId);
287- return true;
288- }
289-
290- if (toolName.length === 0) return false;
291- const pending = pendingToolStartsByName.get(toolName) ?? 0;
292- if (pending <= 0) return false;
293- if (pending === 1) {
294- pendingToolStartsByName.delete(toolName);
295- } else {
296- pendingToolStartsByName.set(toolName, pending - 1);
297- }
298- return true;
299-}
300-
301278 type StreamTextResult = ReturnType<typeof streamText>;
302279 type StreamTextResultFull = StreamTextResult & {
303280 fullStream: AsyncIterable<StreamChunk>;
@@ -1116,9 +1093,6 @@ export async function* runTurn(options: {
11161093 // awaited, causing an unhandled rejection that crashes the app.
11171094 // We catch it here to mark it as handled (awaiting it later will still throw).
11181095 result.response.catch(() => {});
1119- const pendingToolStartsById = new Set<string>();
1120- const pendingToolStartsByName = new Map<string, number>();
1121-
11221096 // Stream events
11231097 for await (const chunk of result.fullStream) {
11241098 const c = chunk as StreamChunk;
@@ -1161,26 +1135,10 @@ export async function* runTurn(options: {
11611135 }
11621136
11631137 case "tool-input-start": {
1164- const toolName =
1165- typeof c.toolName === "string" && c.toolName.length > 0
1166- ? c.toolName
1167- : "";
1168- const toolCallId = String(c.toolCallId ?? "");
1169- if (toolCallId.length > 0) {
1170- pendingToolStartsById.add(toolCallId);
1171- } else if (toolName.length > 0) {
1172- pendingToolStartsByName.set(
1173- toolName,
1174- (pendingToolStartsByName.get(toolName) ?? 0) + 1,
1175- );
1176- } else {
1177- break;
1178- }
11791138 yield {
1180- type: "tool-call-start",
1181- toolCallId,
1182- toolName,
1183- // tool-input-start usually arrives before full args are available.
1139+ type: "tool-input-start",
1140+ toolCallId: String(c.toolCallId ?? ""),
1141+ toolName: String(c.toolName ?? ""),
11841142 args: c.input ?? c.args,
11851143 };
11861144 break;
@@ -1189,16 +1147,6 @@ export async function* runTurn(options: {
11891147 case "tool-call": {
11901148 const toolName = String(c.toolName ?? "");
11911149 const toolCallId = String(c.toolCallId ?? "");
1192- if (
1193- consumePendingToolInputStart(
1194- pendingToolStartsById,
1195- pendingToolStartsByName,
1196- toolCallId,
1197- toolName,
1198- )
1199- ) {
1200- break;
1201- }
12021150 yield {
12031151 type: "tool-call-start",
12041152 toolCallId,