Thread-state TTL cleanup: deletes thread-state rows
from mastra_thread_state once their updatedAt is older than the TTL. Keys
on updatedAt for the same reason purgeExpiredThreads does — thread state
has no terminal status, so time-since-last-write is the only "done" signal.
ISO-8601 TEXT encoding; missing table reads as zero; scheduling stays with the
caller. Independent of the thread TTL (an orphan row is reaped here or at
offboarding by purgeTenant), so it self-bounds without touching the delicate
messages-before-threads ordering of purgeExpiredThreads.
Thread-state TTL cleanup: deletes thread-state rows from
mastra_thread_stateonce theirupdatedAtis older than the TTL. Keys onupdatedAtfor the same reasonpurgeExpiredThreadsdoes — thread state has no terminal status, so time-since-last-write is the only "done" signal. ISO-8601 TEXT encoding; missing table reads as zero; scheduling stays with the caller. Independent of the thread TTL (an orphan row is reaped here or at offboarding by purgeTenant), so it self-bounds without touching the delicate messages-before-threads ordering of purgeExpiredThreads.