Skip to content

Commit 8eb2f13

Browse files
author
pi-workspace
committed
fix(opencode): OpenCode Go quota stops show as usage limits
OpenCode types its own execution failures: an exhausted subscription is `provider.quota` and a 429 is `provider.rate-limit`. The OpenCode 2 adapter forwarded that code but hardcoded the T3 failure class to `provider_error`, so a Go usage limit failed the thread as a generic provider error instead of showing Limited. Map those two types to `usage_limit`; every other type stays `provider_error`. No reset time is set, since OpenCode does not report one. Refs #16366
1 parent 5047ee7 commit 8eb2f13

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,44 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
532532
}).pipe(Effect.scoped),
533533
);
534534

535+
it.effect("shows an OpenCode Go quota stop as a usage limit", () =>
536+
Effect.gen(function* () {
537+
const { runtime, thread } = yield* resumed([
538+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
539+
promptAccepted,
540+
// OpenCode's typed quota failure, as an exhausted Go session reports it.
541+
event("session.execution.failed", {
542+
sessionID: SESSION,
543+
error: { type: "provider.quota", message: "Go usage limit exceeded" },
544+
}),
545+
]);
546+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
547+
yield* runtime.startTurn(turnInput(thread));
548+
const ended = yield* Fiber.join(terminal);
549+
assert.equal(ended?.status, "failed");
550+
assert.equal(ended?.status === "failed" ? ended.failure.class : undefined, "usage_limit");
551+
assert.equal(ended?.status === "failed" ? ended.failure.code : undefined, "provider.quota");
552+
}).pipe(Effect.scoped),
553+
);
554+
555+
it.effect("shows an OpenCode rate-limit stop as a usage limit", () =>
556+
Effect.gen(function* () {
557+
const { runtime, thread } = yield* resumed([
558+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
559+
promptAccepted,
560+
event("session.execution.failed", {
561+
sessionID: SESSION,
562+
error: { type: "provider.rate-limit", message: "Rate limit exceeded" },
563+
}),
564+
]);
565+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
566+
yield* runtime.startTurn(turnInput(thread));
567+
const ended = yield* Fiber.join(terminal);
568+
assert.equal(ended?.status, "failed");
569+
assert.equal(ended?.status === "failed" ? ended.failure.class : undefined, "usage_limit");
570+
}).pipe(Effect.scoped),
571+
);
572+
535573
it.effect("ends the turn when its terminal event is one this build cannot decode", () =>
536574
Effect.gen(function* () {
537575
const { runtime, thread } = yield* resumed([

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
type OrchestrationV2ConversationMessage,
4343
type OrchestrationV2ExecutionNode,
4444
type OrchestrationV2ProviderCapabilities,
45+
type OrchestrationV2ProviderFailureClass,
4546
type OrchestrationV2ProviderSession,
4647
type OrchestrationV2ProviderThread,
4748
type OrchestrationV2ProviderTurn,
@@ -649,6 +650,14 @@ const stringField = (record: Readonly<Record<string, unknown>> | undefined, key:
649650
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
650651
};
651652

653+
/**
654+
* OpenCode types its own execution failures. A quota or rate-limit stop is the
655+
* usage limit T3 already recovers from, not a generic provider error, so the
656+
* thread shows Limited instead of Failed. OpenCode reports no reset time.
657+
*/
658+
const failureClassFor = (type: string): OrchestrationV2ProviderFailureClass =>
659+
type === "provider.quota" || type === "provider.rate-limit" ? "usage_limit" : "provider_error";
660+
652661
/** How a background subagent ended, from the `state` of OpenCode's report to its parent. */
653662
const reportOutcome = (state: string | undefined) =>
654663
state === "completed"
@@ -2366,7 +2375,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
23662375
failure: makeProviderFailure({
23672376
message: event.data.error.message,
23682377
code: event.data.error.type,
2369-
class: "provider_error",
2378+
class: failureClassFor(event.data.error.type),
23702379
}),
23712380
});
23722381
default:

0 commit comments

Comments
 (0)