Open
Description
As mentioned in #7970 (comment), keeping the internal state of the plugin is currently done manually. This is prone to errors, increases the cognitive load during maintenance, and makes the code generally harder to understand. We should refactor it so that it's easier to understand and maintain invariants.