{"record":{"id":"ebc9d89d1c5887ea","repo":"Tencent/WeKnora","slug":"failed-to-record-authorization-completion-w","errorCode":null,"errorMessage":"failed to record authorization completion: %w","messagePattern":"failed to record authorization completion: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/oauth_manager.go","lineNumber":219,"sourceCode":"\t\treturn frontendRedirect, serviceID, fmt.Errorf(\"failed to load MCP service: %w\", err)\n\t}\n\tif service == nil {\n\t\treturn frontendRedirect, serviceID, fmt.Errorf(\"MCP service not found\")\n\t}\n\n\th, err := m.newHandler(ctx, service, st.TenantID, principal, st.RedirectURI)\n\tif err != nil {\n\t\treturn frontendRedirect, serviceID, err\n\t}\n\t// Re-prime the expected state so the library's CSRF check passes after\n\t// reconstructing the handler in this separate request.\n\th.SetExpectedState(state)\n\n\tif err := h.ProcessAuthorizationResponse(ctx, code, state, st.CodeVerifier); err != nil {\n\t\treturn frontendRedirect, serviceID, fmt.Errorf(\"token exchange failed: %w\", err)\n\t}\n\tif err := m.states.CompleteAttempt(ctx, state); err != nil {\n\t\treturn frontendRedirect, serviceID, fmt.Errorf(\"failed to record authorization completion: %w\", err)\n\t}\n\t// ProcessAuthorizationResponse persists the token via the TokenStore.\n\tlogger.GetLogger(ctx).Infof(\n\t\t\"MCP OAuth authorized: service=%s principal=%s\", st.ServiceID, principal.StorageID(),\n\t)\n\treturn frontendRedirect, serviceID, nil\n}\n\n// IsAuthorizationAttemptComplete reports whether this exact authorization\n// attempt completed for the requested principal and service. A pre-existing\n// token must never satisfy a newly opened OAuth popup.\nfunc (m *OAuthManager) IsAuthorizationAttemptComplete(\n\tctx context.Context,\n\ttenantID uint64,\n\tprincipal types.Principal,\n\tserviceID, attemptID string,\n) (bool, error) {\n\tattempt, err := m.states.Attempt(ctx, attemptID)","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/oauth_manager.go#L201-L237","documentation":"Returned by CompleteAuthorization when, after a successful token exchange, recording the completion (persisting tokens/linked client state via the manager's completion step) fails. The user is authorized upstream but the system has not durably saved it, so the connection appears incomplete.","triggerScenarios":"Thrown at internal/mcp/oauth_manager.go:219 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error for the storage/backend cause","Verify token persistence repository health and connectivity","Retry the completion; the provider session may allow re-running without re-consent"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}