fix: always drop orphaned OpenAI reasoning blocks in session history
downgradeOpenAIReasoningBlocks was only called on model change, but orphaned reasoning items (e.g. from an aborted stream) can exist without a model switch and cause a 400 from the OpenAI Responses API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
e33017982c
commit
46bf210e04
@@ -204,7 +204,7 @@ describe("sanitizeSessionHistory", () => {
|
||||
expect(result.map((msg) => msg.role)).toEqual(["user"]);
|
||||
});
|
||||
|
||||
it("does not downgrade openai reasoning when the model has not changed", async () => {
|
||||
it("downgrades orphaned openai reasoning even when the model has not changed", async () => {
|
||||
const sessionEntries = [
|
||||
makeModelSnapshotEntry({
|
||||
provider: "openai",
|
||||
@@ -222,7 +222,7 @@ describe("sanitizeSessionHistory", () => {
|
||||
sessionManager,
|
||||
});
|
||||
|
||||
expect(result).toEqual(messages);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("downgrades openai reasoning only when the model changes", async () => {
|
||||
|
||||
@@ -457,10 +457,9 @@ export async function sanitizeSessionHistory(params: {
|
||||
modelId: params.modelId,
|
||||
})
|
||||
: false;
|
||||
const sanitizedOpenAI =
|
||||
isOpenAIResponsesApi && modelChanged
|
||||
? downgradeOpenAIReasoningBlocks(sanitizedToolResults)
|
||||
: sanitizedToolResults;
|
||||
const sanitizedOpenAI = isOpenAIResponsesApi
|
||||
? downgradeOpenAIReasoningBlocks(sanitizedToolResults)
|
||||
: sanitizedToolResults;
|
||||
|
||||
if (hasSnapshot && (!priorSnapshot || modelChanged)) {
|
||||
appendModelSnapshot(params.sessionManager, {
|
||||
|
||||
Reference in New Issue
Block a user