Skip to content

Commit 1e2f5aa

Browse files
Oliwer Jonssonclaude
authored andcommitted
fix(server): log why the Claude capability probe failed
probeClaudeCapabilities maps every failure (a 25s timeout, SDK spawn error, initialization error) to `undefined`. The provider card then says "Could not verify Claude authentication status", and nothing records what actually went wrong. Log the error tag, message, and timeout before discarding the failure. Done with Claude Opus 5.5 in Claude Code. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent e5a46d6 commit 1e2f5aa

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeCapabilitiesProbe.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
1010
import { assert, it } from "@effect/vitest";
1111
import * as Effect from "effect/Effect";
1212
import * as FileSystem from "effect/FileSystem";
13+
import * as Layer from "effect/Layer";
14+
import * as Logger from "effect/Logger";
1315
import * as Path from "effect/Path";
1416
import * as Schema from "effect/Schema";
1517

@@ -223,3 +225,45 @@ it.effect("preserves initialized capabilities when optional usage times out", ()
223225
assert.equal(abortSignal?.aborted, true);
224226
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
225227
);
228+
229+
it.effect("logs why a capability probe failed before reporting no capabilities", () => {
230+
const messages: Array<unknown> = [];
231+
const logCapture = Logger.make<unknown, void>(({ message }) => {
232+
messages.push(...(Array.isArray(message) ? message : [message]));
233+
});
234+
return Effect.gen(function* () {
235+
const initializationStarted = yield* Deferred.make<void>();
236+
let abortSignal: AbortSignal | undefined;
237+
const query = vi.spyOn(ClaudeSdk, "query").mockImplementation(({ options }) => {
238+
abortSignal = options?.abortController?.signal;
239+
return {
240+
initializationResult: () => {
241+
Deferred.doneUnsafe(initializationStarted, Effect.void);
242+
return new Promise(() => {});
243+
},
244+
} as unknown as ReturnType<typeof ClaudeSdk.query>;
245+
});
246+
yield* Effect.addFinalizer(() => Effect.sync(() => query.mockRestore()));
247+
const probe = yield* probeClaudeCapabilities(
248+
decodeClaudeSettings({ binaryPath: "claude" }),
249+
).pipe(Effect.forkChild);
250+
yield* Deferred.await(initializationStarted);
251+
yield* TestClock.adjust("25 seconds");
252+
const capabilities = yield* Fiber.join(probe);
253+
assert.equal(capabilities, undefined);
254+
assert.equal(abortSignal?.aborted, true);
255+
assert.include(messages, "Claude capability probe failed.");
256+
const annotations = messages.find(
257+
(message): message is Record<string, unknown> =>
258+
typeof message === "object" && message !== null && "errorTag" in message,
259+
);
260+
assert.equal(annotations?.errorTag, "TimeoutError");
261+
assert.equal(annotations?.timeoutMs, 25_000);
262+
assert.isString(annotations?.detail);
263+
}).pipe(
264+
Effect.scoped,
265+
Effect.provide(
266+
Layer.merge(NodeServices.layer, Logger.layer([logCapture], { mergeWithExisting: false })),
267+
),
268+
);
269+
});

‎apps/server/src/provider/Layers/ClaudeProvider.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,14 @@ const probeClaudeCapabilities = (
396396
if (!abort.signal.aborted) abort.abort();
397397
}),
398398
),
399+
// Callers only see `undefined`, so this log is the one record of why the probe failed.
400+
Effect.tapError((error) =>
401+
Effect.logWarning("Claude capability probe failed.", {
402+
errorTag: error._tag,
403+
detail: error.message,
404+
...(error._tag === "TimeoutError" ? { timeoutMs: CAPABILITIES_PROBE_TIMEOUT_MS } : {}),
405+
}),
406+
),
399407
Effect.result,
400408
Effect.map((result) => (Result.isSuccess(result) ? result.success : undefined)),
401409
);

0 commit comments

Comments
 (0)