Skip to content

Commit 12a2663

Browse files
committed
fix(llm): restore id field in stateless reasoning replay items
PR anomalyco#34027 introduced a type alias OpenAIResponsesReasoningReplay = Omit<OpenAIResponsesReasoningInput, 'id'> and built the replay object without the id field. The Azure/OpenAI Responses API requires that reasoning items carrying encrypted_content also carry a matching id, so omitting it causes HTTP 400 invalid_payload on continuation turns. Fixes: - Remove the Omit alias so OpenAIResponsesReasoningReplay is OpenAIResponsesReasoningInput - Add id: reasoning.id to the replay object literal in lowerMessages - Make id required (Schema.String) in OpenAIResponsesReasoningItem schema - Update the join-summary test to assert id is present - Add regression test proving the id is forwarded in the lowered input Closes anomalyco#49574
1 parent 5a83358 commit 12a2663

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎packages/llm/src/protocols/openai-responses.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const OpenAIResponsesReasoningSummaryText = Schema.Struct({
5555

5656
const OpenAIResponsesReasoningItem = Schema.Struct({
5757
type: Schema.tag("reasoning"),
58-
id: Schema.optionalKey(Schema.String),
58+
id: Schema.String,
5959
summary: Schema.Array(OpenAIResponsesReasoningSummaryText),
6060
encrypted_content: optionalNull(Schema.String),
6161
})
@@ -103,7 +103,7 @@ type OpenAIResponsesReasoningInput = {
103103
summary: Array<{ type: "summary_text"; text: string }>
104104
encrypted_content?: string | null
105105
}
106-
type OpenAIResponsesReasoningReplay = Omit<OpenAIResponsesReasoningInput, "id">
106+
type OpenAIResponsesReasoningReplay = OpenAIResponsesReasoningInput
107107

108108
const OpenAIResponsesTool = Schema.Struct({
109109
type: Schema.tag("function"),
@@ -400,6 +400,7 @@ const lowerMessages = Effect.fn("OpenAIResponses.lowerMessages")(function* (requ
400400
}
401401
const replay = {
402402
type: reasoning.type,
403+
id: reasoning.id,
403404
summary: reasoning.summary,
404405
encrypted_content: reasoning.encrypted_content,
405406
}

‎packages/llm/test/provider/openai-responses.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ describe("OpenAI Responses route", () => {
10911091
expect(prepared.body.input).toEqual([
10921092
{
10931093
type: "reasoning",
1094+
id: "rs_1",
10941095
encrypted_content: "encrypted-state",
10951096
summary: [
10961097
{ type: "summary_text", text: "First" },
@@ -1469,4 +1470,44 @@ describe("OpenAI Responses route", () => {
14691470
expect(error.message).toContain("HTTP 400")
14701471
}),
14711472
)
1473+
it.effect("includes id in stateless reasoning replay item", () =>
1474+
Effect.gen(function* () {
1475+
// Regression for the bug introduced by PR #34027: the replay object
1476+
// built in lowerMessages explicitly omitted id via the Omit type alias,
1477+
// causing HTTP 400 from the Responses API when encrypted_content was
1478+
// present (the API requires id and encrypted_content as a matched pair).
1479+
const prepared = yield* LLMClient.prepare<OpenAIResponses.OpenAIResponsesBody>(
1480+
LLM.request({
1481+
id: "req_reasoning_replay_id",
1482+
model,
1483+
messages: [
1484+
Message.assistant([
1485+
{
1486+
type: "reasoning",
1487+
text: "I considered the question carefully.",
1488+
providerMetadata: {
1489+
openai: {
1490+
itemId: "rs_abc123",
1491+
reasoningEncryptedContent: "encrypted-abc123",
1492+
},
1493+
},
1494+
},
1495+
]),
1496+
],
1497+
providerOptions: { openai: { store: false } },
1498+
}),
1499+
)
1500+
1501+
const reasoningItem = prepared.body.input.find(
1502+
(item) => "type" in item && item.type === "reasoning",
1503+
)
1504+
expect(reasoningItem).toBeDefined()
1505+
expect(reasoningItem).toEqual({
1506+
type: "reasoning",
1507+
id: "rs_abc123",
1508+
encrypted_content: "encrypted-abc123",
1509+
summary: [{ type: "summary_text", text: "I considered the question carefully." }],
1510+
})
1511+
}),
1512+
)
14721513
})

0 commit comments

Comments
 (0)