Skip to content

Commit ac78174

Browse files
committed
fix(minimax): gate reasoning_details parsing on the routed model
A nonempty reasoningDetailsModels list was enabling MiniMax snapshot parsing for every openai-chat model on the provider. Carry the last requested model into both parser paths and match with modelInList. Also update the MiniMax #950 replay assertion: preserved reasoning now serializes as reasoning_details, which is what made shard 4/4 red.
1 parent e01b67d commit ac78174

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎src/adapters/openai-chat.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,12 +1439,14 @@ function canSerializeOpenAIChatServiceTier(
14391439
}
14401440

14411441
export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAdapter {
1442+
let lastRequestedModelId: string | undefined;
14421443
return {
14431444
name: "openai-chat",
14441445

14451446
formatErrorBody: formatOpenAIChatErrorBody,
14461447

14471448
buildRequest(parsed: OcxParsedRequest) {
1449+
lastRequestedModelId = parsed.modelId;
14481450
const { url, headers, hasCredential } = openAIChatTransport(provider);
14491451
const messages = frameAgentRouterMessages(provider.baseUrl, messagesToChatFormat(parsed, provider));
14501452
const tools = toolsToChatFormatForProvider(parsed, provider);
@@ -1717,7 +1719,9 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
17171719
// A piece that does not extend the previous snapshot is appended whole, which
17181720
// keeps incremental senders parseable on the same path.
17191721
const reasoningDetailSnapshots = new Map<string, string>();
1720-
const reasoningDetailsOptIn = (provider.reasoningDetailsModels?.length ?? 0) > 0;
1722+
// Gate on the routed model, not list length: a mixed openai-chat provider
1723+
// can list MiniMax ids without putting every sibling on MiniMax semantics.
1724+
const reasoningDetailsOptIn = modelInList(provider.reasoningDetailsModels, lastRequestedModelId ?? "");
17211725

17221726
const handleDataLine = function* (line: string): Generator<AdapterEvent, "continue" | "terminate"> {
17231727
const rawPayload = sseFieldValue(line, "data");
@@ -2083,7 +2087,7 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
20832087

20842088
const msg = rawMessage as Record<string, unknown>;
20852089
let reasoningText = reasoningTextFrom(msg);
2086-
if (reasoningText === undefined && (provider.reasoningDetailsModels?.length ?? 0) > 0) {
2090+
if (reasoningText === undefined && modelInList(provider.reasoningDetailsModels, lastRequestedModelId ?? "")) {
20872091
// MiniMax split-reasoning responses carry the same thinking in both
20882092
// reasoning_content and reasoning_details; the array is the fallback
20892093
// when only the structured form arrives.

‎tests/deepseek-reasoning-replay-gaps.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,16 @@ describe("issue #950 — tool-call reasoning replay invariant (openai-chat wire)
291291
rememberReasoningForCall("call_1", REASONING, missResult.replayScope);
292292
const hit = toolCallAssistant(minimaxWire([userMessage(), functionCallOutputItem()]).wire.messages);
293293
expect(hit).toBeDefined();
294-
expect(hit!["reasoning_content"]).toBe(REASONING);
294+
expect(hit!["reasoning_content"]).toBeUndefined();
295+
expect(hit!["reasoning_details"]).toEqual([
296+
{
297+
type: "reasoning.text",
298+
id: "reasoning-text-1",
299+
format: "MiniMax-response-v1",
300+
index: 0,
301+
text: REASONING,
302+
},
303+
]);
295304
});
296305

297306
test("P2 guard: a requires-only custom model never gets a placeholder on the orphan path", () => {

‎tests/minimax-reasoning-split.test.ts‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ function body(provider: OcxProviderConfig, modelId: string, reasoning?: Reasonin
2121
return JSON.parse(request.body as string) as Record<string, unknown>;
2222
}
2323

24+
function adapterFor(provider: OcxProviderConfig, modelId: string) {
25+
const adapter = createOpenAIChatAdapter(provider);
26+
adapter.buildRequest(parsed(modelId));
27+
return adapter;
28+
}
29+
2430
function minimaxRoute(modelId = "MiniMax-M3", provider: Partial<OcxProviderConfig> = {}) {
2531
const config: OcxConfig = {
2632
port: 10100,
@@ -160,8 +166,7 @@ describe("MiniMax split reasoning", () => {
160166
usage: { total_tokens: 10 },
161167
}));
162168

163-
const events = await createOpenAIChatAdapter(route.provider).parseResponse(response, createTranslatorBudget());
164-
169+
const events = await adapterFor(route.provider, route.modelId).parseResponse(response, createTranslatorBudget());
165170
expect(events).toContainEqual({ type: "reasoning_raw_delta", text: "full thinking" });
166171
expect(events).toContainEqual({ type: "text_delta", text: "final answer" });
167172
});
@@ -185,7 +190,7 @@ describe("MiniMax split reasoning", () => {
185190
});
186191

187192
const events: Array<{ type: string; text?: string }> = [];
188-
for await (const event of createOpenAIChatAdapter(route.provider).parseStream(new Response(stream), createTranslatorBudget())) {
193+
for await (const event of adapterFor(route.provider, route.modelId).parseStream(new Response(stream), createTranslatorBudget())) {
189194
events.push(event);
190195
}
191196

@@ -222,4 +227,31 @@ describe("MiniMax split reasoning", () => {
222227

223228
expect(events.some(e => e.type === "reasoning_raw_delta")).toBe(false);
224229
});
230+
231+
test("a non-matching model on an opted-in provider ignores reasoning_details", async () => {
232+
const provider: OcxProviderConfig = {
233+
adapter: "openai-chat",
234+
baseUrl: "https://example.test/v1",
235+
reasoningDetailsModels: ["MiniMax-M3"],
236+
};
237+
const response = new Response(JSON.stringify({
238+
id: "resp-1",
239+
object: "chat.completion",
240+
created: 0,
241+
model: "other-model",
242+
choices: [{
243+
index: 0,
244+
finish_reason: "stop",
245+
message: {
246+
role: "assistant",
247+
content: "answer",
248+
reasoning_details: [{ type: "reasoning.text", id: "reasoning-text-1", format: "MiniMax-response-v1", index: 0, text: "thinking" }],
249+
},
250+
}],
251+
}));
252+
253+
const events = await adapterFor(provider, "other-model").parseResponse(response, createTranslatorBudget());
254+
255+
expect(events.some(e => e.type === "reasoning_raw_delta")).toBe(false);
256+
});
225257
});

0 commit comments

Comments
 (0)