@devries-cameron20 / t3code-1 / commits / 6f41364805
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(opencode): Claude usage limits through OpenCode keep their reset time (#29301)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 2, 2026 at 11:47 UTC 6f41364805e31a1f8d59c18c7cc451630cd9265d
2 files changed +56 -1
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+45
@@ -563,6 +563,22 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
563 status: 429,
564 },
565 },
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 + },
582 ] as const)("classifies $name as $failureClass", ({ error, failureClass }) =>
583 Effect.gen(function* () {
584 const { runtime, thread } = yield* resumed([
@@ -583,6 +599,35 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
599 }).pipe(Effect.scoped),
600 );
601
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 +
631 it.effect("ends the turn when its terminal event is one this build cannot decode", () =>
632 Effect.gen(function* () {
633 const { runtime, thread } = yield* resumed([
packages/provider-opencode/src/server/v2/adapter.ts
+11 -1
@@ -524,6 +524,12 @@ const wakeTurnId = (sessionId: string, attemptId: string) => `${sessionId}:wake:
524 const isWakeTurn = (turn: OrchestrationV2ProviderTurn) =>
525 turn.nativeTurnRef?.nativeId?.includes(":wake:") === true;
526
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 +
533 const INTERRUPT_TIMEOUT = "10 seconds";
534 const INSTRUCTIONS_KEY = "t3-code";
535 const RECONNECT_ATTEMPTS = 5;
@@ -2152,14 +2158,18 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
2158 const { type, message, status, response } = event.data.error;
2159 // OpenCode types an empty balance as provider.quota too, but it answers
2160 // that with HTTP 402 and it never resets. Usage windows and budgets are 429.
2161 + const claudeLimit = claudeUsageLimit(message);
2162 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;
2166 return yield* endExecution(state, turn, {
2167 status: "failed",
2168 failure: makeProviderFailure({
2169 message: readableProviderErrorMessage(message, status, response?.body),
2170 code: type,
2171 class: usageLimit ? "usage_limit" : "provider_error",
2172 + resetAt: claudeLimit?.resetAt ?? null,
2173 }),
2174 });
2175 }