Repository navigation
v0.6.0
Added
- A pluggable scheduler.
AshWorkflow.Scheduleris the behaviour a module implements to decide when a workflow's automatic steps and timeouts run. Choose one on theworkflowblock withscheduler, or once for an application withconfig :ash_workflow, scheduler: ....AshWorkflow.Scheduler.Obanis the default and generates the same AshOban triggers as before, with the same trigger, worker and scheduler module names, so nothing already enqueued is orphaned. AshWorkflow.Scheduler.Workdescribes one unit of scheduled work in AshWorkflow's own terms. It carriesmatch, an expression selecting records eligible now, anddeadline, the rule for computing the exact instant — the same fact in the two shapes that opposite scheduling strategies need. A scheduler that polls reads one; a scheduler that arms timers reads the other.AshWorkflow.Scheduler.execute/3runs a unit of work and routes failure to the step'son_error. It belongs to AshWorkflow rather than to each implementation, so changing the scheduler changes when work happens and never what it does.AshWorkflow.Info.scheduler/1.AshWorkflow.Info.transition/2, returning the merged view of a transition name: every step it leaves, one route per declared target with thewhenexpression that selects it, the union of the accepted inputs, and the generated action name. A name declared on more than one step becomes a single action, and reading what that action accepts and where it can go previously meant combining the workflow entities with the generated Ash action by hand.state_attributeon theworkflowsection. Names the attribute the current step is stored in, and is passed down toash_state_machine. It defaults to:state, so nothing changes for workflows that do not set it. A resource that already has a lifecycle column of its own —status, say — can now use AshWorkflow without renaming that column. Everything generated follows the name: the state machine, the transition and timeout actions, thematchexpression on everyAshWorkflow.Scheduler.Work, thecurrent_step,available_actionsandpending_deadlinescalculations, andAshWorkflow.Info.recommended_indexes/1.AshWorkflow.Info.state_attribute/1reports it. Thestate_entered_atattribute keeps its name.- A
retryblock on a step or a timeout. Declaresmax_attemptsandbackofffor its generated work, so a failing step or timeout action can run again beforeon_errormoves it to its error state.max_attemptsdefaults to1, so nothing changes for a step or timeout that does not declare one.AshWorkflow.Scheduler.Obanturns the block into the generated trigger's ownmax_attemptsandbackoff.AshWorkflow.Scheduler.Precisere-arms its timer for the backoff delay instead, under the same key the original deadline used.AshWorkflow.Verifiers.ValidateRetryrejects the block on a manual step, a wait state, or a terminal step, since none of them has a generated trigger for it to apply to. self_scheduled?on a timeout. Declares that something other than cron drives this trigger, at whatever resolution the deadline needs, which permits a deadline shorter than a cron expression can ask for. It changes nothing about what is generated — the scheduler module and its cron still exist, soAshOban.schedule/2andAshOban.schedule_and_run_triggers/1keep working.demos/atsis the worked example: a GenServer ticks every second and invokes the trigger, which is what makes its 30-second deadline honourable.- Compile-time rejection of a transition name shared across steps that declare different policies. Because such steps merge into one action and Ash requires every applicable policy to pass, the differing policies blocked each other and nobody could call the action — a silent runtime lockout, now a build error with guidance.
- Indexes for the generated triggers. Resources using
AshPostgres.DataLayernow get a(state, <timeout field>)composite index per distinct timeout field, or(state)alone for workflows with no timeouts. Every trigger filters onstate, andago/2compiles to a bind parameter rather than a per-row function call, so a timeout's query reaches Postgres asstate = $1 AND state_entered_at <= $2— indexable all along, but unindexed by default, which made every poll a sequential scan. Indexes are createdconcurrently, so adding them to an existing table does not lock it. An existingcustom_indexesentry on the same fields takes precedence. generate_indexes?on theworkflowblock, to turn that off.AshWorkflow.Info.recommended_indexes/1, returning the same list as data, for resources on other data layers and for tooling.pending_deadlinescalculation. Lists the timeouts ahead of a record in its current step, soonest first, each withdue_at,kindandtarget. Derived on read from the DSL and the record's own timestamps, so there is no new table and nothing that can drift out of sync — a forward-looking companion to the transition log's history. Adue_atin the past means "was due", not "will fire": a non-repeating action timeout does not change state, so its deadline stays derivable after it fires.- Conditional
on_successrouting.on_successis now a repeatable entity instead of a scalar option, so an automatic step can fan out to different states based on what its action computed:on_success :interview, when: expr(screen_score >= 5). It reuses the sameAshWorkflow.Entities.Routeentity conditional transitions already use, and the inline shorthand (step :x, action: :y, on_success: :z, on_error: :w) still works for the common unconditional case.on_successconditions evaluate after the step's own action has run, since the point is to branch on what the action produced — the same way a manual transition'srouteconditions do. Entries are evaluated in declaration order, first match wins; at most one unconditionalon_successis allowed per step, and it must come last, as the fallback. - Undo. An
undoblock on theworkflowsection, plusundoable?: trueon individual transitions, generates anundoaction that rewinds a record to the state before its most recent state change. Opt-in twice over: nothing is undoable unless declared so, because undo restores state only — it does not roll back accepted attributes or compensate side effects. Optionalwithin(time limit) andsame_actor?(only the actor who transitioned) constraints, and apolicyof its own, since no step's policy can govern an action that spans two states. - Undo appends, never erases. An undo writes a new transition log row with
triggered_by: :undoandundoes_idpointing at the row it reverses. The log stays append-only, and both readings of history remain derivable from the same rows:history/2andstate_at/3answer literally by default, or from the corrected account witheffective: true. Undoing an undo is a redo and needs no special handling. Seedocumentation/design/workflow-undo.mdfor why this was chosen over anundoneflag on the reversed row. undoable?/2andundo_target/2on resources with undo enabled, answering whether a record can be rewound and where it would land without writing. Distinct from Ash's generatedcan_undo?/2, which asks whether the actor is authorized to call the action.AshWorkflow.Info.undoable_edges/1andundoable_edge?/3, andAshWorkflow.Errors.UndoNotPermittedwith areasonfield so callers can branch without matching on message text.- Compile-time rejection of incoherent undo configuration:
undowithout atransition_log, a log without the self-referencingundoesrelationship, anundoblock with nothing marked undoable,undoable?: truewith noundoblock, andsame_actor?withoutbelongs_to_actor. - Wait states. A step that declares no action and no transitions, whose only exit is a timeout with
transition_to, is now a valid step. Previously such a step was misclassified as automatic and failed to compile withreferences action :, but no such action is defined, which made "sit here until a deadline passes" inexpressible even though the generated timeout triggers already supported it. Combined with a timeoutfield, this is how you give each record its own delay without blocking a process to wait for it. AshWorkflow.Entities.Step.wait_state?/1, alongside the existingmanual?/1.- Compile-time rejection of a wait state whose timeouts all lack
transition_to(records could never leave), or which declareson_success/on_error(with no action, neither could fire). check_intervalon theworkflowblock, setting the Oban cron for every generated trigger on the resource — automatic steps included, which previously had no way to change their polling interval at all. Individual timeouts still override it.- Documentation of what polling costs: one scheduler per trigger, each querying on every tick regardless of whether any record is waiting, so the cost scales with the size of the workflow rather than the number of records.
Changed
-
Breaking: The
timeoutentity'safteroption is renamed tofire_after, with no alias.afteris a reserved block clause in Elixir, sotimeout :x do after {3, :days} ... endnever parsed — it swallowed every following line into anafter:clause — and a timeout that also wanted aretryblock had no inline spelling left to reach for.fire_afteris not reserved, so both the inline form and the block form work, and a timeout can now combine a duration with aretryblock without contorting the call intodo: (retry do ... end). A workflow still declaringafter: {3, :days}fails to compile withunknown options [:after], valid options are: [..., :fire_after, ...]; rename the option to fix it. ThedeadlinemapAshWorkflow.Scheduler.Workbuilds for a timeout renames itsafterkey tofire_afterthe same way. -
Breaking:
AshWorkflow.Info.workflow_graph/1returns everything the entities hold. Each step's entry keeps its:terminaland:manualflags and gains:name,:action,:policy,:retry,:initialand:wait_state.:transitionsis now a list of maps rather than of target names, one per reachable target, carrying:name,:to,:condition,:undoable?and:accept. A conditional transition contributes one entry per route, each with that route'swhenexpression as:condition.:timeoutsis a list of maps rather than of{name, target}tuples, carrying:name,:to,:fire_after,:field,:action,:repeatand:retry, so a timeout that runs an action is distinguishable from one that moves the workflow.:on_successis a list of%{to:, condition:}routes in declaration order, replacing both the old scalar:on_successand:on_success_targets. A caller drawing the workflow can now label every edge, show which branch is conditional and mark the entry point without calling anything else. -
Breaking: Resources must add the
AshObanextension themselves:use Ash.Resource, domain: MyApp.Domain, extensions: [AshWorkflow, AshOban]AshWorkflow no longer adds it.
add_extensionsis static inuse Spark.Dsl.Extension, so it cannot depend on which scheduler a workflow selects — and a workflow whose deadlines are run by something other than Oban should not carry the ash_oban DSL.AshWorkflow.Scheduler.Obanchecks for the extension and fails at compile time with the fix in the message.AshStateMachineis still added for you. -
Breaking: A timeout whose
fire_afteris shorter than one minute is now a compile error unless it setsself_scheduled?: true. Timeouts fire when an Oban cron scheduler next notices the deadline has passed, and cron cannot poll below one minute —Oban.Cronzeroes the seconds field and only wakes on minute boundaries. Sofire_after: {30, :seconds}compiled happily and then fired up to 60 seconds late, an error larger than the deadline itself. The DSL accepted:secondsdurations and the docs advertised them, which made this a documented promise the scheduler could not keep.Sub-minute durations paired with a custom
fieldwere an idiom for "as soon as that instant has passed", sincefire_aftermust be positive. Spell that{1, :minutes}— under any polling interval it means the same thing. -
Breaking: Timeout-generated names are now scoped by step. The hidden action is
__timeout_<step>_<name>(was__timeout_<name>), its Oban trigger is__timeout_trigger_<step>_<name>, and worker/scheduler modules gain a step namespace. This means two steps can each declare a timeout with the same name — previously that failed to compile with an ash_oban "defined more than once" error. Update any code referring to a generated timeout action by name. -
Breaking: The minimum supported Elixir is now 1.17, raised from 1.15. The ash release carrying the security fixes below uses
Duration, which does not exist before 1.17, and the newest ash that still compiles on 1.15 (3.30.1) remains affected by the HIGH advisory — so supporting 1.15/1.16 and shipping a patched ash were mutually exclusive. -
AshWorkflow.Transformers.AddObanTriggersis replaced byAshWorkflow.Transformers.AddScheduler, which builds theWorklist and delegates to the selected scheduler. -
terminal: trueis derived. A step that declares no action, no transitions, no timeouts, noon_successand noon_errorhas no way out, soAshWorkflow.Entities.Step.terminal?/1reports it as terminal whether or not the option is set.step :approvedis now enough. The option stays as an assertion:AshWorkflow.Verifiers.ValidateWorkflowstill rejects a step that sets it and then declares something outgoing, and everything that reads the flag — the scheduler's work list, the generated policies, the state machine,AshWorkflow.Info.workflow_graph/1— now reads the predicate.A step that becomes terminal by accident is caught by the reachability check rather than by a missing-action error: an end state nothing transitions to is unreachable. The error for a stranded step therefore changes.
step :strandedin an otherwise working workflow now reports "not reachable from the first step", and a workflow of nothing but terminal steps reports "must have at least one non-terminal step". -
Triggers now stream with
:keysetrather than:full_read. ash_oban suggests:full_readwhen awhereclause changes between batches, which ours do, but keyset orders by primary key: unlike:offset, a row leaving the filter mid-stream cannot shift another row past the cursor. A record becoming eligible at a key the stream has already passed waits for the next poll, bounded bycheck_interval. In exchange, a backlog after downtime is no longer read into memory in one unpaginated read. -
mix ash_workflow.gen.transition_lognow scaffolds a self-referencingbelongs_to :undoesrelationship and accepts:undoes_id. Logs generated before this need regenerating (or the relationship adding by hand) before undo can be enabled on their workflow. -
A timeout's
check_intervalnow defaults to the workflow-level setting instead of hardcoding"* * * * *". Behaviour is unchanged unless a workflow-levelcheck_intervalis declared.
Fixed
-
A non-repeating action timeout now writes a transition log row.
AshWorkflow.Transformers.AddActionsinjectedAshWorkflow.Changes.RecordEventonly onto actions named by a timeout withrepeat: true, so a one-shot reminder fired and left no trace in the log. Every timeout that names an action now gets the change, and the row hasfrom_state == to_statewithtriggered_by: :timeout, the same shape a repeating timeout's row already had. Two timeouts naming the same action share one row per firing. Only a repeating timeout's action resetsstate_entered_at, through the new:touch_state_entered_atoption onAshWorkflow.Changes.RecordEvent: the reset is how a repeat re-arms its trigger, and a one-shot timeout doing it would push every other deadline on the step back. -
A policy with no authorizer to enforce it is a compile error.
AshWorkflow.Transformers.AddPoliciesgenerates nothing whenAsh.Policy.Authorizeris absent from the resource, so apolicyon a step or on theundoblock was accepted and then silently unenforced: every caller was authorized, including the ones the policy named.AshWorkflow.Verifiers.ValidateStepPoliciesnow names each step that declared one and says how to add the authorizer. -
A timeout naming an action the resource does not define is rejected by
AshWorkflow.Verifiers.ValidateWorkflow. Under the default scheduler AshOban's own verifier caught it on the trigger it generated, but a workflow scheduled byAshWorkflow.Scheduler.Precisegenerates no trigger, so the name went unchecked until the deadline passed. -
A timeout
fieldreferencing a module calculation is now rejected at compile time. Only expression calculations inline into a data-layer filter, so a module calculation passed the verifier and then raised when the scheduler built its query. Use an expression calculation or a plain attribute. -
A manual transition's
routeconditions now see the input the same call accepted.AshWorkflow.Changes.ConditionalTransitionevaluated them againstchangeset.data, soroute :approved, when: expr(decision == :approve)on a transition that accepts:decisioncould only match a value already persisted, and "submit the outcome, then route on the outcome" needed a separate transition name per outcome or a custom change. Routes now read the record as it was loaded with the transition'sacceptlist applied on top.Only the accepted attributes are applied. An attribute written by one of the action's own changes stays invisible to the routes, so a route can still ask what the record looked like when the call arrived — which is what a two-signature sign-off needs, where one action records the current approver and the routes ask whether anyone approved before.
AshWorkflow.Changes.ConditionalOnSuccesscontinues to apply every pending attribute, since an automatic step has no caller input to distinguish from what its action computed. -
from_stateis no longer lost on atomic transitions. An atomic update acts on a query rather than a loaded record, so the changeset has nodatato read the pre-update state from — and that is the path AshOban drives every automatic step and timeout through, meaning most rows on a busy workflow loggedfrom_state: niland were indistinguishable from the:initialrow a create writes. The state is now taken from the last logged row when the changeset cannot supply it. -
mix igniter.install ash_workflowworks.igniterwas declared as an unqualified dependency, so it diverged from theonly: [:dev, :test]that consuming applications use — including the oneigniter.installsets up itself — and the install aborted with "Dependencies have diverged". It is nowoptional: true, matchingash; the mix tasks were already guarded onCode.ensure_loaded?(Igniter). -
A resource with the extension but no steps yet reports "Workflow must have at least one non-terminal step." rather than an internal
expected a map, got: nilfromAddStateMachine— the state every resource is in betweenmix ash.extendand writing its first step. The verifier always had the right message, but transformers run first. -
The generated primary read action no longer collides with a read action the resource already defines. A resource whose
:readwas not primary —defaults [:read]produces exactly that — got a second action of the same name and failed to compile with "Multiple actions (2) with the namereaddefined". The transformer now runs afterAsh.Resource.Transformers.SetPrimaryActions, which is what expandsdefaultsand marks primaries — asking before it ran meant seeing no read action at all on some Elixir versions and generating a duplicate. As a second guard, the generated action is named:__workflow_readwhen:readis already taken. -
A step declaring neither an action, a transition, nor a timeout now reports what it needs, rather than the misleading
Automatic step :x references action :, but no such action is defined on the resource. -
The generated
__on_error_<step>action is now covered by the generated policies and the AshOban bypass. On a resource with an authorizer, AshOban's invocation of it was forbidden, so a failing automatic step silently stayed put instead of routing to its error state. -
Corrected the conditional route example in
AshWorkflow.Entities.Transitiondocs, which usedto :target, when: ...rather than the actualroute :target, when: .... -
documentation/topics/error-handling.mddescribed failure behaviour the library has not had since 0.5.0. It said theon_errortransition never happens automatically, that a failing job retries, and that the record stays in the failing step once retries are exhausted.AshWorkflow.Transformers.AddActionsgenerates__on_error_<step>andAshWorkflow.Transformers.AddSchedulerwires it to the trigger, so the record moves to the error state on the first failure and gets an:error_pathtransition log row. The guide now documents that, and what a step with noon_errordoes instead. -
documentation/topics/timeouts-and-deadlines.mdrecommended"* * * * * *"for sub-minute precision, whichAshWorkflow.Verifiers.ValidateTimeoutPrecisionrejects. It now points atAshWorkflow.Scheduler.Preciseandself_scheduled?, which is what the rest of the guide already taught. -
The same guide said a non-repeating timeout on a custom field keeps firing on every poll cycle. Its trigger keeps matching, but
trigger_once?stops the action running twice for the same record. -
The getting-started tutorial asked for
ash_state_machineandash_obanas prerequisites the reader adds and configures. It now leads withmix igniter.install ash_workflowand keeps manual setup as the fallback. One dependency rule holds across the tutorial and the README: declareash_workflowonly, addAshWorkflowandAshObanto the resource, neverAshStateMachine. -
The tutorial and the README now say that AshWorkflow generates no create action, and show what
initial: truechanges, since the initial step is otherwise the first non-terminal step by declaration order. -
README links into
demos/are absolute, so they resolve on HexDocs.mix docsemitted six unresolved-reference warnings, because the demos are not part of the published package.
Security
- Updated the locked
ashfrom 3.27.7 to 3.32.1, which carried four advisories. The most serious, EEF-CVE-2026-67579 (HIGH), is filter expression injection via a forged keyset pagination cursor — relevant here because the read action this extension generates for ash_oban's triggers uses keyset pagination. The dependency constraint (~> 3.0) was already permissive; only the lockfile held the old version. - Updated the locked
ashto 3.33.5, which fixes EEF-CVE-2026-86338 (MEDIUM): field policies do not filter-nil forbidden calculations and aggregates, so a forbidden value can be inferred from whether a row is returned. Introduced in 2.11.0-rc.0 and fixed in 3.33.4. The~> 3.0constraint already allowed the fix; only the lockfile held the affected version.