Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): 载体缺失的切模也按目标快照收敛思考档位
Zhang Yunjin55397eec2179
diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.mdindex 6b7b1c17fa..bf9eacd64e 100644--- a/docs/dev-rules/pi-harness.md+++ b/docs/dev-rules/pi-harness.md@@ -91,12 +91,17 @@ Cindy 显式设置:models.json、`settings.json` 的 `transport:sse` 与 `retry.漂移给新模型——实测推理模型在 off 下把思考写进正文)。思考意图由 renderer 的原子 selection 携带(主进程只对 Pi 转成 `thinkingEnabled`,点选暂存与 deferred 重放一并回放);目标档位不在启动快照内时按默认档/首档回落(同 `reconcilePiStartupEffort` 口径),目标声明不支持思考时明确 `off`,能力未知-则不动。实现见 `packages/maker-core/src/agents/pi/index.ts` 的 `switchModel` 末尾,+则不动。**载体缺失(旁路入口热切模型)时同样按目标快照收敛**:目标支持思考就按会话档位重新下发一次,+否则保留现有档位——历史实现的「无意图就不动」会让这类切换静默丢思考通道(2026-10-06 实报:Orca lead+切到 `commandcode/deepseek-v4.1-flash` 后 `usage.reasoning` 归零、推理整段写进正文,Pi 侧无任何+`set_thinking_level` 记录,直到用户手动改一次档位才恢复)。实现见+`packages/maker-core/src/agents/pi/index.ts` 的 `switchModel` 末尾,回归见 `pi-provider-routing.test.ts` 的 thinking-level 用例。跨引擎切换提交时还会把这次选择写进本机偏好镜像(普通 send 走 lazy-create 只读镜像、不经过 bootstrap),避免远端推送未回流时新建会话-用旧值。已知未覆盖面:Bot 设置保存、-agent/scheduler/IM 回滚等**旁路入口**热切 Pi 模型时没有 thinking 载体(`SessionRuntimeProfile`-不含该字段),这些路径仍可能保留旧档位;需要补载体或按目标快照收敛后才能彻底消除。+用旧值。**仍未覆盖**:Bot 设置保存、agent/scheduler/IM 回滚等**旁路入口**热切 Pi 模型时没有 thinking+载体(`SessionRuntimeProfile` 不含该字段),按目标快照收敛能保证推理模型不丢通道,但无法区分+「用户本想关思考」;要完全对齐用户意图仍需给这些入口补载体(本机偏好镜像已有+`getThinkingEnabledFromMemory`,目前只在会话启动钩子接入)。Pi 原生负责 threshold 与 overflow 压缩;Cindy 消费 compaction 事件做 UI、usage、digest 投影,并只在本机原生自动压缩确定性失败后锁存下一次发送前换窗。设置页的 Pi 百分比默认 90%(已有显式 override 保留),在每次启动或恢复diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.tsindex 782ab92d15..8785a44935 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts@@ -4142,7 +4142,7 @@ describe("Pi provider-aware model routing", () => {await handle.close();});- it("does not touch the thinking level when the caller sends no thinking intent", async () => {+ it("re-applies the session effort when a switch to a reasoning-capable model carries no intent", async () => {const denseMap = {minimal: "minimal",low: "low",@@ -4174,6 +4174,57 @@ describe("Pi provider-aware model routing", () => {],),);+ const handle = await agent.startSession({+ sessionId: "thinking-converged-without-intent",+ workingDir: cwd,+ model: "model-a",+ providerId: "native-a",+ effort: "high",+ });+ const beforeSwitch = captured.requests.length;++ await handle.setModel!("model-b", { providerId: "native-a" });++ // 旁路入口(scheduler / IM 回滚 / 插件任务 / 会话恢复)不带 thinking 载体,也必须按会话+ // 档位重新下发一次:历史实现的「没有意图就不动」让 Pi 保留旧档位,实测表现是切模后+ // usage.reasoning 归零、推理整段写进正文(2026-10-06 Orca lead 切 commandcode 实报)。+ const switched = captured.requests.slice(beforeSwitch);+ expect(switched).toContainEqual({ type: "set_thinking_level", level: "high" });+ await handle.close();+ });++ it("keeps the thinking level untouched when a switch without an intent targets a model without thinking levels", async () => {+ const denseMap = {+ minimal: "minimal",+ low: "low",+ medium: "medium",+ high: "high",+ xhigh: "xhigh",+ max: "max",+ } as const;+ const agent = new PiAgent(+ byomDeps(+ async () => ({+ providers: [+ {+ id: "native-a",+ name: "Native A",+ baseUrl: "http://a.test",+ api: "openai-responses",+ models: [+ { id: "model-a", reasoning: true, thinkingLevelMap: { ...denseMap } },+ { id: "model-b" },+ ],+ },+ ],+ env: {},+ }),+ [+ { id: "model-a", displayName: "A", contextWindow: 200_000, efforts: ["low", "high"], defaultEffort: "low" },+ { id: "model-b", displayName: "B", contextWindow: 200_000, efforts: [], defaultEffort: null },+ ],+ ),+ );const handle = await agent.startSession({sessionId: "thinking-untouched-without-intent",workingDir: cwd,@@ -4185,7 +4236,7 @@ describe("Pi provider-aware model routing", () => {await handle.setModel!("model-b", { providerId: "native-a" });- // 老调用方(无 intent)保持既有语义:只切模型,不动 thinking level。+ // 载体缺失只补「开」:目标自身没有档位时不猜、不写(要关思考的调用方会显式传 false)。expect(captured.requests.slice(beforeSwitch)diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.tsindex f0167d2c72..41e270542f 100644--- a/packages/maker-core/src/agents/pi/index.ts+++ b/packages/maker-core/src/agents/pi/index.ts@@ -6613,10 +6613,19 @@ export class PiAgent extends BaseAgent {// 上一个模型的档位带过去(Pi 会把 thinkingLevelMap 里的 null 当成关闭// reasoning)。快照未知时不猜、不动 Pi 现有档位。//+ // 载体缺失(scheduler / IM 回滚 / 插件任务 / 会话恢复等旁路入口不带+ // thinkingEnabled)同样必须收敛:目标支持思考时按会话档位重新下发一次。历史上+ // 「没有意图就不动」把这类切换留成了静默失效——2026-10-06 实报的 Orca lead 切到+ // commandcode/deepseek-v4.1-flash 后 usage.reasoning 归零、推理整段写进正文,直到+ // 用户手动改一次档位才恢复;Pi 侧没有任何 set_thinking_level 记录。载体缺失只影响+ // 「开」:目标空档位时保持不动(Pi 会把 null 档位当关闭),显式 false 仍明确发 off。+ //// 失败只告警、不抛:模型切换已经成功,抛出会让上层回滚 route / 终止会话,反而// 制造「Pi 已切模、宿主认为没切」的分裂。用户可在 UI 上重新选择。- if (setOpts && typeof setOpts.thinkingEnabled === 'boolean') {- const requestedEffort = setOpts.effort ?? mutableEffort ?? startupEffort ?? null;+ const explicitThinking =+ setOpts && typeof setOpts.thinkingEnabled === 'boolean' ? setOpts.thinkingEnabled : undefined;+ {+ const requestedEffort = setOpts?.effort ?? mutableEffort ?? startupEffort ?? null;const nativeTarget = provider !== PI_PROVIDER_ID? nativeProviderById.get(provider)?.models.find((candidate) => candidate.id === resolveNativeModelId(provider, model),@@ -6629,7 +6638,7 @@ export class PiAgent extends BaseAgent {: nextEffortSnapshot.length > 0;let level: string | null = null;let appliedEffort: Effort | null = null;- if (!setOpts.thinkingEnabled || targetReasoning === false) {+ if (explicitThinking === false || (explicitThinking === true && targetReasoning === false)) {level = 'off';} else if (targetReasoning === true) {const usable = nextEffortSnapshot && nextEffortSnapshot.length > 0@@ -6665,6 +6674,14 @@ export class PiAgent extends BaseAgent {provider,appliedEffort: reconciled,});+ } else if (explicitThinking === undefined) {+ // 旁路入口(无 intent 载体)也要留痕:这类收敛是新补的能力,出现异常时+ // 需要能把「谁把档位改回来了」和用户主动切档位区分开。+ deps.logger.info('pi: thinking level re-applied after a model switch without an intent carrier', {+ model,+ provider,+ appliedEffort: reconciled,+ });}appliedEffort = reconciled;level = effortToPiThinkingLevel(reconciled);