@cratis/pi 8.5.0 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/package/corpus/harnesses/copilot/instructions/glossary.instructions.md +5 -3
  2. package/package/corpus/harnesses/copilot/instructions/react.instructions.md +3 -1
  3. package/package/corpus/harnesses/copilot/instructions/reactors.instructions.md +3 -1
  4. package/package/corpus/harnesses/copilot/instructions/specs.csharp.instructions.md +6 -3
  5. package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +5 -2
  6. package/package/corpus/rules/glossary.md +5 -3
  7. package/package/corpus/rules/react.md +3 -1
  8. package/package/corpus/rules/reactors.md +3 -1
  9. package/package/corpus/rules/specs.csharp.md +6 -3
  10. package/package/corpus/rules/vertical-slices.md +5 -2
  11. package/package/corpus/skills/cratis-application-growth/SKILL.md +1 -2
  12. package/package/corpus/skills/cratis-application-growth/references/csharp.md +0 -2
  13. package/package/corpus/skills/cratis-application-growth/references/move-and-untangle.md +1 -2
  14. package/package/corpus/skills/cratis-application-growth/references/rename-window.md +1 -3
  15. package/package/corpus/skills/cratis-application-growth/references/service-and-delivery.md +3 -2
  16. package/package/corpus/skills/cratis-application-growth/references/stages.md +2 -2
  17. package/package/corpus/skills/cratis-arc-authorize-request/SKILL.md +2 -2
  18. package/package/corpus/skills/cratis-arc-authorize-request/references/authproxy.md +19 -0
  19. package/package/corpus/skills/cratis-arc-authorize-request/references/csharp-query-security.md +15 -0
  20. package/package/corpus/skills/cratis-arc-authorize-request/references/csharp.md +12 -3
  21. package/package/corpus/skills/cratis-arc-declare-command/SKILL.md +2 -0
  22. package/package/corpus/skills/cratis-arc-declare-command/references/csharp-chronicle.md +46 -7
  23. package/package/corpus/skills/cratis-arc-declare-command/references/csharp-controller.md +3 -1
  24. package/package/corpus/skills/cratis-arc-declare-command/references/csharp-history.md +4 -1
  25. package/package/corpus/skills/cratis-arc-declare-command/references/csharp.md +31 -4
  26. package/package/corpus/skills/cratis-arc-declare-command/references/go.md +1 -1
  27. package/package/corpus/skills/cratis-arc-diagnose-live-query/references/csharp.md +24 -2
  28. package/package/corpus/skills/cratis-arc-expose-mcp-operation/references/csharp.md +49 -0
  29. package/package/corpus/skills/cratis-arc-expose-query/SKILL.md +3 -1
  30. package/package/corpus/skills/cratis-arc-expose-query/references/csharp.md +27 -4
  31. package/package/corpus/skills/cratis-arc-generate-proxies/SKILL.md +1 -0
  32. package/package/corpus/skills/cratis-arc-generate-proxies/references/csharp.md +49 -2
  33. package/package/corpus/skills/cratis-arc-generate-proxies/references/typescript.md +9 -0
  34. package/package/corpus/skills/cratis-arc-host-application/SKILL.md +1 -1
  35. package/package/corpus/skills/cratis-arc-host-application/references/csharp-configuration.md +54 -0
  36. package/package/corpus/skills/cratis-arc-host-application/references/csharp-deployment.md +98 -0
  37. package/package/corpus/skills/cratis-arc-host-application/references/csharp-http.md +9 -1
  38. package/package/corpus/skills/cratis-arc-host-application/references/csharp-identity.md +84 -2
  39. package/package/corpus/skills/cratis-arc-host-application/references/csharp.md +2 -0
  40. package/package/corpus/skills/cratis-arc-invoke-command/references/csharp.md +2 -1
  41. package/package/corpus/skills/cratis-arc-isolate-tenant/SKILL.md +18 -1
  42. package/package/corpus/skills/cratis-arc-page-query/references/csharp.md +2 -0
  43. package/package/corpus/skills/cratis-arc-react-bind-slice/SKILL.md +18 -16
  44. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-commands.md +8 -3
  45. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-host.md +84 -16
  46. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-identity.md +22 -2
  47. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-instant-feedback.md +81 -0
  48. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-localization.md +80 -0
  49. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-navigation.md +103 -0
  50. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-queries.md +40 -1
  51. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-structure.md +117 -0
  52. package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript.md +7 -3
  53. package/package/corpus/skills/cratis-arc-react-separate-view-model/SKILL.md +3 -3
  54. package/package/corpus/skills/cratis-arc-react-separate-view-model/references/typescript.md +27 -6
  55. package/package/corpus/skills/cratis-arc-validate-command/references/csharp-rules.md +23 -2
  56. package/package/corpus/skills/cratis-arc-validate-command/references/csharp.md +28 -2
  57. package/package/corpus/skills/cratis-authproxy-configure/SKILL.md +136 -0
  58. package/package/corpus/skills/cratis-authproxy-configure/references/admission.md +125 -0
  59. package/package/corpus/skills/cratis-authproxy-configure/references/aspire.md +154 -0
  60. package/package/corpus/skills/cratis-authproxy-configure/references/operations.md +122 -0
  61. package/package/corpus/skills/cratis-authproxy-configure/references/services-and-routing.md +114 -0
  62. package/package/corpus/skills/cratis-authproxy-configure/references/sessions-and-logout.md +126 -0
  63. package/package/corpus/skills/cratis-authproxy-configure/references/sign-in-providers.md +116 -0
  64. package/package/corpus/skills/cratis-authproxy-configure/references/tenant-resolution.md +135 -0
  65. package/package/corpus/skills/cratis-choreography-run-workflow/SKILL.md +117 -0
  66. package/package/corpus/skills/cratis-choreography-run-workflow/references/csharp-chronicle.md +164 -0
  67. package/package/corpus/skills/cratis-choreography-run-workflow/references/csharp.md +354 -0
  68. package/package/corpus/skills/cratis-chronicle-cli-operations/SKILL.md +2 -2
  69. package/package/corpus/skills/cratis-chronicle-cli-operations/references/project-tooling.md +28 -0
  70. package/package/corpus/skills/cratis-chronicle-connect-application/references/csharp-services.md +13 -2
  71. package/package/corpus/skills/cratis-chronicle-connect-application/references/csharp.md +12 -0
  72. package/package/corpus/skills/cratis-chronicle-connect-application/references/kotlin.md +2 -0
  73. package/package/corpus/skills/cratis-chronicle-connect-application/references/typescript.md +10 -1
  74. package/package/corpus/skills/cratis-chronicle-constrain-append/SKILL.md +8 -1
  75. package/package/corpus/skills/cratis-chronicle-constrain-append/references/csharp.md +35 -3
  76. package/package/corpus/skills/cratis-chronicle-constrain-append/references/go.md +1 -1
  77. package/package/corpus/skills/cratis-chronicle-constrain-append/references/operations.md +70 -0
  78. package/package/corpus/skills/cratis-chronicle-deploy-kernel/SKILL.md +2 -0
  79. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/configuration.md +27 -0
  80. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/container-and-kubernetes.md +293 -0
  81. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/kernel-options.md +13 -6
  82. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/network-and-tls.md +45 -0
  83. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/storage.md +91 -1
  84. package/package/corpus/skills/cratis-chronicle-deploy-kernel/references/upgrade-and-recovery.md +9 -0
  85. package/package/corpus/skills/cratis-chronicle-evolve-event/SKILL.md +12 -0
  86. package/package/corpus/skills/cratis-chronicle-inspect-observer/SKILL.md +11 -1
  87. package/package/corpus/skills/cratis-chronicle-inspect-observer/references/csharp.md +1 -1
  88. package/package/corpus/skills/cratis-chronicle-project-view/SKILL.md +1 -1
  89. package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-fluent.md +14 -3
  90. package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-model-bound.md +3 -0
  91. package/package/corpus/skills/cratis-chronicle-project-view/references/csharp-reading.md +3 -2
  92. package/package/corpus/skills/cratis-chronicle-project-view/references/csharp.md +23 -0
  93. package/package/corpus/skills/cratis-chronicle-project-view/references/elixir.md +1 -0
  94. package/package/corpus/skills/cratis-chronicle-project-view/references/go.md +2 -1
  95. package/package/corpus/skills/cratis-chronicle-project-view/references/java.md +2 -0
  96. package/package/corpus/skills/cratis-chronicle-project-view/references/kotlin.md +1 -0
  97. package/package/corpus/skills/cratis-chronicle-project-view/references/typescript.md +1 -1
  98. package/package/corpus/skills/cratis-chronicle-protect-decision/SKILL.md +2 -0
  99. package/package/corpus/skills/cratis-chronicle-protect-decision/references/csharp-scopes.md +40 -3
  100. package/package/corpus/skills/cratis-chronicle-protect-decision/references/csharp.md +20 -2
  101. package/package/corpus/skills/cratis-chronicle-protect-decision/references/elixir.md +7 -0
  102. package/package/corpus/skills/cratis-chronicle-protect-decision/references/go.md +9 -1
  103. package/package/corpus/skills/cratis-chronicle-protect-decision/references/java.md +8 -0
  104. package/package/corpus/skills/cratis-chronicle-protect-decision/references/kotlin.md +9 -0
  105. package/package/corpus/skills/cratis-chronicle-protect-decision/references/typescript.md +7 -0
  106. package/package/corpus/skills/cratis-chronicle-protect-personal-data/references/csharp.md +24 -1
  107. package/package/corpus/skills/cratis-chronicle-publish-contract/SKILL.md +1 -1
  108. package/package/corpus/skills/cratis-chronicle-publish-contract/references/csharp.md +41 -0
  109. package/package/corpus/skills/cratis-chronicle-publish-contract/references/webhook-signature-wire-format.md +82 -0
  110. package/package/corpus/skills/cratis-chronicle-react-to-fact/SKILL.md +17 -0
  111. package/package/corpus/skills/cratis-chronicle-react-to-fact/references/csharp-outputs.md +3 -1
  112. package/package/corpus/skills/cratis-chronicle-react-to-fact/references/csharp.md +35 -2
  113. package/package/corpus/skills/cratis-chronicle-react-to-fact/references/elixir.md +11 -0
  114. package/package/corpus/skills/cratis-chronicle-react-to-fact/references/java.md +1 -0
  115. package/package/corpus/skills/cratis-chronicle-react-to-fact/references/kotlin.md +1 -0
  116. package/package/corpus/skills/cratis-chronicle-record-event/SKILL.md +1 -1
  117. package/package/corpus/skills/cratis-chronicle-record-event/references/csharp-coordination.md +31 -2
  118. package/package/corpus/skills/cratis-chronicle-record-event/references/csharp-history.md +21 -4
  119. package/package/corpus/skills/cratis-chronicle-record-event/references/csharp.md +20 -2
  120. package/package/corpus/skills/cratis-chronicle-record-event/references/go.md +1 -1
  121. package/package/corpus/skills/cratis-chronicle-record-event/references/java.md +1 -1
  122. package/package/corpus/skills/cratis-chronicle-record-event/references/kotlin.md +3 -0
  123. package/package/corpus/skills/cratis-chronicle-reduce-state/SKILL.md +2 -1
  124. package/package/corpus/skills/cratis-chronicle-reduce-state/references/csharp.md +3 -1
  125. package/package/corpus/skills/cratis-chronicle-reduce-state/references/java.md +10 -1
  126. package/package/corpus/skills/cratis-chronicle-reduce-state/references/kotlin.md +10 -1
  127. package/package/corpus/skills/cratis-chronicle-reduce-state/references/typescript.md +27 -5
  128. package/package/corpus/skills/cratis-chronicle-select-client/SKILL.md +18 -0
  129. package/package/corpus/skills/cratis-chronicle-select-client/references/elixir.md +21 -1
  130. package/package/corpus/skills/cratis-chronicle-select-client/references/go.md +13 -0
  131. package/package/corpus/skills/cratis-chronicle-select-client/references/java.md +15 -0
  132. package/package/corpus/skills/cratis-chronicle-select-client/references/kotlin.md +15 -0
  133. package/package/corpus/skills/cratis-chronicle-select-client/references/typescript.md +16 -0
  134. package/package/corpus/skills/cratis-code-review/references/csharp-diagnostics.md +28 -2
  135. package/package/corpus/skills/cratis-code-review/references/csharp.md +1 -1
  136. package/package/corpus/skills/cratis-components-accessibility/SKILL.md +6 -8
  137. package/package/corpus/skills/cratis-components-accessibility/references/typescript.md +32 -14
  138. package/package/corpus/skills/cratis-components-build-canvas/SKILL.md +4 -3
  139. package/package/corpus/skills/cratis-components-build-canvas/references/typescript-props.md +1 -1
  140. package/package/corpus/skills/cratis-components-build-canvas/references/typescript.md +4 -2
  141. package/package/corpus/skills/cratis-components-choose-control/SKILL.md +13 -7
  142. package/package/corpus/skills/cratis-components-choose-control/references/from-primereact.md +116 -0
  143. package/package/corpus/skills/cratis-components-choose-control/references/menu.md +90 -0
  144. package/package/corpus/skills/cratis-components-choose-control/references/typescript-composition.md +48 -0
  145. package/package/corpus/skills/cratis-components-choose-control/references/typescript.md +2 -2
  146. package/package/corpus/skills/cratis-components-compose-toolbar/SKILL.md +2 -1
  147. package/package/corpus/skills/cratis-components-compose-toolbar/references/floating-toolbar.md +146 -0
  148. package/package/corpus/skills/cratis-components-diagnose-screen/SKILL.md +102 -0
  149. package/package/corpus/skills/cratis-components-display-list/SKILL.md +10 -10
  150. package/package/corpus/skills/cratis-components-display-list/references/typescript-custom-panel.md +74 -0
  151. package/package/corpus/skills/cratis-components-display-list/references/typescript-datatables.md +2 -7
  152. package/package/corpus/skills/cratis-components-display-list/references/typescript.md +3 -2
  153. package/package/corpus/skills/cratis-components-submit-form/references/typescript-commandform.md +72 -2
  154. package/package/corpus/skills/cratis-components-submit-form/references/typescript.md +5 -3
  155. package/package/corpus/skills/cratis-components-theme-application/SKILL.md +17 -15
  156. package/package/corpus/skills/cratis-components-theme-application/references/localization.md +166 -0
  157. package/package/corpus/skills/cratis-components-theme-application/references/typescript.md +18 -14
  158. package/package/corpus/skills/cratis-components-theme-application/references/upgrade-from-previous-major.md +141 -0
  159. package/package/corpus/skills/cratis-engineering-csharp-conventions/SKILL.md +2 -0
  160. package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp-domain-philosophy.md +31 -3
  161. package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp-fundamentals-helpers.md +119 -0
  162. package/package/corpus/skills/cratis-engineering-csharp-conventions/references/csharp.md +4 -0
  163. package/package/corpus/skills/cratis-fundamentals-concept/references/csharp-serialization.md +70 -0
  164. package/package/corpus/skills/cratis-fundamentals-concept/references/csharp.md +8 -0
  165. package/package/corpus/skills/cratis-fundamentals-concept/references/go.md +1 -0
  166. package/package/corpus/skills/cratis-fundamentals-concept/references/typescript-serialization.md +33 -0
  167. package/package/corpus/skills/cratis-fundamentals-name-value/references/csharp.md +2 -1
  168. package/package/corpus/skills/cratis-fundamentals-type-discovery/references/csharp-diagnostics.md +5 -0
  169. package/package/corpus/skills/cratis-fundamentals-type-discovery/references/go-dependency-injection.md +3 -0
  170. package/package/corpus/skills/cratis-modeling-design-event-model/SKILL.md +6 -4
  171. package/package/corpus/skills/cratis-modeling-design-event-model/references/command-inventory.md +7 -1
  172. package/package/corpus/skills/cratis-modeling-design-event-model/references/model-first.md +13 -1
  173. package/package/corpus/skills/cratis-modeling-design-event-model/references/review-one-slice.md +6 -0
  174. package/package/corpus/skills/cratis-multi-service-local-orchestration/SKILL.md +6 -6
  175. package/package/corpus/skills/cratis-multi-service-local-orchestration/references/csharp-aspire.md +116 -28
  176. package/package/corpus/skills/cratis-multi-service-local-orchestration/references/docker-compose.md +2 -2
  177. package/package/corpus/skills/cratis-observability/references/chronicle-kernel-export.md +46 -0
  178. package/package/corpus/skills/cratis-orleans-jobs/SKILL.md +4 -2
  179. package/package/corpus/skills/cratis-platform-build-application/SKILL.md +8 -0
  180. package/package/corpus/skills/cratis-platform-build-application/references/cratis-identity.md +71 -0
  181. package/package/corpus/skills/cratis-platform-build-application/references/studio-repository.md +96 -0
  182. package/package/corpus/skills/cratis-platform-deliver-slice/SKILL.md +14 -8
  183. package/package/corpus/skills/cratis-platform-deliver-slice/references/csharp.md +167 -3
  184. package/package/corpus/skills/cratis-platform-deliver-slice/references/eventual-consistency.md +150 -0
  185. package/package/corpus/skills/cratis-platform-diagnose-slice/SKILL.md +1 -1
  186. package/package/corpus/skills/cratis-platform-start-application/SKILL.md +21 -0
  187. package/package/corpus/skills/cratis-platform-start-application/references/csharp.md +77 -3
  188. package/package/corpus/skills/cratis-platform-upgrade-application/SKILL.md +118 -0
  189. package/package/corpus/skills/cratis-platform-upgrade-application/references/csharp.md +117 -0
  190. package/package/corpus/skills/cratis-platform-upgrade-application/references/java.md +53 -0
  191. package/package/corpus/skills/cratis-platform-upgrade-application/references/kotlin.md +53 -0
  192. package/package/corpus/skills/cratis-platform-upgrade-application/references/typescript.md +71 -0
  193. package/package/corpus/skills/cratis-screenplay-accept-model/references/csharp.md +29 -0
  194. package/package/corpus/skills/cratis-screenplay-accept-model/references/read-the-evidence.md +82 -1
  195. package/package/corpus/skills/cratis-screenplay-declare-slice/SKILL.md +1 -1
  196. package/package/corpus/skills/cratis-screenplay-declare-slice/references/structure-and-imports.md +10 -0
  197. package/package/corpus/skills/cratis-screenplay-onboard-workspace/SKILL.md +5 -4
  198. package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/cli.md +19 -2
  199. package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/smallest-model.md +87 -0
  200. package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/typescript.md +13 -0
  201. package/package/corpus/skills/cratis-screenplay-onboard-workspace/references/workspace-mcp.md +5 -0
  202. package/package/corpus/skills/cratis-specifications-exercise-backend/SKILL.md +2 -0
  203. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-colocated.md +101 -0
  204. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-command-results.md +3 -1
  205. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-decision-reads.md +1 -0
  206. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-events.md +1 -0
  207. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-integration.md +4 -2
  208. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp-reactors.md +3 -3
  209. package/package/corpus/skills/cratis-specifications-exercise-backend/references/csharp.md +34 -1
  210. package/package/corpus/skills/cratis-specifications-exercise-backend/references/elixir.md +2 -0
  211. package/package/corpus/skills/cratis-specifications-isolate-behavior/SKILL.md +1 -1
  212. package/package/corpus/skills/cratis-specifications-isolate-behavior/references/csharp-running.md +10 -3
  213. package/package/corpus/skills/cratis-specifications-test-application-ui/references/typescript.md +22 -4
  214. package/package/corpus/skills/cratis-specifications-test-typescript-behavior/SKILL.md +2 -1
  215. package/package/corpus/skills/cratis-specifications-test-typescript-behavior/references/typescript.md +40 -0
  216. package/package/profile-catalog.json +15 -0
  217. package/package.json +1 -1
@@ -0,0 +1,164 @@
1
+ # Workflows on Chronicle in C#
2
+
3
+ ## Contents
4
+
5
+ - Keep the journal in Chronicle
6
+ - Choose a trigger
7
+ - Start on an event
8
+ - Start on a schedule
9
+ - Start from a state machine
10
+ - Resume with a signal
11
+ - Look at runs
12
+
13
+ Reference `Cratis.Choreography.Chronicle` next to `Cratis.Choreography`. Names such as `OrderPlaced`, `OrderStateMachine`, `WorkflowNotAdmitted` and `orders.fulfil` are illustrative. Graphs, performers, definitions and starting from code are in `csharp.md`.
14
+
15
+ ## Keep the journal in Chronicle
16
+
17
+ Add the Chronicle journal to the silo, in a host that already connects to Chronicle and hosts Choreography with workflows on:
18
+
19
+ ```csharp
20
+ using Cratis.Choreography.Chronicle.Hosting;
21
+ using Cratis.Choreography.Hosting;
22
+ using Cratis.Choreography.Workflows;
23
+ using Cratis.Chronicle;
24
+
25
+ builder.AddCratisChoreography(new CratisChoreographyOptions
26
+ {
27
+ Workflows = true,
28
+ ConfigureWorkflows = workflows => workflows.Scopes.Add(WorkflowScope.Default.Value)
29
+ });
30
+ builder.Host.UseOrleans(silo => silo.AddEventSourcedWorkflows(options =>
31
+ {
32
+ options.EventStore = "orders";
33
+ options.NamespaceFor = scope =>
34
+ scope == WorkflowScope.Default ? EventStoreNamespaceName.Default : new EventStoreNamespaceName(scope.Value);
35
+ options.ScopeFor = @namespace =>
36
+ @namespace == EventStoreNamespaceName.Default ? WorkflowScope.Default : new WorkflowScope(@namespace.Value);
37
+ }));
38
+ ```
39
+
40
+ - `AddEventSourcedWorkflows` adds the workflow engine and replaces its journal with Chronicle's. Each run is an event source; its facts are appended to the event log and replayed when the run is activated.
41
+ - It registers with the Chronicle client: the run facts as event types, the run listing and open waits as read models, and one reactor per declared event trigger. Add it before the Chronicle client is first resolved.
42
+ - The runs need no grain storage, but the engine still keeps a small run index in the grain storage provider named `workflows` (`WellKnownGrainStorageProviders.Workflows`). `Workflows = true` on the Choreography host registers it.
43
+ - `AddEventSourcedWorkflows` configures only `EventSourcedWorkflowsOptions`. Set `WorkflowsOptions` through `CratisChoreographyOptions.ConfigureWorkflows`.
44
+ - `Scopes` names the scopes the engine looks in for waiting runs after a full restart; it knows none by itself, and the default scope is not added for you. The sample names the default scope, which is enough when every run is in the default namespace. When runs live in more namespaces, name the scope of every one, or register an `IWorkflowScopeSource` that returns them: see Scopes and tenants in `csharp.md`. A run waiting on a timer in a scope that is not named is never woken.
45
+ - There is also an `IServiceCollection` overload: `builder.Services.AddEventSourcedWorkflows(...)`.
46
+
47
+ | Option | Default | Meaning |
48
+ | --- | --- | --- |
49
+ | `EventStore` | `Default` | The event store the facts are appended to |
50
+ | `NamespaceFor` | the scope's value | Maps a `WorkflowScope` onto an event store namespace |
51
+ | `ScopeFor` | the namespace's value | Maps a namespace back onto a scope |
52
+ | `ReadModels` | `true` | Maintain the run listing and the open waits |
53
+ | `OnEvent<TEvent>(...)` | none | Declare an event that admits a run |
54
+ | `Schedule(...)` | none | Declare a schedule that starts a run |
55
+
56
+ The default mapping uses the scope's value as the namespace name and the reverse, exactly as written. `WorkflowScope.Default` is `default` while Chronicle's default namespace is `Default`, so with the default mapping they are two different scopes: a run started from an event in the `Default` namespace is not found under `WorkflowScope.Default`. Either map the two onto each other in both functions, as the sample does, or never hardcode a scope and always take it from the namespace through `ScopeFor`. Set both functions whenever namespace names differ from scope values.
57
+
58
+ The node work of a run is started as jobs in the event store and in the namespace its scope maps to; `WorkflowsOptions.JobsScope` is not used.
59
+
60
+ ## Choose a trigger
61
+
62
+ | Trigger | How |
63
+ | --- | --- |
64
+ | From code | `IWorkflows.Start(...)` |
65
+ | When an event is appended | `options.OnEvent<TEvent>(workflow, (@event, context) => trigger)`; returning `null` skips the event |
66
+ | When a state machine enters a state | `this.StartWorkflow(workflow)` from the state's `OnEnter` |
67
+ | On a schedule | `options.Schedule(new WorkflowSchedule(name, scope, workflow, cron))` |
68
+
69
+ These start runs. A signal does not start a run; it resumes one that is waiting. For every starting trigger, the deduplication key decides whether a run is started again, and the definition's subject kind must equal the trigger's.
70
+
71
+ ## Start on an event
72
+
73
+ Prefer this to writing your own reactor that calls `IWorkflows.Start`: the reactor is registered for you and the event's namespace becomes the run's scope through `ScopeFor`.
74
+
75
+ ```csharp
76
+ using Cratis.Choreography.Workflows;
77
+ using Cratis.Choreography.Workflows.Contracts;
78
+ using Cratis.Choreography.Workflows.Triggers;
79
+
80
+ options.OnEvent<OrderPlaced>("orders.fulfil", (@event, context) => new WorkflowTrigger(
81
+ WorkflowTriggerKind.Manual,
82
+ "orders-events",
83
+ $"order-placed:{context.SequenceNumber.Value}",
84
+ new("order", @event.OrderId),
85
+ WorkflowContractReference.Any,
86
+ "{}",
87
+ [],
88
+ @event.OrderId,
89
+ WorkflowCausationKey.None,
90
+ WorkflowActor.System,
91
+ context.Occurred));
92
+ ```
93
+
94
+ - Derive the deduplication key from the event, so a redelivered or replayed event finds its run instead of starting another.
95
+ - The eighth argument is the correlation key. A later signal reaches the run through it.
96
+ - The engine records the trigger kind in the run's history and does not act on it.
97
+
98
+ ## Start on a schedule
99
+
100
+ ```csharp
101
+ using Cratis.Choreography.Chronicle.Workflows;
102
+
103
+ options.Schedule(new WorkflowSchedule(
104
+ "nightly-reconcile", WorkflowScope.Default, "orders.reconcile", CronExpression.Parse("0 6 * * 1-5")));
105
+ ```
106
+
107
+ - A cron expression has five space-separated fields, evaluated in UTC: minute, hour, day of month, month and day of week (0-6, with 7 also Sunday). A field is `*`, a number, a range `a-b`, a step `*/n`, `a-b/n` or `a/n` (from `a` to the end of the field's range), or a comma-separated list of those. Names such as `MON` are not supported. The wrong number of fields, text that is not a number, a value outside the field's range or a step below one throws `InvalidCronExpression`; a number too large for an integer throws `OverflowException` instead.
108
+ - The schedule names its scope. `WorkflowScope.Default` here relies on the mapping shown under Keep the journal in Chronicle.
109
+ - The run's subject kind is `schedule`, so the workflow's definition must use `schedule` as its subject kind.
110
+ - The deduplication key is the schedule name and the minute it fell due, so several silos admit one run between them.
111
+ - Minutes that fell due while no silo was running are started when the first one is, up to ten minutes back. Older ones are skipped.
112
+
113
+ ## Start from a state machine
114
+
115
+ ```csharp
116
+ using Cratis.Choreography.Chronicle.Workflows;
117
+ using Cratis.Choreography.StateMachines;
118
+
119
+ public class Approved : State<OrderModel>
120
+ {
121
+ public override async Task<OrderModel> OnEnter(OrderModel state)
122
+ {
123
+ var admission = await this.StartWorkflow("orders.after-approval");
124
+ if (!admission.Admitted)
125
+ {
126
+ throw new WorkflowNotAdmitted(admission.Run, admission.Rejections);
127
+ }
128
+
129
+ return state;
130
+ }
131
+ }
132
+ ```
133
+
134
+ - The machine's type name is the subject kind, so the definition's `Subject` must be exactly that name: `"OrderStateMachine"` when the machine is `OrderStateMachine`. A definition written for another trigger, such as `orders.fulfil` with the subject `order`, is refused; give the hook a workflow whose definition has the machine's type name as its subject. The machine's key is the subject id and the run's correlation.
135
+ - `StartWorkflow` returns the admission. Check `Admitted` every time and decide in the state what a refusal means; the sample throws. Never discard the result: a refused admission starts nothing.
136
+ - The default deduplication key is the machine type, the state and the machine's key: entering the state again finds the first run. Pass `deduplication` with a key that is distinct for every entry that should start a new run. `payload` and `scope` are optional.
137
+ - For an event-sourced state machine started without a `scope` argument, the subject id and correlation are the event source id, and the scope comes from the machine's namespace through `ScopeFor`. Passing `scope` switches that off: the subject id and correlation are then the machine's full key. A machine that is not event sourced uses the default scope unless you pass one.
138
+ - A state whose machine is not a grain throws `StateMachineIsNotAGrain`.
139
+
140
+ ## Resume with a signal
141
+
142
+ A `Wait` node of kind `signal` holds the run until a signal arrives with the matching correlation and contract. Raise it from the code that learns the awaited thing happened, for example a reactor on the event:
143
+
144
+ ```csharp
145
+ using Cratis.Choreography.Chronicle.Workflows;
146
+ using Cratis.Choreography.Workflows.Contracts;
147
+
148
+ var scope = options.Value.ScopeFor(context.Namespace);
149
+ var found = await signals.Signal(
150
+ scope, orderId, new WorkflowContractReference("payment-received", 1), "{}", "payments");
151
+ ```
152
+
153
+ - `signals` is the injected `IWorkflowSignals`, `options` the injected `IOptions<EventSourcedWorkflowsOptions>` and `context` the reactor's `EventContext`.
154
+ - The scope must be the one the run was started in. A run started by an event trigger got its scope from the event's namespace through `ScopeFor`; derive the signal's scope the same way.
155
+ - It resolves, through the `resumed` outlet, every open signal wait in the scope whose correlation equals the one given and whose contract equals the one given or is `WorkflowContractReference.Any`.
156
+ - It returns how many matching waits it found in the read model and tried to resolve. That is not a count of resumed runs: a wait that has since closed, or a payload that is not valid JSON of at most 32 KiB, resolves nothing and is still counted. Do not treat a positive number as confirmation; read the run's snapshot.
157
+ - The waits are found in the open-waits read model, which can lag the run. A signal raised before its wait is visible there resolves nothing and is not remembered. A return value of zero means no wait was found; decide in the caller what that means for the process.
158
+ - Signals need `ReadModels` on.
159
+
160
+ ## Look at runs
161
+
162
+ - The `WorkflowRun` read model lists each run's id, workflow, version, subject, correlation, status and activity times. The `OpenWorkflowWait` read model lists the waits that are open. Both are in `Cratis.Choreography.Chronicle.Workflows.Listing` and can lag; use them for screens.
163
+ - The run stays authoritative: `IWorkflows.GetRun(scope, run).GetSnapshot()` answers from the journal.
164
+ - The run's own events in the event log show every step it took, in order.
@@ -0,0 +1,354 @@
1
+ # Workflows in C#
2
+
3
+ ## Contents
4
+
5
+ - Packages
6
+ - Define the graph
7
+ - Node configuration
8
+ - Outlets and failures
9
+ - Perform a capability
10
+ - Send a command from a node
11
+ - Supply the definition
12
+ - Host the engine
13
+ - Start a run
14
+ - Follow, approve and cancel a run
15
+ - Scopes and tenants
16
+ - Test a workflow
17
+
18
+ Choreography is for Cratis's own Orleans-based services; an application does not use it. Names such as `OrderWorkflows`, `ReserveStock`, `Ship`, `IStockService` and `ITenantCatalog` are illustrative.
19
+
20
+ ## Packages
21
+
22
+ | You need | Package |
23
+ | --- | --- |
24
+ | The engine, performers, definitions, hosting | `Cratis.Choreography` |
25
+ | The journal in Chronicle, event triggers, schedules, signals | add `Cratis.Choreography.Chronicle` |
26
+ | A node that executes an Arc command through `Execute<TCommand>` | add `Cratis.Choreography.Arc` |
27
+
28
+ Namespaces are `Cratis.Choreography.Workflows` and its children `Graphs`, `Adapters`, `Definitions`, `Contracts`, `Triggers`, `Runs` and `Waits`; hosting is in `Cratis.Choreography.Hosting`.
29
+
30
+ ## Define the graph
31
+
32
+ A `WorkflowGraph` is a list of nodes and a list of edges. A node is `WorkflowNode(Id, Kind, Capability, Configuration, Outlets, Policy)`; an edge is `WorkflowEdge(From, Outlet, To)`. The outlets are the ones you declare; the engine does not derive them from the kind.
33
+
34
+ ```csharp
35
+ using Cratis.Choreography.Workflows.Graphs;
36
+
37
+ var retrying = new WorkflowNodePolicy(
38
+ MaxAttempts: 3,
39
+ AttemptTimeout: TimeSpan.FromMinutes(1),
40
+ RetryDelay: TimeSpan.FromSeconds(10),
41
+ MaxVisits: 1);
42
+
43
+ var graph = new WorkflowGraph(
44
+ [
45
+ new("start", WorkflowNodeKind.Trigger, new("manual", 1), WorkflowNodeConfiguration.Empty, ["next"], WorkflowNodePolicy.Default),
46
+ new("reserve", WorkflowNodeKind.Action, new("orders.reserve-stock", 1), WorkflowNodeConfiguration.Empty, ["next", "failed"], retrying),
47
+ new("review", WorkflowNodeKind.Approval, new("engine.approval", 1),
48
+ """{"expiresAfter":"2.00:00:00"}""", ["approved", "rejected", "expired"], WorkflowNodePolicy.Default),
49
+ new("ship", WorkflowNodeKind.Action, new("orders.ship", 1), WorkflowNodeConfiguration.Empty, ["next"], retrying),
50
+ new("release", WorkflowNodeKind.Action, new("orders.release-stock", 1), WorkflowNodeConfiguration.Empty, ["next"], retrying)
51
+ ],
52
+ [
53
+ new("start", "next", "reserve"),
54
+ new("reserve", "next", "review"),
55
+ new("review", "approved", "ship"),
56
+ new("review", "rejected", "release"),
57
+ new("review", "expired", "release")
58
+ ]);
59
+ ```
60
+
61
+ - The capability of a `Trigger`, `Wait`, `Approval`, `ForEach` or `Join` node is never looked up; give it a descriptive name. Only `Action` and `Decision` capabilities need a performer.
62
+ - `WorkflowNodePolicy.Default` is one attempt of at most ten minutes, a 30 second retry delay and one visit.
63
+ - A node on a cycle needs `MaxVisits` above 1, or the graph is refused.
64
+ - A run is admitted only when the graph is sound. It is refused for: no trigger, more than one trigger, a duplicate node, an edge to an unknown node, an edge through an undeclared outlet, a `ForEach` without exactly one `Join`, a nested `ForEach`, an unbounded cycle, or a `Wait`, `ForEach` or `Join` node whose configuration cannot be read as that kind's. The configuration of the other kinds is not checked.
65
+
66
+ ## Node configuration
67
+
68
+ Configuration is JSON text with camelCase property names. A `TimeSpan` is written `[d.]hh:mm:ss`. It never holds a secret.
69
+
70
+ | Node | Property | Meaning |
71
+ | --- | --- | --- |
72
+ | `Wait` | `kind` | `signal` or `timer` |
73
+ | `Wait` | `after` | How long a timer waits |
74
+ | `Wait` | `expiresAfter` | How long a signal wait stays open before it expires; zero waits forever |
75
+ | `Wait` | `signal` | The contract a signal wait accepts, `{"id":"payment-received","version":1}`; default is any |
76
+ | `Approval` | `expiresAfter` | How long the approval stays open before it expires; zero waits forever |
77
+ | `ForEach` | `itemsFrom` | The node whose output holds the items |
78
+ | `ForEach` | `itemsProperty` | The property of that output holding the list |
79
+ | `ForEach` | `maxParallelism` | How many action and decision executions across the branches of this `ForEach` may be scheduled or awaiting a retry at once. It does not limit how many branches are open or waiting |
80
+ | `Join` | `forEach` | The `ForEach` it joins |
81
+ | `Join` | `mode` | `all`, `any` or `atLeast` |
82
+ | `Join` | `threshold` | How many branches must succeed for `atLeast` |
83
+
84
+ ```csharp
85
+ new("await-payment", WorkflowNodeKind.Wait, new("orders.await-payment", 1),
86
+ """{"kind":"signal","expiresAfter":"1.00:00:00","signal":{"id":"payment-received","version":1}}""",
87
+ ["resumed", "expired"], WorkflowNodePolicy.Default),
88
+ new("cool-off", WorkflowNodeKind.Wait, new("orders.cool-off", 1),
89
+ """{"kind":"timer","after":"1.00:00:00"}""", ["elapsed"], WorkflowNodePolicy.Default),
90
+ new("per-line", WorkflowNodeKind.ForEach, new("engine.for-each", 1),
91
+ """{"itemsFrom":"load-lines","itemsProperty":"lines","maxParallelism":4}""", ["each"], WorkflowNodePolicy.Default),
92
+ new("all-shipped", WorkflowNodeKind.Join, new("engine.join", 1),
93
+ """{"forEach":"per-line","mode":"all"}""", ["completed", "partial"], WorkflowNodePolicy.Default)
94
+ ```
95
+
96
+ Every item in a `ForEach` list must be an object with a unique, non-empty string `key`; the key names the branch. A join's output holds each branch's `key`, `status`, `outlet` and `output`. A skipped branch counts as succeeded for a join.
97
+
98
+ ## Outlets and failures
99
+
100
+ | Outlet | Taken |
101
+ | --- | --- |
102
+ | `next` | As the ordinary way on |
103
+ | `failed` | When a node failed for good |
104
+ | `fallback` | When a node answered with an outlet it does not declare, or unusable output, and `fallback` is connected |
105
+ | `each` | Once per item by a `ForEach` |
106
+ | `completed` | By a join whose mode was satisfied |
107
+ | `partial` | By a join whose mode was not satisfied once every branch had ended |
108
+ | `resumed` | By a signal wait that was resumed |
109
+ | `elapsed` | By a timer wait once its time has come |
110
+ | `expired` | By a signal or approval wait that ran out of time |
111
+ | `approved` / `rejected` | By an approval that was given or refused |
112
+ | `cancelled` | By a signal wait that was called off |
113
+
114
+ | Failure | Cause | Retried | Routed through |
115
+ | --- | --- | --- | --- |
116
+ | `Error` | The performer reported a failure or threw | While attempts remain | `failed` |
117
+ | `TimedOut` | The attempt ran past `AttemptTimeout` | While attempts remain | `failed` |
118
+ | `InvalidOutlet` | The performer answered with an undeclared outlet | No | `fallback`, else `failed` |
119
+ | `InvalidOutput` | Output was not JSON, too large or not the shape needed | No | `fallback`, else `failed` |
120
+ | `PerformerMissing` | No performer provides the capability | No | `failed` |
121
+ | `VisitLimitExceeded` | The node was reached more often than `MaxVisits` | No | Nothing |
122
+
123
+ A failure with no connected outlet fails the run in the root branch; in a `ForEach` branch it only ends the branch.
124
+
125
+ ## Perform a capability
126
+
127
+ A performer implements `IWorkflowNodePerformer`. Dependencies come from the container. Performers are discovered; do not register them. Two performers for the same capability and version throw `MoreThanOneWorkflowNodePerformer`.
128
+
129
+ ```csharp
130
+ using Cratis.Choreography.Workflows.Adapters;
131
+ using Cratis.Choreography.Workflows.Graphs;
132
+
133
+ public class ReserveStock(IStockService stock) : IWorkflowNodePerformer
134
+ {
135
+ public CapabilityReference Capability => new("orders.reserve-stock", 1);
136
+
137
+ public async Task<WorkflowNodeOutcome> Perform(WorkflowNodeInvocation invocation, CancellationToken cancellationToken)
138
+ {
139
+ var reserved = await stock.Reserve(
140
+ invocation.Input.Value, invocation.Run.Scope.Value, invocation.IdempotencyKey.Value, cancellationToken);
141
+ return reserved
142
+ ? WorkflowNodeOutcome.Succeeded("next", """{"reserved":true}""")
143
+ : WorkflowNodeOutcome.Failed("no stock");
144
+ }
145
+ }
146
+ ```
147
+
148
+ - `invocation.Input` is JSON: `{ "trigger": { "payload", "subject": { "kind", "id" }, "correlation" }, "nodes": { "<node id>": <output> }, "item": <current ForEach item> }`. `nodes` holds, for each node, the output of its latest successful visit in the current branch, or else in the root branch. A branch never sees the output of a sibling branch.
149
+ - `invocation.IdempotencyKey` is the same for every attempt of one node execution. It is derived from the workflow, the trigger's deduplication key and the node execution, not from the scope, so the same workflow and trigger key in two scopes give the same key. Pass the receiver both `invocation.Run.Scope` and the key, and deduplicate there on the pair; a receiver that is already separate per tenant needs the key only.
150
+
151
+ | Outcome | Meaning |
152
+ | --- | --- |
153
+ | `WorkflowNodeOutcome.Succeeded(outlet, output)` | Leaves through an outlet the node declares. The output is optional JSON of at most 32 KiB |
154
+ | `WorkflowNodeOutcome.Failed(reason)` | The attempt failed; retried while attempts remain |
155
+ | `WorkflowNodeOutcome.Skipped(reason)` | The branch ends there; not a failure |
156
+ | `WorkflowNodeOutcome.Ambiguous(reason)` | The effect may or may not have happened. Never retried; the run ends `ReconciliationRequired`. In the root branch a person settles it with `IWorkflowRun.Reconcile`. Never return it from a node inside a `ForEach`: that execution cannot be reconciled |
157
+ | `WorkflowNodeOutcome.Suspended(key, expiresAfter)` | Edge case: the work was accepted and the answer arrives later. The node waits until it is completed by that key or expires through `expired` |
158
+
159
+ A decision node is performed the same way: its performer returns `Succeeded` with one of the node's own outlets.
160
+
161
+ ## Send a command from a node
162
+
163
+ To run an Arc command as the node's work, derive from `ActionNodePerformer` and describe the actions. The command runs through the Arc command pipeline resolved from the host's services.
164
+
165
+ ```csharp
166
+ using System.Text.Json;
167
+ using Cratis.Choreography.Actions;
168
+ using Cratis.Choreography.Arc.Actions;
169
+ using Cratis.Choreography.Workflows.Adapters;
170
+ using Cratis.Choreography.Workflows.Graphs;
171
+
172
+ public class ShipOrder(IServiceProvider services) : ActionNodePerformer(services)
173
+ {
174
+ public override CapabilityReference Capability => new("orders.ship", 1);
175
+
176
+ protected override void Define(ActionsBuilder actions) => actions
177
+ .Execute(context => new Ship(OrderIdFrom(context.Input)));
178
+
179
+ static string OrderIdFrom(string input)
180
+ {
181
+ using var document = JsonDocument.Parse(input);
182
+ return document.RootElement.GetProperty("trigger").GetProperty("subject").GetProperty("id").GetString()!;
183
+ }
184
+ }
185
+ ```
186
+
187
+ - `Execute(context => new Ship(...))` builds the command from the action context; use it for a command that is a record. For a command class with a default constructor, `Execute<TCommand>((command, context) => ...)` creates it and lets you populate it.
188
+ - `context.Input` is the node's input JSON as a string, in the shape shown under Perform a capability. Parse the identifiers you need from it.
189
+ - The node succeeds through `next` when the command succeeds; override `SuccessOutlet` to choose another outlet. A command that is not authorized, not valid or that throws fails the attempt, and the node's policy applies.
190
+ - The action context carries the input and the run's identity, not the idempotency key. A command sent this way must itself be safe to repeat: when the operation was already applied, the command succeeds without applying it again. A command that rejects the repeat fails the attempt, and so the node, although the work was done. When the receiver needs the key to recognise the repeat or to return the original result, implement `IWorkflowNodePerformer` directly.
191
+
192
+ ## Supply the definition
193
+
194
+ A definition source implements `IWorkflowDefinitions`. Sources are discovered; do not register them.
195
+
196
+ ```csharp
197
+ using Cratis.Choreography.Workflows;
198
+ using Cratis.Choreography.Workflows.Definitions;
199
+ using Cratis.Choreography.Workflows.Graphs;
200
+
201
+ public class OrderWorkflows : IWorkflowDefinitions
202
+ {
203
+ public const string FulfilOrder = "orders.fulfil";
204
+
205
+ static readonly WorkflowDefinitionSnapshot _fulfilOrder = new(
206
+ Workflow: FulfilOrder,
207
+ Area: "orders",
208
+ Version: 1,
209
+ Subject: "order",
210
+ Graph: new WorkflowGraph(Nodes: [ /* ... */ ], Edges: [ /* ... */ ]),
211
+ CatalogVersion: "1",
212
+ Capabilities: []);
213
+
214
+ public bool Owns(WorkflowKey workflow) => workflow.Workflow.Value == FulfilOrder;
215
+
216
+ public Task<WorkflowDefinitionSnapshot?> GetActive(WorkflowKey workflow) =>
217
+ Task.FromResult<WorkflowDefinitionSnapshot?>(_fulfilOrder);
218
+ }
219
+ ```
220
+
221
+ - `Subject` is the subject kind the workflow is about. A trigger with another subject kind is rejected.
222
+ - A run pins the snapshot it was admitted with. To change a workflow, return a snapshot with a higher `Version`; runs in flight are unaffected.
223
+ - A workflow that no source owns is rejected with `NoActiveVersion`. A workflow owned by two sources throws `MoreThanOneWorkflowDefinitionSource`.
224
+
225
+ ## Host the engine
226
+
227
+ Workflows are off by default. Switch them on in the Choreography host:
228
+
229
+ ```csharp
230
+ using Cratis.Choreography.Hosting;
231
+
232
+ builder.AddCratisChoreography(new CratisChoreographyOptions { Workflows = true });
233
+ ```
234
+
235
+ - `Workflows = true` adds the engine and the grain storage provider it needs. `IWorkflows` is registered for you.
236
+ - Node work runs as Choreography jobs. `AddCratisChoreography` hosts the job system; with durable storage also register a jobs storage, as for any job. For jobs storage and the remaining host options see `cratis-orleans-jobs`, reference `csharp.md`.
237
+ - With the default storage mode, `GrainStorageMode.MongoDB`, the journal is durable. With `GrainStorageMode.InMemory` nothing survives the process.
238
+ - On durable storage, tell the engine which scopes to look in after a restart; it knows none by itself. For a service with one scope: `ConfigureWorkflows = options => options.Scopes.Add(WorkflowScope.Default.Value)`. For tenants see Scopes and tenants.
239
+ - To keep the journal in Chronicle, add the Chronicle integration: see `csharp-chronicle.md`.
240
+
241
+ `WorkflowsOptions` are set through `CratisChoreographyOptions.ConfigureWorkflows`:
242
+
243
+ | Option | Default | Meaning |
244
+ | --- | --- | --- |
245
+ | `Scopes` | empty | Scopes the engine sweeps and recovers jobs for, besides those a scope source names and those the silo has seen |
246
+ | `WakeRunsItself` | `true` | Keep a grain timer and reminder while a retry or wait deadline is pending |
247
+ | `Sweep` | `true` | Whether the sweep runs on this silo |
248
+ | `SweepInterval` | 30 seconds | How often the sweep asks every unfinished run whether it has anything to do |
249
+ | `SweepStartupDelay` | 20 seconds | How long after start the first sweep runs |
250
+ | `IdleBeforeResume` | 15 minutes | How long a run may be idle before the sweep takes it forward from its history |
251
+ | `JobsScope` | `workflows` | The jobs scope the node work of a run is started in. Not used with the Chronicle journal, where the jobs follow the event store and the namespace the scope maps to |
252
+
253
+ Deadlines and retry times follow from recorded facts, not from in-memory timers. While a deadline or retry is pending the run keeps a grain timer and a reminder; the sweep also expires due waits and starts due retries. Reminders in the co-hosted silo are in memory and do not survive a full cluster restart; the sweep does.
254
+
255
+ ## Start a run
256
+
257
+ ```csharp
258
+ using System.Text.Json;
259
+ using Cratis.Choreography.Workflows;
260
+ using Cratis.Choreography.Workflows.Contracts;
261
+ using Cratis.Choreography.Workflows.Triggers;
262
+
263
+ var admission = await workflows.Start(
264
+ WorkflowScope.Default,
265
+ OrderWorkflows.FulfilOrder,
266
+ new WorkflowTrigger(
267
+ Kind: WorkflowTriggerKind.Manual,
268
+ Source: "orders-api",
269
+ Deduplication: $"order-{orderId}",
270
+ Subject: new("order", orderId),
271
+ Contract: WorkflowContractReference.Any,
272
+ Payload: JsonSerializer.Serialize(new { orderId }),
273
+ Evidence: [],
274
+ Correlation: orderId,
275
+ Causation: WorkflowCausationKey.None,
276
+ Actor: "orders-api",
277
+ OccurredAt: DateTimeOffset.UtcNow));
278
+ ```
279
+
280
+ - `workflows` is the injected `IWorkflows`. `orderId` is a string here.
281
+ - `admission.Admitted` says whether the run was admitted, `admission.Run` is the run id and `admission.Rejections` says why not.
282
+ - `Deduplication` decides the run id together with the workflow id. In the same scope, the same key reaches the same run and starts nothing new. Every call is still checked against the active definition first, so a repeat can be rejected; another scope has its own run.
283
+ - Serialize the payload; never build the JSON by inserting values into a string. A payload that is not valid JSON is rejected.
284
+ - `Correlation` is the key that signals match on. Use the business identifier.
285
+ - The engine records `Kind` in the run's history and does not act on it.
286
+ - `Start` returns when the run is admitted, not when it has finished.
287
+
288
+ ## Follow, approve and cancel a run
289
+
290
+ ```csharp
291
+ var run = workflows.GetRun(WorkflowScope.Default, admission.Run);
292
+ var snapshot = await run.GetSnapshot();
293
+ // snapshot.Status, snapshot.Executions (Execution.Node, Status, Attempt, Outlet, Reason), snapshot.OpenWaits
294
+ ```
295
+
296
+ - Run statuses: `Running`, `Waiting`, `Succeeded`, `Failed`, `Cancelled`, `ReconciliationRequired`.
297
+ - Node statuses: `Pending`, `Scheduled`, `Waiting`, `Succeeded`, `Failed`, `Skipped`, `Unreachable`, `Cancelled`, `ReconciliationRequired`, `RetryPending`.
298
+ - A person's decision on an approval: `await run.ResolveWait(wait, "approved", payload, actor)`, where `wait` comes from `snapshot.OpenWaits`. An approval resolves through `approved` or `rejected`. A wait can be resolved or expired only while open: whichever is recorded first wins.
299
+ - `await run.Cancel(reason)` cancels the run and its open waits. An outcome that arrives afterwards is recorded, but nothing is planned from it.
300
+ - `await run.Reconcile(execution, outcome, actor)` settles a node in the root branch that answered ambiguous and resumes the run. It does nothing for a node execution inside a `ForEach` branch and does not report that; such a run stays `ReconciliationRequired`. Read the snapshot afterwards to confirm.
301
+
302
+ ## Scopes and tenants
303
+
304
+ A `WorkflowScope` is an opaque value that separates one tenant's workflows and runs from another's; `WorkflowScope.Default` is the single scope of a service without tenants. The scope is part of the run's identity, so a run cannot move to another scope.
305
+
306
+ After a full restart the sweep knows only the scopes its silo has served since, those in `WorkflowsOptions.Scopes` and those an `IWorkflowScopeSource` names. `Scopes` starts empty and the default scope is not added for you, so a run waiting on a timer in a scope nothing has touched since the restart is never woken.
307
+
308
+ - One scope: add it to `Scopes`, as shown under Host the engine.
309
+ - Tenants: register an `IWorkflowScopeSource` in the container that returns every scope.
310
+
311
+ ```csharp
312
+ using Cratis.Choreography.Workflows;
313
+ using Cratis.Choreography.Workflows.Sweeping;
314
+
315
+ public class TenantScopes(ITenantCatalog tenants) : IWorkflowScopeSource
316
+ {
317
+ public async Task<IEnumerable<WorkflowScope>> GetScopes(CancellationToken cancellationToken) =>
318
+ (await tenants.All(cancellationToken)).Select(tenant => new WorkflowScope(tenant));
319
+ }
320
+ ```
321
+
322
+ ## Test a workflow
323
+
324
+ Start with the cheapest level that shows the behaviour.
325
+
326
+ | Level | Use it for |
327
+ | --- | --- |
328
+ | The performer alone, called directly with its dependencies substituted | What one capability does and which outcome it reports |
329
+ | A real silo in the test process with in-memory storage | Running a workflow end to end: admission, routing, failure paths, expiry |
330
+ | A host against durable storage | A run that survives a restart while waiting |
331
+
332
+ An in-memory host for specs:
333
+
334
+ ```csharp
335
+ var builder = WebApplication.CreateBuilder();
336
+ builder.Configuration["urls"] = "http://127.0.0.1:0";
337
+ builder.AddCratisChoreography(new CratisChoreographyOptions
338
+ {
339
+ Clustering = ClusteringMode.Localhost,
340
+ Storage = GrainStorageMode.InMemory,
341
+ Workflows = true
342
+ });
343
+
344
+ await using var app = builder.Build();
345
+ await app.StartAsync();
346
+
347
+ var workflows = app.Services.GetRequiredService<IWorkflows>();
348
+ ```
349
+
350
+ - `CratisChoreographyOptions.Local()` gives the same clustering and storage but leaves workflows off, so write the options out.
351
+ - Localhost clustering uses the default Orleans ports, so two such silos cannot run at once on one machine. Share one silo across the specs of a test run.
352
+ - A run proceeds in the background. Poll `GetSnapshot()` under a deadline until the run reaches the expected status; never sleep a fixed time.
353
+ - Use short `after` and `expiresAfter` values in the definition under test to exercise timers and expiry.
354
+ - Assert the run status and the status of the nodes that matter, and count the effect at the receiver to prove a repeated trigger or attempt did not repeat it.
@@ -107,7 +107,7 @@ These commands outside `cratis chronicle` set the target, set up the tool and co
107
107
  | `cratis context set-value <key> <value>` | local | Change one value of the active context |
108
108
  | `cratis context rename <old> <new>`, `context delete <name>` | local | Rename or remove a saved context |
109
109
  | `cratis version` | read | Inventory: the CLI, Screenplay and server versions, the server commit and newer releases. Its `compatible` field only means the server answered, and it exits 0 when the server is unreachable; gate a deployment with `check-release` |
110
- | `cratis get-started` | read | Show the active context, its authentication state, whether the server is reachable, and starter commands; `-o json` reports `canConnect` |
110
+ | `cratis get-started` | read | Show the active context, its authentication state, whether connection setup succeeded, and starter commands; `-o json` reports that as `canConnect`. A guide, not a health check: `canConnect: true` does not prove the server answered, and it exits 0 when setup fails (4 only when the CLI would reuse a matching saved login whose token is unusable: missing, without a readable expiry, expired, or expiring within a minute), and with no CLI configuration it exits 0 with setup instructions (`-o json` returns only `configured: false`) |
111
111
  | `cratis llm-context` | read | Print the command catalog with each command's flags, `effect` and `requiresConfirmation` (`--schema` prints its JSON Schema) |
112
112
  | `cratis init` | local | Write `CHRONICLE.md` and configure the project's AI tools. `--tool claude`, `copilot`, `cursor`, `windsurf` or `pi` targets one tool instead of detecting them; `--force` overwrites existing files; `--no-commands` skips slash commands and prompt files; `--no-context` leaves the tool's instruction file alone; `--refresh` only re-captures the catalog snapshot |
113
113
  | `cratis completions bash`, `zsh`, `fish`, `powershell` | read | Print that shell's completion script to stdout |
@@ -122,6 +122,6 @@ These commands outside `cratis chronicle` set the target, set up the tool and co
122
122
  - **Reading results:** [Inspection results](references/inspection.md) covers output formats, every exit code, which command answers which question, and the `diagnose` readiness gate.
123
123
  - **Release gate or model comparison:** [Recovery outcomes and comparison](references/recovery-and-comparison.md) covers `check-release` before a deploy and the read-only Screenplay namespace comparison after one.
124
124
  - **Authorized recovery:** Check [command effects and write preflight](references/command-effects.md#preflight-for-a-write), then [recovery outcomes](references/recovery-and-comparison.md) for the exact operation. A diagnosis request does not authorize changes. Re-read after an accepted request and verify the actual outcome.
125
- - **CLI upgrades, templates and managed AI installation:** [Project tooling](references/project-tooling.md) covers `cratis ai install`/`update` in unattended setups and pinning a reviewed corpus revision.
125
+ - **CLI upgrades, templates and managed AI installation:** [Project tooling](references/project-tooling.md) covers what `cratis update` changes and leaves alone, `cratis ai install`/`update` in unattended setups and pinning a reviewed corpus revision.
126
126
 
127
127
  Leave mutating interactive keys in the terminal Workbench to an operator.
@@ -32,6 +32,34 @@ fails; `--no-templates` skips it. CLI and template versions are separate. Do not
32
32
  silently enable scaffold scripts; preserve the template's `--allow-scripts`
33
33
  choice. Multi-service orchestration still needs explicit per-store settings.
34
34
 
35
+ What `cratis update` changes beyond the CLI and the templates, and what it leaves alone:
36
+
37
+ - **Container images.** It pulls a newer Stage image or builder image only for a
38
+ supported repository that already has an image with a numeric version tag on
39
+ the machine, wherever that image came from. A repository with no local image,
40
+ or with no tag that parses as a numeric version, is skipped.
41
+ - **Installation method.** The running .NET global tool installation and a
42
+ detected Homebrew installation on macOS are updated by the command itself; a
43
+ .NET local tool is not. `--version <version>` works only for the .NET global
44
+ tool; on a detected macOS Homebrew installation it exits 5 and updates
45
+ nothing. Any other native installation, including a Homebrew installation on
46
+ Linux, is not updated: the command ignores `--version`, prints how to update
47
+ it, still attempts the image and template refreshes, reports `updated: false`
48
+ in `-o json`, and exits 0. Exit 0
49
+ therefore does not prove a newer CLI, and on the automatic paths `updated` can
50
+ reflect the expected version rather than a verified one. Confirm with
51
+ `cratis version` from the executable you intend to use.
52
+ - **Existing applications.** Newer templates change the default set that the
53
+ next `cratis new` uses. When `cratis new` acquires a template package, its
54
+ `--version` overrides that pin (`*` requests the latest); `--template-path`
55
+ uses the local package and bypasses package selection altogether. Newer
56
+ templates never change an application that is already scaffolded.
57
+ - **Installed AI guidance.** It does not touch a Cratis-managed AI corpus
58
+ installation in a repository. Run `cratis ai update` from each directory that
59
+ contains `.cratis/ai.json`; it does not search parent directories, so from a
60
+ subdirectory, or without that file, the command fails and asks for
61
+ `cratis ai install`. What `cratis init` wrote is not such an installation.
62
+
35
63
  For `cratis render` / `run`, use the `cratis-stage-render-slice` skill. The bundled renderer determines support;
36
64
  a CLI upgrade can change admission, generated output and the default container
37
65
  without changing the model. Never infer support from the ESM version alone or
@@ -1,7 +1,5 @@
1
1
  # C#: what the connected client gives you
2
2
 
3
- Names are illustrative.
4
-
5
3
  ## Contents
6
4
 
7
5
  - Services you can inject
@@ -11,6 +9,8 @@ Names are illustrative.
11
9
  - Artifact discovery and registration failures
12
10
  - Federation management
13
11
 
12
+ Names are illustrative.
13
+
14
14
  ## Services you can inject
15
15
 
16
16
  `AddCratisChronicle` (and `AddCratisChronicleClient` on a generic host) registers these. Take the narrowest one a class needs.
@@ -52,6 +52,17 @@ Every appended event records who caused it, the operation it belongs to and the
52
52
  - **Keep `Subject` stable.** It identifies the actor; `Name` is only for display. When a person's name changes, call `await store.Identities.Rename(subject, newName)`: existing events and read models show the new name because they refer to the identity, not a copy.
53
53
  - **Correlation:** one ID per logical operation, read from `ICorrelationIdAccessor.Current` (`Cratis.Execution`). To start a new one for a background job, register `new CorrelationIdAccessor()` yourself with `configure: b => b.WithCorrelationIdAccessor(accessor)` and call `accessor.Modify(CorrelationId.New())` at the start of the job; the value flows with the async call.
54
54
  - **Causation:** an ASP.NET Core request (its route) and an Arc command are recorded for you. For your own unit of work use `using var scope = client.CausationManager.BeginScope("ImportBatch", properties)`; disposing it removes the link. `Add(type, properties)` leaves the link on the chain for every later append in the same flow, so prefer the scope. `properties` is an `IDictionary<string, string>`: never put secrets or personal data in it.
55
+ - **Reading who caused an event:** `GetMetadataAt` returns `CausedBy` as a `ResolvedIdentity` (`Subject`, `Name`, `UserName`, `Resolution`, `OnBehalfOf`). The name is looked up at read time, so a rename shows on the next read, also for events appended before it. `OnBehalfOf` is the next link of the chain and is resolved separately. Check `Resolution` (`IdentityResolution` in `Cratis.Chronicle.EventSequences`) before showing a name:
56
+
57
+ | `Resolution` | Meaning | `Name` |
58
+ | --- | --- | --- |
59
+ | `Resolved` | The identity exists and has a display name | The current name |
60
+ | `NameUnavailable` | The identity exists but its display name is empty | `null` |
61
+ | `Missing` | The stored identity no longer resolves | `null` |
62
+ | `NotSet` | No identity was recorded | `null` |
63
+ | `System` | Chronicle's own system identity | `null` |
64
+
65
+ The read never substitutes the subject for a name it cannot give: choose your own placeholder for a `null` name. A `Resolved` name is whatever was recorded, and that can itself equal the subject, for example when a caller was recorded without a display name, so do not treat `Name` as proof of a human-readable name. `InitiatorType` on the metadata classifies the first link: `Agent` when it acts on behalf of another identity, otherwise `User`; `System` for Chronicle's system identity; `Unknown` when it is missing, not set or the well-known unknown identity. An application's own service identity is **not** `System`: it classifies as `User` or `Agent`, so recognise service identities by their subject, never by display name. `cratis-chronicle-record-event` (`references/csharp-history.md`) owns the metadata read itself.
55
66
 
56
67
  ## Connection failures
57
68
 
@@ -1,5 +1,12 @@
1
1
  # Connect a .NET workload to Chronicle
2
2
 
3
+ ## Contents
4
+
5
+ - Host setup (below)
6
+ - Select a partition and prove readiness
7
+ - Edge cases: readiness of another store, Arc host deployment
8
+ - Not supported in this SDK
9
+
3
10
  Names are illustrative. For a standalone ASP.NET Core service reference `Cratis.Chronicle.AspNetCore`; for a generic host or owned client reference `Cratis.Chronicle`. Supply `Cratis:Chronicle:ConnectionString` from deployment secrets, including `skipTlsValidation=false` for a shared endpoint. Make the kernel reachable and its certificate trusted before diagnosing registration.
4
11
 
5
12
  ```csharp
@@ -73,6 +80,11 @@ Use `await client.GetEventStores(ct)` and `await store.GetNamespaces(ct)` for ro
73
80
  - [Client services](csharp-services.md) — injectable services, the event store's members, identity and causation, connection failures and federation management.
74
81
  - [Behavior patterns](csharp-patterns.md) — ask what a user or scope usually does.
75
82
 
83
+ ## Edge cases
84
+
85
+ - **Readiness of a store the health check does not cover.** The `chronicle` health check is the default and reports the configured store only. For another store the application opens itself, read `client.GetStartupStatus("orders", EventStoreNamespaceName.Default, RegistrationMode.Inline)` in your own readiness endpoint and answer ready only when `State` is `EventStoreStartupState.Completed`. The other states are `NotStarted`, `Connecting`, `Registering` and `Failed`; `PendingArtifacts` lists the kinds of registration work still outstanding and is empty outside registration. The call is local: it neither opens the store nor contacts the kernel, so open the store on the normal startup path. Pass exactly the store name, namespace and registration mode the store was opened with (`options.RegistrationMode` unless a mode was passed to `GetEventStore`); no namespace is resolved for you, and a combination the client has not opened answers `NotStarted`. `Completed` means registration finished on the current connection, not that an observer has caught up.
86
+ - **Arc host deployment.** Deploy a current Arc integration, Chronicle client and kernel together, and upgrade them together. Arc command features such as completing a stream scoped to one event source, several concurrency guards for one event source ID in the same command, and the generated-ID freshness check on staged events rely on all three; do not work around a mismatch in the command.
87
+
76
88
  ## Not supported in this SDK
77
89
 
78
90
  - Borrowing a raw gRPC channel with caller-retained lifetime: let Chronicle construct its transport. Even the constructor accepting `IChronicleConnection` disposes that connection.