@devries-cameron20 / t3code-1 / commits / 817b92f13a
Fork 0

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

fix(pi): stop offering extension-only models for text generation (#24110)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 12, 2026 at 16:51 UTC 817b92f13a1d11922e76d6b79cac42861be972cb
12 files changed +371 -64
apps/server/src/textGeneration/CodexTextGeneration.test.ts
+18
@@ -546,6 +546,8 @@ const PREFLIGHT_PRIMARY_STATES = [
546 "not installed, fallback disabled for project",
547 "signed out",
548 "signed out, fallback failed",
549 + "cannot generate text",
550 + "model cannot generate text",
551 ] as const;
552
553 it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) =>
@@ -590,6 +592,22 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
592 ...(primaryState === "signed out, fallback failed" && instanceId === fallback
593 ? { status: "error", auth: { status: "unknown" } }
594 : {}),
595 + ...(primaryState === "cannot generate text" && instanceId === primary
596 + ? { supportsTextGeneration: false }
597 + : {}),
598 + ...(primaryState === "model cannot generate text" && instanceId === primary
599 + ? {
600 + models: [
601 + {
602 + slug: selection.model,
603 + name: selection.model,
604 + isCustom: false,
605 + supportsTextGeneration: false,
606 + capabilities: null,
607 + },
608 + ],
609 + }
610 + : {}),
611 ...(primaryState === "exhausted" && instanceId === primary
612 ? {
613 usageLimits: {
apps/server/src/textGeneration/TextGeneration.ts
+5 -2
@@ -108,8 +108,11 @@ export const make = Effect.gen(function* () {
108 const unusable =
109 textGeneratorCannotRun ||
110 (selected?.enabled === true &&
111 - selected.status === "error" &&
112 - (!selected.installed || selected.auth.status === "unauthenticated"));
111 + (!isProviderTextGenerationCapable(selected) ||
112 + selected.models.find((model) => model.slug === selection.model)
113 + ?.supportsTextGeneration === false ||
114 + (selected.status === "error" &&
115 + (!selected.installed || selected.auth.status === "unauthenticated"))));
116 if (unusable || exhaustedUsageWindow(selected, now, selection.model)) {
117 const settings = yield* serverSettings.getSettings.pipe(
118 Effect.mapError(
apps/web/src/components/settings/SettingsPanels.tsx
+3 -2
@@ -67,7 +67,7 @@ import { SnoozePresetsRow } from "./SnoozePresetsSettings";
67 import { useDesktopUpdateState } from "../../state/desktopUpdate";
68 import { managedTelemetryOffMessage, usePrimaryManagedPolicy } from "../../state/managedPolicy";
69 import {
70 - getCustomModelOptionsByInstance,
70 + getTextGenerationModelOptionsByInstance,
71 resolveAppModelSelectionState,
72 selectsPlanAgent,
73 } from "../../modelSelection";
@@ -1743,7 +1743,7 @@ export function ThreadsSettingsPanel() {
1743 );
1744 const textGenProvider: ProviderDriverKind =
1745 textGenInstanceEntry?.driverKind ?? DEFAULT_DRIVER_KIND;
1746 - const textGenerationModelOptionsByInstance = getCustomModelOptionsByInstance(
1746 + const textGenerationModelOptionsByInstance = getTextGenerationModelOptionsByInstance(
1747 settings,
1748 textGenerationProviders,
1749 textGenInstanceId,
@@ -1756,6 +1756,7 @@ export function ThreadsSettingsPanel() {
1756 const textGenerationModelDisabledReason = useScopedModelDisabledReason(
1757 settings,
1758 textGenerationModelInstanceEntries,
1759 + true,
1760 );
1761 const mixedAddProjectBaseDirectory = useScopedSettingsMixed(["addProjectBaseDirectory"]);
1762 const mixedTextGenerationModel = useScopedSettingsMixed(["textGenerationModelSelection"]);
apps/web/src/components/settings/SourceControlWritingSettings.tsx
+21 -7
@@ -23,7 +23,7 @@ import { useSettingsScope } from "./SettingsScopeContext";
23 import { providerInstanceEntriesFor } from "../../providerInstances";
24 import { useTextGenerationTargets } from "../../textGenerators";
25 import {
26 - getCustomModelOptionsByInstance,
26 + getTextGenerationModelOptionsByInstance,
27 resolveAppModelSelectionState,
28 selectsPlanAgent,
29 } from "../../modelSelection";
@@ -151,13 +151,13 @@ export function SourceControlWritingSettingsSection() {
151 (entry) =>
152 entry.instanceId === defaultModelSelection.instanceId && entry.enabled && entry.isAvailable,
153 );
154 - const modelOptionsByInstance = getCustomModelOptionsByInstance(
154 + const modelOptionsByInstance = getTextGenerationModelOptionsByInstance(
155 settings,
156 projectEffectiveTextGenerationProviders,
157 activeSelection.instanceId,
158 activeSelection.model,
159 );
160 - const writerModelDisabledReason = useScopedModelDisabledReason(settings, writerEntries);
160 + const writerModelDisabledReason = useScopedModelDisabledReason(settings, writerEntries, true);
161 const writerInstanceEntry = writerEntries.find(
162 (entry) => entry.instanceId === activeSelection.instanceId,
163 );
@@ -179,7 +179,7 @@ export function SourceControlWritingSettingsSection() {
179 },
180 projectAgentProviders,
181 );
182 - const reviewGuideModelOptionsByInstance = getCustomModelOptionsByInstance(
182 + const reviewGuideModelOptionsByInstance = getTextGenerationModelOptionsByInstance(
183 settings,
184 projectAgentProviders,
185 reviewGuideSelection.instanceId,
@@ -595,7 +595,21 @@ export function SourceControlWritingSettingsSection() {
595 <Switch
596 checked={usesDedicatedModel}
597 disabled={!usesDedicatedModel && !canEnableDedicatedModel}
598 - onCheckedChange={(checked) =>
598 + onCheckedChange={(checked) => {
599 + if (checked) {
600 + const reason = writerModelDisabledReason(
601 + defaultModelSelection.instanceId,
602 + defaultModelSelection.model,
603 + );
604 + if (reason) {
605 + toastManager.add({
606 + type: "error",
607 + title: "Writer model not saved",
608 + description: reason,
609 + });
610 + return;
611 + }
612 + }
613 updateSettings({
614 sourceControlWriterModelSelection: checked
615 ? createModelSelection(
@@ -604,8 +618,8 @@ export function SourceControlWritingSettingsSection() {
618 defaultModelSelection.options,
619 )
620 : null,
607 - })
608 - }
621 + });
622 + }}
623 aria-label="Use a separate source control writer model"
624 />
625 </div>
apps/web/src/components/settings/TextGeneratorsSettings.tsx
+2 -2
@@ -28,7 +28,7 @@ import {
28 textGeneratorBrand,
29 textGeneratorDisplayName,
30 } from "../../textGenerators";
31 -import { getCustomModelOptionsByInstance } from "../../modelSelection";
31 +import { getTextGenerationModelOptionsByInstance } from "../../modelSelection";
32 import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
33 import { ProviderModelPicker } from "../chat/ProviderModelPicker";
34 import {
@@ -563,7 +563,7 @@ function TextGenerationTaskPicker({
563 model={selection.model}
564 lockedProvider={null}
565 instanceEntries={targets.entries}
566 - modelOptionsByInstance={getCustomModelOptionsByInstance(
566 + modelOptionsByInstance={getTextGenerationModelOptionsByInstance(
567 settings,
568 targets.providers,
569 selection.instanceId,
apps/web/src/components/settings/VoiceSettingsPanel.tsx
+3 -3
@@ -72,7 +72,7 @@ import {
72 import { updateClientSettings, useClientSettings } from "../../hooks/useSettings";
73 import { runEnvironmentSpeech } from "../../speech/runEnvironmentSpeech";
74 import {
75 - getCustomModelOptionsByInstance,
75 + getTextGenerationModelOptionsByInstance,
76 resolveAppModelSelectionState,
77 } from "../../modelSelection";
78 import { useTextGenerationTargets } from "../../textGenerators";
@@ -531,14 +531,14 @@ function CleanupModelRow() {
531 },
532 textGenerationProviders,
533 );
534 - const modelOptionsByInstance = getCustomModelOptionsByInstance(
534 + const modelOptionsByInstance = getTextGenerationModelOptionsByInstance(
535 settings,
536 textGenerationProviders,
537 selection.instanceId,
538 selection.model,
539 );
540 const instanceEntry = instanceEntries.find((entry) => entry.instanceId === selection.instanceId);
541 - const modelDisabledReason = useScopedModelDisabledReason(settings, instanceEntries);
541 + const modelDisabledReason = useScopedModelDisabledReason(settings, instanceEntries, true);
542 const setModel = (next: ReturnType<typeof createModelSelection>) => {
543 const reason = modelDisabledReason(next.instanceId, next.model);
544 if (reason) {
apps/web/src/components/settings/useScopedModelAvailability.ts
+9 -2
@@ -5,7 +5,10 @@ import {
5 } from "@t3tools/contracts";
6
7 import { mergeEnvironmentSettings } from "../../hooks/useSettings";
8 -import { getCustomModelOptionsByInstance } from "../../modelSelection";
8 +import {
9 + getCustomModelOptionsByInstance,
10 + getTextGenerationModelOptionsByInstance,
11 +} from "../../modelSelection";
12 import {
13 applyProviderInstanceSettings,
14 deriveProviderInstanceEntries,
@@ -17,6 +20,7 @@ import { useSettingsScope } from "./SettingsScopeContext";
20 export function useScopedModelDisabledReason(
21 settings: UnifiedSettings,
22 entries: readonly ProviderInstanceEntry[],
23 + textGeneration = false,
24 ) {
25 const { targets } = useSettingsScope();
26 const { environments } = useEnvironments();
@@ -48,7 +52,10 @@ export function useScopedModelDisabledReason(
52 candidate.settings,
53 candidate.projectId,
54 ).find((option) => option.instanceId === instanceId);
51 - const options = getCustomModelOptionsByInstance(
55 + const optionsForInstance = textGeneration
56 + ? getTextGenerationModelOptionsByInstance
57 + : getCustomModelOptionsByInstance;
58 + const options = optionsForInstance(
59 mergeEnvironmentSettings(candidate.settings, settings),
60 providers,
61 ).get(instanceId);
apps/web/src/modelSelection.test.ts
+56
@@ -25,6 +25,8 @@ import {
25 import {
26 defaultModelSelectionsAreMixed,
27 getAppModelOptionsForInstance,
28 + getCustomModelOptionsByInstance,
29 + getTextGenerationModelOptionsByInstance,
30 resolveAppModelSelectionForInstance,
31 resolveAppModelSelectionState,
32 resolveEffectiveDefaultModelSelection,
@@ -917,6 +919,60 @@ describe("instance-scoped model selection", () => {
919 NO_PROVIDER_MODEL_SELECTION,
920 );
921 });
922 +
923 + it("excludes customized extension models while preserving unknown custom and thread models", () => {
924 + const pi = provider({
925 + provider: ProviderDriverKind.make("pi"),
926 + instanceId: "pi",
927 + models: ["default", "demo/demo-model"],
928 + });
929 + const providers = [
930 + {
931 + ...pi,
932 + models: pi.models.map((model) =>
933 + model.slug === "demo/demo-model" ? { ...model, supportsTextGeneration: false } : model,
934 + ),
935 + },
936 + ];
937 + const settings: UnifiedSettings = {
938 + ...DEFAULT_UNIFIED_SETTINGS,
939 + providerInstances: {
940 + [pi.instanceId]: {
941 + driver: ProviderDriverKind.make("pi"),
942 + config: {
943 + customModels: [
944 + { slug: "demo/demo-model", name: "My extension model" },
945 + { slug: "unknown/model", name: "My custom model" },
946 + ],
947 + },
948 + },
949 + },
950 + textGenerationModelSelection: createModelSelection(pi.instanceId, "demo/demo-model"),
951 + };
952 + const supported = providers.filter((provider) => provider.supportsTextGeneration !== false);
953 + expect(
954 + getTextGenerationModelOptionsByInstance(settings, supported, pi.instanceId, "demo/demo-model")
955 + .get(pi.instanceId)
956 + ?.map((option) => option.slug),
957 + ).toEqual(["default", "unknown/model"]);
958 + expect(resolveAppModelSelectionState(settings, supported)).toEqual(
959 + createModelSelection(pi.instanceId, "default"),
960 + );
961 + expect(
962 + resolveAppModelSelectionState(
963 + {
964 + ...settings,
965 + textGenerationModelSelection: createModelSelection(pi.instanceId, "unknown/model"),
966 + },
967 + supported,
968 + ).model,
969 + ).toBe("unknown/model");
970 + expect(
971 + getCustomModelOptionsByInstance(settings, providers)
972 + .get(pi.instanceId)
973 + ?.map((option) => option.slug),
974 + ).toEqual(["default", "demo/demo-model", "unknown/model"]);
975 + });
976 });
977
978 describe("resolveAppModelSelectionState with the opencode plan agent", () => {
apps/web/src/modelSelection.ts
+40 -8
@@ -366,6 +366,42 @@ export function getCustomModelOptionsByInstance(
366 return out;
367 }
368
369 +function getTextGenerationModelOptionsForInstance(
370 + settings: UnifiedSettings,
371 + entry: ProviderInstanceEntry,
372 + selectedModel?: string | null,
373 +): AppModelOption[] {
374 + const unsupported = new Set(
375 + entry.models
376 + .filter((model) => model.supportsTextGeneration === false)
377 + .map((model) => model.slug),
378 + );
379 + // Filter after custom entries are rebuilt so a display-name override cannot restore a model.
380 + return getAppModelOptionsForInstance(settings, entry, selectedModel).filter(
381 + (option) => !unsupported.has(option.slug),
382 + );
383 +}
384 +
385 +export function getTextGenerationModelOptionsByInstance(
386 + settings: UnifiedSettings,
387 + providers: ReadonlyArray<ServerProvider>,
388 + selectedInstanceId?: ProviderInstanceId | null,
389 + selectedModel?: string | null,
390 +): ReadonlyMap<ProviderInstanceId, ReadonlyArray<ModelEsque>> {
391 + return new Map(
392 + deriveProviderInstanceEntries(
393 + providers.filter((provider) => provider.supportsTextGeneration !== false),
394 + ).map((entry) => [
395 + entry.instanceId,
396 + getTextGenerationModelOptionsForInstance(
397 + settings,
398 + entry,
399 + entry.instanceId === selectedInstanceId ? selectedModel : null,
400 + ),
401 + ]),
402 + );
403 +}
404 +
405 export function selectsPlanAgent(options: ModelSelection["options"]): boolean {
406 return options?.some((option) => option.id === "agent" && option.value === "plan") ?? false;
407 }
@@ -390,7 +426,7 @@ export function resolveAppModelSelectionState(
426 if (entry) {
427 const selectedModel = selectedEntry ? selection.model : null;
428 // Use the cheap generation default; the catalog default is the expensive chat flagship.
393 - const options = getAppModelOptionsForInstance(settings, entry);
429 + const options = getTextGenerationModelOptionsForInstance(settings, entry);
430 const model =
431 resolveSelectableModel(entry.driverKind, selectedModel, options) ??
432 resolveSelectableModel(
@@ -398,13 +434,9 @@ export function resolveAppModelSelectionState(
434 DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[entry.driverKind],
435 options,
436 ) ??
401 - resolveAppModelSelectionForInstance(
402 - entry.instanceId,
403 - settings,
404 - supportedProviders,
405 - selectedModel,
406 - ) ??
407 - entry.models[0]?.slug ??
437 + options.find((option) => option.isDefault)?.slug ??
438 + options[0]?.slug ??
439 + entry.models.find((model) => model.supportsTextGeneration !== false)?.slug ??
440 DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[entry.driverKind];
441 if (!model) {
442 return createModelSelection(entry.instanceId, "", []);
packages/contracts/src/server.ts
+3
@@ -83,6 +83,9 @@ export const ServerProviderModel = Schema.Struct({
83 isCustom: Schema.Boolean,
84 isDefault: Schema.optional(Schema.Boolean),
85 isLegacy: Schema.optional(Schema.Boolean),
86 + // False when the provider can run this model in sessions but not for
87 + // application text generation. Absent means supported.
88 + supportsTextGeneration: Schema.optional(Schema.Boolean),
89 capabilities: Schema.NullOr(ModelCapabilities),
90 });
91 export type ServerProviderModel = typeof ServerProviderModel.Type;
packages/provider-pi/src/server/status.test.ts
+132 -21
@@ -2,14 +2,15 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, describe, it } from "@effect/vitest";
3 import * as Cause from "effect/Cause";
4 import * as Effect from "effect/Effect";
5 +import * as Deferred from "effect/Deferred";
6 +import * as Fiber from "effect/Fiber";
7 +import * as TestClock from "effect/testing/TestClock";
8 import * as Queue from "effect/Queue";
9 import * as Schema from "effect/Schema";
10 import * as Sink from "effect/Sink";
11 import * as Stream from "effect/Stream";
12 import * as ChildProcess from "effect/process/ChildProcess";
13 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
11 -import * as Fiber from "effect/Fiber";
12 -import * as TestClock from "effect/testing/TestClock";
14
15 import { checkPiProviderStatus, MINIMUM_PI_VERSION } from "./status.ts";
16
@@ -57,14 +58,10 @@ function piProbeSpawner(version: string) {
58 });
59 }
60
60 -/** Fails the test if status runs `pi auth check` without `authCheck` or with other arguments. */
61 -const piDiscoverySpawner = (
61 +const piRpcProcess = (
62 inventory: unknown,
63 - options: {
64 - readonly version?: string;
65 - readonly state?: unknown;
66 - readonly authCheck?: string | undefined;
67 - } = {},
63 + onModelRequest: Effect.Effect<void> = Effect.void,
64 + state: unknown = {},
65 ) =>
66 Effect.gen(function* () {
67 const stdout = yield* Queue.unbounded<Uint8Array, Cause.Done>();
@@ -79,13 +76,17 @@ const piDiscoverySpawner = (
76 stdinBuffer = stdinBuffer.slice(newline + 1);
77 if (line.length === 0) continue;
78 const request = decodeRpcRequest(line);
79 + if (request.type === "get_available_models") {
80 + yield* onModelRequest;
81 + if (inventory === null) continue;
82 + }
83 const data =
84 request.type === "get_available_models"
85 ? inventory
86 : request.type === "get_commands"
87 ? { commands: [] }
88 : request.type === "get_state"
88 - ? (options.state ?? {})
89 + ? state
90 : {};
91 yield* Queue.offer(
92 stdout,
@@ -96,7 +97,31 @@ const piDiscoverySpawner = (
97 }
98 }),
99 );
99 - return ChildProcessSpawner.make((command) => {
100 + return ChildProcessSpawner.makeHandle({
101 + ...processHandle({}),
102 + exitCode: Effect.never,
103 + isRunning: Effect.succeed(true),
104 + stdin,
105 + stdout: Stream.fromQueue(stdout),
106 + });
107 + });
108 +
109 +/** Makes the extension-free launch exit before answering, like launch args naming an extension provider. */
110 +const exitsWithoutExtensions = Symbol("exitsWithoutExtensions");
111 +
112 +// Text generation lists models with --no-extensions, so its inventory can differ.
113 +const piDiscoverySpawner = (
114 + inventory: unknown,
115 + extensionFreeInventory: unknown = inventory,
116 + onExtensionFreeModelRequest: Effect.Effect<void> = Effect.void,
117 + options: {
118 + readonly version?: string;
119 + readonly state?: unknown;
120 + readonly authCheck?: string | undefined;
121 + } = {},
122 +) =>
123 + Effect.succeed(
124 + ChildProcessSpawner.make((command) => {
125 const args = ChildProcess.isStandardCommand(command) ? command.args : [];
126 if (args.includes("--version")) {
127 return Effect.succeed(processHandle({ stdout: `pi ${options.version ?? "0.84.3"}\n` }));
@@ -107,17 +132,18 @@ const piDiscoverySpawner = (
132 ? Effect.die(`Unexpected pi ${args.join(" ")}`)
133 : Effect.succeed(processHandle({ stdout: options.authCheck, exitCode: 1 }));
134 }
110 - return Effect.succeed(
111 - ChildProcessSpawner.makeHandle({
112 - ...processHandle({}),
113 - exitCode: Effect.never,
114 - isRunning: Effect.succeed(true),
115 - stdin,
116 - stdout: Stream.fromQueue(stdout),
117 - }),
135 + if (args.includes("--no-extensions") && extensionFreeInventory === exitsWithoutExtensions) {
136 + return Effect.succeed(
137 + processHandle({ stderr: 'Error: Unknown provider "demo".', exitCode: 1 }),
138 + );
139 + }
140 + return piRpcProcess(
141 + args.includes("--no-extensions") ? extensionFreeInventory : inventory,
142 + args.includes("--no-extensions") ? onExtensionFreeModelRequest : Effect.void,
143 + options.state,
144 );
119 - });
120 - });
145 + }),
146 + );
147
148 const settings = {
149 enabled: true,
@@ -263,6 +289,8 @@ describe("PiProvider", () => {
289 { provider: "router", id: "auto" },
290 ],
291 },
292 + undefined,
293 + Effect.void,
294 { version: row.version, state: { model: row.activeModel }, authCheck: row.authCheck },
295 );
296 const snapshot = yield* checkPiProviderStatus({
@@ -276,6 +304,89 @@ describe("PiProvider", () => {
304 }).pipe(Effect.provide(NodeServices.layer)),
305 );
306
307 + it.effect("marks models that only load with Pi extensions as unusable for text generation", () =>
308 + Effect.gen(function* () {
309 + const spawner = yield* piDiscoverySpawner(
310 + {
311 + models: [
312 + { provider: "anthropic", id: "claude-sonnet-4" },
313 + { provider: "demo", id: "demo-model" },
314 + ],
315 + },
316 + { models: [{ provider: "anthropic", id: "claude-sonnet-4" }] },
317 + );
318 + const snapshot = yield* checkPiProviderStatus(settings).pipe(
319 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
320 + );
321 + assert.deepEqual(
322 + snapshot.models.map((model) => [model.slug, model.supportsTextGeneration]),
323 + [
324 + ["default", undefined],
325 + ["anthropic/claude-sonnet-4", undefined],
326 + ["demo/demo-model", false],
327 + ],
328 + );
329 + assert.equal(snapshot.supportsTextGeneration, undefined);
330 + }).pipe(Effect.provide(NodeServices.layer)),
331 + );
332 +
333 + it.effect.each([
334 + { label: "exits before answering", extensionFreeInventory: exitsWithoutExtensions },
335 + { label: "lists no models", extensionFreeInventory: { models: [] } },
336 + ])("makes Pi unusable for text generation when Pi without extensions $label", (row) =>
337 + Effect.gen(function* () {
338 + const spawner = yield* piDiscoverySpawner(
339 + { models: [{ provider: "demo", id: "extension-model" }] },
340 + row.extensionFreeInventory,
341 + );
342 + const snapshot = yield* checkPiProviderStatus({
343 + ...settings,
344 + launchArgs: "--provider demo --model extension-model",
345 + customModels: ["local/custom-alias"],
346 + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
347 + assert.equal(snapshot.status, "ready");
348 + assert.equal(snapshot.auth.status, "authenticated");
349 + // Pi default and custom models still run in chat, so the picker keeps them.
350 + assert.deepEqual(
351 + snapshot.models.map((model) => model.slug),
352 + ["default", "demo/extension-model", "local/custom-alias"],
353 + );
354 + assert.equal(snapshot.supportsTextGeneration, false);
355 + }).pipe(Effect.provide(NodeServices.layer)),
356 + );
357 +
358 + it.effect("preserves normal discovery when the extension-free model listing times out", () =>
359 + Effect.gen(function* () {
360 + const modelRequested = yield* Deferred.make<void>();
361 + const spawner = yield* piDiscoverySpawner(
362 + { models: [{ provider: "demo", id: "demo-model" }] },
363 + null,
364 + Deferred.succeed(modelRequested, undefined).pipe(Effect.asVoid),
365 + );
366 + const fiber = yield* checkPiProviderStatus(settings).pipe(
367 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
368 + Effect.forkChild,
369 + );
370 + yield* Deferred.await(modelRequested);
371 + yield* TestClock.adjust("5 seconds");
372 + const snapshot = yield* Fiber.join(fiber);
373 + assert.equal(snapshot.status, "ready");
374 + assert.equal(snapshot.auth.status, "authenticated");
375 + assert.deepEqual(
376 + snapshot.models.map((model) => [model.slug, model.supportsTextGeneration]),
377 + [
378 + ["default", undefined],
379 + ["demo/demo-model", undefined],
380 + ],
381 + );
382 + assert.equal(snapshot.supportsTextGeneration, undefined);
383 + assert.include(
384 + snapshot.slashCommands.map((command) => command.name),
385 + "compact",
386 + );
387 + }).pipe(Effect.provide(NodeServices.layer)),
388 + );
389 +
390 it.effect("advertises a model's service tiers beside its thinking levels", () =>
391 Effect.gen(function* () {
392 const spawner = yield* piDiscoverySpawner({
packages/provider-pi/src/server/status.ts
+79 -17
@@ -11,6 +11,7 @@ import * as DateTime from "effect/DateTime";
11 import * as Effect from "effect/Effect";
12 import * as Stream from "effect/Stream";
13 import * as Exit from "effect/Exit";
14 +import * as Fiber from "effect/Fiber";
15 import * as Option from "effect/Option";
16 import * as Result from "effect/Result";
17 import * as Schema from "effect/Schema";
@@ -57,6 +58,7 @@ const PI_PRESENTATION = {
58
59 const VERSION_PROBE_TIMEOUT_MS = 10_000;
60 const PI_RPC_DISCOVERY_TIMEOUT_MS = 30_000;
61 +const PI_TEXT_GENERATION_DISCOVERY_TIMEOUT_MS = 5_000;
62 /**
63 * get_entries arrived in 0.80.3 and agent_settled landed in source at 0.80.4.
64 * Version 0.80.5 was the first published package containing both hooks.
@@ -81,6 +83,8 @@ interface PiDiscovery extends PiDiscoveredCommands {
83 readonly authenticated: boolean;
84 /** Pi's active model when Pi lists no model of its provider, so it cannot start a turn. */
85 readonly unavailableActiveModel: { readonly provider: string; readonly id: string } | undefined;
86 + /** Pi without extensions can load no model, so text generation fails for every entry. */
87 + readonly textGenerationUnavailable: boolean;
88 }
89
90 function piModelsFromSettings(
@@ -141,6 +145,7 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* (
145 environment: NodeJS.ProcessEnv,
146 launchArgs: ReadonlyArray<string>,
147 cwd?: string,
148 + textGenerationLaunch = false,
149 ) {
150 const launch = buildPiRpcLaunch({
151 launchArgs,
@@ -148,6 +153,8 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* (
153 mcpSession: undefined,
154 extensionPath: undefined,
155 ephemeral: true,
156 + disableExtensions: textGenerationLaunch,
157 + disableTools: textGenerationLaunch,
158 shortLived: true,
159 });
160 const connection = yield* makePiRpcConnection({
@@ -164,12 +171,55 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* (
171 return connection;
172 });
173
174 +// Text generation runs Pi with --no-extensions, so it cannot load models that an
175 +// extension or package registers. Listing models with that launch tells them apart.
176 +const discoverPiTextGenerationModelSlugs = Effect.fn(
177 + "PiProviderStatus.discoverPiTextGenerationModelSlugs",
178 +)(function* (
179 + piSettings: PiSettings,
180 + environment: NodeJS.ProcessEnv,
181 + launchArgs: ReadonlyArray<string>,
182 + cwd?: string,
183 +) {
184 + const connection = yield* makePiDiscoveryConnection(
185 + piSettings,
186 + environment,
187 + launchArgs,
188 + cwd,
189 + true,
190 + );
191 + const modelsData = yield* connection.request({ type: "get_available_models" });
192 + const models = yield* Effect.fromResult(parseDiscoveredModels(modelsData, undefined));
193 + return new Set(models.map((model) => model.slug));
194 +}, Effect.scoped);
195 +
196 const discoverPiViaRpc = Effect.fn("PiProviderStatus.discoverPiViaRpc")(function* (
197 piSettings: PiSettings,
198 environment: NodeJS.ProcessEnv,
199 launchArgs: ReadonlyArray<string>,
200 cwd?: string,
201 ) {
202 + // This optional probe must finish before the normal discovery deadline so
203 + // it cannot discard an otherwise usable catalog and authentication state.
204 + const textGenerationModelSlugsFiber = yield* discoverPiTextGenerationModelSlugs(
205 + piSettings,
206 + environment,
207 + launchArgs,
208 + cwd,
209 + ).pipe(
210 + // Pi exits before answering when launch args name a provider only an extension registers.
211 + Effect.catchIf(
212 + (error) =>
213 + error._tag === "PiRpcError" && (error.operation === "read" || error.operation === "exit"),
214 + () => Effect.succeed(new Set<string>()),
215 + ),
216 + Effect.orElseSucceed(() => undefined),
217 + Effect.timeoutOrElse({
218 + duration: PI_TEXT_GENERATION_DISCOVERY_TIMEOUT_MS,
219 + orElse: () => Effect.void,
220 + }),
221 + Effect.forkScoped,
222 + );
223 const connection = yield* makePiDiscoveryConnection(piSettings, environment, launchArgs, cwd);
224 const stateData = yield* connection.request({ type: "get_state" });
225 const modelsData = yield* connection.request({ type: "get_available_models" });
@@ -178,13 +228,21 @@ const discoverPiViaRpc = Effect.fn("PiProviderStatus.discoverPiViaRpc")(function
228 .pipe(Effect.orElseSucceed(() => undefined));
229 const discoveredModels = yield* Effect.fromResult(parseDiscoveredModels(modelsData, stateData));
230 const { slashCommands, skills } = parsePiDiscoveredCommands(commandsData);
231 + const textGenerationModelSlugs = yield* Fiber.join(textGenerationModelSlugsFiber);
232 // Pi lists only models of providers it holds credentials for, including extension, virtual and
233 // --api-key ones. Turns need only the provider's credentials, so uncatalogued model ids still run.
234 const activeModel = recordField(stateData, "model");
235 const activeProvider = recordString(activeModel, "provider");
236 const activeModelId = recordString(activeModel, "id");
237 return {
187 - models: discoveredModels,
238 + models:
239 + textGenerationModelSlugs === undefined
240 + ? discoveredModels
241 + : discoveredModels.map((model) =>
242 + textGenerationModelSlugs.has(model.slug)
243 + ? model
244 + : { ...model, supportsTextGeneration: false },
245 + ),
246 slashCommands: withPiBuiltinSlashCommands(slashCommands),
247 skills,
248 authenticated: discoveredModels.length > 0,
@@ -194,6 +252,7 @@ const discoverPiViaRpc = Effect.fn("PiProviderStatus.discoverPiViaRpc")(function
252 !discoveredModels.some((model) => model.subProvider === activeProvider)
253 ? { provider: activeProvider, id: activeModelId }
254 : undefined,
255 + textGenerationUnavailable: textGenerationModelSlugs?.size === 0,
256 } satisfies PiDiscovery;
257 }, Effect.scoped);
258
@@ -514,22 +573,25 @@ export const checkPiProviderStatus = Effect.fn("checkPiProviderStatus")(function
573 resolvedLaunchArgs.args,
574 discovery.unavailableActiveModel,
575 );
517 - return buildServerProvider({
518 - presentation: PI_PRESENTATION,
519 - enabled: piSettings.enabled,
520 - checkedAt,
521 - models,
522 - slashCommands: discovery.slashCommands,
523 - skills: discovery.skills,
524 - probe: {
525 - installed: true,
526 - version,
527 - // Other Pi models still work when only the default is unavailable, so keep the picker usable.
528 - status: discovery.authenticated ? "ready" : "warning",
529 - auth: { status: discovery.authenticated ? "authenticated" : "unauthenticated", type: "pi" },
530 - ...(message === undefined ? {} : { message }),
531 - },
532 - });
576 + return {
577 + ...buildServerProvider({
578 + presentation: PI_PRESENTATION,
579 + enabled: piSettings.enabled,
580 + checkedAt,
581 + models,
582 + slashCommands: discovery.slashCommands,
583 + skills: discovery.skills,
584 + probe: {
585 + installed: true,
586 + version,
587 + // Other Pi models still work when only the default is unavailable, so keep the picker usable.
588 + status: discovery.authenticated ? "ready" : "warning",
589 + auth: { status: discovery.authenticated ? "authenticated" : "unauthenticated", type: "pi" },
590 + ...(message === undefined ? {} : { message }),
591 + },
592 + }),
593 + ...(discovery.textGenerationUnavailable ? { supportsTextGeneration: false } : {}),
594 + };
595 });
596
597 export const enrichPiSnapshot = (input: {