Architecture / Decision records / ADR-HIS-058
ADR-HIS-058 Coordination services: the workflow engine's durable steps, no blind replay, the definition form, and tasks without a person in between¶
| Status | Accepted |
| Decided | 2026-11-25 by session RC-1-S15 |
| Record | Drafted 2026-11-25; approved 2026-11-30 by the Enterprise Architecture Board |
| Where the rule lives | services/ess-coordination/ (its README.md; module mod-ess-008, its migration mod-ess-008/src/main/resources/db/mod_ess_008/, workflow/registrations.json, the contract test in mod-ess-008/src/test/java/care/cema/his/ess/mod008/contract/) |
Context¶
Session RC-1-S15 builds MOD-ESS-008 in the coordination unit services/ess-coordination: versioned workflow definitions with durable execution (FR-ESS-WFL-001), and tasks and work queues with stuck-work recovery (FR-ESS-WFL-002). It serves workflow.v1 (IF-ESS-010) of the ESS contracts (ADR-HIS-048).
DEC-ESS-014 decided which work runs on this engine. Every domain whose workflows have human tasks, timers or escalation will define them here, so the choices below bind every later session that writes a definition, registers a task type or a queue, or is the target of a step. The specification and the contract leave these points to the design: - how a step is persisted, dispatched and retried, so that a restart repeats nothing done and a repeated command has one effect (parts 6.3 to 6.6); - what "no blind replay" into medication, billing or identity means for the engine (part 6.11, TEST-ESS-043); - the form of a definition's content, which the configuration item holds (part 6.1); - where task types and queues come from before each domain registers its own; - who is eligible, who supervises, and how the facility of a task is enforced; - what is done until the notification service (MOD-ESS-007, RC-2) exists.
Decision¶
- A step is persisted before it is sent.
- The engine marks a step dispatched with a lease (three times
his.workflow.dispatch-timeout) and commits. - It sends the command outside any transaction, and records the result in a second transaction.
- The idempotency key of a step is
wfl:<instanceId>:<stepId>, andwfl:<instanceId>:<stepId>:compensatefor its compensation. It is the same for every attempt, so an owning domain that honours keys gives one business effect (AC-02). - A lease that runs out means the unit stopped mid-command: the outcome is unknown.
- The only state held in memory is the circuits of point 3. After a restart the scheduler finds every instance as it was: completed steps are never repeated (AC-01), and timers fire from their stored time (part 6.6).
- Several replicas are safe. Each change locks the instance row, and a dispatched step is not taken up again before its lease runs out.
- No blind replay (part 6.11, Architecture 12.3, TEST-ESS-043).
- A step is replay-sensitive when its
<domain>:<target>matches the settinghis.workflow.replay-sensitive-targets. The setting stands for CFG-ISE-007 of Domain 2. - The default fails closed. It covers every step into Domain 1 (identity), Domain 3 (medication) and Domain 5 (billing), and Domain 10's identity operations:
adm:*,cli:*,fin:*,ess:*identit*,ess:*account*,ess:*role*,ess:*service-identit*. Matching ignores case. A pattern by operation name would miss real identity writes such asaddPersonIdentifierorregisterPatient. - The list is the one list of part 6.11. A definition can add a step to it (
"replaySensitive": true), never take one off: a step the list matches stays replay-sensitive whatever its definition says. - A replay-sensitive step whose outcome is unknown is never sent again automatically. Unknown means a timeout, a 5xx answer or an interrupted lease. The step is Failed, the instance is Failed with the flag
reconciliation-required, and it is alerted and on the recovery worklist. - The owning domain's reconciliation answers with
signalWorkflowInstance(step-resultcompletedorfailed). A completed result returns the instance to Pending, and it goes on. - A manual retry of a replay-sensitive step needs three things. The definition's
replayPermitted(the owning domain's rule) must be true. AsecondPersonwho is not the requester must be named. And the policy decision point must permit that person in their own right (ess.wfl.instance.replay-confirm, OV-112, CUX-64). Otherwise the retry is refused. secondPersoninworkflow.v1is an account ID the requester supplies. The unit cannot prove that person confirmed in place, as CUX-64 asks; a step-up assertion in the contract would (a follow-up for the ESS contract session).- An answer that proves the command was not delivered (503, 429, no connection) may be retried, because a retry of it is not a replay.
- Retries and unavailable targets (parts 6.5, PR-WFL-001-2, PR-WFL-001-4).
- Attempts are bounded by the definition (
retry.maxAttempts, defaulthis.workflow.max-attempts5). The backoff starts atinitialBackoffand doubles up tomaxBackoff. - A 4xx answer (other than 408 and 429) is a refusal: the step is Failed at once.
- An unavailable target spends no attempt. After
circuit-thresholdconsecutive unavailable answers, its circuit holds the domain's steps back forcircuit-open-for. The instance stays Pending, and the step showsnextAttemptAtand the reason. - A step Failed for good makes the instance Failed (
failedStepIdin the event) and raises an alert to the administrator and the definition's supervisor. - Definitions, task types and queues are configuration (CFG-001).
- They are the item types
ess.workflow-definition(item key the definition identifier),ess.task-typeandess.work-queue. - The unit subscribes to ConfigurationChanged and reads the version in force through
readConfigurationVersion. It installs a definition version as active and supersedes the previous one, which keeps running for its instances (PR-WFL-001-3, AC-05). Content that cannot run is logged and not installed. - Until each owner registers its own,
workflow/registrations.jsonseeds the following (only what is missing; nothing from configuration is overwritten):- Domain 10's types
ess.workflow-step-skip-approval,ess.configuration-approval,ess.emergency-change-reviewandess.decision-record-review(the last three for ADR-HIS-052 point 5); - the scenario's
adm.duplicate-reviewand queueadm.identity-stewardship, on behalf of Domain 1; ebp.pathway-conflict-reviewof part 6.11, owned by Domain 9.
- Domain 10's types
- The content of a definition.
- A definition has
definitionId,owningDomain,titleandstepsin order. It may addretry {maxAttempts, initialBackoff, maxBackoff}as ISO 8601 durations,onFailure(compensateorrecover), andsupervisorRole. - Each step has
stepId,nameandkind:api:target(the operationId),method,pathwith{instanceId},{businessKey},{patient}and{encounter}, and optionallyawaitResult,replaySensitiveandreplayPermitted;task:taskType, andqueueIdorassigneeRole(else the type's default queue),priority,dueIn;timer:wait;signal:signal.
- Any step may name a
compensationcommand. - Steps run one after the other.
onFailuredefaults tocompensatewhere any step has a compensation. Compensation runs the completed steps' compensations in reverse order, and the instance becomes Compensated (AC-04). A compensation that fails leaves it Failed withcompensation-incomplete, and the administrator'scompensateWorkflowInstanceresumes it. - The command body is references and context only: instance, definition and version, step, business key, context, initiating actor,
onBehalfOfand inputs, withcompensation: trueon a compensation. The headers are Idempotency-Key, X-Correlation-Id, X-Facility of the context and the unit's service token (part 6.9, part 13). Each owning domain decides for itself on the command. - An event-driven step is a
signalstep: the owning domain reacts to its own events and signals. - Commands go to
his.workflow.targets.<domain>. A domain without an address is unavailable, so its steps wait. - Tasks.
- Creation is by the service of the type's owning domain (part 3). A task always has a queue or an assignee (BR-ESS-026). A user assignee without a queue takes the type's default queue.
- A facility- or department-scoped queue requires the task's facility to be the queue's. The facility is then immutable: the service never changes it, and a trigger refuses any change.
- A claim or a start moves Assigned to In Progress (section 4.3). Claiming a task another user holds is 409.
- Completion is checked against the type's
completionEvidence(JSON Schema 2020-12) and itsoutcomes, and a refusal needs a reason. WhereoutcomeConfirmationisowning-domain, a person's completion is recorded with the flagawaiting-confirmation, published as TaskStateChanged with changecompletion-recorded, and the task stays open until the owning domain's service completes it (part 6.10). - At the due time a task becomes Overdue. Where its type names an
escalationPolicy, the escalation is requested in the same run and the task is Escalated.overdue=truelists both (AC-02). - IdentityChanged keeps a projection of account states and role assignments. A suspended or deactivated account returns its open tasks to their queue with the flag
returned-to-queue. So does a revoked assignment, for queues whose eligible roles the account no longer holds. - "Eligible active users" counts the active accounts holding an eligible role. IdentityChanged does not carry an assignment's facility scope, so the count is enterprise-wide.
- Stuck work is computed when read, from each record's last state or owner change, against CFG-ESS-015 (critical 15 minutes, others 24 hours). The scheduler alerts each episode once.
- Notifications until IF-ESS-009. Escalations and stuck alerts go through the module's notification port. Until the notification service exists, the default records each request in
notification_requestin the caller's transaction, and logs it. - Pathway conflicts (part 6.11, AC-06).
- The rule is built as
PathwayConflicts.received. Its idempotency key isebp.pathway-conflict:<conflictId>. It takes the attending practitioner from Domain 1's readEncounter, and assigns to that practitioner's account if it is active, otherwise tohis.workflow.pathway-conflict-fallback-role(CFG-EBP-015, the unit supervisor on duty). Priority is High and the task is due in 24 hours. - The subscription to PathwayConflictDetected waits for Domain 9's event contract.
- IF-ESS-001 version 1 cannot find the account of a practitioner. Until it can,
PractitionerAccountsresolves none, and the review goes to the unit supervisor on duty. - Authorization.
- Every operation asks the policy decision point first. Action codes are
ess.wfl.<record>.<verb>, for recordsdefinition,instance,task,queueandtask-type. Resource types areess.WorkflowDefinition,ess.WorkflowInstance,ess.Task,ess.WorkQueueandess.TaskType. - The request carries the task type, the owning domain, the queue with its
eligibleRolesandsupervisorRoles, and the assignee. The decision point decides eligibility and supervision, because roles are not in the token (DEC-ESS-008). - For a record with a facility, the decision is asked for that facility, with the caller's X-Facility as
requestFacility. Lists are filtered row by row through the same decision. - The unit checks what depends on the record itself:
- a service starts, signals and cancels only its own domain's definitions, and creates and cancels only its own types;
- retry, skip, compensation, claim, release, start, reassignment and recovery are for persons;
- the second person of a replay is not the requester.
- Storage.
- Each record keeps its contract representation in
doc(jsonb) beside its key and filter columns. The engine's own state is inruntime, and a task's evidence and pending completion ininternal. revisionis the ETag and the contract'sversion.- A command runs its change, audit event (
ess.wfl.definition,ess.wfl.instance,ess.wfl.task), domain event and Idempotency-Key record in one transaction. - The engine runs in transactions of its own (REQUIRES_NEW), also when it continues an instance right after a request has committed.
- Each record keeps its contract representation in
- The provider contract test follows ADR-HIS-052 point 11:
his-contract verifyin the pinned Node.js image against the unit on a random port, one operation at a time on its own fixture at revision 3, thenvalidate-eventon the published TaskStateChanged and WorkflowInstanceStateChanged.
Consequences¶
- An owning domain that writes a definition:
- names its step commands' paths;
- expects every step into Domain 1, 3 or 5 to wait for its reconciliation when the outcome is unknown, since the default list holds them all back; a narrower list is changed in CFG-ISE-007, not in a definition;
- honours the Idempotency-Key of each command;
- answers with a step-result signal where it set
awaitResult; - reconciles a replay-sensitive step it is told is
reconciliation-required; - sets
replayPermittedonly where its reconciliation rule allows a replay. - The configuration service (MOD-ESS-012) registers the three item types of point 4, with this unit's content forms. Until then definitions are installed only by the seed, or by a configuration published under those types.
- The policy decision service (RC-1-S16, RC-1-S17) registers:
- the actions and resource types of point 9;
- the eligibility and supervision rules on
eligibleRolesandsupervisorRoles; ess.wfl.instance.replay-confirm;- the roles
ess.workflow-administrator,identity-steward,identity-steward-leadandebp.unit-supervisor-on-duty. - Domain 2 publishes CFG-ISE-007 where this unit can read it; the setting of point 2 then follows it.
- Domain 9's event contract adds the subscription of point 8. A practitioner lookup in IF-ESS-001 then replaces the default of
PractitionerAccounts. - The notification service (RC-2) takes over the requests of point 7.
Alternatives considered¶
- An external workflow engine (Temporal, Camunda, Flowable). Rejected for this slice. It adds a platform component that is not in the technology stack sheet, with its own persistence and operation at Tier 2. Its replay model would still need the reconciliation rule of point 2 for medication, billing and identity. The engine here is one table per record kind in the unit's own database, under the kit's outbox, audit and policy.
- Retry every failed command with its key, sensitive targets included. Rejected: part 6.11 forbids a blind replay into those targets even with a key, because the owning domain's reconciliation must decide what happened.