chenhg5/cc-connect · error

provider %q not found in project %q

Error message

provider %q not found in project %q

What it means

Provider model patcher: providerName was not found among the project's agent.providers names, nor among its provider_refs pointing at the global providers table, so no TOML key can be located to write the new model value and the update is aborted without modifying the file.

Source

Thrown at config/config.go:1260

	projSpan := spans[projectIdx]

	for j, prov := range cfg.Projects[projectIdx].Agent.Providers {
		if prov.Name == providerName {
			if j < len(projSpan.agentProviders) {
				ps := projSpan.agentProviders[j]
				lines = upsertTomlStringKey(lines, ps.start+1, ps.end, "model", model)
				return writeRawConfig(joinConfigLines(lines, hadTrailing))
			}
			break
		}
	}

	for _, ref := range cfg.Projects[projectIdx].Agent.ProviderRefs {
		if ref == providerName {
			return patchGlobalProviderField(lines, hadTrailing, cfg, providerName, "model", model)
		}
	}
	return fmt.Errorf("provider %q not found in project %q", providerName, projectName)
}

func patchGlobalProviderField(lines []string, hadTrailing bool, cfg *Config, providerName, key, value string) error {
	globalStarts := make([]int, 0, 4)
	for i := range lines {
		if matchTableHeader(lines[i], "[[providers]]") {
			globalStarts = append(globalStarts, i)
		}
	}
	for k, gp := range cfg.Providers {
		if gp.Name != providerName || k >= len(globalStarts) {
			continue
		}
		gstart := globalStarts[k]
		gend := len(lines) - 1
		if k+1 < len(globalStarts) {
			gend = globalStarts[k+1] - 1
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add the global provider's name to the project's provider_refs so it can be patched via [[providers]]
  2. Or define the provider inline under the project's agent.providers
  3. Correct the providerName argument to match an existing provider exactly
  4. Verify available names from the parsed config before saving

Example fix

// before
provider_refs = ["kimi"]
// after (provider "glm" now resolvable)
provider_refs = ["kimi", "glm"]
Defensive patterns

Strategy: validation

Validate before calling

known := map[string]bool{}
for _, p := range proj.Agent.Providers { known[p.Name] = true }
for _, r := range proj.Agent.ProviderRefs { known[r] = true }
if !known[providerName] { return fmt.Errorf("provider %q unknown", providerName) }

Try / catch

if err := config.SaveProviderModel(proj, prov, model); err != nil {
	if strings.Contains(err.Error(), "not found in project") {
		// offer to add the provider or fix the name
	}
	return err
}

Prevention

When it happens

Trigger: Calling SaveProviderModel(project, providerName, model) where providerName matches no cfg.Projects[idx].Agent.Providers[i].Name and is absent from Agent.ProviderRefs.

Common situations: Referring to a provider defined globally but never added to provider_refs; renaming a provider block but saving with the old name; typo in the provider name in a script.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/45b8c28eb311097e. Report an issue: GitHub.