Skip to content

Commit e928338

Browse files
committed
fix: invalidate checkpoints after OpenAI ID rewrites
1 parent 3bf9da8 commit e928338

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/agents/embedded-agent-helpers/openai.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ describe("normalizeOpenAIResponsesToolCallIds", () => {
9595
expect(toolResultId(secondResult)).toBe(secondCallId);
9696
});
9797

98+
it("strips a checkpoint when rekeying a pre-checkpoint tool call", () => {
99+
const rawId = "functions.gateway:0|fc_tmp_checkpoint";
100+
const owner: AssistantMessage = {
101+
...buildAssistantToolCall(rawId),
102+
content: [
103+
{ type: "toolCall", id: rawId, name: "gateway", arguments: {} },
104+
{ type: "text", text: "after checkpoint" },
105+
],
106+
providerReplay: {
107+
v: 1,
108+
type: "openai-responses-compaction",
109+
id: "cmp_replay",
110+
data: "opaque-checkpoint",
111+
replayIndex: 1,
112+
provider: "openrouter",
113+
api: "openai-responses",
114+
model: "moonshotai/kimi-k2.5",
115+
},
116+
};
117+
118+
const [rewrittenOwner, rewrittenResult] = normalizeOpenAIResponsesToolCallIds([
119+
owner,
120+
buildToolResult(rawId),
121+
]);
122+
123+
expect(rewrittenOwner?.role === "assistant" ? rewrittenOwner.providerReplay : undefined).toBe(
124+
undefined,
125+
);
126+
expect(toolResultId(rewrittenResult)).toBe(toolCallId(rewrittenOwner));
127+
});
128+
98129
it("normalizes mixed result aliases and incomplete persisted pairings independently", () => {
99130
const pairedId = "functions.gateway:0|fc_tmp_paired";
100131
const assistantOnlyId = "functions.read:0|fc_tmp_assistant_only";

‎src/agents/embedded-agent-helpers/openai.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function normalizeOpenAIResponsesToolCallIds(messages: AgentMessage[]): A
230230
continue;
231231
}
232232
changed = true;
233-
rewrittenMessages.push({ ...assistantMsg, content: nextContent } as AgentMessage);
233+
rewrittenMessages.push(replaceCompactionReplayOwnerContent(assistantMsg, nextContent));
234234
continue;
235235
}
236236

@@ -343,7 +343,7 @@ export function downgradeOpenAIFunctionCallReasoningPairs(
343343
continue;
344344
}
345345
changed = true;
346-
rewrittenMessages.push({ ...assistantMsg, content: nextContent } as AgentMessage);
346+
rewrittenMessages.push(replaceCompactionReplayOwnerContent(assistantMsg, nextContent));
347347
continue;
348348
}
349349

0 commit comments

Comments
 (0)