Hmbown/CodeWhale · error

The provider catalog exceeds

Error message

The provider catalog exceeds ${MAX_PROVIDER_MODELS} models.

What it means

Thrown when appending a fetched page would push the accumulated model entries past MAX_PROVIDER_MODELS, the hard cap on catalog size. It prevents unbounded memory growth in the browser if a provider reports an enormous or runaway catalog.

Solutions

  1. Reduce the number of models the provider exposes or filter the provider's model list in configuration
  2. Restart loading after fixing any Runtime cursor bug (overlapping pages)
  3. Check the Runtime for duplicate entries across pages that inflate entries.length
  4. Raise MAX_PROVIDER_MODELS only if a legitimately huge catalog must be supported

Example fix

// before: fetching all pages unconditionally
const models = await collectProviderModelPages(provider.id, fetchPage);
// after: pre-filter the provider or paginate from a filtered query
const models = await collectProviderModelPages(provider.id, (p) => fetchPage(p + '?search=' + query));
Defensive patterns

Strategy: validation

Validate before calling

if (provider.modelCount > MAX_PROVIDER_MODELS) warn('provider catalog exceeds client cap before loading');

Type guard

const fitsCap = (n, cap) => Number.isSafeInteger(n) && n >= 0 && n <= cap;

Try / catch

try { models = await collectProviderModelPages(id, fetch); } catch (e) { if (String(e.message).includes('exceeds')) offerFilteredSearch(); }

Prevention

When it happens

Trigger: entries.length + pageEntries.length > MAX_PROVIDER_MODELS during pagination — the provider's catalog is larger than the cap, or a cursor loop is fetching more entries than `total` promised.

Common situations: A provider exposing tens of thousands of models; a Runtime cursor bug returning overlapping pages so entries accumulate past total; a misconfigured provider config listing a non-paginated mega-catalog.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/60accf68f2e8c22a. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_web/app.mjs:682

      `/v1/providers/${encodeURIComponent(provider)}/models?${query.toString()}`,
    );
    if (String(response?.provider || "") !== provider) {
      throw new Error("The Runtime returned a model page for a different provider.");
    }
    if (!Array.isArray(response?.models)
      || response.models.length > PROVIDER_MODELS_PAGE_SIZE
      || !Number.isSafeInteger(response.total)
      || response.total < 0
      || response.total > MAX_PROVIDER_MODELS) {
      throw new Error("The Runtime returned an invalid provider model page.");
    }
    if (expectedTotal !== undefined && expectedTotal !== response.total) {
      throw new Error("The provider catalog changed; restart loading its models.");
    }
    expectedTotal = response.total;
    const pageEntries = response.models;
    if (entries.length + pageEntries.length > MAX_PROVIDER_MODELS) {
      throw new Error(`The provider catalog exceeds ${MAX_PROVIDER_MODELS} models.`);
    }
    entries.push(...pageEntries);

    const nextCursor = typeof response?.nextCursor === "string"
      ? response.nextCursor.trim()
      : "";
    if (!nextCursor) {
      if (entries.length !== expectedTotal) {
        throw new Error("The Runtime returned an incomplete provider model catalog.");
      }
      return entries;
    }
    if (pageEntries.length === 0 || seenCursors.has(nextCursor)) {
      throw new Error("The Runtime returned a non-progressing model cursor.");
    }
    if (entries.length >= expectedTotal) {
      throw new Error("The Runtime returned a cursor beyond its provider model catalog.");
    }

View on GitHub (pinned to 73e0f67d83)