fix(agents): repair orphaned tool results for OpenAI after history truncation

repairToolUseResultPairing was gated behind !isOpenAi, skipping orphaned
tool_result cleanup for OpenAI providers. When limitHistoryTurns truncated
conversation history, tool_result messages whose matching tool_call was
before the truncation point survived and were sent as function_call_output
items with stale call_id references. OpenAI rejects these with:
"No tool call found for function call output with call_id ..."

Enable the repair universally — all providers need it after truncation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ben Marvell
2026-02-23 14:12:11 +00:00
parent 2247b81219
commit 97b065aa6e

View File

@@ -103,7 +103,10 @@ export function resolveTranscriptPolicy(params: {
: sanitizeToolCallIds
? "strict"
: undefined;
const repairToolUseResultPairing = isGoogle || isAnthropic;
// All providers need orphaned tool_result repair after history truncation.
// OpenAI rejects function_call_output items whose call_id has no matching
// function_call in the conversation, so the repair must run universally.
const repairToolUseResultPairing = true;
const sanitizeThoughtSignatures =
isOpenRouterGemini || isGoogle ? { allowBase64Only: true, includeCamelCase: true } : undefined;
@@ -111,7 +114,7 @@ export function resolveTranscriptPolicy(params: {
sanitizeMode: isOpenAi ? "images-only" : needsNonImageSanitize ? "full" : "images-only",
sanitizeToolCallIds: !isOpenAi && sanitizeToolCallIds,
toolCallIdMode,
repairToolUseResultPairing: !isOpenAi && repairToolUseResultPairing,
repairToolUseResultPairing,
preserveSignatures: false,
sanitizeThoughtSignatures: isOpenAi ? undefined : sanitizeThoughtSignatures,
sanitizeThinkingSignatures: false,