Skip to content

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

Merged
Tioit-Wang merged 1 commit into
vastsa:mainfrom
FFXFF1:fix/mistral-disable-store-compat
Nov 24, 2026
Merged

Tioit-Wang merged 1 commit into
vastsa:mainfrom
FFXFF1:fix/mistral-disable-store-compat

Conversation

@FFXFF1

@FFXFF1 FFXFF1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary / 概要

Mistral's OpenAI-compatible Chat Completions endpoint (https://api.mistral.ai/v1/chat/completions) strictly rejects the OpenAI-only store request body field with HTTP 422 (extra_forbidden). Because @earendil-works/pi-ai's openai-completions detectCompat() does not classify Mistral as a non-standard endpoint, supportsStore defaulted to true and emitted "store": false on every request.

This PR adds Mistral endpoint compatibility detection following the existing zhipuRequestCompat / deepseekRequestCompat pattern:

  • packages/shared/src/provider-presets.ts: Added isMistralEndpoint() (matching mistral.ai / *.mistral.ai hostnames and the mistral preset while rejecting spoofed hostnames and rows repointed to another published vendor) and mistralRequestCompat() returning { supportsStore: false }.
  • packages/agent-runtime/src/provider-binding.ts: Wired mistralRequestCompat({ vendorKey: provider.vendorKey, baseUrl }) into buildProviderModel() for openai-completions bindings, omitting store without disturbing DeepSeek reasoning replay compatibility or OpenAI defaults.
  • Tests: Added unit tests in packages/shared/src/provider-presets.test.ts and end-to-end wire-body streamSimple tests in packages/agent-runtime/src/provider-binding.test.ts covering Mistral + deepseek-v4-1-flash-1017, Mistral native models, custom rows pointing at api.mistral.ai, and unchanged OpenAI behavior.

Requirement link / 需求关联

  • Linked requirement issue / 已关联对应的需求 Issue:Closes Mistral(api.mistral.ai)请求报 422:不允许 "store" 字段 #2539
  • Issue explains the background and the expected outcome / Issue 已说明需求背景和期望效果
  • UI changes carry a fitting reference: screenshot, sketch, or demo / 涉及 UI 的改动已提供合适的截图、设计参考或 Demo (N/A — runtime/shared request compatibility fix only, no UI changes)
  • UI changes include before / after screenshots, uploaded to the PR (not committed to the repo) / UI 变更已附修改前后截图(直接上传到 PR,不要提交进仓库) (N/A — no UI changes)

Verification

  • Reproduced before fix via buildProviderModel + createProviderModels(...).streamSimple(..., { fetch }): both deepseek-v4-1-flash-1017 and mistral-large-latest on https://api.mistral.ai/v1 emitted "store": false in the request JSON body.
  • Verified after fix: "store" is omitted from the serialized JSON body for Mistral requests while DeepSeek reasoning replay flags (requiresReasoningContentOnAssistantMessages, supportsReasoningEffort: false, requiresNonEmptyReasoningReplay) and OpenAI "store": false remain intact.
  • Ran:
    • pnpm --filter @pi-desktop/shared build && pnpm --filter @pi-desktop/shared typecheck — PASS
    • pnpm --filter @pi-desktop/agent-runtime build && pnpm --filter @pi-desktop/agent-runtime typecheck — PASS
    • pnpm --filter @pi-desktop/shared test — all test files PASS (provider-presets.test.ts: 31/31)
    • pnpm --filter @pi-desktop/agent-runtime exec vitest run src/provider-binding.test.ts — 61/61 PASS
    • pnpm lint:biome — 151 files checked, 0 errors
    • pnpm check:pr-base — PASS (origin/main is ancestor of HEAD)

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AIUO CodePilot · Preliminary review

Diff-only preliminary review of the Mistral `store` suppression change. The compat helper mirrors the existing DeepSeek/Zhipu patterns and the tests cover hosted, custom, and OpenAI rows. One likely functional gap is that `mistralCompat` is spread after `deepseekCompat`, so `{supportsStore:false}` can overwrite a DeepSeek/Zhipu compat entry if those presets also define `supportsStore`—but this depends on shared code not shown. No concrete added-line defect is sufficiently evidenced from the supplied diff alone. Verification limits: no tests or repository access; all claims are unverified.

No evidenced findings in the supplied diff.

Head: deef429
Base: 7254a04
CI: no-statuses; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@Tioit-Wang

Copy link
Copy Markdown
Collaborator

Review: this fixes the reported store: false rejection, and the payload tests are useful. I found a duplicate, stronger implementation in #2541: it tests the final serialized request body through streamSimple for Mistral-hosted DeepSeek, native Mistral, custom Mistral URL, and unchanged OpenAI behavior, while preserving DeepSeek reasoning replay. Please coordinate with #2541 and close this duplicate if that coverage remains; do not merge both implementations. Also, this head is based on 7254a04 and is 15 commits behind/diverged from current origin/main d07b742, so it is not mergeable under the repository's base gate until refreshed. I have not approved or merged it.

@Tioit-Wang

Copy link
Copy Markdown
Collaborator

Correction to my earlier comparison: I attributed the committed wire-body tests to the wrong PR. The regression tests are in #2540; #2541's diff changes only the bundled pi-ai patch and lockfile, with the smoke verification described but not committed as tests. Given the reusable, host-level request tests and focused compatibility detection in #2540, I recommend consolidating on #2540 instead. The same current-main base-refresh blocker applies to both; neither should merge until one candidate is refreshed and all required gates pass.

Mistral's Chat Completions endpoint (`https://api.mistral.ai/v1/chat/completions`)
strictly rejects the OpenAI-only `store` field with HTTP 422 (`extra_forbidden`).
Because pi-ai's `openai-completions` auto-detection does not classify Mistral as a
non-standard endpoint, `supportsStore` defaulted to `true` and emitted `store: false`.

Add `isMistralEndpoint` and `mistralRequestCompat` in `@pi-desktop/shared` and wire
`supportsStore: false` in `buildProviderModel` for `openai-completions` bindings so
Mistral requests omit `store` while preserving DeepSeek replay compatibility and
OpenAI defaults.

fixes vastsa#2539
@FFXFF1

FFXFF1 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up review and re-checking the committed regression tests, @Tioit-Wang!

I've rebased this branch cleanly onto current origin/main (9213ba26) -> head 66158df8 and re-verified locally:

  • pnpm --filter @pi-desktop/shared build && typecheck + provider-presets.test.ts (31/31 passed)
  • pnpm --filter @pi-desktop/agent-runtime build && typecheck + provider-binding.test.ts (61/61 passed)
  • pnpm lint:biome (152 files checked, clean)
  • pnpm check:pr-base (origin/main is an ancestor of HEAD)

Ready for CI and another look whenever you have a moment.

@FFXFF1
FFXFF1 force-pushed the fix/mistral-disable-store-compat branch from deef429 to 66158df Compare November 24, 2026 15:05
@Tioit-Wang
Tioit-Wang merged commit a71791c into vastsa:main Nov 24, 2026
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

This issue is fixed by merged PR #2562, which continues #2540 from the current main base and preserves your implementation commit. Its serialized request-body tests and refreshed CI pass. I am closing this superseded PR to avoid a duplicate merge. The broader pnpm test:e2e command still has an unrelated session-revision failure reproduced on clean main and documented on #2562.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mistral(api.mistral.ai)请求报 422:不允许 "store" 字段

2 participants