Proper way to update shader graph in the session

I use the Cycles render engine inside an other application (as render engine, of course). So, if I would like to render the scene, I create a session, add objects and shaders to the scene, and then call


All words perfect. But after that I would like to change one parameter in one shader, or use some new shader for one of the object inside the scene. Instead of recreating the session from scratch (because it can take many time, if the scene contains heavy geometry), I should simply update the graph of the changed shader. So, I build new graph and call


It seem that this is not enough. For example, if the old graph in the shader contains DiffuseBSDF node, and new graph contains PrincipledBSDF node, then the render process is crashed.
Ok, I find, that if for all objects with changed shader call the method


then the Cycles properly update the shader graph and render finished correctly. But I think that this is not proper method, because in the Blender connector to the Cycles this method is never called. May be I should use another method to tagging require updates?

Another related problem. If the shader contains displacement node (connected to the Displacement output of the shader), then after rendering process the positions of the mesh vertices is shifted from it original positions. After updating this shader and starting new rendering process, the object is rendered deformed twice (vertices shifted by the previous version of the shader and the new one).

So, the question - what the proper way to update or change the shader’s graph without recreation session from scratch? What objects should be tag updated? Or may be some initial setting of the session should be defined?