Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): 启动侧「明确关闭」意图不再因下发被拒而丢失(Greptile P1)

Zhang Yunjincfbc75cb23e1
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.ts
index 86338048e5..f99e58eee8 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
@@ -4375,6 +4375,82 @@ describe("Pi provider-aware model routing", () => {
await handle.close();
});
+ it("keeps the declared-off marker when the startup off assert is rejected", async () => {
+ const denseMap = {
+ minimal: "minimal",
+ low: "low",
+ medium: "medium",
+ high: "high",
+ xhigh: "xhigh",
+ max: "max",
+ } as const;
+ let failNextThinking = false;
+ captured.requestHandler = async (command) => {
+ if (command.type === "get_state") {
+ return {
+ success: true,
+ data: { sessionFile: "/mock/s.jsonl", model: { contextWindow: 200_000 } },
+ };
+ }
+ if (command.type === "set_model") {
+ return { success: true, data: { contextWindow: 200_000 } };
+ }
+ if (command.type === "set_thinking_level") {
+ if (failNextThinking) {
+ failNextThinking = false;
+ return { success: false, error: "transient" };
+ }
+ return { success: true, data: {} };
+ }
+ return { success: true, data: {} };
+ };
+ 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", reasoning: true, thinkingLevelMap: { ...denseMap } },
+ ],
+ },
+ ],
+ env: {},
+ }),
+ [
+ { id: "model-a", displayName: "A", contextWindow: 200_000, efforts: ["low", "high"], defaultEffort: "low" },
+ { id: "model-b", displayName: "B", contextWindow: 200_000, efforts: ["low", "high"], defaultEffort: "low" },
+ ],
+ ),
+ );
+ // 宿主带的用户意图:启动即关;这次 off 下发被拒(只告警)。
+ failNextThinking = true;
+ const handle = await agent.startSession({
+ sessionId: "thinking-off-marker-survives-rejected-startup",
+ workingDir: cwd,
+ model: "model-a",
+ providerId: "native-a",
+ effort: "high",
+ thinkingEnabled: false,
+ });
+ const beforeSwitch = captured.requests.length;
+
+ await handle.setModel!("model-b", { providerId: "native-a" });
+
+ // 启动 off 被拒只告警,但意图标记必须保留:无载体切模不得重开用户关闭的思考,
+ // 否则恢复失败一次就永久丢失「明确关闭」。
+ expect(
+ captured.requests
+ .slice(beforeSwitch)
+ .some((request) => request.type === "set_thinking_level"),
+ ).toBe(false);
+ await handle.close();
+ });
+
it("keeps the model switch successful when the post-switch thinking level is rejected", async () => {
const denseMap = {
minimal: "minimal",
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index 85200addc7..a4a322a4f2 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -5863,14 +5863,16 @@ export class PiAgent extends BaseAgent {
}
if (opts.thinkingEnabled === false) {
+ // 启动/恢复侧记录的是宿主带来的用户意图(本机偏好镜像),不是会被用户看到的交互
+ // 操作:这次下发即使被拒(只告警),标记也必须承认该意图——否则恢复失败一次就
+ // 永久丢失「明确关闭」,之后无载体切模会按会话档位重开(2026-10-06 Greptile P1)。
+ // 与之相反,setThinkingEnabled 是交互开关、失败会抛给用户,标记只在成功后更新。
+ thinkingExplicitlyOff = true;
const resp = await proc.request({
type: 'set_thinking_level',
level: 'off',
});
- if (resp.success) {
- // 同款口径:只在 Pi 确认后才承认「明确关闭」。
- thinkingExplicitlyOff = true;
- } else {
+ if (!resp.success) {
this.deps.logger.warn('pi set_thinking_level rejected', { effort: 'off', error: resp.error });
}
} else if (startupEffort) {