Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/api/providers/__tests__/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,20 @@ describe("OpenAiHandler", () => {
expect(model.id).toBe("")
expect(model.info).toBeDefined()
})

it("should set preserveReasoning when openAiR1FormatEnabled is on", () => {
const r1Handler = new OpenAiHandler({
...mockOptions,
openAiR1FormatEnabled: true,
})
const model = r1Handler.getModel()
expect(model.info.preserveReasoning).toBe(true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks preserveReasoning — would it still pass if the ...info spread got dropped (silently losing contextWindow/supportsImages)? Might be worth asserting the whole object.

Suggested change
expect(model.info.preserveReasoning).toBe(true)
expect(model.info).toEqual({ ...openAiModelInfoSaneDefaults, preserveReasoning: true })

})

it("should not set preserveReasoning by default", () => {
const model = handler.getModel()
expect(model.info.preserveReasoning).toBeUndefined()
})
})

describe("Azure AI Inference Service", () => {
Expand Down
10 changes: 9 additions & 1 deletion src/api/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,15 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
settings: this.options,
defaultTemperature: 0,
})
return { id, info, ...params }
// Local OpenAI-compatible reasoning models (llama.cpp, LM Studio, Ollama)
// stream reasoning_content, but Roo strips it from the follow-up context
// unless info.preserveReasoning is set. When the user enables the R1 format
// toggle, treat the model as preserving reasoning so the chain is fed back.
return {
id,
info: this.options.openAiR1FormatEnabled ? { ...info, preserveReasoning: true } : info,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createMessage() treats a model as R1-format via modelId.includes("deepseek-reasoner") || enabledR1Format (line 90), but this gate only checks the toggle. If someone points openAiModelId at a custom endpoint whose id contains deepseek-reasoner without flipping the toggle, wouldn't createMessage still use R1 conversion while preserveReasoning never gets set here — leaving the original bug open for that case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces preserveReasoning: true whenever the toggle is on, even if openAiCustomModelInfo.preserveReasoning was explicitly set to false. Should an explicit value win here, e.g. info.preserveReasoning ?? true?

...params,
}
}

async completePrompt(prompt: string, options?: CompletePromptOptions): Promise<string> {
Expand Down
Loading