Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(runtime): suppress OpenAI store field for Mistral Chat Completions

FFYXX66158df8ce5f
diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.ts
index 9157d31a1..cc823d753 100644
--- a/packages/agent-runtime/src/provider-binding.test.ts
+++ b/packages/agent-runtime/src/provider-binding.test.ts
@@ -1826,3 +1826,90 @@ describe("session affinity for the adapters' anonymous endpoints (#1634)", () =>
expect(headers?.get("x-session-affinity")).toBe("session-9");
});
});
+
+describe("Mistral Chat Completions store suppression (#2539)", () => {
+ const captureRequestBody = async (
+ provider: RuntimeProviderConfig,
+ ): Promise<Record<string, unknown>> => {
+ const requests: Record<string, unknown>[] = [];
+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);
+ return new Response(
+ JSON.stringify({ choices: [{ delta: { content: "ok" }, finish_reason: "stop" }] }),
+ { status: 200, headers: { "content-type": "application/json" } },
+ );
+ });
+ const model = buildProviderModel(provider);
+ await createProviderModels(provider, model)
+ .streamSimple(
+ model,
+ {
+ systemPrompt: "system",
+ messages: [{ role: "user", content: "hello", timestamp: 1 }],
+ tools: [],
+ },
+ { fetch },
+ )
+ .result();
+ expect(requests).toHaveLength(1);
+ return requests[0];
+ };
+
+ it("omits store for Mistral-hosted DeepSeek models while preserving DeepSeek replay compat", async () => {
+ const provider: RuntimeProviderConfig = {
+ ...keyedProvider,
+ id: "mistral-row",
+ name: "Mistral",
+ vendorKey: "mistral",
+ baseUrl: "https://api.mistral.ai/v1",
+ modelId: "deepseek-v4-1-flash-1017",
+ supportsReasoning: true,
+ supportedThinkingLevels: ["off", "low", "high"],
+ };
+
+ const model = buildProviderModel(provider);
+ expect(model.compat).toMatchObject({
+ supportsStore: false,
+ requiresReasoningContentOnAssistantMessages: true,
+ supportsReasoningEffort: false,
+ requiresNonEmptyReasoningReplay: true,
+ });
+
+ const body = await captureRequestBody(provider);
+ expect(Object.hasOwn(body, "store")).toBe(false);
+ });
+
+ it("omits store for native Mistral models and custom rows pointing at api.mistral.ai", async () => {
+ const nativeBody = await captureRequestBody({
+ ...keyedProvider,
+ id: "mistral-native-row",
+ name: "Mistral",
+ vendorKey: "mistral",
+ baseUrl: "https://api.mistral.ai/v1",
+ modelId: "mistral-large-latest",
+ });
+ expect(Object.hasOwn(nativeBody, "store")).toBe(false);
+
+ const customUrlBody = await captureRequestBody({
+ ...keyedProvider,
+ id: "custom-mistral-row",
+ name: "Custom Mistral",
+ vendorKey: "custom",
+ baseUrl: "https://api.mistral.ai/v1",
+ modelId: "mistral-large-latest",
+ });
+ expect(Object.hasOwn(customUrlBody, "store")).toBe(false);
+ });
+
+ it("keeps OpenAI Chat Completions store behavior unchanged", async () => {
+ const openaiBody = await captureRequestBody({
+ ...keyedProvider,
+ id: "openai-row",
+ name: "OpenAI",
+ vendorKey: "openai",
+ baseUrl: "https://api.openai.com/v1",
+ modelId: "gpt-4o",
+ });
+ expect(openaiBody.store).toBe(false);
+ });
+});
diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.ts
index a700045b3..389e777a6 100644
--- a/packages/agent-runtime/src/provider-binding.ts
+++ b/packages/agent-runtime/src/provider-binding.ts
@@ -38,6 +38,7 @@ import {
resolveNativeWebSearch,
nativeWebSearchTransport,
deepseekRequestCompat,
+ mistralRequestCompat,
zhipuRequestCompat,
type ThinkingLevel,
} from "@pi-desktop/shared";
@@ -379,6 +380,10 @@ export function buildProviderModel(
modelId: provider.modelId,
family: catalogModel.family,
});
+ const mistralCompat = mistralRequestCompat({
+ vendorKey: provider.vendorKey,
+ baseUrl,
+ });
const copilotDefaults =
provider.vendorKey?.trim().toLowerCase() === "github-copilot"
? nativeCopilotHeaders(provider.modelId)
@@ -419,6 +424,7 @@ export function buildProviderModel(
...(thinkingProtocolCompat ?? {}),
...(zhipuCompat ?? {}),
...(deepseekCompat ?? {}),
+ ...(mistralCompat ?? {}),
// Only an explicit saved binding may override endpoint compatibility.
...(typeof catalog?.supportsReasoningEffort === "boolean"
? { supportsReasoningEffort: catalog.supportsReasoningEffort }
diff --git a/packages/shared/src/provider-presets.test.ts b/packages/shared/src/provider-presets.test.ts
index 1e1910544..d76f89df3 100644
--- a/packages/shared/src/provider-presets.test.ts
+++ b/packages/shared/src/provider-presets.test.ts
@@ -5,10 +5,12 @@ import {
deepseekRequestCompat,
DEEPSEEK_REASONING_REPLAY_PLACEHOLDER,
isDeepSeekReasoningReplay,
+ isMistralEndpoint,
isOfficialDeepSeekEndpoint,
isZhipuEndpoint,
matchNamedPreset,
matchZhipuPreset,
+ mistralRequestCompat,
normalizeEndpointUrl,
withoutReasoningReplayPlaceholder,
zhipuRequestCompat,
@@ -400,3 +402,39 @@ describe("withoutReasoningReplayPlaceholder", () => {
expect(withoutReasoningReplayPlaceholder(mention)).toBe(mention);
});
});
+
+describe("Mistral Chat Completions compat (#2539)", () => {
+ it("recognizes Mistral hosts and vendorKey", () => {
+ expect(isMistralEndpoint({ baseUrl: "https://api.mistral.ai/v1" })).toBe(true);
+ expect(isMistralEndpoint({ baseUrl: "https://API.MISTRAL.AI/v1/" })).toBe(true);
+ expect(isMistralEndpoint({ baseUrl: "https://codestral.mistral.ai/v1" })).toBe(true);
+ expect(isMistralEndpoint({ vendorKey: "mistral" })).toBe(true);
+ expect(
+ isMistralEndpoint({
+ vendorKey: "mistral",
+ baseUrl: "https://proxy.example.test/v1",
+ }),
+ ).toBe(true);
+ expect(mistralRequestCompat({ baseUrl: "https://api.mistral.ai/v1" })).toEqual({
+ supportsStore: false,
+ });
+ });
+
+ it("rejects spoofed hosts, unrelated URLs, and rows repointed to another vendor", () => {
+ expect(isMistralEndpoint({ baseUrl: "https://api.mistral.ai.evil.test/v1" })).toBe(false);
+ expect(isMistralEndpoint({ baseUrl: "https://relay.example.test/mistral.ai/v1" })).toBe(false);
+ expect(
+ isMistralEndpoint({
+ vendorKey: "mistral",
+ baseUrl: "https://api.openai.com/v1",
+ }),
+ ).toBe(false);
+ expect(
+ isMistralEndpoint({
+ vendorKey: "mistral",
+ baseUrl: "https://api.openai.com/beta",
+ }),
+ ).toBe(false);
+ expect(mistralRequestCompat({ vendorKey: "openai", baseUrl: "https://api.openai.com/v1" })).toBeUndefined();
+ });
+});
diff --git a/packages/shared/src/provider-presets.ts b/packages/shared/src/provider-presets.ts
index 427a604c9..413cdf278 100644
--- a/packages/shared/src/provider-presets.ts
+++ b/packages/shared/src/provider-presets.ts
@@ -480,6 +480,40 @@ export function zhipuRequestCompat(input: {
: undefined;
}
+function isMistralHostname(baseUrl: string | undefined): boolean {
+ const raw = baseUrl?.trim();
+ if (!raw) return false;
+ try {
+ const hostname = new URL(raw).hostname.toLowerCase();
+ return hostname === "mistral.ai" || hostname.endsWith(".mistral.ai");
+ } catch {
+ return false;
+ }
+}
+
+/** Whether a configured row targets Mistral's Chat Completions endpoint. */
+export function isMistralEndpoint(input: {
+ vendorKey?: string;
+ baseUrl?: string;
+}): boolean {
+ if (isMistralHostname(input.baseUrl)) return true;
+ if (addressesPublishedVendorHost(input.baseUrl)) return false;
+ return matchNamedPreset(input)?.id === "mistral";
+}
+
+/**
+ * Mistral's Chat Completions endpoint strictly rejects the OpenAI-only `store`
+ * field with HTTP 422 (`extra_forbidden`, #2539). pi-ai's `openai-completions`
+ * auto-detection does not classify Mistral as non-standard, so suppress `store`
+ * explicitly here.
+ */
+export function mistralRequestCompat(input: {
+ vendorKey?: string;
+ baseUrl?: string;
+}): { supportsStore: false } | undefined {
+ return isMistralEndpoint(input) ? { supportsStore: false } : undefined;
+}
+
function mentionsDeepSeek(value: string | undefined): boolean {
return (value ?? "").toLowerCase().includes("deepseek");
}