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
2 changes: 1 addition & 1 deletion src/plugin/hooks/create-session-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function createSessionHooks(args: {

// Model fallback hook (configurable via model_fallback config + disabled_hooks)
// This handles automatic model switching when model errors occur
const isModelFallbackConfigEnabled = pluginConfig.model_fallback ?? false
const isModelFallbackConfigEnabled = pluginConfig.model_fallback ?? true
const modelFallback = isModelFallbackConfigEnabled && isHookEnabled("model-fallback")
? safeHook("model-fallback", () =>
createModelFallbackHook({
Expand Down
8 changes: 8 additions & 0 deletions src/shared/model-error-classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ const RETRYABLE_MESSAGE_PATTERNS = [
"timeout",
"service unavailable",
"internal_server_error",
"free usage",
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Custom agent: Opencode Compatibility

To correctly align with the OpenCode SDK's error classification, FreeUsageLimitError must be handled as a structured error class rather than using a substring match on its message. The right approach is to add "FreeUsageLimitError" directly to the RETRYABLE_ERROR_NAMES Set (which explicitly checks error.name). Using "free usage" in RETRYABLE_MESSAGE_PATTERNS circumvents the SDK's type system and risks false positive retries.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/shared/model-error-classifier.ts, line 58:

<comment>To correctly align with the OpenCode SDK's error classification, `FreeUsageLimitError` must be handled as a structured error class rather than using a substring match on its message. The right approach is to add `"FreeUsageLimitError"` directly to the `RETRYABLE_ERROR_NAMES` Set (which explicitly checks `error.name`). Using `"free usage"` in `RETRYABLE_MESSAGE_PATTERNS` circumvents the SDK's type system and risks false positive retries.</comment>

<file context>
@@ -55,9 +55,17 @@ const RETRYABLE_MESSAGE_PATTERNS = [
   "timeout",
   "service unavailable",
   "internal_server_error",
+  "free usage",
+  "usage exceeded",
+  "credit",
</file context>
Fix with Cubic

"usage exceeded",
"credit",
"balance",
"temporarily unavailable",
"try again",
"503",
"502",
"504",
"429",
"529",
]

const AUTO_RETRY_GATE_PATTERNS = [
Expand Down
Loading