When you say that all references originating from the old esp are deleted, is that a new behavior by OpenMW or is Vanilla Morrowind doing the same?
I think vanilla is doing the same, but I'm not sure (been way too long).
Can you please explain a bit more why this process isn't perfect?
As in existing objects you gained (like gold) would stay with you even if you deleted an esp that gave a quest with a gold reward, but would removing the esp remove the quest from the journal and npcs added with it?
In this example, the gold would remain, the quest / added NPCs would be gone.
There are a few more complications. Let's say the mod moves an object from a parent plugin to another location, and because of an unrelated change that object happens to get stored in your savegame - then it'll remain in the new position after the mod is removed. Creatures spawned by a levelled list are not going to be removed. Objects placed at runtime by scripts will not be removed.
If such plugin were to be reactivated, would the quest be able to be restarted as if it never was done in the first place with the OpenMW implementation?
Theoretically yes, assuming we don't have a bug somewhere and that quest isn't affected by any of the above gotchas.
Are scripts kept track of in the OpenMW save file format and deleted from runtime when an esp that added them is removed?
Yes.
So then, the OpenMW way is cleaning the save file in the same way that save cleaner software works by removing unused references and scripts? Just automatically without user input? Vanilla mods that require to clean a save to install/uninstall and such don't need the extra step like before by the user?
I have no idea how said software precisely works.