M4-S3 — The workflow engine
Section titled “M4-S3 — The workflow engine”| Module | M4 — The process engines |
| After this session you can | Trace a request through the workflow’s state machine, including a sub-workflow and an external step, and explain what the engine stores at each move. |
| Time | 68 min with a facilitator · about 68 min on your own |
| Before you start | M4-S2 (reaction runs and commands) and M2-S3 (definitions and records). Larkspur Lab, Rami Aziz signed in; private windows for Sara Qasim and Omar Haddad; the workbench API window with its address and token set. |
| Go deeper | Engine: Workflow and owner resolution · Workflow model and API reference · Requests and services |
◆ Orientation (1 min) — Where a request really is
Section titled “◆ Orientation (1 min) — Where a request really is”A Purchase Request above 25,000 goes through a technical review before Sara Qasim approves it. You designed routes like this in ACE M3-S3 with a sub-workflow and a condition. The designer shows the route; the engine keeps something else: a stack of open workflow instances inside the record, and a history beside it. In this session you learn to read that stack, predict how each action changes it, and explain the refusals a person sees when the engine says no. M4-S4 then uses the same stack to work out who owns each step and when it is late.
▤ Concept (11 min) — Definitions, the stack and the move
Section titled “▤ Concept (11 min) — Definitions, the stack and the move”Three services, one state machine
Section titled “Three services, one state machine”| Concern | Service | What it keeps |
|---|---|---|
| Step moves, owner resolution, sub-workflows | data service | The entry’s workflow state, inside the entry |
| The HTTP routes people and clients call to act | workflow service | Nothing of its own for a move; it calls the data service |
| Time limits and workflow-status views | workflow service | Time-limit records (M4-S4) |
| Working-time arithmetic | clock service | Nothing: it computes a due date and forgets |
When a person clicks an action, the workflow service receives the call and passes it to the data service directly over internal HTTP, then returns the data service’s answer. There is no bus hop and no reply token on that path: on the 1.10 line the old bridge that sent a command over the bus and waited for an answer is gone. A reaction that moves a workflow (M4-S2) still sends a bus command and parks its saga until the completion event comes back. Both paths end in the same write logic in the data service, so a rule you change there changes both.
Definition and state
Section titled “Definition and state”The definition of a workflow lives on the entity: an ordered list of steps, each with a type, its actions and their targets, its owner settings and its time limit. The step types matter for prediction:
| Type | What the engine does with it |
|---|---|
| Entry | The first step; its owner is always the entry’s creator |
| Intermediate | An ordinary step |
| Exit | The last step; it may have no owner; a person cannot move onto it by hand |
| Ad hoc | A step inserted at run time, where the step allows it |
| Sub-workflow step | Starts another workflow of the same entity as a child |
| External step | Waits for another system to return; a person cannot execute its actions |
The state lives inside the entry itself, in fields whose names start with _meta, which the
form never shows:
_metaCurrentStepsis the stack: one item per open workflow instance, main or sub. Each item holdsworkflowId,currentStep, aninstanceId, theowner, the full eligible setoriginalOwner,active, and the links between parent and child (isInSubWorkflow,subWorkflowInstanceId,parentWorkflowInstanceId,parentStepId). Exactly one item isactive: the one a person acts on now._metaWorkflowHistoryholds one history per instance, each with itsstepsHistory: who acted, on which step, when it was received and how long it took.
Because the state is part of the entry, it travels with every read of the entry, it is protected by the same write guards, and a reaction can address a step by its position in the stack.
What one action does
Section titled “What one action does”flowchart TD
A["A person runs an action"] --> B["Workflow service: HTTP call to the data service"]
B --> C["Checks: owner, comment, re-verification, external step"]
C --> D["Next step: thresholds, conditional targets, repeat, default target"]
D --> E{"What kind of move?"}
E -->|"into a sub-workflow"| F["Park the parent, push a child instance"]
E -->|"out of a sub-workflow"| G["Close the child, resume the parent at its merge step"]
E -->|"normal"| H["Record history, set the next step and owner"]
F --> I["Write only if the state is unchanged since the checks"]
G --> I
H --> I
I --> J["Publish: action executed, step reached, step exited"]
What to notice: the events are published only after the write succeeds, and the write succeeds only if nobody changed the workflow state in between.
Choosing the next step. The engine first applies a group decision’s threshold (the action’s target may become a failure target), then the action’s conditional targets in order, taking the first whose expression is true (an expression that fails to evaluate is skipped, not raised), then the default target. A step whose owners must all act repeats until each has acted. The owner of the next step is resolved last; that is M4-S4.
The three kinds of move.
- Entering a sub-workflow. The parent instance stays on the sub-workflow step but becomes
inactive (
active: false,isInSubWorkflow: true), and a new active instance is pushed on top of the stack. No history is written for the start itself. - Leaving it. When the child reaches its exit, the engine records it, closes the child and makes the parent active again at its merge step. If that merge step is itself an exit and the parent is a child too, the completion cascades upwards.
- A normal move. One history row (one per owner on a parallel step), then the new current step and owner.
Events, and their order. Every move publishes action executed, then step reached, then step exited, the last only if the step actually changed. Reactions, time limits and the request lists you met in ACP all listen to these.
Moves that are not actions
Section titled “Moves that are not actions”Not every move comes from an action button. Every history row records a change mode, and reading it is the fastest way to know which kind of move happened:
| Change mode | What caused it | What the engine does |
|---|---|---|
Normal | A person or a reaction ran a step’s action | The move described above |
MoveToStep | An administrator or a reaction moved the request forward to a chosen step | Only steps of workflows already open in the stack are valid targets; a person may never move onto the exit step |
ReturnToStep | A return to a step already passed | A backward move by the system is recorded as a return, so the history shows the true direction |
ResetWorkflow | A reset | The main workflow goes back to its first step, keeping the same instance id; a reset sub-workflow resumes its parent |
EndWorkflow | An end | Every open sub-workflow is closed and the main workflow moves to its exit |
AdHoc | A step inserted at run time | Allowed only where the step permits ad-hoc steps; the inserted step’s definition is kept in the entry |
Two details explain surprises. Moving or returning to another workflow’s step closes every sub-workflow that sat above it in the stack, so a reset of the main workflow silently abandons an open technical review. And a reassigned owner is forgotten at the next move unless it was a permanent change, because the engine clears that flag on every transition; M4-S4 shows how a permanent change wins the next owner resolution.
Refusals you can now explain
Section titled “Refusals you can now explain”- Two people act at once. Since 1.10 every workflow write is conditional: the engine
snapshots the workflow state before computing the move and writes only if it is unchanged. The
second caller gets 409 with the code
UPDATE_CONFLICT, and nothing is published for it. Before 1.10, both calls succeeded and every reaction ran twice. - A manual action on an external step. The engine refuses it outright. Only a reaction, or the
other system’s return call with its token, can complete an external step; the return answers
success,alreadyProcessed,invalidorexecutionFailed, andsuccessmeans accepted, not finished. - An action that needs re-verification. Since 1.10 an action can require its executor to verify
their identity again just before it runs. The check sits in the data service, so it applies to
every client; reactions, external-step returns and administrative modifications are exempt. The
refusal’s code,
WORKFLOW_ACTION_STEP_UP_REQUIRED, is the contract; do not rely on its HTTP status.
Services, requests and the lists
Section titled “Services, requests and the lists”A service is an entity published to the catalog with a workflow; a request is one entry of it. The portal’s Inbox, My requests and Watching lists do not query workflow state across every entity. They read request rows, a mirror the data service rebuilds from the entry after each change, with the visible step, the owner and the watchers. That mirror explains two things you may see: a list can lag a move by a moment, and a repair migration in 1.10 rebuilt rows whose visible step was wrong. If a request shows the wrong step in the Inbox but the right one on its form, the form (the entry) is the truth.
▶ Guided demo (10 min) — The stack of a request
Section titled “▶ Guided demo (10 min) — The stack of a request”Starting state. Larkspur Lab as seeded. Purchase request PR-2031 (Spare impellers for P-104, value 8,400) waits at Procurement Review, owned by Sara Qasim.
-
Open PR-2031 in the portal. The form shows the step Procurement Review and Sara as owner.
-
In the API window, read the entry’s workflow state:
Terminal window curl -s "$BASE/api/v2/entities/purchase_requests/entries/<PR-2031 id>" \-H "x-app-token: $TOKEN" | jq '.result.entry.value._metaCurrentSteps'One item:
currentStepis the Procurement Review step id,activeistrue,owneris Sara. -
Read the history:
jq '.result.entry.value._metaWorkflowHistory[0].stepsHistory | map({step: .stepId, by: .executedBy, at: .executedAt})'on the same answer. One row: the submission at Draft. -
In the designer, open Data Entities › Purchase Requests › Workflows and match the step ids to their names.
-
As Sara, approve PR-2031 at Procurement Review. The value is below 25,000, so it goes to Approval.
-
Read the stack again. Still one item, now at Approval; the history has a second row with Sara and the action she ran.
Screenshot pending The API answer for PR-2031 showing one item in _metaCurrentSteps with currentStep, active true and the owner What to notice: the stack has one item because no sub-workflow is open; the step’s name is not stored, only its id.
✓ Practice (4 min) — Reading state
Section titled “✓ Practice (4 min) — Reading state”A request’s _metaCurrentSteps has two items. The first has active: false and
isInSubWorkflow: true; the second has active: true. Where is the request?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A planner moves a work order and the step does not change, because the step repeats until every owner has acted. Which events are published?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
The Inbox shows a request at Procurement Review, but its form shows Approval. What is true?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
⛏ Lab (33 min) — Predict and read a request through its technical review
Section titled “⛏ Lab (33 min) — Predict and read a request through its technical review”Goal. Submit a purchase request above the threshold, and before every move write down what you expect in the stack, then read it and compare.
Before you start. The demo’s API window. Sara Qasim (Procurement Lead) and Omar Haddad (in the Maintenance Planners group, which owns Engineering Check) in private windows. A table in your notes with four columns: move, predicted stack, actual stack, events.
- As yourself, open Services, select Apply on Purchase Request, then New Request. Fill Item “Replacement compressor head, C-220”, Supplier Halcyon Valves, Value 31,500, and submit. Note the request’s number and id.
- Predict the stack after submission, then read it with the demo’s command. Expect one active item at Procurement Review.
- Predict what Sara’s approval does at 31,500. Write it down: the conditional target sends the request to the Technical Review sub-workflow step; the parent is parked and a child pushed.
- As Sara, approve the request at Procurement Review.
- Read the stack. Two items: the parent with
active: false,isInSubWorkflow: trueandcurrentStepon the sub-workflow step; the child active at Engineering Check, withparentWorkflowInstanceIdequal to the parent’sinstanceId.
Screenshot pending The API answer showing two stack items, the parked parent and the active child of the Technical Review sub-workflow
What to notice: the child’s parentWorkflowInstanceId equals the parent’s instanceId; that link is how the engine finds where to merge back.
6. Read the histories: jq '.result.entry.value._metaWorkflowHistory | map({wf: .workflowId, rows: (.stepsHistory | length)})'.
The main history gained Sara’s row; the child’s history has no row yet, because entering a
sub-workflow writes none.
7. In the logs window, search for the request’s trace: the data service logged the move once.
8. As Omar, open the Inbox. The request is there, at Engineering Check.
9. Predict what Omar’s Pass does: the child reaches its exit, the child closes, the parent
resumes at its merge step Approval.
10. As Omar, run Pass.
11. Read the stack. One item again, the parent, active at Approval, isInSubWorkflow false.
12. Read the histories again. The child’s history has Omar’s row; the main history recorded the
return at the merge step.
13. A conflict. Open the request as Sara in two browser tabs. In the first tab, run Approve.
In the second tab, without reloading, run Reject.
14. The second tab shows a conflict message. Read the stack: the request is at Approved, and the
history has one approval, not a rejection.
15. In Reaction Logs, the reaction Notify requester of decision ran once for this request,
not twice.
16. An external step. Open PR-2027 (Annual bearing contract), which waits at Supplier
Confirmation, an external step. As Sara, look at its actions.
17. Try to run Confirmed from the form, or with the API window’s execute-action call from the
workbench. The engine refuses it.
18. Fill in your table’s last column for every move: the events in order.
Check.
- Every move in your table has a prediction written before the read.
- After step 5: two items, parent parked, child active, linked by instance id.
- After step 11: one item, parent active at Approval.
- The stale Reject was refused and nothing was published for it.
- The manual action on the external step was refused.
- The events column shows executed, reached, exited for every move that changed step.
Pass condition. Your table matches the stored stack at every read, and where a prediction was wrong you have written which rule you missed.
If something goes wrong
| What you see | What to do |
|---|---|
| Sara’s approval goes straight to Approval | The value is not above 25,000, or the conditional target’s expression reads another field. Check the action’s conditional targets in Workflows. |
| Omar does not see the request | Check that he is a member of Maintenance Planners and that the step’s owner is that group. M4-S4 explains owner resolution in detail. |
| The second tab’s Reject succeeded | You reloaded the tab between the two actions; repeat with a fresh request. |
The API answer has no _metaCurrentSteps | Your token is not a system viewer’s. Use the workbench token, which has system View. |
Model answer
After submission the stack has one active item at Procurement Review. Sara’s approval at 31,500
matched the conditional target, so the engine recorded her row in the main history, parked the
parent on the Technical Review step (active: false, isInSubWorkflow: true) and pushed the
child at Engineering Check, whose owner is inherited from the sub-workflow step’s owner. No
history was written for the start. Omar’s Pass took the child to its exit: the engine recorded
his row in the child’s history, closed the child and resumed the parent at the merge step
Approval. Each move published action executed and step reached, then step exited because the
step changed. The stale Reject failed the conditional write with UPDATE_CONFLICT, so it was not
recorded and no reaction ran for it. The external step refused the manual action because only a
reaction or the other system’s return may complete it.
◇ Worked scenario (2 min) — “The approval vanished”
Section titled “◇ Worked scenario (2 min) — “The approval vanished””Sara reports that she approved PR-2050 yesterday, the screen said it worked, and today the request is back at Procurement Review. Decide at each step before you read on.
Step 1. What does the history say? You read _metaWorkflowHistory. Sara’s approval is there,
at 16:02. A later row at 16:05 shows the change mode ReturnToStep, done by the system user.
Someone or something moved the request back.
Step 2. Who returns a request? A person cannot move a request backwards with a forward move; the engine re-routes a backward system move as a return so the history records the true direction. So this was a reaction or an administrator. Reaction Logs for PR-2050 at 16:05 shows a run of Return incomplete requests, which moves a request back to Procurement Review when its Quote attachment is empty.
Step 3. Why did it match? The reaction fires On Entry Updated. Sara’s approval itself did not touch Quote, but the step’s own reaction Stamp approval date updated the entry at 16:05, and Return incomplete requests has no condition on the step: any update of a request with no quote sends it back, including one at Approval.
Step 4. The fix. You add the condition “current step is Approval or later is excluded” to the criteria, or better, move the rule to where it belongs: a mandatory Quote on the Procurement Review step, so an incomplete request can never be approved. The second is the designer’s tool for the job and leaves nothing to race.
The lesson: when a request moves “by itself”, the history’s change mode and actor tell you which engine moved it, and Reaction Logs tells you why.
✓ Practice (6 min) — Moves and refusals
Section titled “✓ Practice (6 min) — Moves and refusals”A client application retries an Approve call after a timeout. The first call had in fact succeeded. What does the retry get on the 1.10 line?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A step’s action has two conditional targets. The first expression throws an error for a request with no Value; the second is true. Where does the request go?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
An outside supplier system completes an external step through its return call and receives
success. Thirty seconds later the request is still at the external step. Is something wrong?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
A reaction moves purchase requests to the next step. One of those steps requires re-verification of the executor. What happens when the reaction runs?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Put what happens when a person’s action takes a request into a sub-workflow in the order the engine does it.
Check your answer
The correct order is D → B → C → E → A. Open the explanation under each item to see why it sits where it does.
↺ Recap (1 min) — The stack is the truth
Section titled “↺ Recap (1 min) — The stack is the truth”You can now read where a request really is from its stack, predict what an action does to it, including a sub-workflow’s park and merge, and explain the engine’s refusals: a stale action, a manual action on an external step, a missing re-verification. Next, M4-S4: who becomes the owner of the step the engine just chose, and when that step becomes late.