Skip to content

Commit 5d174be

Browse files
t3dotggclaude
andcommitted
fix(server): mark 529 overload results as failed turns
A success-subtype result with api_error_status 529 carried an error message but kept the completed status. Route the overload check through one helper used by both the status and the error message, and add a test. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 7c03cd9 commit 5d174be

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,56 @@ describe("ClaudeAdapterLive", () => {
17881788
);
17891789
});
17901790

1791+
it.effect("fails a turn when a success result reports a 529 overload", () => {
1792+
const harness = makeHarness();
1793+
return Effect.gen(function* () {
1794+
const adapter = yield* ClaudeAdapter;
1795+
1796+
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
1797+
Stream.runCollect,
1798+
Effect.forkChild,
1799+
);
1800+
1801+
const session = yield* adapter.startSession({
1802+
threadId: THREAD_ID,
1803+
provider: ProviderDriverKind.make("claudeAgent"),
1804+
runtimeMode: "full-access",
1805+
});
1806+
1807+
yield* adapter.sendTurn({
1808+
threadId: session.threadId,
1809+
input: "hello",
1810+
attachments: [],
1811+
});
1812+
1813+
harness.query.emit({
1814+
type: "result",
1815+
subtype: "success",
1816+
is_error: true,
1817+
api_error_status: 529,
1818+
result: "",
1819+
errors: [],
1820+
stop_reason: null,
1821+
session_id: "sdk-session-overload",
1822+
uuid: "result-overload",
1823+
} as unknown as SDKMessage);
1824+
1825+
const runtimeEvents = Array.from(yield* Fiber.join(runtimeEventsFiber));
1826+
const turnCompleted = runtimeEvents[runtimeEvents.length - 1];
1827+
assert.equal(turnCompleted?.type, "turn.completed");
1828+
if (turnCompleted?.type === "turn.completed") {
1829+
assert.equal(turnCompleted.payload.state, "failed");
1830+
assert.equal(
1831+
turnCompleted.payload.errorMessage,
1832+
"Claude API is overloaded (529). Try again shortly.",
1833+
);
1834+
}
1835+
}).pipe(
1836+
Effect.provideService(Random.Random, makeDeterministicRandomService()),
1837+
Effect.provide(harness.layer),
1838+
);
1839+
});
1840+
17911841
it.effect("interruptTurn settles live tasks and closes the provider session", () => {
17921842
const harness = makeHarness();
17931843
return Effect.gen(function* () {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function resultUserFacingError(result: SDKResultMessage): string | undefined {
438438
// Structured failure markers for results whose error list is empty or
439439
// diagnostic-only: an overloaded API (529) and the terminal reasons the
440440
// CLI stamps when it gives up on a turn.
441-
if (result.subtype === "success" && result.api_error_status === 529) {
441+
if (isOverloadedResult(result)) {
442442
return "Claude API is overloaded (529). Try again shortly.";
443443
}
444444
switch (result.terminal_reason) {
@@ -1394,8 +1394,20 @@ const FAILED_TERMINAL_REASONS: ReadonlySet<NonNullable<SDKResultMessage["termina
13941394
"turn_setup_failed",
13951395
]);
13961396

1397+
/**
1398+
* The CLI reports repeated 529 overload failures as a success-subtype result
1399+
* with api_error_status 529 and an empty error list; the status code is the
1400+
* only structured failure signal.
1401+
*/
1402+
function isOverloadedResult(result: SDKResultMessage): boolean {
1403+
return result.subtype === "success" && result.api_error_status === 529;
1404+
}
1405+
13971406
function turnStatusFromResult(result: SDKResultMessage): ProviderRuntimeTurnStatus {
1398-
if (result.terminal_reason !== undefined && FAILED_TERMINAL_REASONS.has(result.terminal_reason)) {
1407+
if (
1408+
isOverloadedResult(result) ||
1409+
(result.terminal_reason !== undefined && FAILED_TERMINAL_REASONS.has(result.terminal_reason))
1410+
) {
13991411
return "failed";
14001412
}
14011413
if (result.subtype === "success") {

0 commit comments

Comments
 (0)