Refactor and fix the leader election in agentk
- Refactor leader election to make it more robust
This change set refactors the leader election implemented with the leader runner and the leader module wrapper.
The refactored implementation fixes the problems mentioned in #398 (closed), but also fixes additional bugs that were discovered during the refactoring, including that a module could have never been restarted after being re-elected as the leader.
The leader module wrapper now has the responsibility to start and stop the module. The leader module wrapper registers and unregisters callbacks to the leader runner in order to request a start or stop of the module depending on the leadership status.
Closes: #398 (closed)
- Always run leader election
This changes the leader runner behavior which previously conditionally depending on if there were any leader modules registered would start the election or not. Now, it always starts the election.
However, in reality this doesn't happen, because e.g. the
startboard_vulnerability
module is a leader-only module an is always
enabled.