Skip to content

Commit cbcd0fd

Browse files
fix(server): allow more time for Pi model discovery (pingdotgg#15529)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 2b6c291 commit cbcd0fd

3 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎packages/provider-pi/src/server/driver.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
256256
);
257257
const probe = yield* instance.snapshotForCwd!("/pending").pipe(Effect.flip, Effect.forkChild);
258258
yield* Deferred.await(pendingCommand);
259-
yield* TestClock.adjust("15 seconds");
259+
yield* TestClock.adjust("30 seconds");
260260
const error = yield* Fiber.join(probe);
261261
assert.equal(error._tag, "ProviderDriverError");
262262
assert.include(error.detail, "workspace commands");

‎packages/provider-pi/src/server/status.test.ts‎

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { assert, describe, it } from "@effect/vitest";
33
import * as Cause from "effect/Cause";
4+
import * as Deferred from "effect/Deferred";
5+
import * as Duration from "effect/Duration";
46
import * as Effect from "effect/Effect";
7+
import * as Fiber from "effect/Fiber";
58
import * as Queue from "effect/Queue";
69
import * as Schema from "effect/Schema";
710
import * as Sink from "effect/Sink";
811
import * as Stream from "effect/Stream";
912
import * as ChildProcess from "effect/process/ChildProcess";
1013
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
14+
import * as TestClock from "effect/testing/TestClock";
1115

1216
import { checkPiProviderStatus, MINIMUM_PI_VERSION } from "./status.ts";
1317

@@ -52,7 +56,13 @@ function piProbeSpawner(version: string) {
5256
});
5357
}
5458

55-
const piDiscoverySpawner = (inventory: unknown) =>
59+
const piDiscoverySpawner = (
60+
inventory: unknown,
61+
slowStartup?: {
62+
readonly delay: Duration.Input;
63+
readonly getStateReceived: Deferred.Deferred<void>;
64+
},
65+
) =>
5666
Effect.gen(function* () {
5767
const stdout = yield* Queue.unbounded<Uint8Array, Cause.Done>();
5868
let stdinBuffer = "";
@@ -66,6 +76,10 @@ const piDiscoverySpawner = (inventory: unknown) =>
6676
stdinBuffer = stdinBuffer.slice(newline + 1);
6777
if (line.length === 0) continue;
6878
const request = decodeRpcRequest(line);
79+
if (request.type === "get_state" && slowStartup !== undefined) {
80+
yield* Deferred.succeed(slowStartup.getStateReceived, undefined);
81+
yield* Effect.sleep(slowStartup.delay);
82+
}
6983
const data =
7084
request.type === "get_available_models"
7185
? inventory
@@ -131,14 +145,20 @@ describe("PiProvider", () => {
131145
}).pipe(Effect.provide(NodeServices.layer)),
132146
);
133147

134-
it.effect("reports only the models returned by successful Pi discovery", () =>
148+
it.effect("reports discovered models when Pi startup takes 20 seconds", () =>
135149
Effect.gen(function* () {
136-
const spawner = yield* piDiscoverySpawner({
137-
models: [{ provider: "anthropic", id: "claude-sonnet-4" }],
138-
});
139-
const snapshot = yield* checkPiProviderStatus(settings).pipe(
150+
const getStateReceived = yield* Deferred.make<void>();
151+
const spawner = yield* piDiscoverySpawner(
152+
{ models: [{ provider: "anthropic", id: "claude-sonnet-4" }] },
153+
{ delay: "20 seconds", getStateReceived },
154+
);
155+
const probe = yield* checkPiProviderStatus(settings).pipe(
140156
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
157+
Effect.forkChild,
141158
);
159+
yield* Deferred.await(getStateReceived);
160+
yield* TestClock.adjust("20 seconds");
161+
const snapshot = yield* Fiber.join(probe);
142162
assert.equal(snapshot.status, "ready");
143163
assert.equal(snapshot.auth.status, "authenticated");
144164
assert.deepEqual(
@@ -149,6 +169,29 @@ describe("PiProvider", () => {
149169
}).pipe(Effect.provide(NodeServices.layer)),
150170
);
151171

172+
it.effect("keeps compatible Pi selectable when startup outlasts the discovery deadline", () =>
173+
Effect.gen(function* () {
174+
const getStateReceived = yield* Deferred.make<void>();
175+
const spawner = yield* piDiscoverySpawner(
176+
{ models: [{ provider: "anthropic", id: "claude-sonnet-4" }] },
177+
{ delay: "1 hour", getStateReceived },
178+
);
179+
const probe = yield* checkPiProviderStatus(settings).pipe(
180+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
181+
Effect.forkChild,
182+
);
183+
yield* Deferred.await(getStateReceived);
184+
yield* TestClock.adjust("30 seconds");
185+
const snapshot = yield* Fiber.join(probe);
186+
assert.equal(snapshot.status, "ready");
187+
assert.equal(snapshot.auth.status, "unknown");
188+
assert.deepEqual(
189+
snapshot.models.map((model) => model.slug),
190+
["default"],
191+
);
192+
}).pipe(Effect.provide(NodeServices.layer)),
193+
);
194+
152195
it.effect("reports a known unauthenticated inventory when Pi returns no usable models", () =>
153196
Effect.gen(function* () {
154197
const spawner = yield* piDiscoverySpawner({ models: [] });

‎packages/provider-pi/src/server/status.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const PI_PRESENTATION = {
5757
} as const;
5858

5959
const VERSION_PROBE_TIMEOUT_MS = 4_000;
60-
const PI_RPC_DISCOVERY_TIMEOUT_MS = 15_000;
60+
const PI_RPC_DISCOVERY_TIMEOUT_MS = 30_000;
6161
/**
6262
* get_entries arrived in 0.80.3 and agent_settled landed in source at 0.80.4.
6363
* Version 0.80.5 was the first published package containing both hooks.

0 commit comments

Comments
 (0)