Durable-Object boot wiring. Fail fast if the backgroundTasks storage domain is
missing, re-register the static executors, start execution-mode workflow
workers, THEN call init(pubsub) — whose internal recoverStaleTasks()
re-drives any task the evicted instance left mid-flight. Executors and the
workflow subscriber both go in BEFORE recovery publishes work. A failed
startup unwinds attempted components in reverse order. Memoized per
instance: init is itself idempotent (initPromise), and boot() from both
fetch() and alarm() must not double-register.
DO-alarm duty: ensure the DO is booted (a FRESH post-eviction instance
recovers HERE, since the alarm is what woke it — see the recovery seam
above), then run the manager's TTL cleanup. The hosting DO re-arms the alarm
after this returns. Cleanup is core's own cleanup() — the belt to the
storage-layer purgeExpiredBackgroundTasks cron braces (that one needs no
live manager); running both is harmless (each only deletes rows past the
TTL).
A BackgroundTaskManager bound to a hosting DO's Mastra + pubsub, with the boot/alarm lifecycle that makes DO eviction survivable. The hosting DO owns alarm arming (it needs
ctx.storage.setAlarm); this class owns the manager wiring, the recovery-firingboot(), and the alarmcleanup()duty. The raw manager is reachable as.managerfor the tenant-bound routes to wrap — never expose it directly over HTTP.