Skip to content

fix: expand model key regex and fallbackOn categories#27

Open
tmogeid wants to merge 1 commit into
Smart-Coders-HQ:mainfrom
tmogeid:fix/model-key-regex-and-docs
Open

fix: expand model key regex and fallbackOn categories#27
tmogeid wants to merge 1 commit into
Smart-Coders-HQ:mainfrom
tmogeid:fix/model-key-regex-and-docs

Conversation

@tmogeid

@tmogeid tmogeid commented Jul 17, 2026

Copy link
Copy Markdown

Problem

The MODEL_KEY_RE regex in src/config/schema.ts and src/config/agent-loader.ts uses charset [a-zA-Z0-9._-] for the modelID portion, which rejects model keys containing forward slashes or colons.

This blocks users from configuring fallback models with nested provider paths (e.g. nvidia/z-ai/glm-5.2, openrouter/tencent/hy3:free).

Additionally, the ErrorCategory type only supports 5 categories (rate_limit, quota_exceeded, 5xx, timeout, overloaded), which doesn't cover common failure modes like auth errors, billing issues, or premium subscription requirements.

Changes

1. Fix MODEL_KEY_RE regex

Add \/: to the modelID charset in both regex definitions:

- /^[a-zA-Z0-9_-]{1,100}\/[a-zA-Z0-9._-]{1,100}$/
+ /^[a-zA-Z0-9_-]{1,100}\/[a-zA-Z0-9._\/:-]{1,100}$/

This allows nested provider paths with slashes and colons (for model IDs like openrouter/tencent/hy3:free).

2. Expand ErrorCategory to 29 categories

The original 5 categories only covered rate limits, quotas, server errors, timeouts, and overload. The expanded set adds:

  • Auth errors: unauthorized, 401, 403
  • Credit errors: insufficient_credits, insufficient_balance, no_credits, out_of_credits, insufficient_funds
  • Billing errors: billing, credit_balance, payment_required
  • Premium barriers: premium, premium_subscription, subscription_required
  • HTTP status codes: 429, 500, 502, 503, 504
  • Limit errors: limit, insufficient_quota, quota_exceeded_message

3. Update classifier with new patterns

The classifier now recognizes messages like "unauthorized", "insufficient balance", "premium subscription", etc. and maps them to the appropriate categories.

4. Fix README

  • opencode.jsonc -> opencode.json (the correct filename)
  • Added nested provider path examples
  • Added extended fallbackOn categories documentation

Testing

  • TypeScript typecheck passes (tsc --noEmit — 0 errors)
  • All detection/config/agent-loader tests pass (51/51)
  • Full suite: 166 pass, 2 pre-existing failures (Windows file I/O, unrelated)

…ackOn to 29 categories

- Fix MODEL_KEY_RE regex to accept nested provider paths with slashes and colons
  (e.g. nvidia/z-ai/glm-5.2, openrouter/tencent/hy3:free)
- Expand ErrorCategory type from 5 to 29 categories for broader error coverage
- Update classifier to recognize new error patterns (auth, billing, premium, etc.)
- Fix README: opencode.jsonc -> opencode.json, add extended fallbackOn docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant