siyuan-note/siyuan · error

configuration is not initialized

Error message

configuration is not initialized

What it means

persistOAuthCredentialsLocked needs the global model.Conf configuration object to persist (encrypted) MCP OAuth credentials, but Conf is nil — the application configuration has not been loaded/initialized yet. Writing the credential store is therefore aborted.

Solutions

  1. Ensure the kernel/workspace is fully booted (model.Conf loaded) before invoking MCP OAuth credential operations
  2. In tests, initialize model.Conf (load or create a conf object) in the test setup before touching the credential store
  3. If running embedded, call the same initialization path as kernel Boot() to populate model.Conf

Example fix

// before
putOAuthCredential(cred) // Conf not loaded yet
// after
model.Conf = conf.NewAppConf() // or complete normal boot first
putOAuthCredential(cred)
Defensive patterns

Strategy: validation

Validate before calling

if model.Conf == nil {
    return fmt.Errorf("configuration not initialized: complete kernel boot before MCP OAuth operations")
}

Try / catch

if err := putOAuthCredential(cred); err != nil {
    if strings.Contains(err.Error(), "configuration is not initialized") {
        // defer persistence until after boot, or initialize conf now
    }
}

Prevention

When it happens

Trigger: putOAuthCredential, removeOAuthCredential, or markOAuthCredentialRejected runs before kernel configuration initialization completes (or after it was torn down), reaching persistOAuthCredentialsLocked with model.Conf == nil.

Common situations: An MCP OAuth flow triggered very early during kernel boot before Conf is loaded; tests instantiating the credential store without initializing model.Conf; embedding the kernel without calling the standard workspace boot sequence.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/5c9d8614d1fa01be. Report an issue: GitHub.

Appendix: source

Thrown at kernel/mcp/client/oauth_store.go:107

		logging.LogWarnf("mcp oauth: parse credentials failed: %s", err)
		return
	}
	oauthCredentialStore.credentials = data.Credentials
}

func decryptOAuthCredentials(ciphertext string) (decrypted []byte) {
	defer func() {
		if recovered := recover(); recovered != nil {
			logging.LogWarnf("mcp oauth: decrypt credentials failed: %v", recovered)
			decrypted = nil
		}
	}()
	return util.AESDecrypt(ciphertext)
}

func persistOAuthCredentialsLocked() error {
	if model.Conf == nil {
		return fmt.Errorf("configuration is not initialized")
	}
	data, err := json.Marshal(&oauthCredentialData{Credentials: oauthCredentialStore.credentials})
	if err != nil {
		return err
	}
	model.Conf.SetMCPOAuth(util.AESEncrypt(string(data)))
	return nil
}

func getOAuthCredential(serverID, endpoint string) (oauthCredential, bool) {
	oauthCredentialStore.Lock()
	defer oauthCredentialStore.Unlock()
	loadOAuthCredentialsLocked()
	for i := len(oauthCredentialStore.credentials) - 1; i >= 0; i-- {
		credential := oauthCredentialStore.credentials[i]
		credentialEndpoint := credential.Endpoint
		if credentialEndpoint == "" {
			credentialEndpoint = credential.Resource

View on GitHub (pinned to 9f775e8a12)