router-for-me/CLIProxyAPI · error

core auth manager unavailable

Error message

core auth manager unavailable

What it means

Thrown by Host.authByIndex when the plugin host cannot resolve the core auth manager (h.currentAuthManager() returns nil). The auth manager is the shared registry of loaded credential files; without it, no auth_index can be resolved. It signals the host (or the SDK service backing it) was constructed or shut down without wiring the auth manager into the plugin host.

Source

Thrown at internal/pluginhost/auth_callbacks.go:222

				}
			}
		}
		files = append(files, fileEntry)
	}
	sort.Slice(files, func(i, j int) bool {
		return strings.ToLower(files[i].Name) < strings.ToLower(files[j].Name)
	})
	return files, nil
}

func (h *Host) authByIndex(authIndex string) (*coreauth.Auth, error) {
	authIndex = strings.TrimSpace(authIndex)
	if authIndex == "" {
		return nil, fmt.Errorf("auth_index is required")
	}
	manager := h.currentAuthManager()
	if manager == nil {
		return nil, fmt.Errorf("core auth manager unavailable")
	}
	for _, auth := range manager.List() {
		if auth == nil {
			continue
		}
		auth.EnsureIndex()
		if auth.Index == authIndex {
			return auth, nil
		}
	}
	return nil, fmt.Errorf("auth not found for auth_index %s", authIndex)
}

func (h *Host) authPhysicalJSONByIndex(authIndex string) (*coreauth.Auth, []byte, error) {
	auth, errGet := h.authByIndex(authIndex)
	if errGet != nil {
		return nil, nil, errGet
	}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Ensure the Host is created through the normal service builder path so the auth manager is set before any plugin callback runs
  2. If constructing Host manually (tests/tools), inject the core auth manager via the host's setter/option before calling auth callbacks
  3. Stop or gate plugin goroutines before tearing down the service so callbacks do not race manager teardown
  4. Retry once after startup completes if the callback fired during initialization

Example fix

// before
host := pluginhost.New(opts) // no auth manager wired
auth, err := host.AuthByIndex("abc") // core auth manager unavailable

// after
host := pluginhost.New(opts)
host.SetAuthManager(coreService.AuthManager()) // wire manager first
auth, err := host.AuthByIndex("abc")
Defensive patterns

Strategy: validation

Validate before calling

// before calling an auth-by-index callback:
if host.CurrentAuthManager() == nil {
    return fmt.Errorf("auth manager not ready; wire it before use")
}

Prevention

When it happens

Trigger: Calling a plugin host auth callback (e.g. hostAuthsList/Get-by-index style API) before the core service registered its auth manager, after the host was stopped/torn down, or when the Host was built standalone (e.g. tests or a plugin-only host) with no coreauth manager attached.

Common situations: Unit tests instantiating pluginhost.Host directly without injecting an auth manager; invoking plugin callbacks during shutdown while a plugin goroutine is still processing a request; embedding the SDK but skipping the builder step that connects the auth store.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/d37a9e7133bb6738. Report an issue: GitHub.