I've often wondered how the game determines when Grimmy makes a visit - and I would guess it does some random probability calculation for each elder at the same time every day, adjusting the probability for any life-lengthening traits or achievements the Sim may have.
But in my dynasty attempt, Agnes left me wondering if there might be more to it than that. She had finished the tasks the dynasty needed of her (portraits of the founder, a replicator full of Ambrosia, a pond stocked with deathfish), and in her final days, she was trying to complete her LTW. I saw the "Expire" action appear in her queue while she was sitting at the computer working on the book that would complete her LTW. It was after midnight, and the moment she completed that book, she stood up and went to Grimmy. She was 92.
Watching that play out left me wondering whether the algorithm takes anything else into consideration, like allowing a Sim who is actively working on a wish to complete it before that bell tolls. Since then, I've had several other Sims expire of old age, and it doesn't seem to matter what they are doing at the time. My 2nd generation spouse made it to 112, even though he wasn't doing much toward the end, and the 3rd generation spouse was in her early 90s, despite still working as an Astronaut and working out frequently.
This thread reminds me to make a mental note to have the 6th generation of an Immortal Dynasty be a girl that takes an elder spouse, to make sure there is room in the house to bring in the final generation.