@cratis/pi 7.47.1 → 7.48.2
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.
- package/package/corpus/harnesses/copilot/instructions/application-profile.instructions.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/local-work-artifacts.instructions.md +6 -2
- package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +1 -1
- package/package/corpus/hooks/README.md +11 -5
- package/package/corpus/hooks/scripts/cratis-cleanup-worktrees.sh +44 -4
- package/package/corpus/prompts/ship-changes.prompt.md +4 -1
- package/package/corpus/rules/application-profile.md +1 -1
- package/package/corpus/rules/local-work-artifacts.md +6 -2
- package/package/corpus/rules/vertical-slices.md +1 -1
- package/package/corpus/skills/cratis-arc-command/SKILL.md +7 -6
- package/package/corpus/skills/cratis-arc-command/references/decisions-and-routing.md +41 -11
- package/package/corpus/skills/cratis-arc-command/references/read-model-injection.md +2 -1
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +18 -4
- package/package/corpus/skills/cratis-chronicle-decision-reads/SKILL.md +41 -6
- package/package/corpus/skills/cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md +213 -0
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +17 -4
- package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +3 -1
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +12 -3
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +6 -2
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +2 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +110 -167
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +74 -170
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/case-tables-and-whole-numbers.md +15 -35
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/choosing-generation.md +4 -6
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/render-example.md +23 -27
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/rendered-application.md +21 -33
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +61 -92
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/scene-runtime.md +4 -12
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/verification.json +10 -14
- package/package.json +1 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Choosing how a write-side rule holds
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Route first
|
|
6
|
+
- The matrix
|
|
7
|
+
- A plain read guards nothing
|
|
8
|
+
- Constraints
|
|
9
|
+
- Decision reads and protected decisions
|
|
10
|
+
- Arc traps
|
|
11
|
+
- Chronicle-only traps
|
|
12
|
+
- Costs and why protection is opt-in
|
|
13
|
+
- Checklist for generated code
|
|
14
|
+
|
|
15
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
16
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
17
|
+
|
|
18
|
+
Shared by the Chronicle, Arc and Screenplay consistency skills. It answers one
|
|
19
|
+
question: **which mechanism makes this rule hold while other writers append at the
|
|
20
|
+
same time**, and which look correct but do not. Read it before writing a command,
|
|
21
|
+
validator, endpoint or handler that reads state and then appends.
|
|
22
|
+
|
|
23
|
+
Verified against Chronicle source at v19.59.1 (decision-read refusals of
|
|
24
|
+
self-reducing models since 19.58.0) and Arc main `0986d097a`. Published guides, which
|
|
25
|
+
this agrees with:
|
|
26
|
+
[Chronicle: choosing how a rule holds](/chronicle/dynamic-consistency-boundary/choosing/),
|
|
27
|
+
[decision reads](/chronicle/read-models/decision-reads/),
|
|
28
|
+
[Arc: choosing how a command's rule holds](/arc/backend/csharp/chronicle/consistency/).
|
|
29
|
+
|
|
30
|
+
## Route first
|
|
31
|
+
|
|
32
|
+
Take the first step that matches the rule.
|
|
33
|
+
|
|
34
|
+
1. **A value must be unique, or something may exist once** (email, ISBN, one
|
|
35
|
+
registration per source): a constraint. Not a read, not a validator.
|
|
36
|
+
2. **The rule uses data outside Chronicle events**: record the external fact as an
|
|
37
|
+
event first, then decide on it; otherwise accept the risk and repair. No decision
|
|
38
|
+
read covers external state.
|
|
39
|
+
3. **A rare violation is acceptable** (overbooking you can compensate): append
|
|
40
|
+
normally and repair with a reactor that returns a correcting event.
|
|
41
|
+
4. **Someone edited what someone else changed** (the user saw revision N): an explicit
|
|
42
|
+
concurrency scope built from the revision the user supplied.
|
|
43
|
+
5. **A rule over one key's history** (cannot ship before payment, stock or count
|
|
44
|
+
on one key): a decision read of a flat, event-source-keyed projection.
|
|
45
|
+
6. **A rule over one stream inside a source**: a stream-scoped decision read
|
|
46
|
+
(Chronicle) or `IStreamReads`/`StreamDecision` (Arc).
|
|
47
|
+
7. **A rule across two keys** (course capacity and a student's course limit): one
|
|
48
|
+
decision read per key, one event per event source, one atomic `AppendMany`; or
|
|
49
|
+
put every fact the rule needs on one event source and use one read.
|
|
50
|
+
8. **Rich behaviour over one lifecycle** (many rules, one key): a richer flat
|
|
51
|
+
projection read as one decision read, or in Arc an aggregate root.
|
|
52
|
+
9. **Only a UX hint** (disable a button, show seats left): a plain read.
|
|
53
|
+
10. **Only input shape** (range, format, required): a validator. No guard needed.
|
|
54
|
+
|
|
55
|
+
## The matrix
|
|
56
|
+
|
|
57
|
+
| Rule shape | Use | Never use | Too much |
|
|
58
|
+
| --- | --- | --- | --- |
|
|
59
|
+
| Unique value | `[Unique]` property or `IConstraint` | read model check then append | decision read or scope (they guard one key's history) |
|
|
60
|
+
| Create once | `[Unique]` on the event type | "does it exist" read then append | decision read |
|
|
61
|
+
| One key's history, stock, count | decision read; Arc `[ProtectedDecision]` + `DecisionRead<T>` | plain read model, validator read, `concurrency: true` | aggregate for one counter |
|
|
62
|
+
| Two keys | two decision reads + one event per source in one `AppendMany` | two separate appends, a guard on one side only | none |
|
|
63
|
+
| One stream | stream-scoped decision read; Arc `IStreamReads` | whole-source read when one stream matters | none |
|
|
64
|
+
| Edit conflict | explicit scope from the user's revision | last writer wins by accident | constraint |
|
|
65
|
+
| Rich behaviour | richer projection read once; Arc aggregate | rules spread over validators and plain reads | aggregate for one rule |
|
|
66
|
+
| Rare violation acceptable | append, repair with a reactor | presenting a plain read as a guarantee | decision read |
|
|
67
|
+
| UX hint | plain read | treating the hint as enforcement | decision read (several calls and a full fold) |
|
|
68
|
+
| Hot key, long history | shorten histories (split by period or stream); constraint for uniqueness | ignoring cost: each decision read refolds the key | none |
|
|
69
|
+
|
|
70
|
+
Not a guard: a plain read, a `CommandValidator` that reads, `Result<,>`, returning
|
|
71
|
+
`ValidationResult.Error`, `concurrency: true`, the default optimistic append, a
|
|
72
|
+
reactor, or an `ExpectedRevision` you never pass into a scope.
|
|
73
|
+
|
|
74
|
+
## A plain read guards nothing
|
|
75
|
+
|
|
76
|
+
Whatever the backing, a plain read captures no position and enrolls no guard.
|
|
77
|
+
|
|
78
|
+
| Backing | Freshness | Guard |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| Materialized projection or reducer (default) | may lag the log | none |
|
|
81
|
+
| `[Passive]` projection | fresh at read time | none |
|
|
82
|
+
| `[Passive]` reducer | fresh at read time | none |
|
|
83
|
+
| Self-reducing model (19.58.0) | as its `[Passive]` setting | none |
|
|
84
|
+
|
|
85
|
+
Passive is fresher, not safer. Capturing the tail yourself before a materialized
|
|
86
|
+
read does not fix it: the read may be older than the position you captured, and
|
|
87
|
+
the events in between are neither seen nor guarded. Do not rebuild a decision read
|
|
88
|
+
by hand. Every Arc read-model injection (`Handle`, `Provide`, validator
|
|
89
|
+
constructor) and every `IReadModels.GetInstanceById` is a plain read, on a
|
|
90
|
+
protected command too.
|
|
91
|
+
|
|
92
|
+
## Constraints
|
|
93
|
+
|
|
94
|
+
A constraint binds every writer, whichever client or service appends, per namespace
|
|
95
|
+
and per event sequence. It cannot count, sum or test a predicate; it expresses
|
|
96
|
+
uniqueness (with release on a removal event), create-once and closed streams.
|
|
97
|
+
|
|
98
|
+
- The claim is settled after the durable append (decision 0005, accepted, not yet
|
|
99
|
+
implemented in every store). A failed index update is logged and a later duplicate
|
|
100
|
+
may pass until a reindex. SQL and InMemory stores do not yet settle claims
|
|
101
|
+
(#3744 and the decision's gap list). A constraint is the right mechanism, not an
|
|
102
|
+
unconditional proof.
|
|
103
|
+
- Tenants in different namespaces can claim the same value.
|
|
104
|
+
- `[RemoveConstraint]` releases attribute constraints (`[Unique]` on a property
|
|
105
|
+
or on the event type); on a fluent `IConstraint` it compiles and does nothing,
|
|
106
|
+
so use `.RemovedWith<T>()` there.
|
|
107
|
+
- It is not re-run when the kernel retries a duplicate sequence number.
|
|
108
|
+
- For a friendly message use `.WithMessage`; Arc maps a violation to HTTP 400.
|
|
109
|
+
|
|
110
|
+
## Decision reads and protected decisions
|
|
111
|
+
|
|
112
|
+
A decision read folds an admitted projection in a fresh session after capturing
|
|
113
|
+
the log boundary, and the append is rejected if an event of the model's types
|
|
114
|
+
for that key arrived after the boundary, **whoever wrote it** (the kernel checks the
|
|
115
|
+
stored tail filtered by key, types and route). See the skill's
|
|
116
|
+
[admission and ownership](admission-and-ownership.md) for the refusal list.
|
|
117
|
+
|
|
118
|
+
- **Admission.** A flat projection keyed by event source, with a finite event-type
|
|
119
|
+
set and an `Id` property (string, or Guid in lowercase hyphenated form). Reducers,
|
|
120
|
+
self-reducing models, joins, children, `FromEvery`, event-property routing and
|
|
121
|
+
other sequences are refused. A model without `Id`, or keyed by a concept that does
|
|
122
|
+
not convert, refuses with `KeyConversion`; in Arc that surfaces as HTTP 500.
|
|
123
|
+
- **Absent models are guarded.** A concurrent creation conflicts. Do not fabricate a
|
|
124
|
+
default instance for an absent model.
|
|
125
|
+
- **Cross-key.** A read on key X guards X even when the command appends only to Y.
|
|
126
|
+
Per-key reads cover only keys in the read set: when new keys can join the set
|
|
127
|
+
("a member holds at most three loans" with each loan on its own source), write the
|
|
128
|
+
facts on a key that is read, usually the member's.
|
|
129
|
+
- **Every deciding writer must be guarded.** The guard detects every matching
|
|
130
|
+
event appended after its boundary, but it protects only the decision that carries
|
|
131
|
+
it. If the guarded write lands first, a writer that decides on the same facts
|
|
132
|
+
without a guard (a plain read, an `[Unprotected]` command, a direct append) can
|
|
133
|
+
still append on stale state and break the rule. The rule holds only when every
|
|
134
|
+
writer that decides on it is guarded, or when it is a constraint, which checks
|
|
135
|
+
every append.
|
|
136
|
+
- **Conflict.** No automatic retry. Reread and decide again, or resubmit. Revise/redact,
|
|
137
|
+
other sequences, external state, projection definition changes and writes that
|
|
138
|
+
bypass the kernel's serialized append path (duplicate grain activations, direct
|
|
139
|
+
storage writes) are outside the guard.
|
|
140
|
+
- **Empty protected commit.** A unit that enrolled a decision read and staged no
|
|
141
|
+
events appends an empty batch with the guard scopes. At Chronicle v19.59.1 the kernel
|
|
142
|
+
validators (`AppendManyValidator`, `AppendManyForEventSourcesValidator`) accept an
|
|
143
|
+
empty batch when a scope carries an actual boundary or expects no matching event, and the integration
|
|
144
|
+
spec `for_ReadModels/when_reading_for_a_decision` shows `AppendMany([], guardedBy:)`
|
|
145
|
+
succeeds when nothing changed and reports a concurrency violation when the model
|
|
146
|
+
changed. A kernel that rejects an empty batch ("At least one event is required.")
|
|
147
|
+
surfaces as `DecisionReadValidateOnlyNotSupported`, which fails closed. Read from
|
|
148
|
+
source, not run end to end: treat validate-only as supported on a current kernel
|
|
149
|
+
and assert it with an integration specification before relying on it.
|
|
150
|
+
- **Arc opt-in.** Protection is per command: `[ProtectedDecision]` marks a command
|
|
151
|
+
that takes `DecisionRead<T>` or command-aware `IDecisionReads`; unmarked commands
|
|
152
|
+
keep legacy behaviour, `[Unprotected]` opts out. There is no app-wide option, because
|
|
153
|
+
making it default would refuse validators with dependencies, refused shapes and
|
|
154
|
+
commands appending through an injected `IEventLog`.
|
|
155
|
+
The key is the command's event source id; for other keys use
|
|
156
|
+
`IDecisionReads.Get<T>((ReadModelKey)id)`.
|
|
157
|
+
|
|
158
|
+
## Arc traps
|
|
159
|
+
|
|
160
|
+
| Trap | What happens | Fix |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| Read model injected into `Handle`, `Provide` or a validator, then events returned | plain read; two requests both win | decision read, constraint or stream decision |
|
|
163
|
+
| `CommandValidator` that reads state | advisory; also refused on a protected command | validator for shape rules only |
|
|
164
|
+
| Protected command with a discoverable validator that has constructor dependencies or several public constructors | HTTP 500, nothing runs | parameterless validator (exactly one public parameterless constructor); move state rules into the decision |
|
|
165
|
+
| `concurrency: true` on `EventStreamId`, `EventStreamType` or `EventSourceType` | reads the narrowed tail after `Handle`; changes granularity, not the decision. A command that also reads `IReadModels` still triggers `ARCCHR0011` | decision read, explicit scope or stream decision |
|
|
166
|
+
| Default (no attributes) | Arc reads the tail when the unit of work commits, after `Handle` | only protects the window between that read and the write |
|
|
167
|
+
| First append into a scope | unchecked unless `ChronicleOptions.ConcurrencyOptions.CheckFirstAppendIntoAScope` is set | constraint, or an aggregate (new aggregates expect no first event) |
|
|
168
|
+
| Two or more key candidates (`EventSourceId`-typed, `[Key]`-marked or implicitly convertible) | `ARCCHR0002` warns, and `[Key]` does not silence it. At runtime Arc silently takes the first eligible property in declaration order (`EventSourceId`-typed or `[Key]`-marked, no priority for derived types; an unmarked `ConceptAs<Guid>` is not eligible). With one candidate Arc keys by it silently; with none each call gets a new id | implement `ICanProvideEventSourceId` |
|
|
169
|
+
| No id property | a random event source id per call; nothing can conflict | give the command a key |
|
|
170
|
+
| `[Unprotected]` command taking `DecisionRead<T>` | resolves to an unguarded read | use `[ProtectedDecision]` |
|
|
171
|
+
| Injected `IEventLog.Append` in `Handle` | immediate write that survives a conflict rollback | return events |
|
|
172
|
+
| Aggregate `Commit()` whose result is ignored, or `Failed()` without `Commit()` | staged events still commit | return `await aggregate.Commit()` |
|
|
173
|
+
| Aggregate with an enrolled decision read | `Commit()` throws `ProtectedUnitOfWorkRequiresOwner` | choose one mechanism per command |
|
|
174
|
+
| Aggregate for a rule across aggregates | each aggregate guards only itself | cross-key decision reads |
|
|
175
|
+
| Tests without `UseDecisionReads()` and a competing `AppendConcurrently` | the race is never exercised | `CommandScenario` with decision reads |
|
|
176
|
+
|
|
177
|
+
## Chronicle-only traps
|
|
178
|
+
|
|
179
|
+
- Decision read, then plain `IEventLog.Append`: the immediate append bypasses the
|
|
180
|
+
guard. Stage with `Transactional.Append`, or pass `guardedBy:` to `AppendMany`.
|
|
181
|
+
- `Get<T>` needs an ambient unit of work. `GetDetached<T>` enrolls nothing until you
|
|
182
|
+
pass it to `AppendMany(..., guardedBy:)` or `AddDecisionRead`.
|
|
183
|
+
- The ASP.NET Core middleware commits **after** the response. Call
|
|
184
|
+
`IUnitOfWorkCompletionFeature.CommitAsync()` before responding and check
|
|
185
|
+
`IsSuccess` and `GetDecisionConflicts()`; the middleware reports no concurrency
|
|
186
|
+
violations, so a late commit failure never reaches the caller.
|
|
187
|
+
- Ignoring the `AppendResult` loses a violation silently: violations are results.
|
|
188
|
+
- An explicit scope and a decision read on the same source in one unit throw
|
|
189
|
+
`DecisionReadConflictsWithConcurrencyScope`; pick one.
|
|
190
|
+
- A manual scope built without a sequence number is skipped by the kernel; check
|
|
191
|
+
`ConcurrencyCheckPerformed`. Capture the tail before reading the facts.
|
|
192
|
+
- Arc has a static class also named `ConcurrencyScopeBuilder`; in an Arc project
|
|
193
|
+
qualify Chronicle's builder.
|
|
194
|
+
|
|
195
|
+
## Costs and why protection is opt-in
|
|
196
|
+
|
|
197
|
+
A decision read makes about four calls per attempt (up to three attempts), folds the
|
|
198
|
+
key's whole history of the model's types on every read, shares a per-model-type
|
|
199
|
+
projection grain across keys and tenants, and is not retried on conflict. Use it
|
|
200
|
+
where histories are short and write contention per key is low; shorten histories
|
|
201
|
+
before reaching for it on a hot key. A constraint costs one index lookup inside the
|
|
202
|
+
append. Decision reads are .NET only.
|
|
203
|
+
|
|
204
|
+
## Checklist for generated code
|
|
205
|
+
|
|
206
|
+
- Name the mechanism and say why the rule shape needs it. A plain read, validator,
|
|
207
|
+
`Result<,>` or `concurrency: true` is never presented as the guard.
|
|
208
|
+
- Uniqueness is a constraint. A state rule has a decision read, scope or stream
|
|
209
|
+
decision enrolled **before** the events are staged.
|
|
210
|
+
- The decision-read model is admitted (flat projection, `Id`, event-source keyed).
|
|
211
|
+
- Cross-key rules append one event per source atomically.
|
|
212
|
+
- A specification interleaves a competing append and asserts the conflict.
|
|
213
|
+
- What stays unguarded (an unguarded writer's own decision, external state, revisions) is stated.
|
|
@@ -13,6 +13,16 @@ already be stale by the time the append lands; a constraint cannot be.
|
|
|
13
13
|
|
|
14
14
|
Constraints are discovered automatically. There is no registration call.
|
|
15
15
|
|
|
16
|
+
A constraint binds **every** writer, whichever client or service appends, so it is
|
|
17
|
+
the mechanism for uniqueness and create-once. It cannot count, sum or test a
|
|
18
|
+
predicate: capacity and stock rules need a decision read, a stream decision or an
|
|
19
|
+
aggregate. Read [choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md)
|
|
20
|
+
when it is unclear which one a rule needs. Limits: the claim is settled after the
|
|
21
|
+
durable append (decision 0005), so a failed index update can let a later duplicate
|
|
22
|
+
through until a reindex; constraints apply per event store namespace and event
|
|
23
|
+
sequence, so tenants in different namespaces can claim the same value; and a
|
|
24
|
+
constraint is not re-run when the kernel retries a duplicate sequence number.
|
|
25
|
+
|
|
16
26
|
## Verified product sources
|
|
17
27
|
|
|
18
28
|
| Package | Version | Purpose |
|
|
@@ -32,9 +42,10 @@ memory.
|
|
|
32
42
|
|
|
33
43
|
- The rule rejects **command input** — a range, a format, a cross-field
|
|
34
44
|
condition: use `cratis-arc-command-validation`.
|
|
35
|
-
- The rule is state-dependent
|
|
36
|
-
stream/projection decision reads with
|
|
37
|
-
|
|
45
|
+
- The rule is state-dependent (a count, a capacity, a status) and needs
|
|
46
|
+
concurrency protection: use enrolled stream/projection decision reads with
|
|
47
|
+
`cratis-arc-command-validation` and `cratis-chronicle-decision-reads`. Plain
|
|
48
|
+
injected models, validators and `Result<,>` alone remain advisory.
|
|
38
49
|
- You are creating or changing a read model that the rule reads: use
|
|
39
50
|
`cratis-chronicle-read-model`.
|
|
40
51
|
- You are writing the specification and want the `EventScenario` mechanics in
|
|
@@ -261,7 +272,9 @@ removing a manual closure. Closing does not erase history or prevent replay.
|
|
|
261
272
|
- **The constraint never fires.** You used class-level `[Unique]` for a value
|
|
262
273
|
that has to be unique across event sources, or property-level `[Unique]` for
|
|
263
274
|
a "one per event source" rule. Re-read Step 1 — the kind is the switch.
|
|
264
|
-
- **`[RemoveConstraint]` releases nothing.**
|
|
275
|
+
- **`[RemoveConstraint]` releases nothing.** It releases attribute constraints
|
|
276
|
+
(`[Unique]` on a property or on the event type); on a fluent `IConstraint` it
|
|
277
|
+
compiles and does nothing, so use `.RemovedWith<T>()` there. Otherwise the string does not match the
|
|
265
278
|
`[Unique]` name. When `[Unique]` had no explicit name the real name is the
|
|
266
279
|
member or type name, which is easy to get wrong; name it explicitly.
|
|
267
280
|
- **`PropertyDoesNotExistOnEventType` at startup.** A non-member-access lambda
|
|
@@ -132,7 +132,9 @@ If a field can only be filled by reaching into another behavior's read model to
|
|
|
132
132
|
*learn a fact the events should have carried*, you have found a missing event or
|
|
133
133
|
a wrong stream boundary. Fix the model. A read-only cross-slice read through
|
|
134
134
|
Chronicle is allowed where the rule needs it (an injected read model read by
|
|
135
|
-
explicit key, or a `[Passive]` projection for a
|
|
135
|
+
explicit key, or a `[Passive]` projection for a current read; a rule that must hold under
|
|
136
|
+
concurrency needs a decision read or constraint, see
|
|
137
|
+
[choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md)); see
|
|
136
138
|
Cross-slice patterns in `rules/vertical-slices.md`. Make such a read deliberate
|
|
137
139
|
and name it in the brief, with the consistency it needs: a rule that must hold
|
|
138
140
|
under concurrency needs enrolled guarded reads, not plain injection or a stale
|
|
@@ -173,12 +173,19 @@ Neighbouring members include `GetInstances<T>`, `GetSnapshotsById<T>`,
|
|
|
173
173
|
surface on `IReadModels`** — filtered reads go through the sink, which is what
|
|
174
174
|
the Arc query methods above do.
|
|
175
175
|
|
|
176
|
-
### `[Passive]` when the read
|
|
176
|
+
### `[Passive]` when the read must be current
|
|
177
177
|
|
|
178
178
|
`Cratis.Chronicle.ReadModels.PassiveAttribute` on the read-model type makes it
|
|
179
179
|
passive: no sink, nothing materialized, and the instance is computed on demand
|
|
180
|
-
from the events at the moment it is read. Reach for it when a
|
|
181
|
-
|
|
180
|
+
from the events at the moment it is read. Reach for it when a read must be
|
|
181
|
+
current rather than eventually consistent.
|
|
182
|
+
|
|
183
|
+
**Passive is fresher, not safer.** A materialized read may lag the log; a passive
|
|
184
|
+
read is current when read. Neither captures a position or enrolls a guard, so
|
|
185
|
+
neither makes a rule hold when two requests race. To guard a decision use a decision
|
|
186
|
+
read over a flat, event-source-keyed projection with an `Id` property (reducers and
|
|
187
|
+
self-reducing models are refused), a constraint for uniqueness, or an aggregate;
|
|
188
|
+
see [choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md).
|
|
182
189
|
|
|
183
190
|
**`IMongoCollection<T>` reads only the sink.** It cannot compute passive state:
|
|
184
191
|
a fresh passive model has no maintained collection, and a formerly active one
|
|
@@ -232,6 +239,8 @@ spans streams.
|
|
|
232
239
|
- Query methods are `static` and declare `ISubject<...>` rather than a concrete
|
|
233
240
|
subject type.
|
|
234
241
|
- A direct `GetInstanceById` result is checked for absence before use.
|
|
242
|
+
- A plain read, materialized or passive, is never presented as the guard of a
|
|
243
|
+
write-side rule.
|
|
235
244
|
- Passive access goes through Chronicle, not a sink collection; consistency,
|
|
236
245
|
access frequency, and non-materialization requirements justify the choice.
|
|
237
246
|
- Summary payloads and embedded children are bounded; growing histories have
|
|
@@ -134,8 +134,12 @@ public sealed class ReducerAttribute(string id = "", string? eventSequence = def
|
|
|
134
134
|
`Cratis.Chronicle.ReadModels.PassiveAttribute` (`[Passive]`) goes on the **read
|
|
135
135
|
model type** and makes it passive as a whole: no sink, nothing materialized, and
|
|
136
136
|
the instance is computed on demand when it is read. Reach for it when a
|
|
137
|
-
command-side
|
|
138
|
-
read
|
|
137
|
+
command-side read needs the model current at the moment it is read. Passive is
|
|
138
|
+
fresher, not safer: a passive reducer read captures no position and guards nothing,
|
|
139
|
+
and a reducer (or a self-reducing model, since Chronicle 19.58.0) is refused by
|
|
140
|
+
decision reads. For a rule that must hold under concurrent writers use a flat
|
|
141
|
+
projection with a decision read; see
|
|
142
|
+
[choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md).
|
|
139
143
|
|
|
140
144
|
## Filtering which events reach the reducer
|
|
141
145
|
|
|
@@ -109,7 +109,8 @@ option, mark it `ASSUMED` in the slice or module `documentation` and in the sess
|
|
|
109
109
|
- Forbidden: a caller-supplied copy of state in `require`, a boolean attestation input
|
|
110
110
|
(`confirmsX == true`) standing in for a rule, and rules hidden in `handler` or
|
|
111
111
|
implementation-hint prose. An unguarded materialized read is unsafe for a protected
|
|
112
|
-
decision; that is not "read models never drive decisions".
|
|
112
|
+
decision; that is not "read models never drive decisions". See
|
|
113
|
+
`../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md`.
|
|
113
114
|
3. **Play the races and retries.** For each enforced or recorded rule write the concurrent case
|
|
114
115
|
(two commands at once), the retry case (same request again after a lost reply) and the
|
|
115
116
|
duplicate case (same intent, new id). State the outcome and which construct produces it.
|