Skip to Content
Motoko

The wake

In an evicted object pi-durable has no process to keep its timers in, so the runtime arms the host with pi-durable's wake: active while some task can run or is running, and at, the earliest sleep. The host keeps one Lifecycle job for it:

  • active: the job is due now;
  • asleep until at, nothing running: the job is due at at;
  • nothing to do: the job is cancelled.

The runtime arms only active from before every call that can start work until the call is done, also while other calls end, and arms what is due once no such call is under way, so a call that started nothing leaves no job behind and no job is cancelled under a call starting work.

When the job runs it calls instance.resume(). That opens the instance if the object was evicted, and opening carries on what the lost isolate left: pi-durable sends an interrupted model request again and reruns a replay-safe tool call. It also runs the sleeps now due. While work runs, the job waits on it past its own run, inside the alarm's work (trackAlarmWork, so the alarm's memory-limit breaker counts it), and keeps the job a heartbeat, 30 seconds, out: an object evicted mid-run is restarted by that alarm and carries the run on, with no call from anyone. A wait lasts at most ten minutes, since an alarm may run fifteen; longer work is waited on by a fresh alarm. While the job runs or waits, an arm only updates what it reads when it is done, so the job is never moved under itself. A run that fails through the Lifecycle's retries (the instance cannot open) is tried again a heartbeat out, doubling up to ten minutes, its count kept in the object's storage.

The capability never calls ctx.storage.setAlarm() and defines no alarm(): the Lifecycle owns the object's one alarm and sets it from the job queue.