Skip to content
TypeScript

fix(server): update Claude Agent SDK to 0.3.260 (#9135)

Theo Browne560afffdea82
diff --git a/apps/server/package.json b/apps/server/package.json
index ca74368348e..3e80321d606 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -22,7 +22,7 @@
"test": "vp test run"
},
"dependencies": {
- "@anthropic-ai/claude-agent-sdk": "^0.3.170",
+ "@anthropic-ai/claude-agent-sdk": "^0.3.260",
"@effect/platform-bun": "catalog:",
"@effect/platform-node": "catalog:",
"@effect/sql-sqlite-bun": "catalog:",
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
index 99bb95d83c6..8fcf3cc9213 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
@@ -2090,6 +2090,177 @@ describe("ClaudeAdapterLive", () => {
);
});
+ it.effect("fails a turn when the result carries a give-up terminal_reason", () => {
+ const harness = makeHarness();
+ return Effect.gen(function* () {
+ const adapter = yield* ClaudeAdapter;
+
+ const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
+ Stream.runCollect,
+ Effect.forkChild,
+ );
+
+ const session = yield* adapter.startSession({
+ threadId: THREAD_ID,
+ provider: ProviderDriverKind.make("claudeAgent"),
+ runtimeMode: "full-access",
+ });
+
+ const turn = yield* adapter.sendTurn({
+ threadId: session.threadId,
+ input: "hello",
+ attachments: [],
+ });
+
+ // The CLI stamps subtype success with an empty error list when it
+ // gives up after exhausting API retries; the terminal_reason is the
+ // only structured failure signal.
+ harness.query.emit({
+ type: "result",
+ subtype: "success",
+ is_error: false,
+ result: "",
+ errors: [],
+ stop_reason: null,
+ terminal_reason: "api_error",
+ session_id: "sdk-session-api-error",
+ uuid: "result-api-error",
+ } as unknown as SDKMessage);
+
+ const runtimeEvents = Array.from(yield* Fiber.join(runtimeEventsFiber));
+ assert.deepEqual(
+ runtimeEvents.map((event) => event.type),
+ [
+ "session.started",
+ "session.configured",
+ "session.state.changed",
+ "turn.started",
+ "thread.started",
+ "runtime.error",
+ "turn.completed",
+ ],
+ );
+
+ const turnCompleted = runtimeEvents[runtimeEvents.length - 1];
+ assert.equal(turnCompleted?.type, "turn.completed");
+ if (turnCompleted?.type === "turn.completed") {
+ assert.equal(String(turnCompleted.turnId), String(turn.turnId));
+ assert.equal(turnCompleted.payload.state, "failed");
+ assert.equal(
+ turnCompleted.payload.errorMessage,
+ "Claude gave up after repeated API errors.",
+ );
+ }
+ }).pipe(
+ Effect.provideService(Random.Random, makeDeterministicRandomService()),
+ Effect.provide(harness.layer),
+ );
+ });
+
+ it.effect("fails a turn for every dead-turn terminal_reason", () => {
+ const reasons = [
+ "blocking_limit",
+ "rapid_refill_breaker",
+ "prompt_too_long",
+ "image_error",
+ "model_error",
+ "malformed_tool_use_exhausted",
+ "budget_exhausted",
+ "structured_output_retry_exhausted",
+ "tool_deferred_unavailable",
+ "turn_setup_failed",
+ ];
+ // One harness per reason: the fake query settles a single turn.
+ const runDeadTurn = (reason: string) => {
+ const harness = makeHarness();
+ return Effect.gen(function* () {
+ const adapter = yield* ClaudeAdapter;
+ const completionFiber = yield* adapter.streamEvents.pipe(
+ Stream.filter((event) => event.type === "turn.completed"),
+ Stream.runHead,
+ Effect.forkChild,
+ );
+ const session = yield* adapter.startSession({
+ threadId: THREAD_ID,
+ provider: ProviderDriverKind.make("claudeAgent"),
+ runtimeMode: "full-access",
+ });
+ yield* adapter.sendTurn({ threadId: session.threadId, input: "hello", attachments: [] });
+ harness.query.emit({
+ type: "result",
+ subtype: "success",
+ is_error: false,
+ result: "",
+ errors: [],
+ stop_reason: null,
+ terminal_reason: reason,
+ session_id: "sdk-session-dead-turn",
+ uuid: `result-${reason}`,
+ } as unknown as SDKMessage);
+ const completed = yield* Fiber.join(completionFiber);
+ assert.equal(completed._tag, "Some");
+ if (completed._tag === "Some" && completed.value.type === "turn.completed") {
+ assert.equal(completed.value.payload.state, "failed", reason);
+ assert.ok(completed.value.payload.errorMessage, `${reason} carries an error message`);
+ }
+ }).pipe(
+ Effect.provideService(Random.Random, makeDeterministicRandomService()),
+ Effect.provide(harness.layer),
+ );
+ };
+ return Effect.forEach(reasons, runDeadTurn, { discard: true });
+ });
+
+ it.effect("fails a turn when a success result reports a 529 overload", () => {
+ const harness = makeHarness();
+ return Effect.gen(function* () {
+ const adapter = yield* ClaudeAdapter;
+
+ const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
+ Stream.runCollect,
+ Effect.forkChild,
+ );
+
+ const session = yield* adapter.startSession({
+ threadId: THREAD_ID,
+ provider: ProviderDriverKind.make("claudeAgent"),
+ runtimeMode: "full-access",
+ });
+
+ yield* adapter.sendTurn({
+ threadId: session.threadId,
+ input: "hello",
+ attachments: [],
+ });
+
+ harness.query.emit({
+ type: "result",
+ subtype: "success",
+ is_error: true,
+ api_error_status: 529,
+ result: "",
+ errors: [],
+ stop_reason: null,
+ session_id: "sdk-session-overload",
+ uuid: "result-overload",
+ } as unknown as SDKMessage);
+
+ const runtimeEvents = Array.from(yield* Fiber.join(runtimeEventsFiber));
+ const turnCompleted = runtimeEvents[runtimeEvents.length - 1];
+ assert.equal(turnCompleted?.type, "turn.completed");
+ if (turnCompleted?.type === "turn.completed") {
+ assert.equal(turnCompleted.payload.state, "failed");
+ assert.equal(
+ turnCompleted.payload.errorMessage,
+ "Claude API is overloaded (529). Try again shortly.",
+ );
+ }
+ }).pipe(
+ Effect.provideService(Random.Random, makeDeterministicRandomService()),
+ Effect.provide(harness.layer),
+ );
+ });
+
it.effect("interruptTurn settles live tasks and closes the provider session", () => {
const harness = makeHarness();
return Effect.gen(function* () {
@@ -3088,7 +3259,36 @@ describe("ClaudeAdapterLive", () => {
{ type: "system", subtype: "plugin_install", session_id: "session", uuid: "pi" },
{ type: "system", subtype: "memory_recall", session_id: "session", uuid: "mr" },
{ type: "system", subtype: "elicitation_complete", session_id: "session", uuid: "ec" },
+ {
+ type: "system",
+ subtype: "control_request_progress",
+ request_id: "ctrl-1",
+ status: "started",
+ session_id: "session",
+ uuid: "crp",
+ },
+ {
+ type: "system",
+ subtype: "worker_shutting_down",
+ reason: "host_exit",
+ session_id: "session",
+ uuid: "wsd",
+ },
+ {
+ type: "system",
+ subtype: "informational",
+ content: "Loaded 3 skills",
+ level: "notice",
+ session_id: "session",
+ uuid: "info",
+ },
{ type: "prompt_suggestion", suggestion: "try this", session_id: "session", uuid: "ps" },
+ {
+ type: "conversation_reset",
+ new_conversation_id: "conv-2",
+ session_id: "session",
+ uuid: "cr",
+ },
{
type: "system",
subtype: "notification",
@@ -3111,6 +3311,27 @@ describe("ClaudeAdapterLive", () => {
session_id: "session",
uuid: "notif-high",
} as unknown as SDKMessage);
+ // Warning-level informational notes and refusals without a fallback
+ // model surface as warning rows too.
+ harness.query.emit({
+ type: "system",
+ subtype: "informational",
+ content: "Stop hook prevented continuation",
+ level: "warning",
+ prevent_continuation: true,
+ session_id: "session",
+ uuid: "info-warn",
+ } as unknown as SDKMessage);
+ harness.query.emit({
+ type: "system",
+ subtype: "model_refusal_no_fallback",
+ original_model: "claude-opus-5",
+ request_id: null,
+ api_refusal_explanation: "The request was declined by the API.",
+ content: "Model refused",
+ session_id: "session",
+ uuid: "mrnf",
+ } as unknown as SDKMessage);
// session_state_changed maps to the matching session states.
for (const [state, uuid] of [
["running", "ssc-run"],
@@ -3141,10 +3362,15 @@ describe("ClaudeAdapterLive", () => {
yield* Effect.yieldNow;
const warnings = runtimeEvents.filter((event) => event.type === "runtime.warning");
- // Exactly one warning: the high-priority notification. Nothing else.
+ // Exactly three warnings: the high-priority notification, the
+ // warning-level informational note, and the refusal. Nothing else.
assert.deepEqual(
warnings.map((event) => event.payload.message),
- ["context window nearly full"],
+ [
+ "context window nearly full",
+ "Stop hook prevented continuation",
+ "The request was declined by the API.",
+ ],
);
const sessionStates = runtimeEvents
.filter((event) => event.type === "session.state.changed")
@@ -4190,6 +4416,7 @@ describe("ClaudeAdapterLive", () => {
{ command: "pwd" },
{
signal: new AbortController().signal,
+ requestId: "request-1",
suggestions: [
{
type: "setMode",
@@ -4301,6 +4528,7 @@ describe("ClaudeAdapterLive", () => {
{ title: "hello" },
{
signal: new AbortController().signal,
+ requestId: "request-2",
suggestions: [],
toolUseID: "tool-use-mcp-1",
},
@@ -4327,6 +4555,7 @@ describe("ClaudeAdapterLive", () => {
{ command: "git status" },
{
signal: new AbortController().signal,
+ requestId: "request-3",
suggestions: [
{
type: "addRules",
@@ -4385,6 +4614,7 @@ describe("ClaudeAdapterLive", () => {
{},
{
signal: new AbortController().signal,
+ requestId: "request-4",
toolUseID: "tool-agent-1",
},
);
@@ -4409,6 +4639,7 @@ describe("ClaudeAdapterLive", () => {
{ pattern: "foo", path: "src" },
{
signal: new AbortController().signal,
+ requestId: "request-5",
toolUseID: "tool-grep-approval-1",
},
);
@@ -4951,6 +5182,7 @@ describe("ClaudeAdapterLive", () => {
},
{
signal: new AbortController().signal,
+ requestId: "request-6",
toolUseID: "tool-exit-1",
},
);
@@ -5073,7 +5305,7 @@ describe("ClaudeAdapterLive", () => {
dialogKind: "resume_return",
payload: { sessionAgeMinutes: 145, estimatedTokens: 275123 },
},
- { signal: new AbortController().signal },
+ { signal: new AbortController().signal, requestId: "request-dialog" },
);
const requested = yield* Stream.runHead(adapter.streamEvents);
@@ -5173,6 +5405,7 @@ describe("ClaudeAdapterLive", () => {
const permissionPromise = canUseTool("AskUserQuestion", askInput, {
signal: new AbortController().signal,
+ requestId: "request-7",
toolUseID: "tool-ask-1",
});
@@ -5299,6 +5532,7 @@ describe("ClaudeAdapterLive", () => {
const permissionPromise = canUseTool("AskUserQuestion", askInput, {
signal: new AbortController().signal,
+ requestId: "request-8",
toolUseID: "tool-ask-2",
});
@@ -5364,6 +5598,7 @@ describe("ClaudeAdapterLive", () => {
},
{
signal: controller.signal,
+ requestId: "request-9",
toolUseID: "tool-ask-abort",
},
);
@@ -5439,6 +5674,7 @@ describe("ClaudeAdapterLive", () => {
},
{
signal: controller.signal,
+ requestId: "request-10",
toolUseID: "tool-ask-pre-aborted",
},
);
@@ -5495,7 +5731,11 @@ describe("ClaudeAdapterLive", () => {
},
],
},
- { signal: new AbortController().signal, toolUseID: "tool-ask-stop" },
+ {
+ signal: new AbortController().signal,
+ requestId: "request-stop",
+ toolUseID: "tool-ask-stop",
+ },
);
const requestedEvent = yield* Stream.runHead(adapter.streamEvents);
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.ts b/apps/server/src/provider/Layers/ClaudeAdapter.ts
index 5848bcc457d..75c0283eceb 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.ts
@@ -434,10 +434,45 @@ function resultErrorsText(result: SDKResultMessage): string {
* so they must never become the error banner.
*/
function resultUserFacingError(result: SDKResultMessage): string | undefined {
- if (result.subtype === "success" || !Array.isArray(result.errors)) {
- return undefined;
+ const listed =
+ result.subtype === "success" || !Array.isArray(result.errors)
+ ? undefined
+ : result.errors.find((error) => !error.startsWith("[ede_diagnostic]"));
+ if (listed) {
+ return listed;
+ }
+ // Structured failure markers for results whose error list is empty or
+ // diagnostic-only: an overloaded API (529) and the terminal reasons the
+ // CLI stamps when it gives up on a turn.
+ if (isOverloadedResult(result)) {
+ return "Claude API is overloaded (529). Try again shortly.";
+ }
+ switch (result.terminal_reason) {
+ case "api_error":
+ return "Claude gave up after repeated API errors.";
+ case "malformed_tool_use_exhausted":
+ return "Claude gave up after repeated malformed tool calls.";
+ case "budget_exhausted":
+ return "Claude stopped: the turn's token budget was exhausted.";
+ case "structured_output_retry_exhausted":
+ return "Claude could not produce the requested structured output.";
+ case "tool_deferred_unavailable":
+ return "Claude could not resume a deferred tool call: the tool is no longer available.";
+ case "turn_setup_failed":
+ return "Claude could not start the turn.";
+ case "blocking_limit":
+ return "Claude stopped: a usage limit blocked the request.";
+ case "rapid_refill_breaker":
+ return "Claude stopped: the context refilled too quickly after compaction.";
+ case "prompt_too_long":
+ return "Claude stopped: the prompt exceeds the model's context window.";
+ case "image_error":
+ return "Claude stopped: an image in the conversation could not be processed.";
+ case "model_error":
+ return "Claude stopped: the model returned an error.";
+ default:
+ return undefined;
}
- return result.errors.find((error) => !error.startsWith("[ede_diagnostic]"));
}
function isInterruptedResult(result: SDKResultMessage): boolean {
@@ -1390,7 +1425,43 @@ const buildUserMessageEffect = Effect.fn("buildUserMessageEffect")(function* (
return buildUserMessage({ sdkContent });
});
+/**
+ * terminal_reason values the CLI classifies as dead turns: the turn died
+ * rather than finished, even when the result subtype is success and the
+ * error list is empty. Kept in sync with the messages in
+ * resultUserFacingError.
+ */
+const FAILED_TERMINAL_REASONS: ReadonlySet<NonNullable<SDKResultMessage["terminal_reason"]>> =
+ new Set([
+ "api_error",
+ "malformed_tool_use_exhausted",
+ "budget_exhausted",
+ "structured_output_retry_exhausted",
+ "tool_deferred_unavailable",
+ "turn_setup_failed",
+ "blocking_limit",
+ "rapid_refill_breaker",
+ "prompt_too_long",
+ "image_error",
+ "model_error",
+ ]);
+
+/**
+ * The CLI reports repeated 529 overload failures as a success-subtype result
+ * with api_error_status 529 and an empty error list; the status code is the
+ * only structured failure signal.
+ */
+function isOverloadedResult(result: SDKResultMessage): boolean {
+ return result.subtype === "success" && result.api_error_status === 529;
+}
+
function turnStatusFromResult(result: SDKResultMessage): ProviderRuntimeTurnStatus {
+ if (
+ isOverloadedResult(result) ||
+ (result.terminal_reason !== undefined && FAILED_TERMINAL_REASONS.has(result.terminal_reason))
+ ) {
+ return "failed";
+ }
if (result.subtype === "success") {
return "completed";
}
@@ -3174,15 +3245,11 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
// Undeclared-but-real subtypes (absent from the SDK's union, so they can't
// be switch cases): consumed intentionally without emitting, otherwise
// they fall through to the unknown-subtype warning and surface as spurious
- // error rows in client work logs. `background_tasks_changed` is a roster
- // snapshot ({tasks: [...]}) — the task_* lifecycle events carry the
- // authoritative per-agent data and the typed background_tasks control
- // request is the reconciliation source. `vcs_state_changed`
+ // error rows in client work logs. `vcs_state_changed`
// ({kind: commit|push|rebase}) and `code_change_published`
// ({provider, url, repo}) are informational CLI notices; the work log
// already shows the underlying git/gh tool calls.
switch (message.subtype as string) {
- case "background_tasks_changed":
case "vcs_state_changed":
case "code_change_published":
return;
@@ -3497,12 +3564,39 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
return;
// Inner protocol/UX details with no T3 surface today — consumed
// deliberately so they don't masquerade as unknown-subtype warnings.
+ // `background_tasks_changed` is a roster snapshot ({tasks: [...]}); the
+ // task_* lifecycle events carry the authoritative per-agent data and
+ // the typed background_tasks control request is the reconciliation
+ // source. `control_request_progress` is a liveness heartbeat for an
+ // in-flight control request. `worker_shutting_down` is a Remote
+ // Control worker notice; the session close path reports the outcome.
case "model_refusal_fallback":
case "local_command_output":
case "plugin_install":
case "commands_changed":
case "memory_recall":
case "elicitation_complete":
+ case "background_tasks_changed":
+ case "control_request_progress":
+ case "worker_shutting_down":
+ return;
+ case "informational":
+ // Transcript-level CLI notes. Only warnings (e.g. a Stop hook that
+ // refused continuation) warrant a work-log row; info/notice/
+ // suggestion levels are CLI chrome.
+ if (message.level === "warning") {
+ yield* emitRuntimeWarning(context, message.content, message);
+ }
+ return;
+ case "model_refusal_no_fallback":
+ // The API refused the request and no fallback model was available.
+ // The terminal result reports the failed turn; this row carries the
+ // refusal explanation the result's error list lacks.
+ yield* emitRuntimeWarning(
+ context,
+ message.api_refusal_explanation?.trim() || message.content,
+ message,
+ );
return;
case "permission_denied":
yield* offerRuntimeEvent({
@@ -3528,7 +3622,7 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
// handled above, so `message` narrows to never here — a new SDK
// release adding a subtype fails this typecheck instead of silently
// warning at runtime. The runtime fallback still catches undeclared
- // wire-only subtypes (like background_tasks_changed used to be).
+ // wire-only subtypes (like vcs_state_changed).
message satisfies never;
const unknownMessage = message as never as { subtype: string };
yield* emitRuntimeWarning(
@@ -3657,7 +3751,10 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
yield* handleSdkTelemetryMessage(context, message);
return;
// Composer prompt suggestions have no T3 surface; consumed deliberately.
+ // `conversation_reset` announces a CLI-side conversation id swap
+ // (e.g. /clear); T3 keeps its own thread identity and resume cursor.
case "prompt_suggestion":
+ case "conversation_reset":
return;
default: {
// Exhaustiveness guard (see handleSystemMessage): new SDK top-level
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2a7e45ca857..d69028c3609 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -476,8 +476,8 @@ importers:
apps/server:
dependencies:
'@anthropic-ai/claude-agent-sdk':
- specifier: ^0.3.170
- version: 0.3.170(@anthropic-ai/[email protected]([email protected]))(@modelcontextprotocol/[email protected]([email protected]))([email protected])
+ specifier: ^0.3.260
+ version: 0.3.260(@anthropic-ai/[email protected]([email protected]))(@modelcontextprotocol/[email protected]([email protected]))([email protected])
'@effect/platform-bun':
specifier: 4.0.0-beta.103
version: 4.0.0-beta.103([email protected])([email protected](patch_hash=af36b7948b6f9c56623074662b51dade5699880c1a7c71245de73e13c3185fb6))([email protected])
@@ -1011,8 +1011,8 @@ packages:
'@alchemy.run/[email protected]':
resolution: {integrity: sha512-5agdhQxWBodxa5hDRyjnpx91RTU3g+qd5fxYB7uNDCaOzB0XC47UU/KHR6zf6jhz/NXf61gJS+vhYwn8NHeRoQ==}
- '@anthropic-ai/[email protected]':
- resolution: {integrity: sha512-pAvhfk+iTodXZ6RF18Kz7BEUWFjL7EcR3tKuhUNdPpE1NAYCR3mSHGbafi72JsrNwKEDIs7FU31z3fqhwy8QzA==}
+ '@anthropic-ai/[email protected]':
+ resolution: {integrity: sha512-PmABtP4Rwd6l95itQrqzguv6rS9uACqikPB9g8BPeWRKZOpy3xpEOjJLYauof3BFk2wNZnfhr0Ttx8ttcZzq0w==}
engines: {node: '>=18.0.0'}
peerDependencies:
'@anthropic-ai/sdk': '>=0.93.0'
@@ -10527,7 +10527,7 @@ snapshots:
'@alchemy.run/[email protected]': {}
dependencies:
'@anthropic-ai/sdk': 0.93.0([email protected])
'@modelcontextprotocol/sdk': 1.29.0([email protected])
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 7d2f9f99861..ee1bd25547f 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -90,6 +90,7 @@ minimumReleaseAgeExclude:
+ - "@anthropic-ai/[email protected]"
overrides:
# The SDK always receives the user's Claude executable, so its bundled binaries are unused.