Introducing a new way to review your PRs.

Read the announcement

elsa-workflows / elsa-core

The Workflow Engine for .NET

View on GitHub

32 documents · Updated Oct 7, 2026

docs / workflow-alterations

Workflow alterations

Workflow alterations let an operator change a running workflow instance without publishing a new workflow definition or starting a replacement instance. An alteration plan selects one or more instances, applies a set of supported changes, records the result for each instance, and resumes work when the changed state still has scheduled work.

System role

Workflow alterations sit between workflow management and workflow runtime. The management side selects instances and tracks plans. The runtime side loads each instance, applies changes to its live execution state, saves that state, and can continue the workflow.

The capability supports both a planned asynchronous path and a direct path for known instance IDs:

PathUseResult
Plan submissionApply the same changes to a filtered set of instancesA plan creates one job per matching instance and runs in the background
Direct runApply changes to an explicit set of instance IDsThe caller receives one result per instance
Dry runCheck which instances a filter would selectThe system returns matching IDs without changing state

Related pages: Workflow engine, Workflow runtime, and Studio platform.

Alteration plans

An alteration plan is the unit of work for a batch change. It contains the alterations to apply and a workflow-instance filter. The filter can select by instance identity, correlation, definition, status, time, incident state, or activity conditions; an empty filter selects all instances only when that option is enabled.

The plan runs through the published system workflow Elsa.Alterations.ExecuteAlterationPlan. That workflow stores the plan, finds matching instances, creates per-instance jobs, dispatches the jobs, and waits for completion. This separates selection from execution and gives the operator a plan and job record to inspect.

The plan flow is shown below.

flowchart LR
    A[Alteration request] --> B[Create plan]
    B --> C[Find matching instances]
    C --> D[Create one job per instance]
    D --> E[Dispatch jobs]
    E --> F[Run alterations]
    F --> G[Save job result]
    G --> H{All jobs terminal?}
    H -- No --> G
    H -- Yes --> I[Complete plan]
    I --> J[Signal waiting workflows]

Plan states describe the batch phase: Pending, Generating, Dispatching, Running, Completed, or Failed. A job has its own Pending, Running, Completed, or Failed state and stores a log for one workflow instance. The plan manager considers both completed and failed jobs terminal when it decides that the plan can complete.

Plan selection

The selection filter defines the boundary of a batch change before any job is made. The dry-run endpoint uses the same kind of filter as submission so an operator can see the target set before accepting the plan.

References: src/…/AlterationPlanParams.cs• L5-24 src/…/AlterationWorkflowInstanceFilter.cs• L7-78 src/…/GenerateAlterationJobs.cs• L42-52 src/…/Endpoint.cs• L10-35

Plan completion

Each job reports its result after the alteration runner finishes. When no jobs remain pending or running, the plan becomes complete and emits a completion event. A workflow that waits for that event can resume through the alteration completion bookmark.

References: src/…/DefaultAlterationJobRunner.cs• L38-56 src/…/AlterationPlanManager.cs• L21-42 src/…/AlterationJobCompletedHandler.cs• L8-26

Alteration activities

Alteration activities are the built-in change types that a plan can carry. Each type expresses an operator intent. A matching handler applies that intent to the live workflow execution context.

ActivityTargetPurpose
CancelWhole instanceStops the workflow instance
CancelActivityActivity or activity instanceStops a selected activity execution
ScheduleActivityActivity or activity instanceSchedules an activity for execution, including a faulted activity when possible
ModifyVariableWorkflow variableSets a variable to a new value
MigrateWhole instanceMoves the instance to a selected newer workflow version

The list is extensible. A new alteration type needs a handler that can recognize it and apply it through the alteration context. The built-in registration connects the five shipped types to their handlers.

Alteration context

An alteration handler receives the workflow execution context, the current alteration log, and cancellation state. It can mark the change as successful or failed. It can also add a commit action for side effects that must happen only after the alteration set has passed its checks.

Handlers run in plan order. The runtime stops when a handler marks an alteration as failed, so later changes in that run do not apply. Successful changes write their log entries into the workflow execution log.

References: src/…/IAlterationHandler.cs• L5-20 src/…/AlterationHandlerContext.cs• L29-72 src/…/AlterationHandlerContext.cs• L85-154 src/…/ServiceCollectionExtensions.cs• L14-25

Completion bookmarks

The AlterationPlanCompleted trigger lets a workflow wait for a named plan to finish. When the trigger is used inside a workflow, it creates a bookmark with the plan ID. Plan completion places a matching stimulus on the bookmark queue, which allows the waiting workflow to resume.

This signal is separate from the per-instance job result. A job tells the system that one instance finished. The plan completion signal tells waiting workflows that the full batch reached a terminal state.

References: src/…/AlterationPlanCompleted.cs• L12-55 src/…/AlterationPlanCompletedPayload.cs• L5-9 src/…/AlterationPlanCompletedHandler.cs• L11-30

Runtime alteration middleware

The alteration runner uses the normal workflow runtime to load and save an instance, but replaces the normal activity scheduler at the end of that run with an alteration middleware. This gives handlers a complete execution context without treating the alteration itself as ordinary workflow work.

The runtime alteration flow is shown below.

sequenceDiagram
    participant Caller
    participant Runner
    participant Runtime as Workflow runtime
    participant Middleware as Alteration middleware
    participant Store as State store

    Caller->>Runner: Run changes for instance
    Runner->>Runtime: Load state and definition
    Runtime-->>Runner: Execution context
    Runner->>Middleware: Apply alterations
    Middleware-->>Runner: Result and log
    Runner->>Store: Commit updated state
    Runner->>Runtime: Import updated state
    Runner-->>Caller: Result

The middleware finds handlers for each alteration, collects permitted commit actions, and runs those actions after all handlers succeed. The runner then commits the changed workflow state. If the altered context still contains scheduled work and the job succeeded, completion handling dispatches the workflow instance so normal runtime processing can continue.

Scheduled work

Scheduling is the link between an alteration and normal workflow execution. An alteration can change the state so that work is ready to run, but the alteration pass does not itself become the normal activity scheduler. The completion path checks for scheduled work and dispatches the instance when needed.

References: src/…/DefaultAlterationRunner.cs• L42-98 src/…/RunAlterationsMiddleware.cs• L18-57 src/…/ResumeWorkflowInstance.cs• L11-42

HTTP endpoints

The backend exposes alteration operations through endpoints that use the single alterations permission resource. View permission protects plan inspection. Execute permission protects operations that can select or change workflow instances.

EndpointPermissionPurpose
POST /alterations/submitExecuteStart an asynchronous plan from alterations and a filter
POST /alterations/dry-runExecuteReturn the instances selected by a filter
POST /alterations/runExecuteApply alterations to explicit instance IDs
GET /alterations/{id}ViewReturn a plan and its jobs
GET or POST /alterations/workflows/retryExecuteSchedule faulted or selected activities again

The retry operation is a focused use of the alteration system. It creates ScheduleActivity changes for the requested activities or for the instance's faulted activities, then dispatches the updated instance.

References: src/…/Endpoint.cs• L12-57 src/…/Endpoint.cs• L10-40 src/…/Endpoint.cs• L8-43 src/…/Endpoint.cs• L9-51 src/…/Endpoint.cs• L16-77 src/…/AlterationPermissions.cs• L7-25

Studio shell integration

The Studio alterations feature provides the operator surface for inspecting a running instance, staging changes, previewing the request, submitting a plan, and viewing plan progress. It is an optional remote feature, so Studio checks backend capability before it shows the Alterations menu and instance actions.

The instance editor presents the workflow diagram with a side panel. Operators can select an activity, choose an activity action, edit a variable, or choose a workflow version. The editor keeps these choices staged until the operator reviews the changes and the exact JSON request, then submits them as a plan for the selected instance.

The plan view reports plan state and per-job progress. It polls the backend so the operator can follow asynchronous work without treating the system workflow's own runtime status as the source of truth.

Feature availability

The backend shell feature is named Alterations and depends on the endpoint and workflow runtime features. The Studio module uses the remote feature name Elsa.Alterations.ShellFeatures.Alterations. When that capability is unavailable, the menu and alteration controls stay hidden rather than sending requests to an unsupported endpoint.

References: src/…/AlterationsFeature.cs• L22-32 src/…/Feature.cs• L7-18 src/…/AlterationsMenu.cs• L10-49 src/…/RemoteFeatureNames.cs• L1-20

Staging and submission

Staging is a temporary editor state. It does not change the workflow instance until submission succeeds. The submit dialog shows the selected changes, previews the request sent to /alterations/submit, and returns the plan ID for progress tracking.

References: src/…/AlterationDesignerHost.razor.cs• L150-247 src/…/AlterationDesignerHost.razor.cs• L249-339 src/…/AlterationSubmitDialog.razor• L79-145 src/…/AlterationSubmitDialog.razor• L225-273

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the server alteration type discriminator, its handler registration, and the Studio catalog type ID aligned. A mismatch can make a staged JSON change deserialize but receive no handler.
  • Keep activity and variable target rules aligned between the Studio editor and the server alteration fields. The editor can create a request that the handler cannot resolve.
  • Preserve the plan-to-job relationship when changing plan selection or dispatch. Plan progress and completion depend on one job per matched workflow instance.
  • Preserve the completion bookmark payload and stimulus hash together. A change to one without the other prevents waiting workflows from resuming.
  • Keep the remote feature name aligned between the backend shell feature and Studio feature. A mismatch can hide a supported feature or expose controls for an unavailable endpoint.
  • Keep execute and view permission checks aligned with endpoint intent. A missing execute check can allow state changes through a new route.

Important failure modes

TriggerConsequenceGuard
A plan filter matches no workflow instancesThe plan has no jobs and completes without changing a workflowUse the dry-run endpoint before submitting a broad filter
A plan references an unknown workflow instance or definitionThe job records an error and the alteration is not appliedCheck job logs and verify instance and definition IDs before retrying
An activity alteration omits both activity ID and activity-instance IDThe handler fails the alterationSupply one valid target or select the activity in Studio
A variable ID does not exist in the running instanceThe handler fails the alteration and logs the failureRead the instance variable list before building ModifyVariable
A migration target version is not availableThe instance remains on its current version and the job failsSelect a published version that belongs to the instance definition
One or more jobs failFailed jobs become terminal; the plan can complete with failed job resultsInspect every job log instead of using plan completion alone as proof of success
The alteration leaves scheduled work but the resume dispatch is unavailableThe changed state is saved but normal workflow processing does not continueMonitor runtime dispatch and resume the instance after restoring the dispatcher
The backend alteration feature is absentStudio hides alteration navigation and controlsEnable the backend shell feature before enabling the Studio module

Key files

FileWhy to read it
src/…/ExecuteAlterationPlanWorkflow.csDefines the end-to-end plan lifecycle as a system workflow
src/…/AlterationPlanParams.csDefines the input contract for a plan
src/…/AlterationWorkflowInstanceFilter.csDefines how plans select workflow instances
src/…/DefaultAlterationRunner.csShows how a running instance is loaded, altered, committed, and returned to runtime
src/…/RunAlterationsMiddleware.csShows the handler and commit boundary for alterations
src/modules/Elsa.Alterations/AlterationTypes/Defines the built-in change intents
src/modules/Elsa.Alterations/AlterationHandlers/Defines how built-in intents affect workflow state
src/modules/Elsa.Alterations/Endpoints/Alterations/Defines plan submission, preview, direct execution, and inspection contracts
src/…/AlterationPermissions.csDefines the view and execute authorization contract
src/…/AlterationPlanCompletedPayload.csDefines the payload used to resume workflows waiting for plan completion
src/…/AlterationsFeature.csRegisters the backend capability with the application shell
src/…/AlterationDesignerHost.razor.csCoordinates Studio selection, staging, dry-run, and submission
src/studio/modules/Elsa.Studio.Alterations/Components/AlterationSubmitDialog.razorShows review, request preview, and asynchronous submission result
src/…/AlterationCatalog.csDefines the built-in alteration choices shown in Studio