{"record":{"id":"5c9d8614d1fa01be","repo":"siyuan-note/siyuan","slug":"configuration-is-not-initialized","errorCode":null,"errorMessage":"configuration is not initialized","messagePattern":"configuration is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/client/oauth_store.go","lineNumber":107,"sourceCode":"\t\tlogging.LogWarnf(\"mcp oauth: parse credentials failed: %s\", err)\n\t\treturn\n\t}\n\toauthCredentialStore.credentials = data.Credentials\n}\n\nfunc decryptOAuthCredentials(ciphertext string) (decrypted []byte) {\n\tdefer func() {\n\t\tif recovered := recover(); recovered != nil {\n\t\t\tlogging.LogWarnf(\"mcp oauth: decrypt credentials failed: %v\", recovered)\n\t\t\tdecrypted = nil\n\t\t}\n\t}()\n\treturn util.AESDecrypt(ciphertext)\n}\n\nfunc persistOAuthCredentialsLocked() error {\n\tif model.Conf == nil {\n\t\treturn fmt.Errorf(\"configuration is not initialized\")\n\t}\n\tdata, err := json.Marshal(&oauthCredentialData{Credentials: oauthCredentialStore.credentials})\n\tif err != nil {\n\t\treturn err\n\t}\n\tmodel.Conf.SetMCPOAuth(util.AESEncrypt(string(data)))\n\treturn nil\n}\n\nfunc getOAuthCredential(serverID, endpoint string) (oauthCredential, bool) {\n\toauthCredentialStore.Lock()\n\tdefer oauthCredentialStore.Unlock()\n\tloadOAuthCredentialsLocked()\n\tfor i := len(oauthCredentialStore.credentials) - 1; i >= 0; i-- {\n\t\tcredential := oauthCredentialStore.credentials[i]\n\t\tcredentialEndpoint := credential.Endpoint\n\t\tif credentialEndpoint == \"\" {\n\t\t\tcredentialEndpoint = credential.Resource","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/client/oauth_store.go#L89-L125","documentation":"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.","triggerScenarios":"putOAuthCredential, removeOAuthCredential, or markOAuthCredentialRejected runs before kernel configuration initialization completes (or after it was torn down), reaching persistOAuthCredentialsLocked with model.Conf == nil.","commonSituations":"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.","solutions":["Ensure the kernel/workspace is fully booted (model.Conf loaded) before invoking MCP OAuth credential operations","In tests, initialize model.Conf (load or create a conf object) in the test setup before touching the credential store","If running embedded, call the same initialization path as kernel Boot() to populate model.Conf"],"exampleFix":"// before\nputOAuthCredential(cred) // Conf not loaded yet\n// after\nmodel.Conf = conf.NewAppConf() // or complete normal boot first\nputOAuthCredential(cred)","handlingStrategy":"validation","validationCode":"if model.Conf == nil {\n    return fmt.Errorf(\"configuration not initialized: complete kernel boot before MCP OAuth operations\")\n}","typeGuard":null,"tryCatchPattern":"if err := putOAuthCredential(cred); err != nil {\n    if strings.Contains(err.Error(), \"configuration is not initialized\") {\n        // defer persistence until after boot, or initialize conf now\n    }\n}","preventionTips":["Sequence MCP OAuth work after Conf loading in startup code","Initialize model.Conf in test fixtures","Avoid calling credential APIs from pre-boot hooks"],"tags":["config","initialization","mcp","oauth"],"backgroundTag":"missing-configuration","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}