I got an answer from the Godot forum (thanks hexgrid!). It turns out the program is trying to evaluate the comparison before it evaluates undo_queue.size(), so making it a little wordier as such:
var slots = undo_queue.size()
if slots > QUEUE_LIMIT:
...
...
fixed the issue.