Repository navigation
fix(core): ignore duplicate provider tool-call ids #5038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b39080d
8997280
1684ddc
825e0ed
0972eea
9681a7a
0295f7b
4fedaa3
665014e
bfa0028
7032e6e
7f80a73
cdbeb48
b2b4b70
63a9c80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,10 @@ import { | |
| runWithRuntimeContentGenerator, | ||
| type RuntimeContentGeneratorView, | ||
| } from './agent-context.js'; | ||
| import { type ToolCallRequestInfo } from '../../core/turn.js'; | ||
| import { | ||
| createDuplicateProviderToolCallResponse, | ||
| type ToolCallRequestInfo, | ||
| } from '../../core/turn.js'; | ||
| import { | ||
| CoreToolScheduler, | ||
| type ToolCall, | ||
|
|
@@ -654,6 +657,7 @@ export class AgentCore { | |
| let turnCounter = 0; | ||
| let finalText = ''; | ||
| let terminateMode: AgentTerminateMode | null = null; | ||
| const handledProviderToolCallIds = new Set<string>(); | ||
|
|
||
| while (true) { | ||
| // Check abort before starting a new round — prevents unnecessary API | ||
|
|
@@ -815,6 +819,7 @@ export class AgentCore { | |
| toolsList, | ||
| currentResponseId, | ||
| wasOutputTruncated, | ||
| handledProviderToolCallIds, | ||
| ); | ||
|
|
||
| const externalInputs = this.drainExternalInputs(options); | ||
|
|
@@ -1090,6 +1095,7 @@ export class AgentCore { | |
| toolsList: FunctionDeclaration[], | ||
| responseId?: string, | ||
| wasOutputTruncated = false, | ||
| handledProviderToolCallIds = new Set<string>(), | ||
| ): Promise<Content[]> { | ||
| const toolResponseParts: Part[] = []; | ||
|
|
||
|
|
@@ -1100,9 +1106,58 @@ export class AgentCore { | |
| const authorizedCalls: FunctionCall[] = []; | ||
| for (const fc of functionCalls) { | ||
| const callId = fc.id ?? `${fc.name}-${Date.now()}`; | ||
| const providerCallId = fc.id; | ||
| const toolName = String(fc.name); | ||
|
|
||
|
YingchaoX marked this conversation as resolved.
Resolved
|
||
| if (providerCallId) { | ||
| if (handledProviderToolCallIds.has(providerCallId)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Zero debug logging when a duplicate provider tool call is detected and suppressed. If a model repeatedly emits the same tool-call ID, the only observability is via emitted events — no log trail exists in Consider adding a debug log at the detection point: this.runtimeContext.getDebugLogger()?.debug(
`[processFunctionCalls] Suppressing duplicate provider tool-call id: ${providerCallId} (tool: ${toolName}, round: ${currentRound})`,
);Same applies to the CLI path in — qwen3.7-max via Qwen Code /review
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in |
||
| const args = (fc.args ?? {}) as Record<string, unknown>; | ||
| const request: ToolCallRequestInfo = { | ||
| callId, | ||
|
YingchaoX marked this conversation as resolved.
Resolved
|
||
| providerCallId, | ||
| name: toolName, | ||
| args, | ||
| isClientInitiated: true, | ||
| prompt_id: promptId, | ||
| response_id: responseId, | ||
| wasOutputTruncated, | ||
| }; | ||
| const response = createDuplicateProviderToolCallResponse(request); | ||
| const errorMessage = response.error?.message; | ||
| const eventCallId = `${callId}:duplicate:${currentRound}:${toolResponseParts.length}`; | ||
|
|
||
|
YingchaoX marked this conversation as resolved.
Resolved
|
||
| this.eventEmitter?.emit(AgentEventType.TOOL_CALL, { | ||
| subagentId: this.subagentId, | ||
| round: currentRound, | ||
| callId: eventCallId, | ||
| name: toolName, | ||
| args, | ||
| description: errorMessage, | ||
| isOutputMarkdown: false, | ||
| timestamp: Date.now(), | ||
| } as AgentToolCallEvent); | ||
|
|
||
| this.eventEmitter?.emit(AgentEventType.TOOL_RESULT, { | ||
| subagentId: this.subagentId, | ||
| round: currentRound, | ||
| callId: eventCallId, | ||
| name: toolName, | ||
| success: false, | ||
| error: errorMessage, | ||
| responseParts: response.responseParts, | ||
| resultDisplay: response.resultDisplay, | ||
| durationMs: 0, | ||
| timestamp: Date.now(), | ||
| } as AgentToolResultEvent); | ||
|
|
||
| toolResponseParts.push(...response.responseParts); | ||
|
YingchaoX marked this conversation as resolved.
Resolved
|
||
| this.recordToolCallStats(toolName, false, 0, errorMessage); | ||
| continue; | ||
| } | ||
| handledProviderToolCallIds.add(providerCallId); | ||
| } | ||
|
|
||
| if (!allowedToolNames.has(fc.name)) { | ||
| const toolName = String(fc.name); | ||
| const errorMessage = `Tool "${toolName}" not found. Tools must use the exact names provided.`; | ||
|
|
||
| // Emit TOOL_CALL event for visibility | ||
|
|
@@ -1338,6 +1393,7 @@ export class AgentCore { | |
| const args = (fc.args ?? {}) as Record<string, unknown>; | ||
| const request: ToolCallRequestInfo = { | ||
| callId, | ||
| ...(fc.id ? { providerCallId: fc.id } : {}), | ||
| name: toolName, | ||
| args, | ||
| isClientInitiated: true, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.