Deploy Code Changes
View as MarkdownFlows can stay open for days or months, so new code meets Flows that started under old code. This page shows how to change Flow code safely, what runs again when a Worker stops, and how to update Steps that already wait.
What a deploy changes
- A Step runs the code of the Worker that takes it. Dex runs no earlier
Step again. A Flow that waits in a Step runs the
Executeof the Worker that takes it when its conditions are met. - During a rolling deploy, old and new Workers both take calls. Dex routes by Flow type, so an old Worker still runs every Step and RPC it registers, with its old code. A Worker that lacks a Step type or RPC declines it, and Dex hands the call to another Worker without using up the attempt. See Routing and availability.
- A Step that already waits keeps its old conditions. New
WaitForcode applies to Step executions that start after the deploy. To satisfy an existing condition, publish to its Channel or skip its Timer. To install new conditions, start a new Flow or time travel the run to that Step'sWaitFor.
When a Worker stops
A deploy stops Workers, and a Worker can also crash. A graceful stop lets running tasks finish within the drain period. An interrupted attempt fails when Dex detects the disconnect or a timeout, and an eligible Worker can take its retry if the retry policy allows. Steps whose results Dex committed stay finished, and a waiting Step holds no Worker. So give each external call an idempotency key. Attempts and Worker failures covers detection, graceful stops, and long Steps.
Versioning Flow code
Dex decides a Flow's next Step from its saved state, without running earlier Step code again. So Dex never fails a Flow because its earlier Steps ran under different code. Open Flows still meet the new code: changed business rules, missing Step implementations, renamed RPCs, or incompatible data.
Lock business behavior at Flow start
When a rule change must not affect open Flows, store a business version when the Flow starts, in an Attribute or the start input. Branch on that stored value, not on the Worker build that serves the call. Open Flows keep the old behavior, and new Flows get the new one. Use this for any change to a decision, price, retry policy, deadline, or other customer-visible meaning.
Example: add a fee to Charge
The order Flow from Order Processing charges the order amount. A new rule adds a handling fee, and open orders keep the old price.
- Record the version at start. The new start handler sets the Attribute
pricing-versionto 2. Flows that started earlier have no value, which means version 1. - Branch on the stored value.
Chargecharges the amount for version 1 and the amount plus the fee for version 2. A Flow that already waits inShipnever runsChargeagain. - Add a Step type for a changed contract. If the refund needs a new input
field that old Flows never stored, add a Step type such as
RefundWithFeeand go to it only from version 2. KeepRefundfor version 1. - Deploy both, then start version 2. One Worker build holds
Chargewith the branch,Refund, andRefundWithFee. Wait until it replaces the old build before the start handler writes version 2, because an old Worker still runs its oldCharge. During the rollout, an older Worker handsRefundWithFeecalls to a newer one. - Retire the old path. When no open Flow has version 1, remove the
version 1 branch and
Refund. Search for such Flows first. Ifpricing-versionis an indexed Attribute, the search can filter on it.
The stored Attribute picks the path whatever Worker build serves the Flow, so Step code needs no version marker.
Evolve data and contracts additively
Add optional fields. Code that reads a payload gives a safe default to a field that older runs did not set, and ignores unknown fields. Existing field values keep their meaning. For an incompatible payload or output, add a new Step type or RPC name instead of changing the old one.
A newer Worker that cannot decode a stored input or Attribute fails the attempt like any Step error, and every retry fails the same way. Watch Step failures after each deploy, as Upgrades and compatibility shows. Fix the code, then rerun the Step with Time Travel.
Keep old definitions until old Flows finish
Keep a Flow type, Step type, or RPC registered under its name while an open Flow can still call it, through retries and any approved Time Travel. Deploy the new definition alongside the old one. New Flows reach it through a decision that branches on the stored version, or through new code that starts a new Flow type.
Before you remove the old definition, confirm that no running, waiting,
retrying, or recoverable terminal Flow needs it. Start with a search by Flow
type. --all reads every page of results:
dexcli flow search --all --query 'FlowType = "OldFlowType"'
Stop new starts that can take the old path. Account for search lag, check the candidate runs directly, and record which runs are approved for retirement. Remove the old code only when no candidate run remains or every remaining run is approved.
Check before you deploy
Test a new Worker build against open Flows:
-
List the open Flows of the type. Search for running Flows and for the Step types they wait in. Active-Step search is off by default, so
ActiveStepTypesfinds only Flows that turn it on.dexcli flow search --all --query 'FlowType = "OrderFlow" AND ExecutionStatus = "Running"'
dexcli flow search --all --query 'FlowType = "OrderFlow" AND ActiveStepTypes = "Ship"' -
Confirm the new build registers every Step type and RPC those Flows can reach. If no Worker has one, a Step waits in the queue and an RPC fails.
-
Test the new build against Flows started by the old one. Use a server for tests. The Quick Start's restart test has the shape to copy:
- Start a Worker from the old build. Start Flows and wait until each reaches the Step you care about: wait for an earlier Step to complete, or inspect the run.
- Stop that Worker gracefully.
- Start a Worker from the new build against the same Dex Server. Skip
Timers with
skip-timer, send the messages the Flows wait for, and wait for each Flow to finish. - Check each Flow's result and Attributes, and that the new build raised no decoding error.
Update waiting Steps with Time Travel
To make a Step that already waits use new WaitFor code,
time travel its run to that Step
execution, before its WaitFor. The Worker that takes it runs the new
WaitFor, which returns the new Wait. The Flow ID and Run ID stay the same.
An operator or a deploy job does this for each affected run:
- Wait until every Worker that serves the Flow runs the new build.
- Find candidate runs, such as with the
ActiveStepTypessearch field. A match is only a candidate. It works only when the Flow turns on active-Step search, it does not say whether the Step waits or runs a method, and search results can lag. - Before each time travel, check the run's current Run ID and run attempt.
Confirm in its open Step executions that the exact Step execution, such as
Review-2, still waits. Use the exact execution ID, because a Step-type selector can choose an earlier execution of the same type. - Review what the run did after that Step execution was created. Skip a run that went beyond the approved scope.
- Time travel the run to that Step execution's
WaitFor. Then check that the Step waits on the new Wait.
Like every Time Travel, this is a privileged change to the run, so it needs authorization. The point is when that Step execution was created, so it must still be inside the run's history window.
Time Travel restores the whole run, not one Step. Work after the point can run again, including parallel Steps and their external calls. Changed code can also change the later path and the Step execution numbers. Earlier external effects remain. Use it only when the rollback scope is approved and repeating that work is safe.
Choose whether later input applies again. If it should, enable write reapply
explicitly. Dex applies eligible input before WaitFor runs, so check that the
new Wait still listens to every Channel whose messages must count. The default
differs between Dex Web, the CLI, and a Client; see
Time travel dialog fields and the
CLI reference.
The new WaitFor declares its Timers again. So a deadline measured from a
business time must come from a stored value, as
Business deadlines
shows. A Flow timeout that was still pending at the point restarts with its
full duration.
Next
- Operate and Debug: find a Flow, fix one that is stuck or failed, and recover it with Time Travel.
- Server Failover: what runs again when a Dex Server node fails over.
- Run a server for tests: test a new build against Flows started by the old one.
- Time travel in the server reference: the point types and how to read open Step executions.
- Step guarantees