@devries-cameron20 / t3code-1 / commits / 1c748ed776
Fork 0

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

fix(providers): slow Grok, Pi and fx starts no longer show as unavailable (#28400)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Nov 1, 2026 at 16:06 UTC 1c748ed776843ae6fe61de58948d4dcdfac07612
6 files changed +177 -12
apps/server/src/provider/GrokProvider.test.ts
+69
@@ -5,9 +5,16 @@ import * as NodeURL from "node:url";
5 import * as NodeServices from "@effect/platform-node/NodeServices";
6 import { describe, expect, it } from "@effect/vitest";
7 import * as Effect from "effect/Effect";
8 +import * as Fiber from "effect/Fiber";
9 import * as FileSystem from "effect/FileSystem";
10 +import * as PlatformError from "effect/PlatformError";
11 import * as Schema from "effect/Schema";
12 +import * as Sink from "effect/Sink";
13 +import * as Stream from "effect/Stream";
14 import { HttpClient, HttpClientResponse } from "effect/http";
15 +import * as ChildProcess from "effect/process/ChildProcess";
16 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17 +import * as TestClock from "effect/testing/TestClock";
18 import { GrokSettings } from "@t3tools/provider-grok/settings";
19
20 import {
@@ -221,6 +228,68 @@ it.layer(NodeServices.layer)("checkGrokProviderStatus", (it) => {
228 }),
229 );
230
231 + it.effect.each([
232 + {
233 + label: "answers after 6 s",
234 + versionDelay: "6 seconds",
235 + version: "1.0.52",
236 + message: "Grok CLI is installed but ACP initialize failed. Model options may be incomplete.",
237 + probesAfterVersion: true,
238 + },
239 + {
240 + label: "never answers",
241 + versionDelay: "Infinity",
242 + version: null,
243 + message: "Grok CLI is installed but timed out while running `grok --version`.",
244 + probesAfterVersion: false,
245 + },
246 + ] as const)("gives `grok --version` 10 s when it $label", (row) =>
247 + Effect.gen(function* () {
248 + // A fake CLI runs on wall time, so a stub answers `--version` on the test clock.
249 + const spawned: Array<string> = [];
250 + const spawner = ChildProcessSpawner.make((command) => {
251 + const args = ChildProcess.isStandardCommand(command) ? command.args : [];
252 + spawned.push(args.join(" "));
253 + if (!args.includes("--version")) {
254 + return Effect.fail(
255 + PlatformError.systemError({
256 + _tag: "PermissionDenied",
257 + module: "ChildProcess",
258 + method: "spawn",
259 + description: "Only `grok --version` is stubbed.",
260 + }),
261 + );
262 + }
263 + const handle = ChildProcessSpawner.makeHandle({
264 + pid: ChildProcessSpawner.ProcessId(900_000_201),
265 + exitCode: Effect.delay(Effect.succeed(ChildProcessSpawner.ExitCode(0)), row.versionDelay),
266 + isRunning: Effect.succeed(true),
267 + kill: () => Effect.void,
268 + unref: Effect.succeed(Effect.void),
269 + stdin: Sink.drain,
270 + stdout: Stream.encodeText(
271 + Stream.fromEffect(Effect.delay(Effect.succeed("grok 1.0.52\n"), row.versionDelay)),
272 + ),
273 + stderr: Stream.empty,
274 + all: Stream.empty,
275 + getInputFd: () => Sink.drain,
276 + getOutputFd: () => Stream.empty,
277 + });
278 + return Effect.succeed(handle);
279 + });
280 + const fiber = yield* checkGrokProviderStatus(decodeGrokSettings({ enabled: true }), {}).pipe(
281 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
282 + Effect.forkChild,
283 + );
284 + yield* TestClock.adjust("10 seconds");
285 + const snapshot = yield* Fiber.join(fiber);
286 + expect(snapshot.installed).toBe(true);
287 + expect(snapshot.version).toBe(row.version);
288 + expect(snapshot.message).toBe(row.message);
289 + expect(spawned.length > 1).toBe(row.probesAfterVersion);
290 + }),
291 + );
292 +
293 // A stand-in for the Grok CLI: `--version` and `models` print canned text,
294 // and `agent stdio` execs the mock ACP agent so `initialize` returns model metadata.
295 // A list of `models` outputs is served in call order, repeating the last one.
packages/provider-fx/src/server/status.test.ts
+52 -5
@@ -1,11 +1,14 @@
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, describe, it } from "@effect/vitest";
3 +import type * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
5 +import * as Fiber from "effect/Fiber";
6 import * as Schema from "effect/Schema";
7 import * as Sink from "effect/Sink";
8 import * as Stream from "effect/Stream";
9 import * as ChildProcess from "effect/process/ChildProcess";
10 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
11 +import * as TestClock from "effect/testing/TestClock";
12
13 import { FxSettings } from "../settings.ts";
14 import { checkFxProviderStatus } from "./status.ts";
@@ -13,15 +16,21 @@ import { checkFxProviderStatus } from "./status.ts";
16 const encoder = new TextEncoder();
17 const settings = Schema.decodeSync(FxSettings)({ enabled: true });
18
16 -function processHandle(stdout: string, code: number) {
19 +/** Holds stdout and the exit back until `answered` completes, like a CLI slow to answer. */
20 +function processHandle(stdout: string, code: number, answered: Effect.Effect<void> = Effect.void) {
21 return ChildProcessSpawner.makeHandle({
22 pid: ChildProcessSpawner.ProcessId(900_000_101),
19 - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(code)),
23 + exitCode: Effect.as(answered, ChildProcessSpawner.ExitCode(code)),
24 isRunning: Effect.succeed(false),
25 kill: () => Effect.void,
26 unref: Effect.succeed(Effect.void),
27 stdin: Sink.drain,
24 - stdout: stdout.length === 0 ? Stream.empty : Stream.succeed(encoder.encode(stdout)),
28 + stdout: Stream.unwrap(
29 + Effect.as(
30 + answered,
31 + stdout.length === 0 ? Stream.empty : Stream.succeed(encoder.encode(stdout)),
32 + ),
33 + ),
34 stderr: Stream.empty,
35 all: Stream.empty,
36 getInputFd: () => Sink.drain,
@@ -30,7 +39,7 @@ function processHandle(stdout: string, code: number) {
39 }
40
41 /** Answers `fx` invocations by their arguments and records which ran. */
33 -const check = (statusJson: string) =>
42 +const check = (statusJson: string, versionDelay: Duration.Input = 0) =>
43 Effect.gen(function* () {
44 const outputs: Record<string, string> = {
45 "--version": "fx 0.0.13\n",
@@ -50,7 +59,13 @@ const check = (statusJson: string) =>
59 const args = ChildProcess.isStandardCommand(command) ? command.args.join(" ") : "";
60 invoked.push(args);
61 const stdout = outputs[args];
53 - return Effect.succeed(processHandle(stdout ?? "", stdout === undefined ? 2 : 0));
62 + return Effect.succeed(
63 + processHandle(
64 + stdout ?? "",
65 + stdout === undefined ? 2 : 0,
66 + args === "--version" ? Effect.sleep(versionDelay) : Effect.void,
67 + ),
68 + );
69 });
70 const draft = yield* checkFxProviderStatus(settings, {}).pipe(
71 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
@@ -59,6 +74,38 @@ const check = (statusJson: string) =>
74 }).pipe(Effect.provide(NodeServices.layer));
75
76 describe("checkFxProviderStatus", () => {
77 + it.effect.each([
78 + {
79 + label: "answers after 6 s",
80 + versionDelay: "6 seconds",
81 + status: "ready",
82 + version: "0.0.13",
83 + message: undefined,
84 + invoked: ["--version", "status --json", "models --json"],
85 + },
86 + {
87 + label: "never answers",
88 + versionDelay: "Infinity",
89 + status: "error",
90 + version: null,
91 + message: "Failed to run `fx --version`.",
92 + invoked: ["--version"],
93 + },
94 + ] as const)("gives `fx --version` 10 s when it $label", (row) =>
95 + Effect.gen(function* () {
96 + const fiber = yield* check(
97 + JSON.stringify({ kind: "status", model: "anthropic/claude-opus-5.5", auth: "fx login" }),
98 + row.versionDelay,
99 + ).pipe(Effect.forkChild);
100 + yield* TestClock.adjust("10 seconds");
101 + const { draft, invoked } = yield* Fiber.join(fiber);
102 + assert.equal(draft.status, row.status);
103 + assert.equal(draft.version, row.version);
104 + assert.equal(draft.message, row.message);
105 + assert.deepEqual(invoked, [...row.invoked]);
106 + }),
107 + );
108 +
109 // `fx status --json` from fx 0.0.13, trimmed to the fields T3 reads plus a few it ignores.
110 it.effect("reports sign-in from `fx status` without opening an ACP session", () =>
111 Effect.gen(function* () {
packages/provider-fx/src/server/status.ts
+3 -2
@@ -19,7 +19,6 @@ import {
19 import {
20 AUTH_PROBE_TIMEOUT_MS,
21 buildServerProvider,
22 - DEFAULT_TIMEOUT_MS,
22 isCommandMissingCause,
23 nonEmptyTrimmed,
24 parseGenericCliVersion,
@@ -135,6 +134,8 @@ const FxModels = Schema.fromJsonString(
134 );
135 const decodeFxModels = Schema.decodeUnknownOption(FxModels);
136
137 +const VERSION_PROBE_TIMEOUT_MS = 10_000;
138 +
139 function fxAuth(auth: string | undefined): ServerProviderAuth {
140 const method = nonEmptyTrimmed(auth);
141 if (method === undefined) return { status: "unknown" };
@@ -163,7 +164,7 @@ export const checkFxProviderStatus = Effect.fn("checkFxProviderStatus")(function
164 }
165
166 const versionResult = yield* runFxCli(settings, ["--version"], environment).pipe(
166 - Effect.timeoutOption(DEFAULT_TIMEOUT_MS),
167 + Effect.timeoutOption(VERSION_PROBE_TIMEOUT_MS),
168 Effect.result,
169 );
170 if (Result.isFailure(versionResult) || Option.isNone(versionResult.success)) {
packages/provider-grok/src/server/status.ts
+1 -1
@@ -58,7 +58,7 @@ const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
58 optionDescriptors: [],
59 });
60
61 -const VERSION_PROBE_TIMEOUT_MS = 4_000;
61 +const VERSION_PROBE_TIMEOUT_MS = 10_000;
62 // Grok writes the initialize result only after startup work (settings,
63 // skill discovery, file watching). From a home directory that work measured
64 // 9-14s on CLI 1.0.52, so an 8s cap records a healthy CLI as a failed probe.
packages/provider-pi/src/server/status.test.ts
+49 -2
@@ -8,6 +8,8 @@ import * as Sink from "effect/Sink";
8 import * as Stream from "effect/Stream";
9 import * as ChildProcess from "effect/process/ChildProcess";
10 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
11 +import * as Fiber from "effect/Fiber";
12 +import * as TestClock from "effect/testing/TestClock";
13
14 import { checkPiProviderStatus, MINIMUM_PI_VERSION } from "./status.ts";
15
@@ -21,19 +23,22 @@ function processHandle(input: {
23 readonly stdout?: string;
24 readonly stderr?: string;
25 readonly exitCode?: number;
26 + /** Holds stdout and the exit back until it completes, like a CLI slow to answer. */
27 + readonly answered?: Effect.Effect<void>;
28 }) {
29 + const answered = input.answered ?? Effect.void;
30 const bytes = (value: string | undefined) =>
31 value === undefined || value.length === 0
32 ? Stream.empty
33 : Stream.succeed(encoder.encode(value));
34 return ChildProcessSpawner.makeHandle({
35 pid: ChildProcessSpawner.ProcessId(900_000_001),
31 - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(input.exitCode ?? 0)),
36 + exitCode: Effect.as(answered, ChildProcessSpawner.ExitCode(input.exitCode ?? 0)),
37 isRunning: Effect.succeed(false),
38 kill: () => Effect.void,
39 unref: Effect.succeed(Effect.void),
40 stdin: Sink.drain,
36 - stdout: bytes(input.stdout),
41 + stdout: Stream.unwrap(Effect.as(answered, bytes(input.stdout))),
42 stderr: bytes(input.stderr),
43 all: Stream.empty,
44 getInputFd: () => Sink.drain,
@@ -148,6 +153,48 @@ describe("PiProvider", () => {
153 }).pipe(Effect.provide(NodeServices.layer)),
154 );
155
156 + it.effect.each([
157 + {
158 + label: "answers after 6 s",
159 + versionDelay: "6 seconds",
160 + status: "ready",
161 + version: "0.84.3",
162 + message: "could not refresh its models and commands",
163 + probesAfterVersion: true,
164 + },
165 + {
166 + label: "never answers",
167 + versionDelay: "Infinity",
168 + status: "error",
169 + version: null,
170 + message: "Pi CLI is installed but timed out while running `pi --version`.",
171 + probesAfterVersion: false,
172 + },
173 + ] as const)("gives `pi --version` 10 s when it $label", (row) =>
174 + Effect.gen(function* () {
175 + const spawned: Array<string> = [];
176 + const spawner = ChildProcessSpawner.make((command) => {
177 + const args = ChildProcess.isStandardCommand(command) ? command.args : [];
178 + spawned.push(args.join(" "));
179 + return Effect.succeed(
180 + args.includes("--version")
181 + ? processHandle({ stdout: "pi 0.84.3\n", answered: Effect.sleep(row.versionDelay) })
182 + : processHandle({ stderr: "RPC startup failed", exitCode: 1 }),
183 + );
184 + });
185 + const fiber = yield* checkPiProviderStatus(settings).pipe(
186 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
187 + Effect.forkChild,
188 + );
189 + yield* TestClock.adjust("10 seconds");
190 + const snapshot = yield* Fiber.join(fiber);
191 + assert.equal(snapshot.status, row.status);
192 + assert.equal(snapshot.version, row.version);
193 + assert.include(snapshot.message ?? "", row.message);
194 + assert.equal(spawned.length > 1, row.probesAfterVersion);
195 + }).pipe(Effect.provide(NodeServices.layer)),
196 + );
197 +
198 it.effect("reports a known unauthenticated inventory when Pi returns no usable models", () =>
199 Effect.gen(function* () {
200 const spawner = yield* piDiscoverySpawner({ models: [] });
packages/provider-pi/src/server/status.ts
+3 -2
@@ -29,6 +29,7 @@ import {
29 import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
30 import {
31 buildServerProvider,
32 + DEFAULT_TIMEOUT_MS,
33 isCommandMissingCause,
34 parseGenericCliVersion,
35 providerModelsFromSettings,
@@ -56,7 +57,7 @@ const PI_PRESENTATION = {
57 reportsContextWindow: true,
58 } as const;
59
59 -const VERSION_PROBE_TIMEOUT_MS = 4_000;
60 +const VERSION_PROBE_TIMEOUT_MS = 10_000;
61 const PI_RPC_DISCOVERY_TIMEOUT_MS = 30_000;
62 /**
63 * get_entries arrived in 0.80.3 and agent_settled landed in source at 0.80.4.
@@ -278,7 +279,7 @@ const describeUnavailablePiModel = Effect.fn("PiProviderStatus.describeUnavailab
279 }),
280 ),
281 ),
281 - Effect.timeout(VERSION_PROBE_TIMEOUT_MS),
282 + Effect.timeout(DEFAULT_TIMEOUT_MS),
283 Effect.option,
284 );
285 const missingCredentials = Option.exists(