Detecting action added into undo stack

Is there a way to detect whether some actions is(are) added into the undo stack?

What I’d like to do is to display the number of remaining undo actions and redo actions.
As an example ‘12/3’ means I can undo up to 12 steps or redo up to 3 steps from now.
But when I check undo stack right after the action which takes some time, I find that action is not added into stack yet.
Delaying undo stack checking would not be a solution.

Thanks in advance

I reproduced that behaviour. Looks like when you delete a task you need some time before the data appears in the undo stack.
If you don’t want to delay general undo stack check, you can use onBeforeUndoStack function and delay the undo stack check there because there is no onAfterUndoStack function. Here is the snippet demonstrating how it works: