Skip to content

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

  1. A step is persisted before it is sent.
  2. The engine marks a step dispatched with a lease (three times his.workflow.dispatch-timeout) and commits.
  3. It sends the command outside any transaction, and records the result in a second transaction.
  4. The idempotency key of a step is wfl:<instanceId>:<stepId>, and wfl:<instanceId>:<stepId>:compensate for its compensation. It is the same for every attempt, so an owning domain that honours keys gives one business effect (AC-02).
  5. A lease that runs out means the unit stopped mid-command: the outcome is unknown.
  6. 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).
  7. Several replicas are safe. Each change locks the instance row, and a dispatched step is not taken up again before its lease runs out.
  8. No blind replay (part 6.11, Architecture 12.3, TEST-ESS-043).
  9. A step is replay-sensitive when its <domain>:<target> matches the setting his.workflow.replay-sensitive-targets. The setting stands for CFG-ISE-007 of Domain 2.
  10. 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 as addPersonIdentifier or registerPatient.
  11. 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.
  12. 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.
  13. The owning domain's reconciliation answers with signalWorkflowInstance (step-result completed or failed). A completed result returns the instance to Pending, and it goes on.
  14. A manual retry of a replay-sensitive step needs three things. The definition's replayPermitted (the owning domain's rule) must be true. A secondPerson who 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.
  15. secondPerson in workflow.v1 is 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).
  16. 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.
  17. Retries and unavailable targets (parts 6.5, PR-WFL-001-2, PR-WFL-001-4).
  18. Attempts are bounded by the definition (retry.maxAttempts, default his.workflow.max-attempts 5). The backoff starts at initialBackoff and doubles up to maxBackoff.
  19. A 4xx answer (other than 408 and 429) is a refusal: the step is Failed at once.
  20. An unavailable target spends no attempt. After circuit-threshold consecutive unavailable answers, its circuit holds the domain's steps back for circuit-open-for. The instance stays Pending, and the step shows nextAttemptAt and the reason.
  21. A step Failed for good makes the instance Failed (failedStepId in the event) and raises an alert to the administrator and the definition's supervisor.
  22. Definitions, task types and queues are configuration (CFG-001).
  23. They are the item types ess.workflow-definition (item key the definition identifier), ess.task-type and ess.work-queue.
  24. 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.
  25. Until each owner registers its own, workflow/registrations.json seeds 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-review and ess.decision-record-review (the last three for ADR-HIS-052 point 5);
    • the scenario's adm.duplicate-review and queue adm.identity-stewardship, on behalf of Domain 1;
    • ebp.pathway-conflict-review of part 6.11, owned by Domain 9.
  26. The content of a definition.
  27. A definition has definitionId, owningDomain, title and steps in order. It may add retry {maxAttempts, initialBackoff, maxBackoff} as ISO 8601 durations, onFailure (compensate or recover), and supervisorRole.
  28. Each step has stepId, name and kind:
    • api: target (the operationId), method, path with {instanceId}, {businessKey}, {patient} and {encounter}, and optionally awaitResult, replaySensitive and replayPermitted;
    • task: taskType, and queueId or assigneeRole (else the type's default queue), priority, dueIn;
    • timer: wait;
    • signal: signal.
  29. Any step may name a compensation command.
  30. Steps run one after the other. onFailure defaults to compensate where 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 with compensation-incomplete, and the administrator's compensateWorkflowInstance resumes it.
  31. The command body is references and context only: instance, definition and version, step, business key, context, initiating actor, onBehalfOf and inputs, with compensation: true on 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.
  32. An event-driven step is a signal step: the owning domain reacts to its own events and signals.
  33. Commands go to his.workflow.targets.<domain>. A domain without an address is unavailable, so its steps wait.
  34. Tasks.
  35. 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.
  36. 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.
  37. A claim or a start moves Assigned to In Progress (section 4.3). Claiming a task another user holds is 409.
  38. Completion is checked against the type's completionEvidence (JSON Schema 2020-12) and its outcomes, and a refusal needs a reason. Where outcomeConfirmation is owning-domain, a person's completion is recorded with the flag awaiting-confirmation, published as TaskStateChanged with change completion-recorded, and the task stays open until the owning domain's service completes it (part 6.10).
  39. 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=true lists both (AC-02).
  40. 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.
  41. "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.
  42. 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.
  43. 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_request in the caller's transaction, and logs it.
  44. Pathway conflicts (part 6.11, AC-06).
  45. The rule is built as PathwayConflicts.received. Its idempotency key is ebp.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 to his.workflow.pathway-conflict-fallback-role (CFG-EBP-015, the unit supervisor on duty). Priority is High and the task is due in 24 hours.
  46. The subscription to PathwayConflictDetected waits for Domain 9's event contract.
  47. IF-ESS-001 version 1 cannot find the account of a practitioner. Until it can, PractitionerAccounts resolves none, and the review goes to the unit supervisor on duty.
  48. Authorization.
  49. Every operation asks the policy decision point first. Action codes are ess.wfl.<record>.<verb>, for records definition, instance, task, queue and task-type. Resource types are ess.WorkflowDefinition, ess.WorkflowInstance, ess.Task, ess.WorkQueue and ess.TaskType.
  50. The request carries the task type, the owning domain, the queue with its eligibleRoles and supervisorRoles, and the assignee. The decision point decides eligibility and supervision, because roles are not in the token (DEC-ESS-008).
  51. 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.
  52. 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.
  53. Storage.
    • Each record keeps its contract representation in doc (jsonb) beside its key and filter columns. The engine's own state is in runtime, and a task's evidence and pending completion in internal.
    • revision is the ETag and the contract's version.
    • 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.
  54. The provider contract test follows ADR-HIS-052 point 11: his-contract verify in the pinned Node.js image against the unit on a random port, one operation at a time on its own fixture at revision 3, then validate-event on 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 replayPermitted only 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 eligibleRoles and supervisorRoles;
  • ess.wfl.instance.replay-confirm;
  • the roles ess.workflow-administrator, identity-steward, identity-steward-lead and ebp.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.