Skip to content

Commit 97b065a

Browse files
easternblocclaude
andcommitted
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 <[email protected]>
1 parent 2247b81 commit 97b065a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/agents/transcript-policy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ export function resolveTranscriptPolicy(params: {
103103
: sanitizeToolCallIds
104104
? "strict"
105105
: undefined;
106-
const repairToolUseResultPairing = isGoogle || isAnthropic;
106+
// All providers need orphaned tool_result repair after history truncation.
107+
// OpenAI rejects function_call_output items whose call_id has no matching
108+
// function_call in the conversation, so the repair must run universally.
109+
const repairToolUseResultPairing = true;
107110
const sanitizeThoughtSignatures =
108111
isOpenRouterGemini || isGoogle ? { allowBase64Only: true, includeCamelCase: true } : undefined;
109112

110113
return {
111114
sanitizeMode: isOpenAi ? "images-only" : needsNonImageSanitize ? "full" : "images-only",
112115
sanitizeToolCallIds: !isOpenAi && sanitizeToolCallIds,
113116
toolCallIdMode,
114-
repairToolUseResultPairing: !isOpenAi && repairToolUseResultPairing,
117+
repairToolUseResultPairing,
115118
preserveSignatures: false,
116119
sanitizeThoughtSignatures: isOpenAi ? undefined : sanitizeThoughtSignatures,
117120
sanitizeThinkingSignatures: false,

0 commit comments

Comments
 (0)