Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ passed, the thread is still eligible, and its persisted run/message identity is
scheduler's tick therefore adds at most five seconds of timing slack, while the provider reset time
controls the earliest continuation.

Claude gateway 429 responses can put their cooldown after a nested upstream error and include
the provider name in the message. The adapter reads the gateway's countdown in either position
and leaves any countdown quoted inside the upstream error out of the recovery time.

The fork retains its explicit continuation prompt, which asks the provider to resume only incomplete
work, inspect the current workspace and subagent state, repair partial operations, and avoid
repeating completed work or expanding scope. Recovery survives a server restart, as upstream now supports. An explicit thread restart, archive, settle, a newer turn, or a changed provider selection invalidates the saved recovery. The one-hour wait and scheduler behavior are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10045,6 +10045,24 @@ describe("ClaudeAdapterV2 background wake turns", () => {
it.effect.each([
{ cooldown: " (reset after 1h2m3s)", seconds: 3723 },
{ cooldown: " (reset after 4m 6s) (last error: rate limited)", seconds: 246 },
{
cooldown:
" via provider claude (last error: rate_limit_error: Please try again later.) (reset after 1h39m47s)",
seconds: 5987,
},
{
cooldown: " via provider claude (reset after 1m) (last error: rate limited (reset after 1h))",
seconds: 60,
},
{
cooldown: " (last error: rate limited (reset after 1h)) (reset after 1m)",
seconds: 60,
description: "Server is temporarily limiting requests (not your usage limit)",
},
{
cooldown: " via provider claude (last error: rate limited (reset after 1h))",
seconds: 0,
},
{ cooldown: "", seconds: 0 },
])("keeps a gateway's reset on a direct 429 with cooldown '$cooldown'", (input) =>
Effect.gen(function* () {
Expand All @@ -10061,7 +10079,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
}),
);
// An API-key session reports a gateway 429 only as text, with no rate_limit_info.
const result = `API Error: Request rejected (429) · All credentials for model claude-opus-5-5 are cooling down${input.cooldown}`;
const result = `API Error: ${input.description ?? "Request rejected (429)"} · All credentials for model claude-opus-5-5 are cooling down${input.cooldown}`;
yield* Queue.offerAll(harness.sdkMessages, [
makeAssistantErrorFrame({
uuid: "00000000-0000-4000-8000-000000000654",
Expand Down
27 changes: 17 additions & 10 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4860,6 +4860,22 @@ function gatewayCooldownResetAt(
: undefined;
}

function gateway429Cooldown(result: string) {
const proxyHeader =
/^API Error: (?:Request rejected \(429\)|Server is temporarily limiting requests \(not your usage limit\)) · All credentials for model (?:requested model|[^\s()]+) are cooling down(?: via provider [^\s()]+)?(?: |$)/.exec(
result,
);
if (proxyHeader === null)
return /\(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/.exec(result);

// The proxy appends its countdown before or after the quoted upstream error.
const details = result.slice(proxyHeader[0].length);
return (
/^\(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/.exec(details) ??
/^\(last error: [\s\S]*\) \(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)$/.exec(details)
);
}

const CLAUDE_UNSUPPORTED_VERSION_ERROR =
/^API Error: 400 Claude Code (\d+\.\d+\.\d+) does not support this model; version (\d+\.\d+\.\d+) or newer is required\./;

Expand Down Expand Up @@ -4937,16 +4953,7 @@ function providerFailureFromResult(
// API-key sessions get no rate_limit_info, so a gateway's 429 carries its reset only as text.
const resetAt =
apiErrorStatus === 429 && message.result.startsWith("API Error:")
? gatewayCooldownResetAt(
// CLIProxyAPI nests upstream errors in its message; only its own cooldown counts.
(message.result.startsWith(
"API Error: Request rejected (429) · All credentials for model ",
)
? /^API Error: Request rejected \(429\) · All credentials for model [^\s()]+ are cooling down \(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/
: /\(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/
).exec(message.result),
receivedAt,
)
? gatewayCooldownResetAt(gateway429Cooldown(message.result), receivedAt)
: undefined;
return makeProviderFailure({
message: listedError ?? structuredError ?? failureHint ?? message.result,
Expand Down
Loading