DEV Community

Deploying new Temporal workflow code while workflows are running

Remdore on November 16, 2026

A Temporal workflow can run for minutes, days or months, and the code behind it will change while it runs. Temporal's answer is that workflow code ...
Collapse
 
_firelinks profile image
Mike Dabydeen •

The 42 could have failed in CI instead of in production. Temporal's Python testing docs suggest this as a CI check: fetch the histories of recent open and closed workflows with client.list_workflows(...).map_histories(), run them through a Replayer built with the new workflow code, and fail the build on any error. Your unpatched audit would have hit the same TMPRL1100 against every history already past step 4, before any worker picked one up.

The same check answers the rollback question. Before rolling back, replay the open histories against the previous build. Anything that already ran the new audit fails that replay, so you'd know it was 50 workflows, not zero, before choosing between a rollback and a reset.

Collapse
 
remdore profile image
Remdore •

That's the check I should have run, and it's the same replay I did by hand in the earlier post, just pointed at live histories. One limit from these runs: it only sees histories as they are when CI runs. In the restart case, 42 workflows were past step 4 at the moment of the deploy, but a check run a minute earlier would have found fewer, because the rest were still on their way there. It still fails the build as soon as one open history is past the change, and with 42 there it would have. For the rollback, I agree completely: replaying the open histories against the old build first would have shown the 50 before I chose.

Collapse
 
_firelinks profile image
Mike Dabydeen •

The gap only bites in one case: CI finds zero open histories past step 4, and some get there before the deploy lands. With 42 it fails either way. With a trickle of traffic it can pass at noon and break at 12:05. Running the same replay as the last step of the deploy, against histories fetched at that moment, narrows the window to seconds, but it can't close it.

Worker Versioning (GA across the SDKs since March) takes the race out instead. A Pinned workflow is guaranteed to complete on the Worker Deployment Version it started on, so your 42 would have finished on the old build while new starts went to the new one, as long as the old workers stay up until they drain. The replay check then only has to cover the workflows you set to Auto-Upgrade.

Thread Thread
 
remdore profile image
Remdore •

Agreed, running it as the deploy's last step narrows the window and doesn't close it. I didn't try Worker Versioning in these runs, so I can't say from them how Pinned behaves. The closest thing I measured was the overlap without it: old and new workers on the same task queue for 60 seconds. The new worker ran nothing, the old one carried every workflow past step 4, and 83 broke once it stopped. Pinning is meant to make that overlap safe, as long as the old workers outlive the last pinned workflow. That's the run I'd do next.

Thread Thread
 
_firelinks profile image
Mike Dabydeen •

For that run, I'd gate the old workers' shutdown on the server rather than a timer. temporal worker deployment describe-version reports a DrainageStatus for the old build: draining while pinned workflows are still open, drained once the last one closes. Stop the old workers after drained and every workflow that started there should finish there.

Two caveats from Temporal's sunset docs. The status is refreshed periodically, so drained can trail the last close for a little while, which only costs you idle workers. And if you query closed pinned workflows, those queries still need a worker on the old build, so keep one up afterwards.

Thread Thread
 
remdore profile image
Remdore •

That's a better stop condition than the timer I'd have used. When I do the pinned run I'll stop the old workers on drained, and keep one old worker around afterwards for the queries. If drained trails the last close by a bit, that also gives me something to time.

Collapse
 
kursatyz profile image
Kürşat Yılmaz •

Distributed orchestration frameworks fail when failure states are masked behind optimistic retry loops.

If execution guarantees aren't crash-safe at the storage engine level, automated retries just amplify cascading outages. Simple state machines with deterministic dead-letter handling always win long term.

Collapse
 
remdore profile image
Remdore •

Here the retries didn't cause an outage, they hid the failure. The 42 broken workflows stayed Running for six minutes, each on its 9th or 10th workflow task attempt, and none counted as a failed workflow. An alert on failed workflows would have stayed quiet. The one that would have caught it is on workflow task failures or nondeterminism warnings.

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

The detail I keep coming back to is the six minutes: 42 broken workflows sat in Running on their 9th or 10th task attempt, and an alert on failed workflows would have stayed quiet. Mike's suggestion to replay recent histories in CI is a good one, and your point that it only sees the histories that exist when CI runs is the honest limit.

At Ascendra Ventures we moved a candidate enrichment pipeline into Temporal, and the rule we designed around is exactly what your test exposes: every person should finish or visibly fail, never sit in the middle. The batch path waits durably for OpenAI parse and embedding jobs, falls back to polling when webhooks go silent, and finalises every person's status so failed work shows up. Worker deploy pipelines were part of that same piece of work, and your 100-workflow run is a good reminder that the deploy is where determinism really gets tested.

Did you try alerting on the nondeterminism warning count itself, rather than on workflow failures?

Collapse
 
remdore profile image
Remdore •

No, I didn't wire up an alert in these runs. I only read the signal by hand, and it was in two places: the attempt count on the pending workflow task, and the warnings in the worker's log. The history isn't a good thing to count, because each broken workflow had exactly one WorkflowTaskFailed event however many retries followed. So an alert built on history events would undercount badly. The worker-side warning or the task attempt count is what I'd alert on.

Collapse
 
mp3sss31 profile image
mp3sss •

The determinism constraint is essentially the same problem as evolving a persisted job queue on the client: if you insert a new step into the middle of an existing state machine, replaying an old recorded history against the new code can diverge the moment it reaches the changed position. The safe move is to version the workflow path - let in-flight instances continue on the old branch and only route new instances through the added activity. It's worth replaying saved histories against the edited code before deploy, the way this post does, so a non-determinism shows up in staging rather than on a run that's already days in.