Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(model-runtime): strip reasoning.mode from ChatGPT Codex requests for models that reject it (#20562)

Arvin Xudf5daf7614f2
diff --git a/packages/model-runtime/src/providers/chatGPT/index.test.ts b/packages/model-runtime/src/providers/chatGPT/index.test.ts
index 2ca2088383a..10aae333b24 100644
--- a/packages/model-runtime/src/providers/chatGPT/index.test.ts
+++ b/packages/model-runtime/src/providers/chatGPT/index.test.ts
@@ -263,4 +263,94 @@ describe('LobeChatGPTAI', () => {
expect(request.reasoning).toEqual({ effort: 'high', summary: 'auto' });
expect(request.tools).toContainEqual({ type: 'web_search' });
});
+
+ // Regression: a stale `agencyConfig.subagent.chatConfig.reasoningMode` reached
+ // gpt-6.1-sol and the Codex backend rejected the whole request with
+ // `400 reasoning.mode is not supported with this model` (unsupported_value),
+ // leaving callSubAgent with no recovery path. The provider now strips
+ // `reasoning.mode` for models outside the gpt-5.6 family.
+ it('strips reasoning.mode for Codex models that reject it', async () => {
+ await instance.chat({
+ messages: [{ content: 'Write a chapter', role: 'user' }],
+ model: 'gpt-6.1-sol',
+ reasoning: { effort: 'max', mode: 'pro', summary: 'auto' },
+ });
+
+ const request = (instance['client'].responses.create as Mock).mock.calls[0][0];
+
+ expect(request.reasoning).toEqual({ effort: 'max', summary: 'auto' });
+ });
+
+ it('reduces mode-only reasoning to the provider baseline on a rejecting model', async () => {
+ await instance.chat({
+ messages: [{ content: 'Write a chapter', role: 'user' }],
+ model: 'gpt-6.1-sol',
+ reasoning: { mode: 'pro' },
+ });
+
+ const request = (instance['client'].responses.create as Mock).mock.calls[0][0];
+
+ // The shared Responses payload pipeline injects the provider baseline
+ // `{ summary: 'auto' }` before this gate runs (mirroring a request with no
+ // reasoning config at all, which is accepted), so stripping `mode` yields
+ // exactly that baseline rather than an absent field.
+ expect(request.reasoning).toEqual({ summary: 'auto' });
+ });
+
+ // Codex review P2: capability must be judged against the mapped upstream
+ // model, not the logical ID. `handlePayload` runs before `modelIdMapping`
+ // resolves the logical model, so the gate lives in `prepareRequest`, which
+ // receives the mapped model.
+ it('strips reasoning.mode when modelIdMapping maps onto a rejecting model', async () => {
+ const mapped = new LobeChatGPTAI({
+ apiKey: 'access-token',
+ chatgptAccountId: 'account-id',
+ modelIdMapping: { 'gpt-5.6-sol': 'gpt-6.1-sol' },
+ });
+ vi.spyOn(mapped['client'].responses, 'create').mockResolvedValue(new ReadableStream() as never);
+
+ await mapped.chat({
+ messages: [{ content: 'Write a chapter', role: 'user' }],
+ model: 'gpt-5.6-sol',
+ reasoning: { effort: 'high', mode: 'pro', summary: 'auto' },
+ });
+
+ const request = (mapped['client'].responses.create as Mock).mock.calls[0][0];
+
+ expect(request.model).toBe('gpt-6.1-sol');
+ expect(request.reasoning).toEqual({ effort: 'high', summary: 'auto' });
+ });
+
+ it('keeps reasoning.mode when modelIdMapping maps onto a supporting model', async () => {
+ const mapped = new LobeChatGPTAI({
+ apiKey: 'access-token',
+ chatgptAccountId: 'account-id',
+ modelIdMapping: { 'gpt-6.1-sol': 'gpt-5.6-sol' },
+ });
+ vi.spyOn(mapped['client'].responses, 'create').mockResolvedValue(new ReadableStream() as never);
+ await mapped.chat({
+ messages: [{ content: 'Write a chapter', role: 'user' }],
+ model: 'gpt-6.1-sol',
+ reasoning: { effort: 'high', mode: 'pro', summary: 'auto' },
+ });
+
+ const request = (mapped['client'].responses.create as Mock).mock.calls[0][0];
+
+ expect(request.reasoning).toMatchObject({ effort: 'high', mode: 'pro', summary: 'auto' });
+ });
+
+ it.each(['gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna'])(
+ 'keeps reasoning.mode for %s (declared capability)',
+ async (model) => {
+ await instance.chat({
+ messages: [{ content: 'Write a chapter', role: 'user' }],
+ model,
+ reasoning: { effort: 'high', mode: 'pro' },
+ });
+
+ const request = (instance['client'].responses.create as Mock).mock.calls[0][0];
+
+ expect(request.reasoning).toMatchObject({ effort: 'high', mode: 'pro' });
+ },
+ );
});
diff --git a/packages/model-runtime/src/providers/chatGPT/index.ts b/packages/model-runtime/src/providers/chatGPT/index.ts
index 0eae6648ec3..6a7a5443f19 100644
--- a/packages/model-runtime/src/providers/chatGPT/index.ts
+++ b/packages/model-runtime/src/providers/chatGPT/index.ts
@@ -23,6 +23,25 @@ interface ChatGPTAdditionalToolsInput {
const isResponsesLiteModel = (model: string | undefined) =>
!!model && CHATGPT_RESPONSES_LITE_MODEL_IDS.has(model);
+/**
+ * Codex models that accept the `reasoning.mode` parameter. Mirrors the
+ * `reasoningMode` extend-param declarations in the model bank (`gpt-5.6-*`):
+ * every other Codex model β€” GPT-6.x included β€” rejects the field with
+ * `400 reasoning.mode is not supported with this model` (invalid_request_error,
+ * unsupported_value), which leaves a callSubAgent run with no way to recover.
+ *
+ * A stale `agencyConfig.subagent.chatConfig.reasoningMode` configured for one
+ * override model must not reach a model that no longer declares the param, so
+ * the provider strips it as a final capability gate regardless of where the
+ * field leaked in from. The gate runs in `prepareRequest`, i.e. after
+ * `modelIdMapping` has resolved the logical model to the actual upstream model
+ * ID, so capability is judged against the model the request really targets.
+ */
+const CHATGPT_REASONING_MODE_MODEL_PREFIXES = ['gpt-5.6-'];
+
+const supportsReasoningMode = (model: string | undefined) =>
+ !!model && CHATGPT_REASONING_MODE_MODEL_PREFIXES.some((prefix) => model.startsWith(prefix));
+
export const LobeChatGPTAI = createOpenAICompatibleRuntime<ChatGPTClientOptions>({
baseURL: CHATGPT_CODEX_BASE_URL,
chatCompletion: {
@@ -63,8 +82,28 @@ export const LobeChatGPTAI = createOpenAICompatibleRuntime<ChatGPTClientOptions>
prepareRequest: (payload) => {
const { safety_identifier: _safetyIdentifier, ...subscriptionPayload } = payload;
- if (!isResponsesLiteModel(payload.model)) {
- return { payload: subscriptionPayload };
+ // Final capability gate for `reasoning.mode`: strip the field for models
+ // the Codex backend rejects it on (see supportsReasoningMode). This runs
+ // after `modelIdMapping`, so a mapping from a supporting logical model
+ // (e.g. gpt-5.6-sol) to a rejecting upstream model (e.g. gpt-6.1-sol)
+ // still strips, and the inverse mapping keeps the field. Effort and
+ // summary stay untouched β€” only `mode` is a subscription-catalog-gated
+ // field, and a stale sub-agent override must not kill the whole request.
+ const reasoning = supportsReasoningMode(subscriptionPayload.model)
+ ? subscriptionPayload.reasoning
+ : (() => {
+ const { mode: _mode, ...reasoningWithoutMode } =
+ (subscriptionPayload.reasoning as { mode?: string } | undefined) ?? {};
+ return Object.keys(reasoningWithoutMode).length > 0 ? reasoningWithoutMode : undefined;
+ })();
+
+ if (!isResponsesLiteModel(subscriptionPayload.model)) {
+ return {
+ payload:
+ reasoning === undefined
+ ? subscriptionPayload
+ : { ...subscriptionPayload, reasoning },
+ };
}
// Codex GPT-5.6 models use Responses Lite: tools move into the input
@@ -73,7 +112,7 @@ export const LobeChatGPTAI = createOpenAICompatibleRuntime<ChatGPTClientOptions>
input,
instructions,
parallel_tool_calls: _parallelToolCalls,
- reasoning,
+ reasoning: _rawReasoning,
tool_choice: toolChoice,
tools,
...rest