Change tasks safely
Add, change, and remove tasks without losing runs that are already in flight.
Runs can outlive a deploy. A run that started yesterday might finish on code you ship today. This page shows what happens to runs during a deploy, and which tool to use for each kind of change.
What happens during a deploy
In a rolling deploy, old and new workers run side by side for a while:
deploy starts deploy ends
│ │
old workers ███████████████████████████████████████▒▒▒▒▒ (finishing)
new workers ▒▒▒▒██████████████████████████████████████████
run of a new task ●──── waits in the queue ────●──── runs on a new worker
run of an old task ●──── runs on whichever worker picks it up first ────►Runlane follows two rules:
- A worker only takes runs for tasks it has. A run for a new task waits in the queue until a new worker picks it up. Old workers leave it alone. You can deploy producers and workers in any order.
- Any worker that has a task can finish its runs. Runs are not tied to the build that started them. New code may finish a run that old code started.
Runs that are running when you deploy
When an old worker gets SIGTERM, it stops taking new runs and gives running attempts time to finish:
old worker ── attempt running on old code ──┐ SIGTERM
│ waits up to the shutdown grace period
├─ finishes in time ──► done, on old code
└─ still running ─────► aborted, back in the queue
new worker picks it up ──► starts from the top, on new code
saved steps are not run again- The grace period is
contractDefaults.worker.shutdownGrace. Change it withshutdownGraceon the worker. - When grace ends,
context.signalaborts. If the attempt then throws, the run goes back in the queue right away. This does not use a retry. See Stop crash loops for the interruption allowance. - A run that is waiting, such as on a sleep or a signal, resumes on whichever worker picks it up. That is usually a new one.
- If the platform kills the process before it finishes, the run's lease expires and another worker picks it up.
In every case, the next attempt runs the handler from the top on the new code. Results saved with context.step.run() come back from storage instead of running again. Code outside steps runs again. See shut down cleanly.
Side effects can run twice
A database write, payment, or email can succeed just before a worker stops, and before Runlane saves that it happened. The next attempt can then do it again. This is true for every job system that retries work, including graphile-worker and pg-boss. It does not only happen during deploys.
Make each side effect safe to repeat. Put it in a step, and pass the step's token to it as an idempotency key:
await context.step.run('create-invoice', { output: invoiceSchema }, ({ token }) =>
createInvoice({ orderId, idempotencyKey: token }),
)createInvoice is your code. Store idempotencyKey in a unique column, so a second call with the same key returns the first invoice instead of creating another. The token is the same on every attempt of this step. See make side effects safe to repeat for database, API, and email patterns.
Rule 2 is the one to plan for. Most changes are safe. A few need one of three tools: a patch, a new task ID, or keeping old workers.
Pick the right tool
What are you changing?
│
├─ Adding a new task ─────────────────────────────► Just deploy
├─ Code that doesn't change steps or schemas ─────► Just deploy
├─ The steps inside a task ───────────────────────► Patch it
├─ A task's input or output, in a breaking way ───► New task ID
├─ Old runs must finish on the old build ─────────► New task ID + keep old workers
└─ Removing a task ───────────────────────────────► Finish its runs, then remove it| Change | Example | What to do |
|---|---|---|
| Add a task | A new email.send-receipt task | Just deploy |
| Change code, not steps | Fix a bug in a helper, change a log line | Just deploy |
| Change steps | Add a tax step between "charge" and "email" | Patch it |
| Break input or output | Rename amount to amountCents | New task ID |
| New code can't run old runs | A dependency upgrade the old code can't live with | Keep old workers |
| Remove a task | Retire report.legacy | Finish its runs first |
Add a task
Just deploy. Runs of the new task wait until a worker that has it picks them up. An old worker never takes them.
A worker that skips runs because it lacks their task logs worker_task_missing and counts runlane.worker.task_missing.count, at most once a minute for each task. A missing task does not go unnoticed. See telemetry.
If a run is useless when it starts late, give it a deadline with startBefore. Maintenance expires it if no worker starts it in time:
await runlane.trigger(sendReceipt, payload, {
startBefore: new Date(Date.now() + 10 * 60_000),
})On the Postgres and SQS lane, each worker that lacks the task hands the message back to SQS. If a deploy takes long enough, the message can reach your dead-letter queue. The run is not lost: maintenance publishes it again later. Expect some dead-letter noise during long deploys.
To see runs that are still waiting:
npm exec -- runlane runs list --task email.send-receipt --status queuedChange code without changing steps
Just deploy, if the change keeps all three of these the same:
- the step keys and the order of steps;
- the schemas for the task's input, output, and saved step results;
- what each step means.
Why this matters: when a run resumes after a wait or a crash, its handler starts again from the top. Runlane replays saved steps by their keys. If the keys, order, or schemas changed, the replay no longer lines up. See durable execution.
Tool 1: Patch a task
Use a patch when you change the steps inside a task. Old runs keep the old path. New runs take the new one.
First, give each build a version:
export const runlane = createRunlane({
lane,
queues,
tasks,
version: 'billing-2026-11-02',
})Then wrap the change in a patch marker:
if (await context.patched('billing-tax-v2')) {
await context.step.run('charge-v2', { output: receiptSchema }, chargeWithTax)
} else {
await context.step.run('charge', { output: receiptSchema }, chargeOriginal)
}- A run that started on this build takes the new branch. A run that started on an older build takes the old branch.
- Give the new operation a new step key, here
charge-v2. Keep the old key and its schema. - When no old runs remain, delete the old branch. Find them with
runlane runs list --version <old-version>.
See deploy task changes for how the choice is saved, how child runs inherit versions, and how to check that old runs have finished.
Tool 2: Use a new task ID
Use a new task ID for a breaking change to a task's input or output. Old and new runs then never share code.
// Keep the old task registered until its runs finish.
export const charge = task({ id: 'billing.charge', schema: oldSchema, run: chargeOld })
// New runs use the new ID.
export const chargeV2 = task({ id: 'billing.charge.v2', schema: newSchema, run: chargeNew })-
Add the new task next to the old one, and deploy.
-
Switch producers to trigger
billing.charge.v2. -
Wait until
billing.chargehas no unfinished runs:npm exec -- runlane runs list --task billing.charge --status queued scheduled running retrying released cancellation_requested -
Remove
billing.charge. See remove a task.
Tool 3: Keep old workers
Use this only when the new build can't run the old code at all, for example after a dependency upgrade that breaks it. Old runs then finish on old workers.
old build registers billing.charge ──► finishes old runs, then shuts down
new build registers billing.charge.v2 ──► runs every new run- Give the new code a new task ID, as in tool 2.
- Leave the old task ID out of the new build.
- Keep some old workers running. Because a worker only takes runs for tasks it has, old runs go to old workers and new runs go to new workers.
- Shut the old workers down when the old task has no unfinished runs.
Both builds must share one storage format. To change Runlane itself, follow Upgrade Runlane. On the Postgres and SQS lane, give the new task its own SQS queue, so messages for old runs don't reach new consumers. See compatible task catalogs.
Remove a task
A task can still have work after you stop triggering it: queued runs, retries, waits, and pending lifecycle hooks.
- Stop triggering the task, and remove its schedules.
- Wait until it has no unfinished runs. Check every unfinished status:
scheduled,queued,running,retrying,released, andcancellation_requested. - Wait until its pending hooks finish.
- Remove the task from your catalog, and deploy.
If you remove it too early, its waiting runs stay queued until a worker with the task comes back, or until their startBefore deadline passes. See remove a task with pending hooks.
Common mistakes
| Mistake | What goes wrong | Do this instead |
|---|---|---|
| Renaming a step key in place | Old runs replay a step that no longer exists | Patch it, and use a new key |
Reusing a version string for new code | Old runs take the new branch | Use a new version for every build |
| Changing a schema in place | Old saved results no longer parse | Keep the old schema, or use a new task ID |
| Removing a task with runs left | Its runs wait with no worker to run them | Finish its runs first |
| Retrying old runs after a breaking change | The new code gets an old payload | Only retry runs the new code can read |
Why Runlane works this way
You run the workers, so Runlane can't keep old builds alive for you. Pinning every run to its build would mean running every old build until its runs finish.
So Runlane follows what most self-hosted job tools do: new code finishes old runs, and a worker never takes a task it doesn't have. On top of that, it gives you patches for safe step changes, and you can still keep old workers when you need to.
| Tool | Where old runs finish | What you do |
|---|---|---|
| Trigger.dev | On the build that started them | Nothing. It hosts every build for you. |
| Temporal | On their pinned build, or on new code with patches | Keep pinned builds running, or patch |
| DBOS | Recovery happens only on processes with the same app version | Keep old processes until their workflows finish, or patch |
| graphile-worker, pg-boss | On any worker that has the task | Keep changes compatible, or use a new task name |
| Runlane | On any worker that has the task | Just deploy, patch, use a new task ID, or keep old workers |