From f5dc1e53cf2a2bdcfda459a38dada0d2bbac117d Mon Sep 17 00:00:00 2001 From: saladday <1203511142@qq.com> Date: Sat, 19 Sep 2026 23:14:32 +0800 Subject: [PATCH 1/2] fix: preserve system prompts for DashScope --- .../resolution/local-model-resolver.test.ts | 38 +++++++++++++++++-- third_party/pi-mono/MINIMAX_CHANGES.md | 8 ++++ .../ai/src/providers/openai-completions.ts | 4 +- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts b/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts index 1187b5710..e4461a248 100644 --- a/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts +++ b/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts @@ -1384,19 +1384,22 @@ describe('LocalModelResolver custom provider compat overrides', () => { }); // The incident was a wire-level symptom: pi chooses the system prompt role from the - // resolved compat, so these two cases pin the request pi would actually send. + // resolved compat, so these cases pin the request pi would actually send. const reasoningModelConfig: LocalModelConfig = { reasoning: true, thinking: { effortOptions: ['low', 'light', 'max'] }, }; - const systemPromptRoleFor = async (compat: LocalModelConfig['compat']) => { + const systemPromptRoleFor = async ( + compat: LocalModelConfig['compat'], + baseURL = 'https://gateway.example/v1', + ) => { const resolver = new LocalModelResolver({ byokConfigGetter: () => ({ custom_provider: { gateway: { api: 'openai-completions', - options: { apiKey: 'gateway-key', baseURL: 'https://gateway.example/v1' }, + options: { apiKey: 'gateway-key', baseURL }, models: { 'kimi-k2-thinking': { ...reasoningModelConfig, compat } }, }, }, @@ -1443,4 +1446,33 @@ describe('LocalModelResolver custom provider compat overrides', () => { it('still sends `developer` when the gateway declares nothing, reproducing the incident', async () => { expect(await systemPromptRoleFor(undefined)).toBe('developer'); }); + + it.each([ + 'https://dashscope.aliyuncs.com/compatible-mode/v1', + 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1', + 'https://dashscope-us.aliyuncs.com/compatible-mode/v1', + ])('keeps the system role for a thinking model at %s', async (baseURL) => { + expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system'); + }); + + it.each([ + ['https://api.openai.com/v1', 'developer'], + ['https://api.moonshot.cn/v1', 'system'], + ['https://api.moonshot.ai/v1', 'system'], + ['https://dashscope.aliyuncs.com.example/v1', 'developer'], + ['https://gateway.example/dashscope.aliyuncs.com/v1', 'developer'], + ])('preserves the system prompt role for %s', async (baseURL, role) => { + expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role); + }); + + it.each([ + 'https://dashscope.aliyuncs.com/compatible-mode/v1', + ])('honors an explicit developer-role override on %s', async (baseURL) => { + expect( + await systemPromptRoleFor( + { supportsDeveloperRole: true }, + baseURL, + ), + ).toBe('developer'); + }); }); diff --git a/third_party/pi-mono/MINIMAX_CHANGES.md b/third_party/pi-mono/MINIMAX_CHANGES.md index 02ca14e7b..d276ff5e9 100644 --- a/third_party/pi-mono/MINIMAX_CHANGES.md +++ b/third_party/pi-mono/MINIMAX_CHANGES.md @@ -13,6 +13,14 @@ This directory vendors `pi-mono` as source so MiniMax can patch, validate, and s No upstream source files are changed in the baseline import. +### 2026-09-19 — preserve the system role for DashScope + +- Reason: DashScope endpoints were treated as supporting the `developer` role, causing thinking-enabled OpenAI-compatible conversations to send an unsupported system-prompt role. +- Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection. +- Change: default to the `system` role for the standard DashScope regional hosts (`dashscope`, `dashscope-intl`, and `dashscope-us` under `aliyuncs.com`). Preserve thinking, other request options, explicit compatibility overrides, and other providers. +- Upstream PR: not opened. +- Validation: offline request-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`. A minimal live `qwen3.5-plus` role comparison on the China DashScope endpoint returned HTTP 200 for `system` and HTTP 400 for `developer`. Other DashScope regions remain untested; this does not establish full CLI acceptance. + ### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility - Reason: the Windows PowerShell 5.1 stdin wrapper called `Parser.ParseInput`, `ScriptBlock.Create`, and other restricted .NET APIs before user commands. Under enterprise App Control / AppLocker `ConstrainedLanguage`, the wrapper therefore failed before commands such as Python could run. diff --git a/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts b/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts index 20f3b9711..de5b09d16 100644 --- a/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts +++ b/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts @@ -1090,6 +1090,7 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz"); const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot."); + const isDashScope = /^https?:\/\/dashscope(?:-intl|-us)?\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl); const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai"); const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com"); const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com"); @@ -1124,7 +1125,8 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet return { supportsStore: !isNonStandard, - supportsDeveloperRole: isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter), + supportsDeveloperRole: + !isDashScope && (isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter)), supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing, supportsUsageInStreaming: true, From ceb224dd945812051aeaef5fb600a2d5a0164697 Mon Sep 17 00:00:00 2001 From: saladday <1203511142@qq.com> Date: Sat, 19 Sep 2026 23:52:47 +0800 Subject: [PATCH 2/2] fix(ai): cover official DashScope plan and workspace hosts --- .../resolution/local-model-resolver.test.ts | 20 +++++++++++++++++++ third_party/pi-mono/MINIMAX_CHANGES.md | 5 +++-- .../ai/src/providers/openai-completions.ts | 4 +++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts b/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts index e4461a248..820f8348a 100644 --- a/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts +++ b/packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts @@ -1451,6 +1451,18 @@ describe('LocalModelResolver custom provider compat overrides', () => { 'https://dashscope.aliyuncs.com/compatible-mode/v1', 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1', 'https://dashscope-us.aliyuncs.com/compatible-mode/v1', + 'https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1', + 'https://coding.dashscope.aliyuncs.com/v1', + 'https://coding-intl.dashscope.aliyuncs.com/v1', + 'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1', + 'https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1', + 'https://trial.cn-beijing.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.cn-beijing.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.eu-central-1.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.us-east-1.maas.aliyuncs.com/compatible-mode/v1', ])('keeps the system role for a thinking model at %s', async (baseURL) => { expect(await systemPromptRoleFor(undefined, baseURL)).toBe('system'); }); @@ -1461,12 +1473,20 @@ describe('LocalModelResolver custom provider compat overrides', () => { ['https://api.moonshot.ai/v1', 'system'], ['https://dashscope.aliyuncs.com.example/v1', 'developer'], ['https://gateway.example/dashscope.aliyuncs.com/v1', 'developer'], + ['https://coding.dashscope.aliyuncs.com.example/v1', 'developer'], + ['https://token-plan.cn-beijing.maas.aliyuncs.com.example/v1', 'developer'], + ['https://gateway.example/token-plan.cn-beijing.maas.aliyuncs.com/v1', 'developer'], + ['https://example-workspace.unknown-region.maas.aliyuncs.com/v1', 'developer'], + ['https://example-workspace.cn-beijing.aliyuncs.com/v1', 'developer'], ])('preserves the system prompt role for %s', async (baseURL, role) => { expect(await systemPromptRoleFor(undefined, baseURL)).toBe(role); }); it.each([ 'https://dashscope.aliyuncs.com/compatible-mode/v1', + 'https://coding.dashscope.aliyuncs.com/v1', + 'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1', + 'https://example-workspace.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1', ])('honors an explicit developer-role override on %s', async (baseURL) => { expect( await systemPromptRoleFor( diff --git a/third_party/pi-mono/MINIMAX_CHANGES.md b/third_party/pi-mono/MINIMAX_CHANGES.md index d276ff5e9..ee5878439 100644 --- a/third_party/pi-mono/MINIMAX_CHANGES.md +++ b/third_party/pi-mono/MINIMAX_CHANGES.md @@ -17,9 +17,10 @@ No upstream source files are changed in the baseline import. - Reason: DashScope endpoints were treated as supporting the `developer` role, causing thinking-enabled OpenAI-compatible conversations to send an unsupported system-prompt role. - Affected package: `packages/ai` (`@earendil-works/pi-ai`), OpenAI Completions compatibility detection. -- Change: default to the `system` role for the standard DashScope regional hosts (`dashscope`, `dashscope-intl`, and `dashscope-us` under `aliyuncs.com`). Preserve thinking, other request options, explicit compatibility overrides, and other providers. +- Change: default to the `system` role for official DashScope regional and Coding Plan hosts, plus workspace, trial, and Token Plan hosts under the documented regional `maas.aliyuncs.com` domains. Preserve thinking, other request options, explicit compatibility overrides, and other providers. +- References: [official endpoint list](https://help.aliyun.com/en/model-studio/base-url), [Coding Plan role rejection](https://github.com/openclaw/openclaw/issues/23575), [Token Plan role rejection](https://github.com/earendil-works/pi/issues/7723), and [merged OpenClaw DashScope fix](https://github.com/openclaw/openclaw/pull/24675). - Upstream PR: not opened. -- Validation: offline request-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`. A minimal live `qwen3.5-plus` role comparison on the China DashScope endpoint returned HTTP 200 for `system` and HTTP 400 for `developer`. Other DashScope regions remain untested; this does not establish full CLI acceptance. +- Validation: request-payload regressions in `packages/local-runtime-v2/src/service/model-system/resolution/local-model-resolver.test.ts`, including official endpoints, unrelated hosts, and explicit compatibility overrides. ### 2026-08-31 — Windows PowerShell ConstrainedLanguage compatibility diff --git a/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts b/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts index de5b09d16..28b413e91 100644 --- a/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts +++ b/third_party/pi-mono/packages/ai/src/providers/openai-completions.ts @@ -1090,7 +1090,9 @@ function detectCompat(model: Model<"openai-completions">): ResolvedOpenAIComplet const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz"); const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot."); - const isDashScope = /^https?:\/\/dashscope(?:-intl|-us)?\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl); + const isDashScope = + /^https?:\/\/(?:dashscope(?:-intl|-us)?|(?:coding(?:-intl)?|cn-hongkong)\.dashscope)\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl) || + /^https?:\/\/[a-z0-9-]+\.(?:cn-beijing|cn-hongkong|ap-southeast-1|ap-northeast-1|eu-central-1|us-east-1)\.maas\.aliyuncs\.com(?::\d+)?(?:\/|$)/i.test(baseUrl); const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai"); const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com"); const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");