Workers, leases, and wakeups
See how workers claim tasks and how interrupted work becomes available again.
Workers turn queued runs into task attempts. Storage remains the source of truth throughout that process.
For local development, runlane dev owns the memory store and starts a worker. App and worker processes connect over its loopback bridge. Without dev, local storage operations fail. In tests, use createTestLane() and control execution with drain() or executeNext().
A lease gives one worker temporary ownership
Before it calls your code, a worker asks storage to claim the run. A successful claim creates a lease. Other workers lose the same claim and do not start that attempt under normal operation.
Configure ownership duration through the runtime lease settings. A shorter lease speeds crash recovery, but a worker that cannot refresh it in time loses ownership and another worker may run the task again.
Long attempts refresh their lease. Connection errors are recorded and retried; one failed refresh does not stop an attempt. Runlane stops when ownership is proven lost or its lease-derived renewal deadline passes without confirmation. These heartbeats update current ownership without adding an event each time. If a worker loses ownership, it cannot later store a success as though it still owns the attempt.
A wakeup is only a hint
A storage-polling worker scans durable state for runnable work. A transport lane sends a message that tells a worker which run to check. In both cases, the worker re-reads storage before it executes anything.
This makes duplicate, late, and stale SQS messages safe inputs. They are not separate jobs and do not carry authoritative task state. If another path already moved the run forward, core ignores or resolves the old wakeup.
Long-running SQS workers use a short visibility window while a message waits to be claimed. On standard queues, they delete the message once storage saves the claim. The run's lease then protects the task. FIFO messages stay held through completion so another worker cannot start the next message in the group too soon. See how the SQS worker holds messages.
Interrupted work becomes available again
When a worker stops refreshing its lease, the lease eventually expires. Maintenance and runnable scans can then recover eligible work. If another valid lifecycle change wins first, that stored change wins the race.
Graceful shutdown releases an attempt as soon as its handler settles with an error after the shutdown abort. It does not wait for lease expiry.
See Stop crash loops for how lease recovery and time limits affect the interruption allowance.
Waiting on a token also releases the worker lease. Completing or timing out the token makes the linked runs eligible to resume. Runlane tries one small resume pass after completion, but maintenance keeps working through any links that remain.
Workers use bounded scans to move past candidates that are no longer runnable. Opaque cursors prevent an old rejected prefix from hiding later work.
Long-running workers pause between incomplete scan pages. A bounded drain() continues immediately, and only executed runs count toward maxRuns.
Shutdown is cooperative
Closing a worker stops acquisition immediately and lets running attempts finish during the worker grace period. After grace, it aborts TaskContext.signal with shutdown. An error interrupts the attempt if the execution or delivery signal was aborted before the error. This includes worker shutdown, a platform time limit, a caller’s signal, or a transport losing its message. The run is requeued without spending a retry. A normal outcome during grace, or a success after abort, keeps its usual meaning. The signal cannot forcibly stop JavaScript or undo an external effect. Pass it into I/O, and stop starting new work after cancellation or shutdown becomes durable.
SQS workers keep renewing held messages during grace, return held, unstarted messages on close and still delete deliveries that finish while closing. A cancelled long poll may take a message after the worker stops waiting; that message returns when its visibility expires. See how SQS work recovers.
Use run workers for process setup and run maintenance for recovery.
A pending awaited task wait parks the handler without running surrounding catch or finally blocks and records a release without a failure. A keyed sleep or signal wait is checkpointed when delivery recovery resumes it or a polling worker claims it directly. run.wait_resolved and its step checkpoint commit in that existing transaction. The next attempt starts at the top and replay continues past the resolved wait. Cancellation and attempt deadlines still take precedence.
Interruptions and durable progress
See Invocation handoff for how Runlane yields before a time limit.