Skip to content

Commit 44a72c6

Browse files
Oliwer Jonssonclaude
authored andcommitted
fix(server): log the probe failure's cause type, not its text
Effect.tryPromise wraps every rejection as UnknownError with a generic message, so `detail` never carried the SDK's reason. Logging the raw rejection text instead could put subprocess output in server logs. Log the cause's error name instead, matching how the CLI health checks report failures without their output. Add a rejection test that checks the cause name is logged and the message is not. Done with Claude Opus 5.5 in Claude Code. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1e2f5aa commit 44a72c6

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

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

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,24 @@ it.effect("preserves initialized capabilities when optional usage times out", ()
226226
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
227227
);
228228

229-
it.effect("logs why a capability probe failed before reporting no capabilities", () => {
229+
const captureProbeFailureLog = () => {
230230
const messages: Array<unknown> = [];
231-
const logCapture = Logger.make<unknown, void>(({ message }) => {
231+
const logger = Logger.make<unknown, void>(({ message }) => {
232232
messages.push(...(Array.isArray(message) ? message : [message]));
233233
});
234+
return {
235+
messages,
236+
layer: Layer.merge(NodeServices.layer, Logger.layer([logger], { mergeWithExisting: false })),
237+
annotations: () =>
238+
messages.find(
239+
(message): message is Record<string, unknown> =>
240+
typeof message === "object" && message !== null && "errorTag" in message,
241+
),
242+
};
243+
};
244+
245+
it.effect("logs a timed-out capability probe before reporting no capabilities", () => {
246+
const log = captureProbeFailureLog();
234247
return Effect.gen(function* () {
235248
const initializationStarted = yield* Deferred.make<void>();
236249
let abortSignal: AbortSignal | undefined;
@@ -252,18 +265,32 @@ it.effect("logs why a capability probe failed before reporting no capabilities",
252265
const capabilities = yield* Fiber.join(probe);
253266
assert.equal(capabilities, undefined);
254267
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,
268+
assert.include(log.messages, "Claude capability probe failed.");
269+
assert.equal(log.annotations()?.errorTag, "TimeoutError");
270+
assert.equal(log.annotations()?.timeoutMs, 25_000);
271+
}).pipe(Effect.scoped, Effect.provide(log.layer));
272+
});
273+
274+
it.effect("logs a rejected capability probe by cause type without its message", () => {
275+
const log = captureProbeFailureLog();
276+
const secret = "secret-subprocess-output";
277+
return Effect.gen(function* () {
278+
const query = vi.spyOn(ClaudeSdk, "query").mockImplementation(
279+
() =>
280+
({
281+
initializationResult: () =>
282+
Promise.reject(new TypeError(`Claude Code process exited: ${secret}`)),
283+
}) as unknown as ReturnType<typeof ClaudeSdk.query>,
259284
);
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-
);
285+
yield* Effect.addFinalizer(() => Effect.sync(() => query.mockRestore()));
286+
const capabilities = yield* probeClaudeCapabilities(
287+
decodeClaudeSettings({ binaryPath: "claude" }),
288+
);
289+
assert.equal(capabilities, undefined);
290+
assert.equal(log.annotations()?.errorTag, "UnknownError");
291+
assert.equal(log.annotations()?.causeName, "TypeError");
292+
assert.equal(log.annotations()?.timeoutMs, undefined);
293+
// @effect-diagnostics-next-line preferSchemaOverJson:off
294+
assert.notInclude(JSON.stringify(log.messages), secret);
295+
}).pipe(Effect.scoped, Effect.provide(log.layer));
269296
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ const probeClaudeCapabilities = (
397397
}),
398398
),
399399
// Callers only see `undefined`, so this log is the one record of why the probe failed.
400+
// Like the CLI health checks, it names the failure without logging SDK or subprocess text.
400401
Effect.tapError((error) =>
401402
Effect.logWarning("Claude capability probe failed.", {
402403
errorTag: error._tag,
403-
detail: error.message,
404+
...(error.cause instanceof Error ? { causeName: error.cause.name } : {}),
404405
...(error._tag === "TimeoutError" ? { timeoutMs: CAPABILITIES_PROBE_TIMEOUT_MS } : {}),
405406
}),
406407
),

0 commit comments

Comments
 (0)