Skip to content

Commit ecab519

Browse files
authored
fix(codex): preserve encrypted reasoning alongside visible summaries (#1966)
1 parent 2267656 commit ecab519

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/core/task/__tests__/apiConversationHistory.spec.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
22

33
import { prepareApiConversationMessage } from "../apiConversationHistory.js"
44
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
5+
import type { ApiHandler } from "../../../api"
56

67
describe("prepareApiConversationMessage", () => {
78
beforeEach(() => {
@@ -83,6 +84,40 @@ describe("prepareApiConversationMessage", () => {
8384
])
8485
})
8586

87+
it.each(["reasoning-1", undefined])("preserves encrypted reasoning alongside its visible text (id: %s)", (id) => {
88+
const api = {
89+
createMessage: vi.fn<ApiHandler["createMessage"]>(),
90+
getModel: vi.fn<ApiHandler["getModel"]>(),
91+
countTokens: vi.fn<ApiHandler["countTokens"]>(),
92+
getEncryptedContent: () => ({ encrypted_content: "encrypted", ...(id ? { id } : {}) }),
93+
}
94+
const result = prepareApiConversationMessage({
95+
message: {
96+
role: "assistant",
97+
content: [
98+
{ type: "text", text: "Reading files" },
99+
{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "a.ts" } },
100+
],
101+
},
102+
reasoning: "visible reasoning",
103+
api,
104+
apiConfiguration: { apiProvider: providerIdentifiers.openaiCodex },
105+
apiConversationHistory: [],
106+
})
107+
108+
expect(result.content).toEqual([
109+
{
110+
type: "reasoning",
111+
text: "visible reasoning",
112+
summary: [],
113+
encrypted_content: "encrypted",
114+
...(id ? { id } : {}),
115+
},
116+
{ type: "text", text: "Reading files" },
117+
{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "a.ts" } },
118+
])
119+
})
120+
86121
it("appends thought signatures for non-Anthropic protocols", () => {
87122
const result = prepareApiConversationMessage({
88123
message: { role: "assistant", content: "answer" },

‎src/core/task/apiConversationHistory.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ function prepareAssistantMessage(
8282
type: "reasoning",
8383
text: reasoning,
8484
summary: [] as any[],
85+
// A visible summary must not discard the encrypted state needed for continuation.
86+
...(reasoningData?.encrypted_content
87+
? {
88+
encrypted_content: reasoningData.encrypted_content,
89+
...(reasoningData.id ? { id: reasoningData.id } : {}),
90+
}
91+
: {}),
8592
}
8693

8794
prependContentBlock(messageWithTs, reasoningBlock)

0 commit comments

Comments
 (0)