I don't really understand what's going on with logger.remove_uncommitted_logs, but that basically shouldn't exist. Those servers made a promise to store entries to some prior leader. It's only safe to break that promise if they know those entries were never marked committed. Remember the basic safety property is: entries are marked committed => those entries will exist on every future leader. The contrapositive is: an entry does not exist on a future leader => the entry was not marked committed. So the only time we know it's safe to discard entries is if we know they conflict with the current leader's log.
I don't really understand what's going on with logger.remove_uncommitted_logs, but that basically shouldn't exist. Those servers made a promise to store entries to some prior leader. It's only safe to break that promise if they know those entries were never marked committed. Remember the basic safety property is: entries are marked committed => those entries will exist on every future leader. The contrapositive is: an entry does not exist on a future leader => the entry was not marked committed. So the only time we know it's safe to discard entries is if we know they conflict with the current leader's log.