Write runner.error frames to native provider logs on SDK failures
The native provider logs are the debugging ground truth, but SDK rejections (query open, message stream, prompt offer, agent open, run start/wait) raised errors without any log write — a failed turn left the log ending mid-conversation with no explanation (audit plan #4: neither of thread 721fc23c's failed turns was explainable from its log). The Claude and Cursor runners now tap every fallible SDK boundary and write a runner.error frame carrying the redacted cause chain. App-verified: with a broken Claude binary the native log now records `runner.error messages.stream | Claude Agent SDK query failed. ← Claude Code native binary not found at ...` where it previously went silent. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
0ac8024a02
commit
08bebb2472
2 files changed
+74
-3
No files matched your search
@@ -411,6 +411,18 @@ export type ClaudeAgentSdkProtocolLogEvent =
|
||||
readonly direction: "incoming";
|
||||
readonly stage: "decoded";
|
||||
readonly payload: SDKMessage;
|
||||
}
|
||||
| {
|
||||
// Failure frame: without it the native log ends mid-conversation with
|
||||
// no trace of WHY (audit plan #4 — failed opens/streams left the
|
||||
// "ground truth" log unable to explain any failed turn).
|
||||
readonly direction: "incoming";
|
||||
readonly stage: "decoded";
|
||||
readonly payload: {
|
||||
readonly type: "runner.error";
|
||||
readonly method: string;
|
||||
readonly message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type ClaudeAgentSdkProtocolLogger = (
|
||||
@@ -498,6 +510,22 @@ export const claudeAgentSdkQueryRunnerLiveLayer: Layer.Layer<
|
||||
});
|
||||
const logProtocolEvent = (event: ClaudeAgentSdkProtocolLogEvent) =>
|
||||
protocolLogger === undefined ? Effect.void : protocolLogger(event);
|
||||
const logRunnerFailure =
|
||||
(method: string) =>
|
||||
<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
||||
effect.pipe(
|
||||
Effect.tapError((error) =>
|
||||
logProtocolEvent({
|
||||
direction: "incoming",
|
||||
stage: "decoded",
|
||||
payload: {
|
||||
type: "runner.error",
|
||||
method,
|
||||
message: makeProviderFailure({ cause: error }).message,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
const promptQueue = yield* Queue.unbounded<SDKUserMessage>();
|
||||
const prompt = Stream.fromQueue(promptQueue).pipe(
|
||||
Stream.catchCause((cause) =>
|
||||
@@ -512,7 +540,7 @@ export const claudeAgentSdkQueryRunnerLiveLayer: Layer.Layer<
|
||||
options: input.options,
|
||||
}),
|
||||
catch: (cause) => queryRunnerError(cause, "query"),
|
||||
});
|
||||
}).pipe(logRunnerFailure("query.open"));
|
||||
yield* logProtocolEvent({
|
||||
direction: "outgoing",
|
||||
stage: "decoded",
|
||||
@@ -533,6 +561,17 @@ export const claudeAgentSdkQueryRunnerLiveLayer: Layer.Layer<
|
||||
payload: message,
|
||||
}),
|
||||
),
|
||||
Stream.tapError((error) =>
|
||||
logProtocolEvent({
|
||||
direction: "incoming",
|
||||
stage: "decoded",
|
||||
payload: {
|
||||
type: "runner.error",
|
||||
method: "messages.stream",
|
||||
message: makeProviderFailure({ cause: error }).message,
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
offer: (message) =>
|
||||
Queue.offer(promptQueue, message).pipe(
|
||||
@@ -547,12 +586,14 @@ export const claudeAgentSdkQueryRunnerLiveLayer: Layer.Layer<
|
||||
},
|
||||
}),
|
||||
),
|
||||
logRunnerFailure("prompt.offer"),
|
||||
),
|
||||
setModel: (model) =>
|
||||
Effect.tryPromise({
|
||||
try: () => queryRuntime.setModel(model),
|
||||
catch: (cause) => queryRunnerError(cause, "setModel"),
|
||||
}).pipe(
|
||||
logRunnerFailure("query.set_model"),
|
||||
Effect.tap(() =>
|
||||
logProtocolEvent({
|
||||
direction: "outgoing",
|
||||
|
||||
@@ -18,6 +18,7 @@ import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { makeProviderFailure } from "../ProviderFailure.ts";
|
||||
import {
|
||||
type EventNdjsonLogger,
|
||||
makeEventNdjsonLogger,
|
||||
@@ -197,6 +198,18 @@ export type CursorAgentSdkProtocolLogEvent =
|
||||
readonly type: "agent.close";
|
||||
readonly agentId: string;
|
||||
};
|
||||
}
|
||||
| {
|
||||
// Failure frame: SDK rejections previously left the native log ending
|
||||
// mid-conversation with no trace of why (audit plan #4 — thread
|
||||
// 721fc23c's failed turns were unexplainable from the log).
|
||||
readonly direction: "incoming";
|
||||
readonly stage: "decoded";
|
||||
readonly payload: {
|
||||
readonly type: "runner.error";
|
||||
readonly method: string;
|
||||
readonly message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type CursorAgentSdkProtocolLogger = (
|
||||
@@ -316,6 +329,22 @@ export const cursorAgentSdkRunnerLiveLayer: Layer.Layer<CursorAgentSdkRunner, ne
|
||||
});
|
||||
const log = (event: CursorAgentSdkProtocolLogEvent) =>
|
||||
protocolLogger === undefined ? Effect.void : protocolLogger(event);
|
||||
const logRunnerFailure =
|
||||
(method: string) =>
|
||||
<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
||||
effect.pipe(
|
||||
Effect.tapError((error) =>
|
||||
log({
|
||||
direction: "incoming",
|
||||
stage: "decoded",
|
||||
payload: {
|
||||
type: "runner.error",
|
||||
method,
|
||||
message: makeProviderFailure({ cause: error }).message,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
yield* log({
|
||||
direction: "outgoing",
|
||||
@@ -334,7 +363,7 @@ export const cursorAgentSdkRunnerLiveLayer: Layer.Layer<CursorAgentSdkRunner, ne
|
||||
? Agent.create(input.options)
|
||||
: Agent.resume(input.agentId!, input.options),
|
||||
catch: (cause) => runnerError(cause, `agent.${input.operation}`),
|
||||
});
|
||||
}).pipe(logRunnerFailure(`agent.${input.operation}`));
|
||||
|
||||
yield* log({
|
||||
direction: "incoming",
|
||||
@@ -406,7 +435,7 @@ export const cursorAgentSdkRunnerLiveLayer: Layer.Layer<CursorAgentSdkRunner, ne
|
||||
},
|
||||
}),
|
||||
catch: (cause) => runnerError(cause, "run.start"),
|
||||
});
|
||||
}).pipe(logRunnerFailure("run.start"));
|
||||
runId = run.id;
|
||||
yield* log({
|
||||
direction: "incoming",
|
||||
@@ -449,6 +478,7 @@ export const cursorAgentSdkRunnerLiveLayer: Layer.Layer<CursorAgentSdkRunner, ne
|
||||
},
|
||||
}),
|
||||
),
|
||||
logRunnerFailure("run.wait"),
|
||||
),
|
||||
cancel: log({
|
||||
direction: "outgoing",
|
||||
|
||||
Reference in new issue
Block a user