@devries-cameron20 / t3code-1 / commits / 6575ce3250
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(pi): explain when Pi's default model has no credentials (#27513)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: GPT 6.1 Sol <codex@openai.com>

Wout Stiens committed Oct 30, 2026 at 13:44 UTC 6575ce32508bd7908444241f3719aa33aaf77f90
2 files changed +177 -17
packages/provider-pi/src/server/status.test.ts
+94 -11
@@ -52,7 +52,15 @@ function piProbeSpawner(version: string) {
52 });
53 }
54
55 -const piDiscoverySpawner = (inventory: unknown) =>
55 +/** Fails the test if status runs `pi auth check` without `authCheck` or with other arguments. */
56 +const piDiscoverySpawner = (
57 + inventory: unknown,
58 + options: {
59 + readonly version?: string;
60 + readonly state?: unknown;
61 + readonly authCheck?: string | undefined;
62 + } = {},
63 +) =>
64 Effect.gen(function* () {
65 const stdout = yield* Queue.unbounded<Uint8Array, Cause.Done>();
66 let stdinBuffer = "";
@@ -71,7 +79,9 @@ const piDiscoverySpawner = (inventory: unknown) =>
79 ? inventory
80 : request.type === "get_commands"
81 ? { commands: [] }
74 - : {};
82 + : request.type === "get_state"
83 + ? (options.state ?? {})
84 + : {};
85 yield* Queue.offer(
86 stdout,
87 encoder.encode(
@@ -83,16 +93,23 @@ const piDiscoverySpawner = (inventory: unknown) =>
93 );
94 return ChildProcessSpawner.make((command) => {
95 const args = ChildProcess.isStandardCommand(command) ? command.args : [];
96 + if (args.includes("--version")) {
97 + return Effect.succeed(processHandle({ stdout: `pi ${options.version ?? "0.84.3"}\n` }));
98 + }
99 + if (args[0] === "auth") {
100 + const expected = ["auth", "check", "--provider", "openai", "--json", "--no-refresh"];
101 + return options.authCheck === undefined || args.join(" ") !== expected.join(" ")
102 + ? Effect.die(`Unexpected pi ${args.join(" ")}`)
103 + : Effect.succeed(processHandle({ stdout: options.authCheck, exitCode: 1 }));
104 + }
105 return Effect.succeed(
87 - args.includes("--version")
88 - ? processHandle({ stdout: "pi 0.84.3\n" })
89 - : ChildProcessSpawner.makeHandle({
90 - ...processHandle({}),
91 - exitCode: Effect.never,
92 - isRunning: Effect.succeed(true),
93 - stdin,
94 - stdout: Stream.fromQueue(stdout),
95 - }),
106 + ChildProcessSpawner.makeHandle({
107 + ...processHandle({}),
108 + exitCode: Effect.never,
109 + isRunning: Effect.succeed(true),
110 + stdin,
111 + stdout: Stream.fromQueue(stdout),
112 + }),
113 );
114 });
115 });
@@ -146,6 +163,72 @@ describe("PiProvider", () => {
163 }).pipe(Effect.provide(NodeServices.layer)),
164 );
165
166 + it.effect.each([
167 + {
168 + label: "a pinned model without credentials",
169 + version: "1.4.0",
170 + activeModel: { provider: "openai", id: "gpt-5" },
171 + authCheck: '{"status":"not_ready","provider":"openai","reason":"credentials_not_configured"}',
172 + message: "Pi default (openai/gpt-5) has no credentials configured for openai.",
173 + },
174 + {
175 + label: "a pinned model with a runtime --api-key",
176 + version: "1.4.0",
177 + launchArgs: "--provider openai --model gpt-5 --api-key fake-key",
178 + activeModel: { provider: "openai", id: "gpt-5" },
179 + authCheck: undefined,
180 + message: "Pi default (openai/gpt-5) uses openai, which has no available models in Pi.",
181 + },
182 + {
183 + label: "a pinned model whose provider auth check cannot find",
184 + version: "1.4.0",
185 + activeModel: { provider: "openai", id: "gpt-5" },
186 + authCheck: '{"status":"not_ready","provider":"openai","reason":"provider_not_found"}',
187 + message: "Pi default (openai/gpt-5) uses openai, which has no available models in Pi.",
188 + },
189 + {
190 + label: "a pinned model on Pi without auth check",
191 + version: MINIMUM_PI_VERSION,
192 + activeModel: { provider: "openai", id: "gpt-5" },
193 + authCheck: undefined,
194 + message: "Pi default (openai/gpt-5) uses openai, which has no available models in Pi.",
195 + },
196 + {
197 + label: "an uncatalogued model id of a provider with credentials",
198 + version: "1.4.0",
199 + activeModel: { provider: "anthropic", id: "claude-next" },
200 + authCheck: undefined,
201 + message: undefined,
202 + },
203 + {
204 + label: "an extension model Pi lists as available",
205 + version: "1.4.0",
206 + activeModel: { provider: "router", id: "auto" },
207 + authCheck: undefined,
208 + message: undefined,
209 + },
210 + ])("diagnoses Pi's active model readiness for $label", (row) =>
211 + Effect.gen(function* () {
212 + const spawner = yield* piDiscoverySpawner(
213 + {
214 + models: [
215 + { provider: "anthropic", id: "claude-sonnet-4" },
216 + { provider: "router", id: "auto" },
217 + ],
218 + },
219 + { version: row.version, state: { model: row.activeModel }, authCheck: row.authCheck },
220 + );
221 + const snapshot = yield* checkPiProviderStatus({
222 + ...settings,
223 + launchArgs: row.launchArgs ?? "",
224 + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
225 + assert.equal(snapshot.status, "ready");
226 + assert.equal(snapshot.auth.status, "authenticated");
227 + if (row.message === undefined) assert.isUndefined(snapshot.message);
228 + else assert.include(snapshot.message ?? "", row.message);
229 + }).pipe(Effect.provide(NodeServices.layer)),
230 + );
231 +
232 // regression: #18498 a malformed model inventory must not restore stale Pi models
233 it.effect.each([
234 ["missing models", {}],
packages/provider-pi/src/server/status.ts
+83 -6
@@ -13,6 +13,7 @@ import * as Stream from "effect/Stream";
13 import * as Exit from "effect/Exit";
14 import * as Option from "effect/Option";
15 import * as Result from "effect/Result";
16 +import * as Schema from "effect/Schema";
17 import * as HttpClient from "effect/http/HttpClient";
18 import * as ChildProcess from "effect/process/ChildProcess";
19 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
@@ -62,6 +63,12 @@ const PI_RPC_DISCOVERY_TIMEOUT_MS = 30_000;
63 * Version 0.80.5 was the first published package containing both hooks.
64 */
65 export const MINIMUM_PI_VERSION = "0.80.5";
66 +/** `pi auth check --json --no-refresh` arrived in 0.84.1. */
67 +const PI_AUTH_CHECK_VERSION = "0.84.1";
68 +
69 +const decodePiAuthCheck = Schema.decodeUnknownOption(
70 + Schema.fromJsonString(Schema.Struct({ reason: Schema.optional(Schema.String) })),
71 +);
72
73 const PI_DEFAULT_MODEL: ServerProviderModel = {
74 slug: "default",
@@ -73,6 +80,8 @@ const PI_DEFAULT_MODEL: ServerProviderModel = {
80 interface PiDiscovery extends PiDiscoveredCommands {
81 readonly models: ReadonlyArray<ServerProviderModel>;
82 readonly authenticated: boolean;
83 + /** Pi's active model when Pi lists no model of its provider, so it cannot start a turn. */
84 + readonly unavailableActiveModel: { readonly provider: string; readonly id: string } | undefined;
85 }
86
87 function piModelsFromSettings(
@@ -169,11 +178,22 @@ const discoverPiViaRpc = Effect.fn("PiProviderStatus.discoverPiViaRpc")(function
178 .pipe(Effect.orElseSucceed(() => undefined));
179 const discoveredModels = yield* Effect.fromResult(parseDiscoveredModels(modelsData, stateData));
180 const { slashCommands, skills } = parsePiDiscoveredCommands(commandsData);
181 + // Pi lists only models of providers it holds credentials for, including extension, virtual and
182 + // --api-key ones. Turns need only the provider's credentials, so uncatalogued model ids still run.
183 + const activeModel = recordField(stateData, "model");
184 + const activeProvider = recordString(activeModel, "provider");
185 + const activeModelId = recordString(activeModel, "id");
186 return {
187 models: discoveredModels,
188 slashCommands: withPiBuiltinSlashCommands(slashCommands),
189 skills,
190 authenticated: discoveredModels.length > 0,
191 + unavailableActiveModel:
192 + activeProvider !== undefined &&
193 + activeModelId !== undefined &&
194 + !discoveredModels.some((model) => model.subProvider === activeProvider)
195 + ? { provider: activeProvider, id: activeModelId }
196 + : undefined,
197 } satisfies PiDiscovery;
198 }, Effect.scoped);
199
@@ -221,6 +241,56 @@ const runPiVersionCommand = Effect.fn("PiProviderStatus.runPiVersionCommand")(fu
241 );
242 });
243
244 +/**
245 + * Explains why Pi's active model cannot start a turn. On Pi versions with `auth check`, asks it
246 + * whether credentials are missing, without refreshing or printing them. That command cannot see
247 + * extension providers or a runtime --api-key, so it only refines Pi's own unavailable verdict,
248 + * and is skipped when launch args supply the key.
249 + */
250 +const describeUnavailablePiModel = Effect.fn("PiProviderStatus.describeUnavailablePiModel")(
251 + function* (
252 + piSettings: PiSettings,
253 + environment: NodeJS.ProcessEnv,
254 + version: string,
255 + launchArgs: ReadonlyArray<string>,
256 + model: { readonly provider: string; readonly id: string },
257 + ) {
258 + const label = `Pi default (${model.provider}/${model.id})`;
259 + const unavailable = `${label} uses ${model.provider}, which has no available models in Pi. Choose another model, or check that provider's setup and the Pi launch arguments.`;
260 + if (
261 + compareSemverVersions(version, PI_AUTH_CHECK_VERSION) < 0 ||
262 + launchArgs.includes("--api-key")
263 + ) {
264 + return unavailable;
265 + }
266 + const command = piSettings.binaryPath || "pi";
267 + const output = yield* resolveSpawnCommand(
268 + command,
269 + ["auth", "check", "--provider", model.provider, "--json", "--no-refresh"],
270 + { env: environment },
271 + ).pipe(
272 + Effect.flatMap((spawnCommand) =>
273 + spawnAndCollect(
274 + command,
275 + ChildProcess.make(spawnCommand.command, spawnCommand.args, {
276 + env: environment,
277 + shell: spawnCommand.shell,
278 + }),
279 + ),
280 + ),
281 + Effect.timeout(VERSION_PROBE_TIMEOUT_MS),
282 + Effect.option,
283 + );
284 + const missingCredentials = Option.exists(
285 + Option.flatMap(output, (result) => decodePiAuthCheck(result.stdout)),
286 + (check) => check.reason === "credentials_not_configured",
287 + );
288 + return missingCredentials
289 + ? `${label} has no credentials configured for ${model.provider}. Choose another model, or run \`pi\` in a terminal and use /login or configure its API key.`
290 + : unavailable;
291 + },
292 +);
293 +
294 export const buildInitialPiProviderSnapshot = Effect.fn(
295 "PiProviderStatus.buildInitialPiProviderSnapshot",
296 )(function* (piSettings: PiSettings): Effect.fn.Return<ServerProviderDraft> {
@@ -432,6 +502,17 @@ export const checkPiProviderStatus = Effect.fn("checkPiProviderStatus")(function
502
503 const discovery = discoveryExit.value.value;
504 const models = piModelsFromSettings(piSettings.customModels, discovery.models);
505 + const message = !discovery.authenticated
506 + ? "Pi has no usable models. Run `pi` in a terminal and use /login, or configure an API key in ~/.pi/agent."
507 + : discovery.unavailableActiveModel === undefined
508 + ? undefined
509 + : yield* describeUnavailablePiModel(
510 + piSettings,
511 + environment,
512 + version,
513 + resolvedLaunchArgs.args,
514 + discovery.unavailableActiveModel,
515 + );
516 return buildServerProvider({
517 presentation: PI_PRESENTATION,
518 enabled: piSettings.enabled,
@@ -442,14 +523,10 @@ export const checkPiProviderStatus = Effect.fn("checkPiProviderStatus")(function
523 probe: {
524 installed: true,
525 version,
526 + // Other Pi models still work when only the default is unavailable, so keep the picker usable.
527 status: discovery.authenticated ? "ready" : "warning",
528 auth: { status: discovery.authenticated ? "authenticated" : "unauthenticated", type: "pi" },
447 - ...(discovery.authenticated
448 - ? {}
449 - : {
450 - message:
451 - "Pi has no usable models. Run `pi` in a terminal and use /login, or configure an API key in ~/.pi/agent.",
452 - }),
529 + ...(message === undefined ? {} : { message }),
530 },
531 });
532 });