@kairos-es/read 0.0.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 (82) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +538 -0
  3. package/dist/cjs/EventLogDurability.js +184 -0
  4. package/dist/cjs/EventLogDurability.js.map +1 -0
  5. package/dist/cjs/ProjectionRunner.js +478 -0
  6. package/dist/cjs/ProjectionRunner.js.map +1 -0
  7. package/dist/cjs/ProjectionStore.js +233 -0
  8. package/dist/cjs/ProjectionStore.js.map +1 -0
  9. package/dist/cjs/foldIntoRef.js +36 -0
  10. package/dist/cjs/foldIntoRef.js.map +1 -0
  11. package/dist/cjs/inMemoryProjectionStore.js +138 -0
  12. package/dist/cjs/inMemoryProjectionStore.js.map +1 -0
  13. package/dist/cjs/index.js +128 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/projectionWiringFault.js +532 -0
  16. package/dist/cjs/projectionWiringFault.js.map +1 -0
  17. package/dist/cjs/runProjection.js +117 -0
  18. package/dist/cjs/runProjection.js.map +1 -0
  19. package/dist/cjs/runProjections.js +144 -0
  20. package/dist/cjs/runProjections.js.map +1 -0
  21. package/dist/cjs/superviseOnProgress.js +580 -0
  22. package/dist/cjs/superviseOnProgress.js.map +1 -0
  23. package/dist/cjs/testing.js +143 -0
  24. package/dist/cjs/testing.js.map +1 -0
  25. package/dist/dts/EventLogDurability.d.ts +182 -0
  26. package/dist/dts/EventLogDurability.d.ts.map +1 -0
  27. package/dist/dts/ProjectionRunner.d.ts +557 -0
  28. package/dist/dts/ProjectionRunner.d.ts.map +1 -0
  29. package/dist/dts/ProjectionStore.d.ts +475 -0
  30. package/dist/dts/ProjectionStore.d.ts.map +1 -0
  31. package/dist/dts/foldIntoRef.d.ts +39 -0
  32. package/dist/dts/foldIntoRef.d.ts.map +1 -0
  33. package/dist/dts/inMemoryProjectionStore.d.ts +11 -0
  34. package/dist/dts/inMemoryProjectionStore.d.ts.map +1 -0
  35. package/dist/dts/index.d.ts +185 -0
  36. package/dist/dts/index.d.ts.map +1 -0
  37. package/dist/dts/projectionWiringFault.d.ts +260 -0
  38. package/dist/dts/projectionWiringFault.d.ts.map +1 -0
  39. package/dist/dts/runProjection.d.ts +185 -0
  40. package/dist/dts/runProjection.d.ts.map +1 -0
  41. package/dist/dts/runProjections.d.ts +480 -0
  42. package/dist/dts/runProjections.d.ts.map +1 -0
  43. package/dist/dts/superviseOnProgress.d.ts +587 -0
  44. package/dist/dts/superviseOnProgress.d.ts.map +1 -0
  45. package/dist/dts/testing.d.ts +207 -0
  46. package/dist/dts/testing.d.ts.map +1 -0
  47. package/dist/esm/EventLogDurability.js +175 -0
  48. package/dist/esm/EventLogDurability.js.map +1 -0
  49. package/dist/esm/ProjectionRunner.js +468 -0
  50. package/dist/esm/ProjectionRunner.js.map +1 -0
  51. package/dist/esm/ProjectionStore.js +223 -0
  52. package/dist/esm/ProjectionStore.js.map +1 -0
  53. package/dist/esm/foldIntoRef.js +29 -0
  54. package/dist/esm/foldIntoRef.js.map +1 -0
  55. package/dist/esm/inMemoryProjectionStore.js +131 -0
  56. package/dist/esm/inMemoryProjectionStore.js.map +1 -0
  57. package/dist/esm/index.js +185 -0
  58. package/dist/esm/index.js.map +1 -0
  59. package/dist/esm/package.json +4 -0
  60. package/dist/esm/projectionWiringFault.js +524 -0
  61. package/dist/esm/projectionWiringFault.js.map +1 -0
  62. package/dist/esm/runProjection.js +109 -0
  63. package/dist/esm/runProjection.js.map +1 -0
  64. package/dist/esm/runProjections.js +137 -0
  65. package/dist/esm/runProjections.js.map +1 -0
  66. package/dist/esm/superviseOnProgress.js +571 -0
  67. package/dist/esm/superviseOnProgress.js.map +1 -0
  68. package/dist/esm/testing.js +133 -0
  69. package/dist/esm/testing.js.map +1 -0
  70. package/package.json +41 -0
  71. package/src/EventLogDurability.ts +201 -0
  72. package/src/ProjectionRunner.ts +923 -0
  73. package/src/ProjectionStore.ts +528 -0
  74. package/src/foldIntoRef.ts +63 -0
  75. package/src/inMemoryProjectionStore.ts +163 -0
  76. package/src/index.ts +218 -0
  77. package/src/projectionWiringFault.ts +694 -0
  78. package/src/runProjection.ts +270 -0
  79. package/src/runProjections.ts +623 -0
  80. package/src/superviseOnProgress.ts +897 -0
  81. package/src/testing.ts +290 -0
  82. package/testing/package.json +6 -0
@@ -0,0 +1,571 @@
1
+ /**
2
+ * `superviseOnProgress` — the projection runner's SUPERVISOR: retry an effect for
3
+ * as long as an EXTERNALLY OBSERVED progress signal keeps moving, and give up when
4
+ * it stops.
5
+ *
6
+ * ## The mechanism
7
+ *
8
+ * A daemon that fails has to be restarted, and something has to decide when
9
+ * restarting has become pointless. The usual answer counts failures, which
10
+ * cannot tell "this keeps failing and nothing is happening" from "this keeps
11
+ * failing and the work is getting done anyway" — and those two want opposite
12
+ * decisions. So this module keys the decision on a SIGNAL the supervised effect
13
+ * does not own: a `Position` read from somewhere else, monotone by construction,
14
+ * whose movement means work landed no matter who landed it. Two mechanisms, kept
15
+ * deliberately apart:
16
+ *
17
+ * - **The schedule decides HOW FAST to restart** — a capped, jittered,
18
+ * sawtoothing exponential that never terminates on its own.
19
+ * - **The circuit-breaker decides WHETHER to keep restarting** — by re-reading
20
+ * `progress` after every failure and counting only the CONSECUTIVE restarts
21
+ * that moved it not at all.
22
+ *
23
+ * Splitting them is what makes a competing writer behave. Two processes
24
+ * accidentally maintaining one materialisation — a deploy overlapping its
25
+ * predecessor, one store passed twice — both fail on every batch, the loser's
26
+ * guarded checkpoint advance being superseded every time; but the WINNER keeps
27
+ * advancing the shared stored position, so every one of the loser's restarts
28
+ * observes movement, its counter resets, and it resynchronises from the winner's
29
+ * position for as long as the winner keeps working: bounded duplicate effort, at
30
+ * the schedule's rate, with no hot loop and no spurious give-up. Only a signal
31
+ * that is genuinely stuck — a poison event whose apply always fails, a
32
+ * persistently broken view store — trips the breaker and fails
33
+ * `ProjectionStalled`.
34
+ *
35
+ * "Accidentally" is the word and it is doing work, because ONE read model
36
+ * materialised N ways is a DELIBERATE shape (`runProjections`) and is not this case
37
+ * at all. Those N runners share a `ProjectionId` but each owns its own checkpoint in
38
+ * its OWN store, so they never contend, no guard is ever lost between them, and
39
+ * nothing here is being relied on to make them safe. The tolerated fault above is
40
+ * two writers over ONE cursor, which is what the construction gate's collision rung
41
+ * refuses when it is a wiring rather than an overlapping deploy — this mechanism
42
+ * degrades gracefully under it and is deliberately not the place it is caught.
43
+ *
44
+ * ## Two observability channels, and which one is primary
45
+ *
46
+ * Every supervision outcome is reported twice: to a HOOK — `onRestart` on every
47
+ * restart, `onStalled` once at the give-up — and to a LOG LINE beside it. The
48
+ * hooks are the primary channel and carry the fault ITSELF, untouched. The log
49
+ * lines are the thin lossy default: every annotation on them is a string or a
50
+ * number — JSON-SAFE, that is, rather than uniformly stringy, because
51
+ * `effect@3.22`'s `Logger.json` throws outright on a `bigint` nested in an
52
+ * annotation value and `CheckpointSuperseded` carries one (the measurement, for
53
+ * each shipped logger, is at the annotations in `shouldRestart`). The one numeric
54
+ * annotation, `noProgressRestarts`, stays numeric on purpose: a serialiser has no
55
+ * quarrel with it and an aggregator can filter and graph on it, both of which a
56
+ * `String` around it would give up for nothing. The fault goes out through
57
+ * `String`, which is to say through the FAULT: `Error.prototype.toString` is
58
+ * `name: message`, so a fault with something to say sets `message` — as all four of
59
+ * the runner's own faults do, `CheckpointSuperseded` included, its `bigint`
60
+ * `expected` interpolated into a `string` and so hidden from every serialiser — and
61
+ * one with nothing to say beyond its tag renders as its tag. The supervisor needs
62
+ * no knowledge of the supervised effect's `E` to label it — it is generic in `E` —
63
+ * and no caller has to supply anything for the purpose.
64
+ *
65
+ * ## Why it is a module of its own, and why it is PACKAGE-INTERNAL
66
+ *
67
+ * Not because the mechanism is on offer for reuse. It is deliberately absent from
68
+ * `@kairos-es/read`'s entry point, and its signature says what it supervises: a
69
+ * `CheckpointKey` names the supervised thing, a `Position` is the signal, a
70
+ * `ProjectionStoreError` is what reading that signal can fail with, and
71
+ * `ProjectionStalled` is a projection-shaped failure on
72
+ * `ProjectionRunner.fibre`'s error channel.
73
+ *
74
+ * It is separate because it is the hardest thing in this package to test THROUGH
75
+ * the pipeline, and the repo has the before and after. Pinning the five-minute
76
+ * default no-progress budget — a quantity about supervision and nothing else —
77
+ * cost ~122 lines while the mechanism lived inside `runProjection`: an in-memory
78
+ * event store, a view store decorated never to commit, a read model, a log-capture
79
+ * layer, and a hand-driven loop stepping the clock some 1200 times. Against a stub
80
+ * it costs 52, and 22 of those are code: one `Effect` yielding a `Position`, one
81
+ * effect that fails, one `TestClock.adjust`, and the rest of the case is the
82
+ * arithmetic it asserts written out. (The figure is re-measured rather than
83
+ * inherited — it read ~37 until the three restart `Duration`s became explicit
84
+ * arguments and the case gained a comment saying why. The ratio is what the
85
+ * argument turns on, and that has not moved.) Every other subtle behaviour is
86
+ * pinned the same way — the
87
+ * `ORIGIN` seeding, the breaker being consulted before the sleep, the interruption
88
+ * trap on the re-read, the counter resetting on progress — because this module
89
+ * knows nothing of `subscribe`, of decoding, of micro-batching, of committing, of
90
+ * slices or of the `Serializer`. Those cases are three suites over one stub
91
+ * (`test/superviseOnProgress.{pacing,breaker,observability}.test.ts`, sharing
92
+ * `test/superviseOnProgress.fixture.ts`), split along the two mechanisms this
93
+ * section keeps apart plus the channel their outcomes leave through. A SEPARATE
94
+ * module bought all of that; a GENERAL one was never needed for any of it.
95
+ *
96
+ * And there is no second consumer here, nor one in prospect. The mechanism needs a
97
+ * caller with a failing effect worth restarting AND a progress signal owned by
98
+ * somebody else; in this library only a projection has both. A command runner's
99
+ * progress IS its own success. The store's poll retry lives in
100
+ * `@kairos-es/store-postgres` and already has a bounded retry with no supervisor
101
+ * over it. A lease renewer for competing consumers is out of scope by ADR-0007.
102
+ *
103
+ * Should such a consumer appear, generalising then is a smaller change than
104
+ * maintaining the claim now — so the cost is recorded here rather than
105
+ * re-derived: `key` becomes a bare `string` label, losing the two discrete
106
+ * `projection`/`partition` annotations an operator greps on (or forcing a generic
107
+ * annotation shape onto every caller); `Position`'s `!==` becomes an
108
+ * `Equivalence` on the signal type; `ProjectionStoreError` becomes a fourth type
109
+ * parameter, and collapsing it to `unknown` instead is what would cost the
110
+ * interruption trap its argument, since "`catchAll` touches only the typed
111
+ * `ProjectionStoreError`" stops being a claim a reader can check against the
112
+ * signature; and `ProjectionStalled` has to be renamed or made generic.
113
+ *
114
+ * ## Platform-neutral
115
+ *
116
+ * No `node:*`, no `Date`, no host RNG: the backoff is `Duration`s scheduled
117
+ * through the `Clock` and the jitter is Effect's `Random` service, so
118
+ * `TestClock` drives all of it.
119
+ */
120
+ import { ORIGIN } from '@kairos-es/core';
121
+ import { Data, Effect, Ref, Schedule, Schema } from 'effect';
122
+ /**
123
+ * Consecutive no-progress restarts before the supervisor gives up: a branded
124
+ * POSITIVE integer.
125
+ *
126
+ * Branded because at `0` the breaker's `restarts >= maxNoProgressRestarts` test
127
+ * is true on the FIRST failure, so the supervisor gives up before it has retried
128
+ * once and before `onRestart` has ever fired — a `ProjectionStalled` for a fault
129
+ * that a single 100-millisecond retry would have cleared, and the flat
130
+ * contradiction of the five-minute budget `DEFAULT_MAX_NO_PROGRESS_RESTARTS`
131
+ * documents. Negative and fractional counts fail the same test the same way.
132
+ *
133
+ * `>= 1` rather than `>= 0` for that reason: "give up immediately" is not a
134
+ * supervision policy this module offers, and a caller who wants one has
135
+ * `Fiber.interrupt`.
136
+ *
137
+ * A distinct brand from `BatchSize` despite the identical refinement, because
138
+ * the two are still writable side by side in one flat options literal, are both
139
+ * bare integers, and differ by an order of magnitude in meaning — nominality is
140
+ * what makes a transposition fail to typecheck rather than silently retune the
141
+ * runner. That the two now tune different mechanisms in different modules is a
142
+ * second reason for the distinction, not a replacement for the first.
143
+ *
144
+ * Construct with `MaxNoProgressRestarts.make(n)` — and retune it by the WALL
145
+ * CLOCK the figure buys, per `DEFAULT_MAX_NO_PROGRESS_RESTARTS`.
146
+ */
147
+ export const MaxNoProgressRestarts = /*#__PURE__*/Schema.Int.pipe(/*#__PURE__*/Schema.positive(), /*#__PURE__*/Schema.brand('MaxNoProgressRestarts'));
148
+ /**
149
+ * Fast enough that a transient blip is invisible, slow enough not to spin.
150
+ *
151
+ * Exported — like the two below and unlike `DEFAULT_MAX_NO_PROGRESS_RESTARTS` —
152
+ * because `resolveProjection` is what RESOLVES it, for both entry points: the
153
+ * construction gate judges the
154
+ * figure that will actually run, so the resolution has to happen before the
155
+ * supervisor is built and the default has to be readable from there. The
156
+ * documentation stays HERE, against the sawtooth arithmetic the three of them
157
+ * define together, because that is what the figure is chosen for.
158
+ */
159
+ export const DEFAULT_RESTART_MIN_DELAY = '100 millis';
160
+ /**
161
+ * The store's own poll retry exhausts after roughly 40 seconds of sustained
162
+ * transient faults before `subscribe` dies, so a 30-second ceiling keeps a
163
+ * restart in the same order of magnitude as the fault it is recovering from —
164
+ * long enough not to hammer a struggling database, short enough that recovery is
165
+ * not measured in minutes.
166
+ *
167
+ * Exported for the reason `DEFAULT_RESTART_MIN_DELAY` gives.
168
+ */
169
+ export const DEFAULT_RESTART_MAX_DELAY = '30 seconds';
170
+ /**
171
+ * A minute of ELAPSED retrying, after which the pacing starts over from
172
+ * `restartMinDelay`.
173
+ *
174
+ * `Schedule.resetAfter` keys on `Schedule.elapsed` — the time since the schedule
175
+ * (or its own last reset) began, NOT the time since the last decision, verified
176
+ * against `effect@3.22`'s `internal/schedule.ts` — and both readings of that are
177
+ * wanted. A run that stays healthy for a minute pushes `elapsed` past the
178
+ * threshold on its way to the next fault, so its backoff starts from
179
+ * `restartMinDelay` again instead of inheriting a ceiling from a fault it
180
+ * recovered from hours ago. And a SUSTAINED outage, whose attempts fail fast,
181
+ * sawtooths back down to `restartMinDelay` every cycle rather than pinning at
182
+ * `restartMaxDelay` for ever, so a store that comes back is noticed within
183
+ * `restartMinDelay` rather than up to `restartMaxDelay` later.
184
+ *
185
+ * Exported for the reason `DEFAULT_RESTART_MIN_DELAY` gives.
186
+ */
187
+ export const DEFAULT_RESTART_RESET_AFTER = '60 seconds';
188
+ /**
189
+ * FORTY zero-progress restarts, chosen for the WALL CLOCK it buys — roughly five
190
+ * minutes — rather than for the count, which on its own means nothing.
191
+ *
192
+ * What the figure has to satisfy is `ProjectionStalled`'s own claim: a view store
193
+ * "broken rather than merely unavailable". So the budget must be long enough that
194
+ * a merely-unavailable view store — a failover, a rolling restart, a brief
195
+ * partition — is back inside it, and comfortably longer than the ~40 seconds the
196
+ * event store itself spends retrying before `subscribe` dies. The arithmetic is
197
+ * written out rather than asserted, because the pacing above is not obvious and
198
+ * the next reader should be able to CHECK the claim:
199
+ *
200
+ * Unjittered, the restart schedule sleeps `0.1, 0.2, 0.4, 0.8, 1.6, 3.2, 6.4,
201
+ * 12.8, 25.6, 30` seconds — the exponential, then the `restartMaxDelay` cap — and
202
+ * then starts over: by the eleventh decision 81.1s have elapsed, past
203
+ * `restartResetAfter`, so `resetAfter` resets the schedule. The pacing is
204
+ * therefore a SAWTOOTH of ten sleeps summing 81.1s. A give-up at the Nth
205
+ * consecutive no-progress failure has slept N-1 times (the breaker is consulted
206
+ * BEFORE each sleep), so 40 restarts is three whole cycles (243.3s) plus the
207
+ * first nine of a fourth (51.1s): 294.4s ≈ 4.9 minutes, which the ±20% jitter
208
+ * spreads to roughly 4.5–5.3. `superviseOnProgress.pacing.test.ts` pins that budget
209
+ * under a `TestClock` — and, beside it, the N-1 that this arithmetic turns on — so a
210
+ * retuning cannot quietly shrink either.
211
+ *
212
+ * Five restarts — the figure this shipped with first — bought 1.5s, which made a
213
+ * ten-second blip a PERMANENT stall and flatly contradicted the documentation
214
+ * above. That is the mistake this figure exists to avoid: if you lower it,
215
+ * recompute the wall clock.
216
+ *
217
+ * Two things make the effective budget longer still. When it is the SUBSCRIPTION
218
+ * that keeps dying rather than the view store refusing to answer, each attempt
219
+ * also burns the store's own ~40-second poll-retry budget before dying. And
220
+ * restarts that DO move the progress signal never count at all, so a busy
221
+ * projection that restarts often can never trip this however long it runs.
222
+ *
223
+ * PRIVATE, where the three restart `Duration`s beside it are exported: the count is
224
+ * BRANDED, so `MaxNoProgressRestarts.make(n)` refused a bad value at the caller's
225
+ * own line and there is nothing left for the construction gate to judge. Nobody
226
+ * outside needs to resolve it, so it is resolved here.
227
+ */
228
+ const DEFAULT_MAX_NO_PROGRESS_RESTARTS = /*#__PURE__*/MaxNoProgressRestarts.make(40);
229
+ /**
230
+ * The supervisor gave up: `noProgressRestarts` consecutive restarts moved the
231
+ * progress signal not at all.
232
+ *
233
+ * This is the only way a supervised daemon's fibre ever fails, and for a
234
+ * projection it means one of two things: a POISON EVENT (an `apply` or a decode
235
+ * that fails deterministically on the event at the checkpoint, so every restart
236
+ * re-reads it and dies again), or a view store still not answering after the
237
+ * WHOLE no-progress budget — broken, that is, rather than merely unavailable.
238
+ * That distinction is only as true as the budget makes it, which is why the
239
+ * default is sized at roughly five minutes of retrying rather than at a tidy
240
+ * restart count (`DEFAULT_MAX_NO_PROGRESS_RESTARTS`). Both need a human; neither
241
+ * is fixed by retrying, which is why the supervisor stops instead of retrying for
242
+ * ever and calling that resilience.
243
+ *
244
+ * Getting it in FRONT of that human is `onStalled`'s job, and the reason that
245
+ * hook exists: this failure lands on the daemon's error channel, and the wiring
246
+ * this library recommends discards the daemon. Beside the hook there is one
247
+ * `Effect.logError`, and nothing else.
248
+ *
249
+ * `position` is the stuck signal — the position everything is failing just
250
+ * after — so the offending event is one query away. `reason` is the last
251
+ * underlying failure, kept as `unknown` because it spans the supervised effect's
252
+ * whole `E`, which this module is generic in.
253
+ */
254
+ export class ProjectionStalled extends /*#__PURE__*/Data.TaggedError('ProjectionStalled') {
255
+ /**
256
+ * The two facts that make a stall diagnosable — how much budget was spent, and
257
+ * where it was spent — as the `Error` field that says why, so the fault renders
258
+ * ITSELF.
259
+ *
260
+ * This class needs the field more than any other fault the read side raises,
261
+ * because of WHERE it lands. `ProjectionStalled` is what `ProjectionRunner.fibre`
262
+ * fails with, which makes it the only one of them a consumer meets without going
263
+ * anywhere near the `ProjectionStore` port: `CheckpointSuperseded` and
264
+ * `ProjectionStoreError` sit on `commit`'s public signature too, but reaching them
265
+ * means calling or implementing that port, whereas the `Fiber.await` route the
266
+ * runner's own documentation recommends ends at whatever this getter says — from a
267
+ * daemon the application only forked.
268
+ *
269
+ * `Data.TaggedError` sets `name` to the tag and leaves `message` empty, and
270
+ * `Cause.pretty` substitutes its own `'An error has occurred'` for an empty one —
271
+ * so unfilled, a caller who did exactly what they were told to do reads
272
+ * `'ProjectionStalled: An error has occurred'` about the single failure this whole
273
+ * module exists to report. Filled, the same call yields a sentence naming the
274
+ * budget that was spent and the position everything is failing just after, which
275
+ * is the first thing an operator queries the log at.
276
+ *
277
+ * ## Why THESE two fields, and why interpolating them is safe
278
+ *
279
+ * `noProgressRestarts` is a `number`. `position` is a branded `bigint`, and
280
+ * TEMPLATE INTERPOLATION of a `bigint` yields its decimal digits — so what leaves
281
+ * this getter is typed `string` and carries no `bigint` for any serialiser to
282
+ * meet. That distinction is worth being exact about, because this package
283
+ * measures a real `bigint` hazard and it is easy to over-apply: `Logger.json`
284
+ * throws on a `bigint` NESTED IN AN ANNOTATION VALUE and loses the whole line, so
285
+ * the reduction in `shouldRestart` hands the logger `String(stored)`. The hazard
286
+ * is about the values a logger is handed, never about a `string` rendered from
287
+ * one — and `String(fault)` is precisely how a fault carrying a `bigint` field
288
+ * crosses that boundary intact.
289
+ *
290
+ * `reason` is deliberately NOT in the label. It spans the supervised effect's
291
+ * whole `E` and arrives as `unknown`, so anything this class said about it would
292
+ * be a guess at somebody else's value — and there is no need to guess: the raw
293
+ * fault reaches `onStalled` untouched, and the give-up log line beside it already
294
+ * carries `String(reason)`, which is the same self-rendering rule applied one
295
+ * level down.
296
+ *
297
+ * A GETTER over two existing fields rather than a `message` field, so neither can
298
+ * disagree with the label. Why a prototype accessor is safe here, how far filling
299
+ * the field reaches and the structured shape it leaves a machine to parse are set
300
+ * out once for all four of these getters on `ProjectionStoreError` in
301
+ * `ProjectionStore.ts`.
302
+ */
303
+ get message() {
304
+ return `no checkpoint progress in ${this.noProgressRestarts} consecutive restarts (stuck at ${this.position})`;
305
+ }
306
+ }
307
+ /**
308
+ * Supervise `run`: retry it while `options.progress` moves, give up with
309
+ * `ProjectionStalled` when it does not.
310
+ *
311
+ * Generic in the supervised effect's `A`, `E` and `R`. The supervisor reads the
312
+ * failure only through `String` and hands it to `onRestart`/`onStalled` as
313
+ * `unknown`, so it has no reason to constrain `E`; its own error channel is exactly
314
+ * `ProjectionStalled`, because the breaker collapses everything else into another
315
+ * restart; and `R` passes through untouched, nothing here adding a requirement,
316
+ * which is what keeps either entry point's requirement list the pipeline's own.
317
+ *
318
+ * ONE CALL rather than a curried supervisor later applied to an attempt. The rank-2
319
+ * intermediate bought exactly one thing: the tuning could be validated before the
320
+ * attempt existed, which fixed the ORDER a mis-tuned supervisor was reported in
321
+ * relative to the runner's other construction-time checks. That argument is now
322
+ * gone outright rather than merely outweighed — the tuning is judged by
323
+ * `projectionWiringFault` before a supervisor, an attempt or a fibre exists, in an
324
+ * order that module declares — so what a curried form would leave behind is a type
325
+ * whose only application sat a line from its construction.
326
+ *
327
+ * It validates NOTHING, which is deliberate rather than an omission. Every
328
+ * construction-time rejection on the read side has ONE home — the wiring gate, whose
329
+ * own single caller is the shared `prepareProjection` phase both entry points run
330
+ * before anything is built — and this module is
331
+ * package-internal with exactly one caller, so a check here would be a SECOND home
332
+ * for one rule: two sentences for one mistake, free to drift, each reachable only by
333
+ * whichever of the two modules its author happened to open. What arrives here has
334
+ * therefore already been resolved and judged, which is why the three restart
335
+ * `Duration`s are REQUIRED on `SuperviseOnProgressOptions` and why nothing below
336
+ * reaches for a default. The mistake still lands as a DEFECT at construction,
337
+ * exactly as `assertServableQuery`'s does; the gate is merely where.
338
+ *
339
+ * Nothing is taken for RENDERING the supervised effect's `E` on the two log lines:
340
+ * the `reason` annotation is `String(fault)`, so the fault labels itself. That is a
341
+ * real reduction rather than a floor, because `Error.prototype.toString` is
342
+ * `name: message` and `Data.TaggedError` sets `name` to the tag — so a fault that
343
+ * fills `message` renders as `'SomeTag: why'`, and one that does not renders as
344
+ * `'SomeTag'`. A caller wanting a better label sets `message` on its own error,
345
+ * where the knowledge belongs and where `Cause.pretty` and every other reader
346
+ * benefit from it too, rather than handing a table to a supervisor that would be
347
+ * the only thing to use it.
348
+ *
349
+ * The returned effect is re-runnable: the two supervision `Ref`s are created INSIDE
350
+ * it rather than here, so every run starts a fresh supervision session instead of
351
+ * inheriting the breaker state a previous run left behind.
352
+ */
353
+ export const superviseOnProgress = (run, options) => {
354
+ // The three restart durations are TAKEN, not defaulted, while the COUNT keeps its
355
+ // default: `SuperviseOnProgressOptions` above argues that asymmetry in full.
356
+ const {
357
+ key,
358
+ progress,
359
+ restartMinDelay,
360
+ restartMaxDelay,
361
+ restartResetAfter
362
+ } = options;
363
+ const maxNoProgressRestarts = options.maxNoProgressRestarts ?? DEFAULT_MAX_NO_PROGRESS_RESTARTS;
364
+ const onRestart = options.onRestart ?? (() => Effect.void);
365
+ const onStalled = options.onStalled ?? (() => Effect.void);
366
+ /**
367
+ * The restart pacing: a capped exponential that NEVER TERMINATES on its own.
368
+ *
369
+ * `Schedule.union` continues while EITHER arm continues and uses the SHORTER
370
+ * of the two delays, so unioning an unbounded exponential with a fixed
371
+ * `spaced(restartMaxDelay)` yields exponential growth up to the cap and then
372
+ * a flat cap — with no `recurs` arm, because the give-up decision belongs to
373
+ * the circuit-breaker (which knows whether anything is progressing) and not
374
+ * to a schedule (which only knows how many times it has fired).
375
+ *
376
+ * `jittered` because restarts are correlated: a database blip restarts every
377
+ * projection in the deployment at the same instant, and an unjittered backoff
378
+ * would march them all back in lockstep.
379
+ *
380
+ * `resetAfter` keys on ELAPSED retrying time rather than on the length of the
381
+ * last run (`Schedule.elapsed`, verified against the installed source), which
382
+ * buys two things at once: a run that stays up for `restartResetAfter` starts
383
+ * its next backoff from `restartMinDelay` instead of inheriting a ceiling from
384
+ * a fault it recovered from hours ago, and a sustained outage sawtooths from
385
+ * `restartMinDelay` up to the cap and back rather than pinning at the cap for
386
+ * ever. The sawtooth is also what makes the no-progress budget computable —
387
+ * the arithmetic is on `DEFAULT_MAX_NO_PROGRESS_RESTARTS`, and a test pins it.
388
+ *
389
+ * Effect v3 caveat: this is the THREE-type-parameter `Schedule<Out, In, R>`
390
+ * that `effect@3` exports. The currently-published `Schedule` docs show a
391
+ * newer four-type-parameter shape — do not copy them; this is written against
392
+ * the installed type definitions.
393
+ */
394
+ const restartSchedule = Schedule.union(Schedule.exponential(restartMinDelay, 2), Schedule.spaced(restartMaxDelay)).pipe(Schedule.jittered, Schedule.resetAfter(restartResetAfter));
395
+ return Effect.gen(function* () {
396
+ // Supervision state, owned OUTSIDE the retried effect so it survives a
397
+ // restart — which is the whole point: the breaker's question is about the
398
+ // sequence of restarts, not about any one of them.
399
+ const noProgressRestarts = yield* Ref.make(0);
400
+ // The signal observed at the previous restart. Seeded with `ORIGIN` rather
401
+ // than with a read of `progress` (which is not read until the first
402
+ // failure): a read model resuming from a non-zero durable checkpoint
403
+ // therefore scores its FIRST failure as progress and gets one extra restart
404
+ // before the counter engages. That errs towards retrying, which is the safe
405
+ // direction for a breaker.
406
+ const lastRestartPosition = yield* Ref.make(ORIGIN);
407
+ /**
408
+ * The circuit-breaker, evaluated on every failure and BEFORE the backoff
409
+ * sleep: does the progress signal show that anything is moving?
410
+ *
411
+ * Keying on the signal rather than on a failure count or on the error's tag
412
+ * is what makes competing runners behave — the module doc sets out that
413
+ * story in full. Conversely a poison event or a broken view store leaves the
414
+ * position pinned however many times the run restarts, so the breaker trips
415
+ * on exactly the cases retrying cannot fix.
416
+ */
417
+ const shouldRestart = reason => Effect.gen(function* () {
418
+ const previous = yield* Ref.get(lastRestartPosition);
419
+ // A view store too broken to answer `readCheckpoint` cannot report
420
+ // progress either, so a failed re-read is treated as "unchanged" and
421
+ // counts towards the breaker. That is the conservative reading: the
422
+ // alternative (retrying for ever because we cannot tell) is exactly the
423
+ // silent stall the breaker exists to end.
424
+ //
425
+ // `catchAll`, not `orElseSucceed`: the latter falls back on any cause
426
+ // carrying no defect, which includes INTERRUPTION, so a scope closing
427
+ // mid-re-read would be absorbed here — the daemon would go on to count a
428
+ // restart, log it and call `onRestart` while it was being torn down, and
429
+ // a teardown arriving on the last of the budget would report a
430
+ // `ProjectionStalled` that never happened — and now PAGE somebody about
431
+ // it, since `onStalled` fires on that branch. It is the same trap
432
+ // `catchAllDefect` avoids at the runner's stream boundary. `catchAll`
433
+ // touches only the typed `ProjectionStoreError`.
434
+ const stored = yield* Effect.catchAll(progress, () => Effect.succeed(previous));
435
+ const progressed = stored !== previous;
436
+ const restarts = progressed ? 0 : (yield* Ref.get(noProgressRestarts)) + 1;
437
+ yield* Ref.set(noProgressRestarts, restarts);
438
+ yield* Ref.set(lastRestartPosition, stored);
439
+ // ## The log line is the LOSSY channel; the hooks are the faithful one
440
+ //
441
+ // Both supervision outcomes now reach a programmatic consumer carrying
442
+ // the fault ITSELF — `onRestart` at the foot of this function,
443
+ // `onStalled` just below — so this block is no longer the only record of
444
+ // what happened. It is the convenience channel: flat, greppable, and
445
+ // reduced to JSON-safe scalars on purpose. Anything that needs a fault's
446
+ // FIELDS takes a hook; anything that needs a line in a log takes this.
447
+ //
448
+ // ## Why every value is JSON-SAFE, MEASURED rather than assumed
449
+ //
450
+ // The bound is serialisability, not stringiness: `noProgressRestarts`
451
+ // below goes out as a NUMBER, which no serialiser objects to and which a
452
+ // log aggregator can filter, threshold and graph on — properties a
453
+ // `String` around it would throw away in exchange for nothing. What has
454
+ // to be reduced is the value class a serialiser genuinely chokes on.
455
+ //
456
+ // A `bigint` is not JSON-serialisable and these faults carry them
457
+ // (`CheckpointSuperseded.expected` is a `Position`). What each logger
458
+ // `effect@3.22` ships actually does with one was established by running
459
+ // it, not read off the documentation:
460
+ //
461
+ // - `Logger.json` special-cases a TOP-LEVEL `bigint` annotation value
462
+ // (`internal/logger.ts`'s `structuredMessage`), but a `bigint` NESTED
463
+ // inside an annotation's object survives `Inspectable.toJSON` into the
464
+ // final `Inspectable.stringifyCircular`, which throws `TypeError: Do
465
+ // not know how to serialize a BigInt`. Nothing catches it, so the throw
466
+ // takes the WHOLE line — every other annotation with it — and lands as
467
+ // a defect inside the supervisor, on the one path whose entire job is
468
+ // to make failures visible.
469
+ // - The DEFAULT logger (`stringLogger`) does not throw: it renders each
470
+ // annotation through `Inspectable.toStringUnknown`, whose `try/catch`
471
+ // falls back to `String(value)`. The same loss, quieter — the offending
472
+ // annotation degrades to a bare tag, or to `[object Object]`.
473
+ // - `Logger.pretty` hands the value to `console.log` and prints `42n`.
474
+ //
475
+ // So the reduction happens HERE, before the logger sees anything.
476
+ // `position` is `String`ed rather than handed over as a `Position`
477
+ // despite all three shipped loggers coping with a bare `bigint`: they
478
+ // render it identically to `String`, so there is nothing to win, and a
479
+ // third-party logger that JSON-encodes its annotation map naively is a
480
+ // real thing.
481
+ //
482
+ // `reason` is `String`ed too, and that is the WHOLE reduction — no table
483
+ // of a caller's fault union, because the faults can label themselves.
484
+ // `Error.prototype.toString` is `name: message` and `Data.TaggedError`
485
+ // sets `name` to the tag, so a fault that fills `message` arrives as
486
+ // `'ProjectionStoreError: connection reset'` and one that does not arrives
487
+ // as its bare tag. This module is generic in `E`, so that is also all it
488
+ // could honestly do: the choice of what to say is the fault's, made once
489
+ // on the class, and `Cause.pretty` and `String(fault)` everywhere else
490
+ // read the same field.
491
+ const annotations = {
492
+ projection: key.projection,
493
+ partition: key.partition,
494
+ position: String(stored),
495
+ noProgressRestarts: restarts,
496
+ reason: String(reason)
497
+ };
498
+ if (restarts >= maxNoProgressRestarts) {
499
+ // Logged HERE, not by the caller, because a stalled projection must
500
+ // never be silent: `runProjection` returns an infallible effect, so
501
+ // unless somebody awaits the fibre the `ProjectionStalled` failure has
502
+ // no other route to an operator.
503
+ //
504
+ // `Effect.annotateLogs`, not a second argument to `logError`. Effect's
505
+ // log constructors are VARIADIC IN THE MESSAGE (`logError: (...message:
506
+ // ReadonlyArray<any>) => Effect<void>`), so an object passed second is
507
+ // a second message and not an annotation at all — it used to arrive as
508
+ // a JSON blob wedged inside the line rather than as the structured
509
+ // fields the reduction above was built for. Annotating puts each field
510
+ // where a logger can render it in its own idiom: `reason=… position=…`
511
+ // under the default logger, discrete keys under `annotations` in
512
+ // `Logger.json`. That is the logger owning the presentation, which is
513
+ // its job; all this module owes it is values it can serialise.
514
+ yield* Effect.annotateLogs(Effect.logError('kairos-es projection stalled: giving up after consecutive restarts with no checkpoint progress'), annotations);
515
+ // ...and then the SEAM, because a log line is not an alert. The
516
+ // give-up is the outcome nothing recovers from, so it gets the hook
517
+ // the restart already had — an application can fail a health check,
518
+ // exit non-zero or page from here. `onStalled`'s doc carries the
519
+ // asymmetry argument in full.
520
+ //
521
+ // AFTER the log, deliberately: the log is the guaranteed route out and
522
+ // a defect from an application's hook must not be able to silence it.
523
+ // The payload is the `ProjectionStalled` this give-up is about to
524
+ // produce, field for field and value for value — `stored` is what was
525
+ // just written to `lastRestartPosition`, `restarts` what was just
526
+ // written to `noProgressRestarts`, and `reason` is the failure the
527
+ // `catchAll` below will carry — so a hook and a caller awaiting the
528
+ // daemon never see two versions of one stall. The RAW fault rather
529
+ // than the log label, for the same reason the annotations take the
530
+ // label: a callback can read a `bigint`, a serialiser cannot.
531
+ yield* onStalled({
532
+ key,
533
+ noProgressRestarts: restarts,
534
+ position: stored,
535
+ reason
536
+ });
537
+ return false;
538
+ }
539
+ yield* Effect.annotateLogs(Effect.logWarning('kairos-es projection restarting from its stored checkpoint'), annotations);
540
+ yield* onRestart({
541
+ key,
542
+ reason,
543
+ noProgressRestarts: restarts
544
+ });
545
+ return true;
546
+ });
547
+ /**
548
+ * `Effect.retry`'s `while` IS the breaker, which is why the retry can exit
549
+ * in exactly one way: the schedule never terminates, so the only path out
550
+ * with a failure is `shouldRestart` returning `false`. The residual error is
551
+ * therefore always the give-up case, and mapping it to `ProjectionStalled`
552
+ * is total rather than a fallback for an unreachable branch.
553
+ *
554
+ * A run that *succeeds* ends the daemon quietly. For a projection that is
555
+ * the honest translation of "there is nothing left to read", which the
556
+ * shipped stores' live tails never say.
557
+ */
558
+ return yield* Effect.retry(run, {
559
+ schedule: restartSchedule,
560
+ while: shouldRestart
561
+ }).pipe(Effect.catchAll(reason => Effect.gen(function* () {
562
+ return yield* new ProjectionStalled({
563
+ key,
564
+ noProgressRestarts: yield* Ref.get(noProgressRestarts),
565
+ position: yield* Ref.get(lastRestartPosition),
566
+ reason
567
+ });
568
+ })));
569
+ });
570
+ };
571
+ //# sourceMappingURL=superviseOnProgress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superviseOnProgress.js","names":["ORIGIN","Data","Effect","Ref","Schedule","Schema","MaxNoProgressRestarts","Int","pipe","positive","brand","DEFAULT_RESTART_MIN_DELAY","DEFAULT_RESTART_MAX_DELAY","DEFAULT_RESTART_RESET_AFTER","DEFAULT_MAX_NO_PROGRESS_RESTARTS","make","ProjectionStalled","TaggedError","message","noProgressRestarts","position","superviseOnProgress","run","options","key","progress","restartMinDelay","restartMaxDelay","restartResetAfter","maxNoProgressRestarts","onRestart","void","onStalled","restartSchedule","union","exponential","spaced","jittered","resetAfter","gen","lastRestartPosition","shouldRestart","reason","previous","get","stored","catchAll","succeed","progressed","restarts","set","annotations","projection","partition","String","annotateLogs","logError","logWarning","retry","schedule","while"],"sources":["../../src/superviseOnProgress.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA,SAASA,MAAM,QAAuB,iBAAiB;AACvD,SAASC,IAAI,EAAiBC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,QAAQ;AAG3E;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMC,qBAAqB,gBAAGD,MAA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