If a pet runs out of longevity it can no longer be used but will not disappear unless you release it
Items to increase longevity are quite difficult to obtain but can be sometimes obtained
When you try and capture a pet, or from homestead trades and the apex mystery wheel