Skip to content

Commit 8198b2e

Browse files
saphidclaudemaria-rcks
authored
fix(kiro): slow kiro-cli starts no longer show Kiro as unavailable (#29841)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 6049196 commit 8198b2e

2 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎apps/server/src/provider/KiroProvider.test.ts‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { assert, describe, it } from "@effect/vitest";
44
import { KiroSettings } from "@t3tools/provider-kiro/settings";
55
import * as Deferred from "effect/Deferred";
6+
import type * as Duration from "effect/Duration";
67
import * as Effect from "effect/Effect";
8+
import * as Fiber from "effect/Fiber";
79
import * as Layer from "effect/Layer";
810
import * as Queue from "effect/Queue";
911
import * as Schema from "effect/Schema";
1012
import * as Sink from "effect/Sink";
1113
import * as Stream from "effect/Stream";
1214
import { ChildProcess, ChildProcessSpawner } from "effect/process";
15+
import * as TestClock from "effect/testing/TestClock";
1316

1417
import {
1518
checkKiroProviderStatus,
@@ -23,18 +26,25 @@ const settings = Schema.decodeSync(KiroSettings)({ enabled: true });
2326
interface CliOutput {
2427
readonly stdout: string;
2528
readonly code: number;
29+
/** Holds stdout and the exit back this long, like a CLI slow to answer. */
30+
readonly delay?: Duration.Input;
2631
}
2732

2833
function processHandle(output: CliOutput) {
34+
const answered = Effect.sleep(output.delay ?? 0);
2935
return ChildProcessSpawner.makeHandle({
3036
pid: ChildProcessSpawner.ProcessId(900_000_002),
31-
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(output.code)),
37+
exitCode: Effect.as(answered, ChildProcessSpawner.ExitCode(output.code)),
3238
isRunning: Effect.succeed(false),
3339
kill: () => Effect.void,
3440
unref: Effect.succeed(Effect.void),
3541
stdin: Sink.drain,
36-
stdout:
37-
output.stdout.length === 0 ? Stream.empty : Stream.succeed(encoder.encode(output.stdout)),
42+
stdout: Stream.unwrap(
43+
Effect.as(
44+
answered,
45+
output.stdout.length === 0 ? Stream.empty : Stream.succeed(encoder.encode(output.stdout)),
46+
),
47+
),
3848
stderr: Stream.empty,
3949
all: Stream.empty,
4050
getInputFd: () => Sink.drain,
@@ -123,6 +133,35 @@ const check = (
123133
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)));
124134

125135
describe("KiroProvider", () => {
136+
it.effect.each([
137+
{
138+
label: "answers after 6 s",
139+
delay: "6 seconds",
140+
status: "ready",
141+
version: "2.27.0",
142+
message: undefined,
143+
},
144+
{
145+
label: "never answers",
146+
delay: "Infinity",
147+
status: "error",
148+
version: null,
149+
message: "Failed to run `kiro-cli --version`.",
150+
},
151+
] as const)("gives `kiro-cli --version` 10 s when it $label", (row) =>
152+
Effect.gen(function* () {
153+
const fiber = yield* check({
154+
"--version": { stdout: "kiro-cli 2.27.0\n", code: 0, delay: row.delay },
155+
"whoami --format json": { stdout: '{"accountType":"ApiKey","email":null}\n', code: 0 },
156+
}).pipe(Effect.forkChild);
157+
yield* TestClock.adjust("10 seconds");
158+
const { snapshot } = yield* Fiber.join(fiber);
159+
assert.equal(snapshot.status, row.status);
160+
assert.equal(snapshot.version, row.version);
161+
assert.equal(snapshot.message, row.message);
162+
}),
163+
);
164+
126165
it.effect("reports a CLI whose version probe exits nonzero as failing to run", () =>
127166
Effect.gen(function* () {
128167
const { snapshot, invoked } = yield* check({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
AUTH_PROBE_TIMEOUT_MS,
2727
buildServerProvider,
2828
COMPACT_SLASH_COMMAND,
29-
DEFAULT_TIMEOUT_MS,
3029
isCommandMissingCause,
3130
parseGenericCliVersion,
3231
buildSelectOptionDescriptor,
@@ -54,6 +53,7 @@ const KIRO_BUILT_IN_MODELS: ReadonlyArray<ServerProviderModel> = [
5453
},
5554
];
5655
const KIRO_API_KEY_ENV = "KIRO_API_KEY";
56+
const VERSION_PROBE_TIMEOUT_MS = 10_000;
5757

5858
/**
5959
* The agent picker is not a model trait, but the composer reads options per
@@ -374,7 +374,7 @@ export const checkKiroProviderStatus = Effect.fn("checkKiroProviderStatus")(func
374374
}
375375

376376
const versionResult = yield* runKiroCli(settings, ["--version"], environment).pipe(
377-
Effect.timeoutOption(DEFAULT_TIMEOUT_MS),
377+
Effect.timeoutOption(VERSION_PROBE_TIMEOUT_MS),
378378
Effect.result,
379379
);
380380
if (Result.isFailure(versionResult) || Option.isNone(versionResult.success)) {

0 commit comments

Comments
 (0)