From 7bfafe3c83d380aea384c12a6c9bd0fe05e70427 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 22 Sep 2025 16:05:16 +0000 Subject: [PATCH 1/5] fix: use system role for OpenAI Compatible provider when streaming is disabled - Changed role from "user" to "system" for system prompt in non-streaming mode - Updated test expectations to match the corrected behavior - Ensures consistency between streaming and non-streaming modes Fixes #8215 --- src/api/providers/__tests__/openai.spec.ts | 2 +- src/api/providers/openai.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/providers/__tests__/openai.spec.ts b/src/api/providers/__tests__/openai.spec.ts index 3e744d6e16e..6ec43a6dfae 100644 --- a/src/api/providers/__tests__/openai.spec.ts +++ b/src/api/providers/__tests__/openai.spec.ts @@ -494,7 +494,7 @@ describe("OpenAiHandler", () => { { model: azureOptions.openAiModelId, messages: [ - { role: "user", content: systemPrompt }, + { role: "system", content: systemPrompt }, { role: "user", content: "Hello!" }, ], }, diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index aebe671712a..cd56bea9446 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -219,8 +219,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } } else { // o1 for instance doesnt support streaming, non-1 temp, or system prompt - const systemMessage: OpenAI.Chat.ChatCompletionUserMessageParam = { - role: "user", + const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { + role: "system", content: systemPrompt, } From 9d154de7b3dbe25f4ab5758757321af100a90f9f Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 20 Oct 2025 18:50:39 +0000 Subject: [PATCH 2/5] docs(openai): clarify non-streaming path comment and rationale for system role; align with review suggestions --- src/api/providers/openai.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index cd56bea9446..a2b52f30539 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -218,9 +218,14 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl yield this.processUsageMetrics(lastUsage, modelInfo) } } else { - // o1 for instance doesnt support streaming, non-1 temp, or system prompt + // Note: o1/o3/o4 models do not support streaming, non-1 temperature, or system prompts. + // This non-streaming branch is for general OpenAI-compatible providers that DO support system prompts. + // The o1/o3/o4 family is handled above in handleO3FamilyMessage(), so we still use a proper "system" role + // here for consistency with streaming behavior and provider expectations. const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { role: "system", + // Use "system" to match streaming behavior; many OpenAI-compatible providers treat system prompts specially + // (e.g., safety, formatting, or caching), and tests assert consistency across modes. content: systemPrompt, } From 74164ee4470bfc630be371a74ab98d913d265dfc Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Tue, 21 Oct 2025 17:20:26 -0500 Subject: [PATCH 3/5] Remove redundant inline comment in non-streaming branch --- src/api/providers/openai.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index a2b52f30539..1be60742d8f 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -224,8 +224,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl // here for consistency with streaming behavior and provider expectations. const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { role: "system", - // Use "system" to match streaming behavior; many OpenAI-compatible providers treat system prompts specially - // (e.g., safety, formatting, or caching), and tests assert consistency across modes. content: systemPrompt, } From 05f9afdc6168b13591292c446fbfa1e2ccec88c7 Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Tue, 21 Oct 2025 17:22:13 -0500 Subject: [PATCH 4/5] Remove unnecessary comment block in non-streaming branch --- src/api/providers/openai.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 1be60742d8f..03496ae2931 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -218,10 +218,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl yield this.processUsageMetrics(lastUsage, modelInfo) } } else { - // Note: o1/o3/o4 models do not support streaming, non-1 temperature, or system prompts. - // This non-streaming branch is for general OpenAI-compatible providers that DO support system prompts. - // The o1/o3/o4 family is handled above in handleO3FamilyMessage(), so we still use a proper "system" role - // here for consistency with streaming behavior and provider expectations. const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { role: "system", content: systemPrompt, From 795f0e9ed007e5355f8711affe1e5420b6bb6f69 Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Tue, 21 Oct 2025 17:25:44 -0500 Subject: [PATCH 5/5] refactor: reorder system message creation for clarity in OpenAiHandler --- src/api/providers/openai.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 03496ae2931..9100ff3c659 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -99,12 +99,12 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl return } - if (this.options.openAiStreamingEnabled ?? true) { - let systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { - role: "system", - content: systemPrompt, - } + let systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { + role: "system", + content: systemPrompt, + } + if (this.options.openAiStreamingEnabled ?? true) { let convertedMessages if (deepseekReasoner) { @@ -218,11 +218,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl yield this.processUsageMetrics(lastUsage, modelInfo) } } else { - const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { - role: "system", - content: systemPrompt, - } - const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming = { model: modelId, messages: deepseekReasoner