The best way to control Claude Code, Codex and more from any computer or phone
fix(pi): say why text generation cannot load a model (#19070)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Scott Norteman committed
Oct 20, 2026 at 00:18 UTC
1de7b16f5de7d9eb0c4a0b160e87b0c7e53f9c64
2 files changed
+47
-6
packages/provider-pi/src/server/textGeneration.test.ts
+29
-1
@@ -14,7 +14,7 @@ import { makePiTextGeneration } from "./textGeneration.ts";
14
const decodeJsonLine = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
15
const encodeJsonLine = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
16
17
-const makeFakePi = (reply: string) =>
17
+const makeFakePi = (reply: string, setModelError?: string) =>
18
Effect.gen(function* () {
19
const stdout = yield* Queue.unbounded<Uint8Array, Cause.Done>();
20
const received: Array<Record<string, unknown>> = [];
@@ -35,6 +35,8 @@ const makeFakePi = (reply: string) =>
35
yield* emit({ type: "agent_settled" });
36
} else if (record["type"] === "get_last_assistant_text") {
37
yield* emit({ ...response, success: true, data: { text: reply } });
38
+ } else if (record["type"] === "set_model" && setModelError !== undefined) {
39
+ yield* emit({ ...response, success: false, error: setModelError });
40
} else {
41
yield* emit({ ...response, success: true });
42
}
@@ -83,3 +85,29 @@ it.effect("puts linked source control context in the Pi thread title prompt", ()
85
assert.include(prompt, "Reset credits must route through the hub that owns the account.");
86
}),
87
);
88
+
89
+it.effect("names the model and the disabled extensions when Pi cannot load it", () =>
90
+ Effect.gen(function* () {
91
+ const pi = yield* makeFakePi("", "Model not found: demo/demo-model");
92
+ const textGeneration = yield* makePiTextGeneration(
93
+ { enabled: true, binaryPath: "pi", launchArgs: "", customModels: [] },
94
+ {},
95
+ ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, pi.spawner));
96
+
97
+ const error = yield* textGeneration
98
+ .generateCommitMessage({
99
+ cwd: process.cwd(),
100
+ branch: "main",
101
+ stagedSummary: "M README.md",
102
+ stagedPatch: "diff --git a/README.md b/README.md",
103
+ modelSelection: createModelSelection(ProviderInstanceId.make("pi"), "demo/demo-model"),
104
+ })
105
+ .pipe(Effect.flip);
106
+
107
+ assert.equal(error._tag, "TextGenerationError");
108
+ assert.include(error.detail, "Pi rejected model 'demo/demo-model'");
109
+ assert.include(error.detail, "Model not found: demo/demo-model");
110
+ assert.include(error.detail, "--no-extensions");
111
+ assert.isUndefined(pi.received.find((record) => record["type"] === "prompt"));
112
+ }),
113
+);
packages/provider-pi/src/server/textGeneration.ts
+18
-5
@@ -60,11 +60,24 @@ export const makePiTextGeneration = Effect.fn("makePiTextGeneration")(function*
60
detail: `Pi model '${modelSelection.model}' must use provider/model format.`,
61
});
62
}
63
- yield* connection.request({
64
- type: "set_model",
65
- provider: parsed.provider,
66
- modelId: parsed.modelId,
67
- });
63
+ yield* connection
64
+ .request({ type: "set_model", provider: parsed.provider, modelId: parsed.modelId })
65
+ .pipe(
66
+ // Model discovery loads extensions that this background helper disables.
67
+ Effect.mapError((error) =>
68
+ error._tag === "PiRpcError" && error.operation === "set_model"
69
+ ? new TextGenerationError({
70
+ operation,
71
+ detail:
72
+ `Pi rejected model '${modelSelection.model}': ${error.detail ?? "unknown error"}. ` +
73
+ "If the model comes from a Pi extension or package, text generation cannot use it " +
74
+ "because it runs Pi with --no-extensions. Pick a built-in Pi model or one defined " +
75
+ "in Pi's models.json.",
76
+ cause: error,
77
+ })
78
+ : error,
79
+ ),
80
+ );
81
}
82
83
yield* connection.request({ type: "prompt", message: prompt });