Skip to content

Commit 6f41364

Browse files
fix(opencode): Claude usage limits through OpenCode keep their reset time (pingdotgg#29301)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a821f03 commit 6f41364

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
563563
status: 429,
564564
},
565565
},
566+
{
567+
name: "a Claude limit without a reset timestamp",
568+
failureClass: "usage_limit",
569+
error: {
570+
type: "provider.unknown",
571+
message: "You've hit your session limit · resets 5:20pm (Europe/Berlin)",
572+
},
573+
},
574+
{
575+
name: "an unrelated provider.unknown failure",
576+
failureClass: "provider_error",
577+
error: {
578+
type: "provider.unknown",
579+
message: "Request failed. Resets at 2026-11-02T20:00:00Z.",
580+
},
581+
},
566582
] as const)("classifies $name as $failureClass", ({ error, failureClass }) =>
567583
Effect.gen(function* () {
568584
const { runtime, thread } = yield* resumed([
@@ -583,6 +599,35 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
583599
}).pipe(Effect.scoped),
584600
);
585601

602+
// regression: #29289 Claude weekly limits through claude-agent lost their usage-limit reset
603+
it.effect(
604+
"classifies a Claude weekly limit as a usage limit that resets at its reported time",
605+
() =>
606+
Effect.gen(function* () {
607+
const message =
608+
"You've hit your weekly limit · resets 9pm (Europe/Paris) Resets at 2026-11-02T20:00:00.000Z.";
609+
const { runtime, thread } = yield* resumed([
610+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
611+
promptAccepted,
612+
event("session.execution.failed", {
613+
sessionID: SESSION,
614+
error: { type: "provider.unknown", message },
615+
}),
616+
]);
617+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
618+
yield* runtime.startTurn(turnInput(thread));
619+
const ended = yield* Fiber.join(terminal);
620+
assert.equal(ended?.status, "failed");
621+
assert.deepEqual(ended?.failure, {
622+
class: "usage_limit",
623+
code: "provider.unknown",
624+
message,
625+
retryable: null,
626+
resetAt: "2026-11-02T20:00:00.000Z",
627+
});
628+
}).pipe(Effect.scoped),
629+
);
630+
586631
it.effect("ends the turn when its terminal event is one this build cannot decode", () =>
587632
Effect.gen(function* () {
588633
const { runtime, thread } = yield* resumed([

‎packages/provider-opencode/src/server/v2/adapter.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ const wakeTurnId = (sessionId: string, attemptId: string) => `${sessionId}:wake:
524524
const isWakeTurn = (turn: OrchestrationV2ProviderTurn) =>
525525
turn.nativeTurnRef?.nativeId?.includes(":wake:") === true;
526526

527+
// OpenCode's claude-agent reports a spent Claude plan as provider.unknown with Claude's own text.
528+
const claudeUsageLimit = (message: string | undefined) =>
529+
message !== undefined && /^You've hit your [^\n·]*\blimit\b/.test(message)
530+
? { resetAt: /\bResets at (\d{4}-\d\d-\d\dT[\d:.]+Z)\.?\s*$/.exec(message)?.[1] ?? null }
531+
: undefined;
532+
527533
const INTERRUPT_TIMEOUT = "10 seconds";
528534
const INSTRUCTIONS_KEY = "t3-code";
529535
const RECONNECT_ATTEMPTS = 5;
@@ -2152,14 +2158,18 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
21522158
const { type, message, status, response } = event.data.error;
21532159
// OpenCode types an empty balance as provider.quota too, but it answers
21542160
// that with HTTP 402 and it never resets. Usage windows and budgets are 429.
2161+
const claudeLimit = claudeUsageLimit(message);
21552162
const usageLimit =
2156-
(type === "provider.quota" && status !== 402) || type === "provider.rate-limit";
2163+
(type === "provider.quota" && status !== 402) ||
2164+
type === "provider.rate-limit" ||
2165+
claudeLimit !== undefined;
21572166
return yield* endExecution(state, turn, {
21582167
status: "failed",
21592168
failure: makeProviderFailure({
21602169
message: readableProviderErrorMessage(message, status, response?.body),
21612170
code: type,
21622171
class: usageLimit ? "usage_limit" : "provider_error",
2172+
resetAt: claudeLimit?.resetAt ?? null,
21632173
}),
21642174
});
21652175
}

0 commit comments

Comments
 (0)