plandex-ai/plandex · error

model config is nil

Error message

model config is nil

What it means

During streaming chat completion, the code resolves which model/fallback config to use via modelConfig.GetFallbackForModelError. If that returns a FallbackResult whose ModelRoleConfig is nil, there is no model role configuration to route the request to, and the library aborts with "model config is nil". This is an internal configuration-resolution failure: the fallback resolver produced no usable model config for this request/retry state.

Source

Thrown at app/server/model/client.go:176

			authVars,
			settings,
			orgUserConfig,
			currentOrgId,
			currentUserId,
		)

		fallbackRes := modelConfig.GetFallbackForModelError(
			numTotalRetry,
			didProviderFallback,
			modelErr,
			authVars,
			settings,
			orgUserConfig,
		)
		resolvedModelConfig := fallbackRes.ModelRoleConfig

		if resolvedModelConfig == nil {
			return nil, fallbackRes, fmt.Errorf("model config is nil")
		}

		providerComposite := resolvedModelConfig.GetProviderComposite(authVars, settings, orgUserConfig)

		baseModelConfig := resolvedModelConfig.GetBaseModelConfig(authVars, settings, orgUserConfig)

		opClient, ok := clients[providerComposite]

		if !ok {
			return nil, fallbackRes, fmt.Errorf("client not found for provider composite: %s", providerComposite)
		}

		if modelErr != nil && modelErr.Kind == shared.ErrCacheSupport {
			for i := range req.Messages {
				for j := range req.Messages[i].Content {
					if req.Messages[i].Content[j].CacheControl != nil {
						req.Messages[i].Content[j].CacheControl = nil
					}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Verify PlanSettings/orgUserConfig define a valid ModelRoleConfig for every model role used by the request and its fallback chain.
  2. Check GetFallbackForModelError: ensure the fallback chain for the requested model has at least one remaining candidate at every retry depth.
  3. Log fallbackRes (number of retries, didProviderFallback, modelErr) before this error to see why resolution failed.
  4. Guard the caller: validate modelConfig/fallback resolution before invoking the streaming call and surface a clear 'no model configured' error to the user.

Example fix

// before
fallbackRes := modelConfig.GetFallbackForModelError(...)
resolvedModelConfig := fallbackRes.ModelRoleConfig
if resolvedModelConfig == nil {
    return nil, fallbackRes, fmt.Errorf("model config is nil")
}
// after
fallbackRes := modelConfig.GetFallbackForModelError(...)
resolvedModelConfig := fallbackRes.ModelRoleConfig
if resolvedModelConfig == nil {
    return nil, fallbackRes, fmt.Errorf("model config is nil for model=%s after retries=%d fallback=%v: %w",
        req.Model, numTotalRetry, didProviderFallback, shared.ErrNoModelConfig)
}
Defensive patterns

Strategy: validation

Validate before calling

// before calling the streaming API
if modelConfig == nil || modelConfig.GetFallbackForModelError(0, false, nil, authVars, settings, orgUserConfig).ModelRoleConfig == nil {
    return fmt.Errorf("no model role configured for model %s; check plan settings and fallback chain", req.Model)
}

Type guard

func hasModelConfig(fb shared.FallbackResult) bool {
    return fb.ModelRoleConfig != nil
}

Try / catch

resp, fallbackRes, err := createChatCompletionStreamExtended(...)
if err != nil {
    if strings.Contains(err.Error(), "model config is nil") {
        log.Printf("model routing failed: retries/fallbacks exhausted, fallbackRes=%+v", fallbackRes)
        return fmt.Errorf("no model available for this request: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: createChatCompletionStreamExtended is called through withStreamingRetries; on any retry (numTotalRetry > 0) or provider fallback (didProviderFallback) or model error, GetFallbackForModelError returns a FallbackResult whose ModelRoleConfig is nil — e.g. all configured fallback models exhausted, or the plan/org settings contain no config for the requested model role.

Common situations: Org/user plan settings reference a model role that is not configured; all fallback models have been tried and removed; misconfigured FallbackChains so the resolver runs out of candidates; settings deserialization yielding empty ModelRoleConfig entries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/428182f6ca82e0d4. Report an issue: GitHub.