@substrat-run/kernel 0.216.0 → 0.218.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 (108) hide show
  1. package/dist/attachment-gate.d.ts +42 -0
  2. package/dist/attachment-gate.d.ts.map +1 -0
  3. package/dist/attachment-gate.js +36 -0
  4. package/dist/attachment-gate.js.map +1 -0
  5. package/dist/broker-counts.d.ts +108 -0
  6. package/dist/broker-counts.d.ts.map +1 -0
  7. package/dist/broker-counts.js +101 -0
  8. package/dist/broker-counts.js.map +1 -0
  9. package/dist/broker-erasure.d.ts +51 -0
  10. package/dist/broker-erasure.d.ts.map +1 -0
  11. package/dist/broker-erasure.js +161 -0
  12. package/dist/broker-erasure.js.map +1 -0
  13. package/dist/broker-relay-erasure.d.ts +27 -0
  14. package/dist/broker-relay-erasure.d.ts.map +1 -0
  15. package/dist/broker-relay-erasure.js +115 -0
  16. package/dist/broker-relay-erasure.js.map +1 -0
  17. package/dist/broker-relay.d.ts +292 -0
  18. package/dist/broker-relay.d.ts.map +1 -0
  19. package/dist/broker-relay.js +494 -0
  20. package/dist/broker-relay.js.map +1 -0
  21. package/dist/broker-schema.d.ts +25 -0
  22. package/dist/broker-schema.d.ts.map +1 -0
  23. package/dist/broker-schema.js +256 -0
  24. package/dist/broker-schema.js.map +1 -0
  25. package/dist/broker-shadow.d.ts +258 -0
  26. package/dist/broker-shadow.d.ts.map +1 -0
  27. package/dist/broker-shadow.js +295 -0
  28. package/dist/broker-shadow.js.map +1 -0
  29. package/dist/broker-telemetry.d.ts +289 -0
  30. package/dist/broker-telemetry.d.ts.map +1 -0
  31. package/dist/broker-telemetry.js +336 -0
  32. package/dist/broker-telemetry.js.map +1 -0
  33. package/dist/cost-rollup.d.ts +6 -0
  34. package/dist/cost-rollup.d.ts.map +1 -1
  35. package/dist/cost-rollup.js +22 -1
  36. package/dist/cost-rollup.js.map +1 -1
  37. package/dist/delivery-broker.d.ts +320 -0
  38. package/dist/delivery-broker.d.ts.map +1 -0
  39. package/dist/delivery-broker.js +571 -0
  40. package/dist/delivery-broker.js.map +1 -0
  41. package/dist/delivery-policy.d.ts +105 -0
  42. package/dist/delivery-policy.d.ts.map +1 -0
  43. package/dist/delivery-policy.js +105 -0
  44. package/dist/delivery-policy.js.map +1 -0
  45. package/dist/directory-lake-keep.d.ts +9 -0
  46. package/dist/directory-lake-keep.d.ts.map +1 -0
  47. package/dist/directory-lake-keep.js +331 -0
  48. package/dist/directory-lake-keep.js.map +1 -0
  49. package/dist/directory-lake-projection.d.ts +50 -0
  50. package/dist/directory-lake-projection.d.ts.map +1 -0
  51. package/dist/directory-lake-projection.js +143 -0
  52. package/dist/directory-lake-projection.js.map +1 -0
  53. package/dist/directory-lake.d.ts +11 -1
  54. package/dist/directory-lake.d.ts.map +1 -1
  55. package/dist/directory-lake.js +3 -1
  56. package/dist/directory-lake.js.map +1 -1
  57. package/dist/index.d.ts +19 -2
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +13 -0
  60. package/dist/index.js.map +1 -1
  61. package/dist/job-run.d.ts +21 -1
  62. package/dist/job-run.d.ts.map +1 -1
  63. package/dist/job-run.js +6 -0
  64. package/dist/job-run.js.map +1 -1
  65. package/dist/migration-digest.d.ts +2 -2
  66. package/dist/migration-digest.d.ts.map +1 -1
  67. package/dist/migration-digest.js +4 -2
  68. package/dist/migration-digest.js.map +1 -1
  69. package/dist/migration-fence.d.ts +1 -1
  70. package/dist/migration-fence.js +3 -3
  71. package/dist/migration-fence.js.map +1 -1
  72. package/dist/outbox-prune.d.ts +8 -1
  73. package/dist/outbox-prune.d.ts.map +1 -1
  74. package/dist/outbox-prune.js +6 -2
  75. package/dist/outbox-prune.js.map +1 -1
  76. package/dist/platform-sweep.d.ts +10 -1
  77. package/dist/platform-sweep.d.ts.map +1 -1
  78. package/dist/platform-sweep.js +37 -1
  79. package/dist/platform-sweep.js.map +1 -1
  80. package/dist/scope-host.d.ts +58 -8
  81. package/dist/scope-host.d.ts.map +1 -1
  82. package/dist/scope-host.js.map +1 -1
  83. package/dist/spine-guard.d.ts.map +1 -1
  84. package/dist/spine-guard.js +2 -0
  85. package/dist/spine-guard.js.map +1 -1
  86. package/dist/spine-restore.d.ts +14 -2
  87. package/dist/spine-restore.d.ts.map +1 -1
  88. package/dist/spine-restore.js.map +1 -1
  89. package/dist/store-driver-releases.d.ts +12 -3
  90. package/dist/store-driver-releases.d.ts.map +1 -1
  91. package/dist/store-driver-releases.js +12 -7
  92. package/dist/store-driver-releases.js.map +1 -1
  93. package/dist/subject-keys.d.ts +7 -0
  94. package/dist/subject-keys.d.ts.map +1 -1
  95. package/dist/subject-keys.js +29 -5
  96. package/dist/subject-keys.js.map +1 -1
  97. package/dist/subject-redaction.d.ts +7 -0
  98. package/dist/subject-redaction.d.ts.map +1 -1
  99. package/dist/subject-redaction.js +34 -27
  100. package/dist/subject-redaction.js.map +1 -1
  101. package/dist/table-ownership.d.ts +6 -0
  102. package/dist/table-ownership.d.ts.map +1 -1
  103. package/dist/table-ownership.js +17 -3
  104. package/dist/table-ownership.js.map +1 -1
  105. package/dist/vertical-owners.d.ts +1 -1
  106. package/dist/vertical-owners.d.ts.map +1 -1
  107. package/dist/vertical-owners.js.map +1 -1
  108. package/package.json +2 -2
@@ -0,0 +1,571 @@
1
+ /**
2
+ * The delivery broker (K-74, rfc/broker-and-tenant-isolation.md §4): one per (tenant, app), and the
3
+ * owner of every message a scope sends once the scope has handed it off.
4
+ *
5
+ * Not the local PEER broker (`@substrat-run/adapter-sqlite/vertical-broker`, #1706), which stands in
6
+ * for the router on a call between apps. This one takes custody of what a commit left behind.
7
+ *
8
+ * What lives here is what both adapters share, so they cannot drift:
9
+ *
10
+ * - **The message** a scope hands off (`BrokerMessage`): an outbox row the scope emitted, or a
11
+ * platform intent it raised, carried whole as its row's JSON. The broker does not interpret it.
12
+ * - **The scope's half** (`handoffBatch`, `advanceMarks`): which rows are due for handoff past the
13
+ * scope's marks, and how far an answer moves them. A mark is the greatest id handed off and
14
+ * acknowledged, per kind. Ids are the kernel's ulid, which only increases within a process and is
15
+ * seeded from the scope's newest id on wake, so `id > mark` is the same watermark
16
+ * `readScopeTimeline` walks. Nothing is written to the scope's own tables: the marks are a cache
17
+ * of what the broker holds (`BrokerStore.marks` is the authority), so a scope that lost them asks.
18
+ * - **The broker's store** (`BrokerStore`): its own SQLite, which both adapters have, behind the
19
+ * three operations it needs. Acceptance is idempotent by message id, so a handoff repeated after a
20
+ * lost acknowledgement stores nothing twice and is acknowledged again.
21
+ *
22
+ * Delivery is effectively once inside the platform: dedup by id at every hop. Toward the internet it
23
+ * is at least once (K-74). A broker delivers to the receivers it was given, one delivery per
24
+ * (message, receiver), each under its subscription's policy (`delivery-policy.ts`, A4); with none it
25
+ * holds what it accepted, bounded by `BROKER_HELD_RETENTION_MS`. Which receivers a message is owed is
26
+ * the mode its handoff named (A5, `broker-shadow.ts`): the recorder alone in shadow. Its tables are `broker-schema.ts`.
27
+ */
28
+ import { migrateBrokerStore } from './broker-schema.js';
29
+ import { addBrokerCounts, nextBrokerCountShipAt, pruneBrokerCounts, readBrokerCounts, shipBrokerCounts, } from './broker-counts.js';
30
+ import { eraseSubjectFromBroker, screenErasedSubjects, } from './broker-erasure.js';
31
+ import { BROKER_TIMING, DEFAULT_DELIVERY_POLICY, backoffMs, classifyFailure, resolvePolicy, } from './delivery-policy.js';
32
+ import { emittedHere } from './scope-copy.js';
33
+ import { receiversFor } from './broker-shadow.js';
34
+ export const BROKER_MESSAGE_KINDS = ['event', 'intent'];
35
+ /** How many rows of each kind one handoff carries. A larger backlog follows in the next one. */
36
+ export const HANDOFF_BATCH = 50;
37
+ /** How many due messages one delivery pass attempts before it yields. */
38
+ export const BROKER_DELIVERY_BATCH = 50;
39
+ /** The waits after each failed handoff, as the scope retries it from its own alarm. */
40
+ export const HANDOFF_RETRY_MS = [1_000, 5_000, 30_000, 2 * 60_000, 10 * 60_000];
41
+ /** How long a settled message is kept, for a duplicate handoff to find it (`BrokerTiming.deliveredRetentionMs`). */
42
+ export const BROKER_DELIVERED_RETENTION_MS = BROKER_TIMING.deliveredRetentionMs;
43
+ /** How long a message nobody delivers is held (a broker with no receiver): the K-70 bound. */
44
+ export const BROKER_HELD_RETENTION_MS = BROKER_TIMING.heldRetentionMs;
45
+ /** The wait after `attempts` failures, on a schedule: its last step repeats. */
46
+ export const retryAfter = (schedule, attempts) => schedule[Math.min(Math.max(attempts, 1), schedule.length) - 1];
47
+ /** The broker's name in its namespace: one per (tenant, app). */
48
+ export const brokerName = (tenantId, app) => `${tenantId}/${app}`;
49
+ /**
50
+ * The reads a handoff makes, one per kind, past the scope's marks. Every row is the scope's own:
51
+ * `emittedHere` leaves out what a copy carried in, for intents as for events. (A copy's intents were
52
+ * settled at load as not carried; one minted at the source after its last event compares above the
53
+ * copy's key and is handed off once, settled. A5's comparison is where that would show.)
54
+ */
55
+ export function handoffQueries(marks, limit = HANDOFF_BATCH) {
56
+ return [
57
+ {
58
+ kind: 'event',
59
+ sql: `SELECT * FROM _substrat_outbox WHERE id > ? AND ${emittedHere()} ORDER BY id LIMIT ?`,
60
+ params: [marks.event ?? '', limit],
61
+ },
62
+ {
63
+ kind: 'intent',
64
+ sql: `SELECT id, kind, payload, requested_by, impersonation, requested_at
65
+ FROM _substrat_platform_requests WHERE id > ? AND ${emittedHere()} ORDER BY id LIMIT ?`,
66
+ params: [marks.intent ?? '', limit],
67
+ },
68
+ ];
69
+ }
70
+ /** A handoff read's rows, as the messages they become. */
71
+ export function messagesOf(kind, rows, ids,
72
+ /**
73
+ * #3474: the invocation whose commit this handoff follows, and the trace it ran under. A row that
74
+ * invocation wrote carries the trace; any other (a backlog from an earlier commit) does not, so a
75
+ * message is never stamped with a trace it was not committed under.
76
+ */
77
+ commit) {
78
+ return rows.map((row) => {
79
+ const invocation = typeof row.invocation_id === 'string' && row.invocation_id !== '' ? row.invocation_id : null;
80
+ const traced = commit?.traceId && invocation !== null && invocation === commit.invocationId ? commit.traceId : null;
81
+ return {
82
+ id: String(row.id),
83
+ kind,
84
+ tenantId: ids.tenantId,
85
+ scopeId: ids.scopeId,
86
+ type: String(kind === 'event' ? row.type : row.kind),
87
+ body: JSON.stringify(row),
88
+ committedAt: String(kind === 'event' ? row.occurred_at : row.requested_at),
89
+ ...(invocation === null ? {} : { invocationId: invocation }),
90
+ ...(traced === null ? {} : { traceId: traced }),
91
+ };
92
+ });
93
+ }
94
+ /**
95
+ * How far an answer moves the marks: per kind, over the longest run of the batch, in id order, that
96
+ * the broker acknowledged. A gap stops it, so an unacknowledged message is handed off again rather
97
+ * than skipped.
98
+ */
99
+ export function advanceMarks(marks, sent, answer) {
100
+ const acked = new Set(answer.acked);
101
+ const next = { ...marks };
102
+ for (const kind of BROKER_MESSAGE_KINDS) {
103
+ for (const m of sent.filter((s) => s.kind === kind).sort((a, b) => (a.id < b.id ? -1 : 1))) {
104
+ if (!acked.has(m.id))
105
+ break;
106
+ next[kind] = m.id;
107
+ }
108
+ }
109
+ return next;
110
+ }
111
+ /** What `BrokerStore.held` probes per statement: under the Durable Object's 100 bound parameters. */
112
+ const HELD_PROBE_CHUNK = 50;
113
+ /** A delivery is open while the broker still owes it: pending, or dead and resendable. */
114
+ const OPEN = "('pending', 'dead')";
115
+ /** A pending delivery may go now only as its lane's head: no lower message id open in its (receiver, lane). */
116
+ const LANE_HEAD = `(d.lane IS NULL OR NOT EXISTS (
117
+ SELECT 1 FROM broker_deliveries e
118
+ WHERE e.receiver = d.receiver AND e.lane = d.lane AND e.state IN ${OPEN} AND e.message_id < d.message_id))`;
119
+ /** How many settled messages one prune deletes; the rest go in the next. */
120
+ const PRUNE_BATCH = 500;
121
+ /** A delivery row joined with its message, as the message it carries. */
122
+ const messageOf = (r) => ({
123
+ id: r.message_id,
124
+ kind: r.kind,
125
+ tenantId: r.tenant_id,
126
+ scopeId: r.scope_id,
127
+ type: r.type,
128
+ body: r.body,
129
+ committedAt: r.committed_at,
130
+ ...(r.ordering_key === null ? {} : { key: r.ordering_key }),
131
+ ...(r.trace_id == null ? {} : { traceId: r.trace_id }),
132
+ ...(r.invocation_id == null ? {} : { invocationId: r.invocation_id }),
133
+ });
134
+ /** The message columns a `DueRow` reads, from `broker_messages m`. */
135
+ const MESSAGE_COLUMNS = 'm.kind, m.tenant_id, m.scope_id, m.type, m.body, m.committed_at, m.ordering_key, m.trace_id, m.invocation_id';
136
+ /**
137
+ * The broker's store (schema: `broker-schema.ts`). Each method is synchronous over `BrokerSql`, and
138
+ * each that writes runs in one transaction.
139
+ *
140
+ * A message is stored once (`broker_messages`, its content) and owed once per receiver
141
+ * (`broker_deliveries`, its fate there), so a receiver that fails or is paused holds back only its
142
+ * own deliveries. Ordering is per (receiver, key): only a lane's head is ever due, so a message stuck
143
+ * on key 17 holds back key 17 at that receiver and nothing else. A dead head keeps its lane stopped,
144
+ * since delivering past it would break the order the receiver asked for: the later messages of that
145
+ * key wait, spending nothing, until the dead letter is resent and delivered, discarded, or expires.
146
+ */
147
+ export class BrokerStore {
148
+ sql;
149
+ policies;
150
+ receivers;
151
+ timing;
152
+ random;
153
+ constructor(sql, opts) {
154
+ this.sql = sql;
155
+ this.policies = new Map(opts.subscriptions.map((s) => [s.name, resolvePolicy(s.policy)]));
156
+ if (this.policies.size !== opts.subscriptions.length)
157
+ throw new Error('BrokerStore: two subscriptions share a name');
158
+ this.receivers = JSON.stringify([...this.policies.keys()]);
159
+ this.timing = { ...BROKER_TIMING, ...opts.timing };
160
+ this.random = opts.random ?? Math.random;
161
+ migrateBrokerStore(sql);
162
+ // A store opened with receivers over rows held while it had none: those still inside their bound
163
+ // become due, from when they arrived, at every receiver it has now. One past it is dropped first,
164
+ // as the prune would have, so it is never sent (its marks stay).
165
+ if (this.policies.size) {
166
+ const now = (opts.now ?? Date.now)();
167
+ sql.transaction(() => {
168
+ this.pruneHeld(now);
169
+ const held = sql.all(`SELECT id, kind, ordering_key, received_at, handoff_mode FROM broker_messages m
170
+ WHERE NOT EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id)`);
171
+ // A5: only the receivers its handoff's mode named, so a message held in shadow never reaches a real one.
172
+ for (const m of held)
173
+ this.owe(m.id, m.ordering_key, m.received_at, receiversFor(m.handoff_mode, m.kind));
174
+ });
175
+ }
176
+ }
177
+ /** The deliveries a new message is owed: one per receiver (of `only`, when given), due at `at`. */
178
+ owe(id, key, at, only) {
179
+ for (const [receiver, policy] of this.policies) {
180
+ if (only && !only.includes(receiver))
181
+ continue;
182
+ this.sql.run(`INSERT OR IGNORE INTO broker_deliveries (message_id, receiver, lane, state, next_at) VALUES (?, ?, ?, 'pending', ?)`, id, receiver, policy.ordered ? key : null, at);
183
+ }
184
+ }
185
+ /**
186
+ * Take custody. Idempotent by id; every id handed in is acknowledged, a duplicate too. `options.mode`
187
+ * (A5) fixes which receivers each new message is owed, and is kept with it; a duplicate keeps the
188
+ * receivers it was first owed, whatever mode it is handed off under again.
189
+ */
190
+ accept(messages, now, options = {}) {
191
+ return this.sql.transaction(() => {
192
+ // #3484: an erased subject's content is refused before it is stored, however late the handoff.
193
+ for (const m of screenErasedSubjects(this.sql, messages)) {
194
+ const known = this.sql.all('SELECT 1 FROM broker_messages WHERE id = ?', m.id).length > 0;
195
+ if (!known) {
196
+ this.sql.run(`INSERT INTO broker_messages
197
+ (id, kind, tenant_id, scope_id, type, body, committed_at, received_at, ordering_key, handoff_mode, trace_id, invocation_id)
198
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, m.id, m.kind, m.tenantId, m.scopeId, m.type, m.body, m.committedAt, now, m.key ?? null, options.mode ?? null, m.traceId ?? null, m.invocationId ?? null);
199
+ this.owe(m.id, m.key ?? null, now, receiversFor(options.mode, m.kind));
200
+ addBrokerCounts(this.sql, [{ tenantId: m.tenantId, scopeId: m.scopeId, channel: m.kind, receiver: '', outcome: 'received', n: 1 }], now);
201
+ }
202
+ this.sql.run(`INSERT INTO broker_marks (tenant_id, scope_id, kind, mark) VALUES (?, ?, ?, ?)
203
+ ON CONFLICT (tenant_id, scope_id, kind) DO UPDATE SET mark = MAX(mark, excluded.mark)`, m.tenantId, m.scopeId, m.kind, m.id);
204
+ }
205
+ return { acked: messages.map((m) => m.id) };
206
+ });
207
+ }
208
+ /** #3484: one message as the store holds it now, or null when it holds none by that id. */
209
+ current(id) {
210
+ const r = this.sql.all(`SELECT m.id AS message_id, '' AS receiver, 0 AS attempts, ${MESSAGE_COLUMNS} FROM broker_messages m WHERE m.id = ?`, id)[0];
211
+ return r ? messageOf(r) : null;
212
+ }
213
+ /** #3484: erase one subject from what this store holds, dead letters included, in one transaction. */
214
+ eraseSubject(target) {
215
+ return this.sql.transaction(() => eraseSubjectFromBroker(this.sql, target));
216
+ }
217
+ marks(tenantId, scopeId) {
218
+ const rows = this.sql.all('SELECT kind, mark FROM broker_marks WHERE tenant_id = ? AND scope_id = ?', tenantId, scopeId);
219
+ return Object.fromEntries(rows.map((r) => [r.kind, r.mark]));
220
+ }
221
+ /**
222
+ * The deliveries due at `now`, oldest due first: pending, at a receiver this store has and that is
223
+ * neither paused nor slowed, and the head of their lane. `skip` names deliveries already attempted
224
+ * this pass (`deliveryKey`), so a wait of zero is not attempted twice in one pass.
225
+ */
226
+ due(now, limit = BROKER_DELIVERY_BATCH, skip = []) {
227
+ return this.sql
228
+ .all(`SELECT d.message_id, d.receiver, d.attempts, ${MESSAGE_COLUMNS}
229
+ FROM broker_deliveries d
230
+ JOIN broker_messages m ON m.id = d.message_id
231
+ LEFT JOIN broker_receivers r ON r.receiver = d.receiver
232
+ WHERE d.state = 'pending' AND d.next_at <= ?
233
+ AND d.receiver IN (SELECT value FROM json_each(?))
234
+ AND (r.blocked_until IS NULL OR r.blocked_until <= ?)
235
+ AND ${LANE_HEAD}
236
+ AND (d.message_id || ' ' || d.receiver) NOT IN (SELECT value FROM json_each(?))
237
+ ORDER BY d.next_at, d.message_id LIMIT ?`, now, this.receivers, now, JSON.stringify(skip), limit)
238
+ .map((r) => ({ receiver: r.receiver, attempts: r.attempts, message: messageOf(r) }));
239
+ }
240
+ /** Whether a receiver is paused or slowed at `now`: nothing is sent to it. */
241
+ blocked(receiver, now) {
242
+ const row = this.sql.all('SELECT blocked_until FROM broker_receivers WHERE receiver = ?', receiver)[0];
243
+ return row?.blocked_until != null && row.blocked_until > now;
244
+ }
245
+ /**
246
+ * Whether a delivery `due` returned may still go now: still pending, its receiver neither paused
247
+ * nor slowed, and still its lane's head. A pass asks right before each send, because a handoff (or
248
+ * a resend) that commits while an earlier send awaits can put a lower id at the head of its lane.
249
+ */
250
+ sendable(id, receiver, now) {
251
+ if (this.blocked(receiver, now))
252
+ return false;
253
+ return (this.sql.all(`SELECT 1 FROM broker_deliveries d WHERE d.message_id = ? AND d.receiver = ? AND d.state = 'pending' AND ${LANE_HEAD}`, id, receiver).length > 0);
254
+ }
255
+ /** A delivery landed: it settles, and the receiver's pause, if any, is over. */
256
+ delivered(id, receiver, now) {
257
+ this.sql.transaction(() => {
258
+ this.count(id, receiver, 'delivered', "d.state = 'pending'", now);
259
+ this.sql.run(`UPDATE broker_deliveries SET state = 'delivered', next_at = NULL, settled_at = ?, last_error = NULL, last_status = NULL
260
+ WHERE message_id = ? AND receiver = ? AND state = 'pending'`, now, id, receiver);
261
+ this.sql.run('DELETE FROM broker_receivers WHERE receiver = ?', receiver);
262
+ });
263
+ }
264
+ /** A delivery failed, as `classifyFailure` read it. Says what follows for that delivery. */
265
+ failed(id, receiver, failure, now) {
266
+ return this.sql.transaction(() => {
267
+ const row = this.sql.all("SELECT attempts FROM broker_deliveries WHERE message_id = ? AND receiver = ? AND state = 'pending'", id, receiver)[0];
268
+ const r = this.sql.all('SELECT failures, open, pause_ms, blocked_until FROM broker_receivers WHERE receiver = ?', receiver)[0] ?? { failures: 0, open: 0, pause_ms: null, blocked_until: null };
269
+ const status = failure.status ?? null;
270
+ if (failure.kind === 'slow') {
271
+ // Not a failure: nothing spent, the run toward a pause unchanged; the receiver waits.
272
+ const wait = Math.min(failure.afterMs ?? this.timing.slowDownMs, this.timing.maxSlowDownMs);
273
+ const until = Math.max(r.blocked_until ?? 0, now + wait);
274
+ this.saveReceiver(receiver, { ...r, blocked_until: until });
275
+ if (row) {
276
+ this.sql.run('UPDATE broker_deliveries SET next_at = ?, last_error = ?, last_status = ? WHERE message_id = ? AND receiver = ?', now + wait, failure.error, status, id, receiver);
277
+ }
278
+ return 'slow';
279
+ }
280
+ if (failure.kind === 'fail') {
281
+ // The receiver answered: it is up, and this message will never land there.
282
+ this.sql.run('DELETE FROM broker_receivers WHERE receiver = ?', receiver);
283
+ }
284
+ else if (r.open) {
285
+ // A failed probe: paused again, for longer.
286
+ const pause = Math.min((r.pause_ms ?? this.timing.pauseMs) * 2, this.timing.maxPauseMs);
287
+ this.saveReceiver(receiver, { failures: r.failures + 1, open: 1, pause_ms: pause, blocked_until: now + pause });
288
+ }
289
+ else if (r.failures + 1 >= this.timing.pauseAfterFailures) {
290
+ this.saveReceiver(receiver, { failures: r.failures + 1, open: 1, pause_ms: this.timing.pauseMs, blocked_until: now + this.timing.pauseMs });
291
+ }
292
+ else {
293
+ this.saveReceiver(receiver, { ...r, failures: r.failures + 1 });
294
+ }
295
+ if (!row)
296
+ return 'retry';
297
+ const attempts = row.attempts + 1;
298
+ const policy = this.policies.get(receiver) ?? DEFAULT_DELIVERY_POLICY;
299
+ if (failure.kind === 'fail' || attempts >= policy.attempts) {
300
+ this.count(id, receiver, 'dead', "d.state = 'pending'", now);
301
+ this.sql.run(`UPDATE broker_deliveries SET state = 'dead', attempts = ?, next_at = NULL, dead_at = ?, last_error = ?, last_status = ?
302
+ WHERE message_id = ? AND receiver = ?`, attempts, now, failure.error, status, id, receiver);
303
+ return 'dead';
304
+ }
305
+ this.count(id, receiver, 'retried', "d.state = 'pending'", now);
306
+ this.sql.run('UPDATE broker_deliveries SET attempts = ?, next_at = ?, last_error = ?, last_status = ? WHERE message_id = ? AND receiver = ?', attempts, now + backoffMs(policy, attempts, this.random), failure.error, status, id, receiver);
307
+ return 'retry';
308
+ });
309
+ }
310
+ saveReceiver(receiver, r) {
311
+ this.sql.run(`INSERT INTO broker_receivers (receiver, failures, open, pause_ms, blocked_until) VALUES (?, ?, ?, ?, ?)
312
+ ON CONFLICT (receiver) DO UPDATE SET failures = excluded.failures, open = excluded.open,
313
+ pause_ms = excluded.pause_ms, blocked_until = excluded.blocked_until`, receiver, r.failures, r.open, r.pause_ms, r.blocked_until);
314
+ }
315
+ /**
316
+ * The dead letters at `now`, oldest first; `content` adds each message's body. One past its
317
+ * retention is not listed, whether or not a prune has expired it yet.
318
+ */
319
+ deadLetters(opts, now) {
320
+ const rows = this.sql.all(`SELECT d.message_id, d.receiver, d.attempts, d.dead_at, d.last_error, d.last_status, d.resends, ${MESSAGE_COLUMNS}
321
+ FROM broker_deliveries d JOIN broker_messages m ON m.id = d.message_id
322
+ WHERE d.state = 'dead' AND d.dead_at > ? AND (? IS NULL OR d.receiver = ?)
323
+ ORDER BY d.dead_at, d.message_id LIMIT ?`, now - this.timing.deadLetterRetentionMs, opts.receiver ?? null, opts.receiver ?? null, opts.limit ?? 50);
324
+ // #3474: a body shown is screened against the scope's erasure tombstones as it is read, as a
325
+ // handoff is screened as it is stored. The erasure already rewrote what was stored (#3484), so
326
+ // this changes nothing today; it is what keeps "an erased subject's content is never shown" true
327
+ // of a row some later path stores without the screen.
328
+ const bodies = opts.content
329
+ ? screenErasedSubjects(this.sql, rows.map(messageOf))
330
+ : [];
331
+ return rows.map((r, i) => ({
332
+ messageId: r.message_id,
333
+ receiver: r.receiver,
334
+ kind: r.kind,
335
+ type: r.type,
336
+ tenantId: r.tenant_id,
337
+ scopeId: r.scope_id,
338
+ committedAt: r.committed_at,
339
+ key: r.ordering_key,
340
+ attempts: r.attempts,
341
+ lastError: r.last_error,
342
+ lastStatus: r.last_status,
343
+ deadAt: r.dead_at,
344
+ expiresAt: r.dead_at + this.timing.deadLetterRetentionMs,
345
+ resends: r.resends,
346
+ traceId: r.trace_id ?? null,
347
+ invocationId: r.invocation_id ?? null,
348
+ ...(opts.content ? { body: bodies[i].body } : {}),
349
+ }));
350
+ }
351
+ /**
352
+ * Resend a dead letter: due now, with its attempts afresh, back at the head of its lane. Only a
353
+ * dead delivery inside its retention moves, so a resend repeated, sent after the message landed, or
354
+ * after the dead letter expired, changes nothing and the receiver gets it at most once. `receiver` omitted: at every receiver where it is dead. Returns how
355
+ * many deliveries it moved.
356
+ */
357
+ resend(id, receiver, now) {
358
+ return this.settleDead('resent', `UPDATE broker_deliveries SET state = 'pending', attempts = 0, next_at = ?, dead_at = NULL, resends = resends + 1`, id, receiver, now);
359
+ }
360
+ /** Discard a dead letter: it settles, and its lane moves on. Idempotent as `resend` is. */
361
+ discard(id, receiver, now) {
362
+ return this.settleDead('discarded', `UPDATE broker_deliveries SET state = 'discarded', settled_at = ?`, id, receiver, now);
363
+ }
364
+ settleDead(outcome, update, id, receiver, now) {
365
+ return this.sql.transaction(() => {
366
+ const where = "WHERE message_id = ? AND state = 'dead' AND dead_at > ? AND (? IS NULL OR receiver = ?)";
367
+ const args = [id, now - this.timing.deadLetterRetentionMs, receiver ?? null, receiver ?? null];
368
+ const moved = this.sql.all(`SELECT receiver FROM broker_deliveries ${where}`, ...args);
369
+ for (const m of moved)
370
+ this.count(id, m.receiver, outcome, "d.state = 'dead'", now);
371
+ this.sql.run(`${update} ${where}`, now, ...args);
372
+ return moved.length;
373
+ });
374
+ }
375
+ /**
376
+ * #3474: count one decision about one delivery, in the transaction making it, when the delivery is
377
+ * in the state the decision moves it from (`guard`, over `broker_deliveries d`), so a decision that
378
+ * moves nothing counts nothing.
379
+ */
380
+ count(id, receiver, outcome, guard, now) {
381
+ const rows = this.sql.all(`SELECT m.tenant_id, m.scope_id, m.kind FROM broker_deliveries d JOIN broker_messages m ON m.id = d.message_id
382
+ WHERE d.message_id = ? AND d.receiver = ? AND ${guard}`, id, receiver);
383
+ addBrokerCounts(this.sql, rows.map((r) => ({ tenantId: r.tenant_id, scopeId: r.scope_id, channel: r.kind, receiver, outcome, n: 1 })), now);
384
+ }
385
+ /** #3474: the exact counts on or after `since` (a UTC day). */
386
+ counts(since) {
387
+ return readBrokerCounts(this.sql, since);
388
+ }
389
+ /** #3474: ship one batch of the counts the lake does not have yet; a throwing sink marks nothing. */
390
+ shipCounts(sink, app, now) {
391
+ return shipBrokerCounts(this.sql, sink, app, now);
392
+ }
393
+ /** #3474: when the counts are next due to ship, or null when the lake has them all. */
394
+ nextCountShipAt() {
395
+ return nextBrokerCountShipAt(this.sql);
396
+ }
397
+ /**
398
+ * Epoch ms the store next has work: the earliest of the next delivery that can go (a lane's head, at
399
+ * a receiver it has, after the receiver's pause or slow-down) and the moment a kept row's bound runs
400
+ * out (a settled message's `deliveredRetentionMs`, a dead letter's `deadLetterRetentionMs`, a held
401
+ * message's `heldRetentionMs`). Null only when it holds nothing, so an idle broker arms nothing and
402
+ * a busy one never keeps a row past its bound for want of an alarm. A message waiting behind its
403
+ * lane's head is not work: the head's settling is what wakes it.
404
+ */
405
+ nextWakeAt() {
406
+ const row = this.sql.all(`SELECT
407
+ (SELECT MIN(MAX(d.next_at, COALESCE(r.blocked_until, 0)))
408
+ FROM broker_deliveries d LEFT JOIN broker_receivers r ON r.receiver = d.receiver
409
+ WHERE d.state = 'pending' AND d.receiver IN (SELECT value FROM json_each(?)) AND ${LANE_HEAD}) AS due,
410
+ (SELECT MIN(last) FROM (SELECT MAX(settled_at) AS last FROM broker_deliveries
411
+ GROUP BY message_id HAVING SUM(state IN ${OPEN}) = 0)) AS settled,
412
+ (SELECT MIN(dead_at) FROM broker_deliveries WHERE state = 'dead') AS dead,
413
+ (SELECT MIN(received_at) FROM broker_messages m
414
+ WHERE NOT EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id)) AS held`, this.receivers)[0];
415
+ const times = [
416
+ row?.due ?? null,
417
+ row?.settled == null ? null : row.settled + this.timing.deliveredRetentionMs,
418
+ row?.dead == null ? null : row.dead + this.timing.deadLetterRetentionMs,
419
+ row?.held == null ? null : row.held + this.timing.heldRetentionMs,
420
+ ].filter((t) => t !== null);
421
+ return times.length ? Math.min(...times) : null;
422
+ }
423
+ /**
424
+ * Drop what the bounds say has been kept long enough (K-70). A dead letter past its bound expires,
425
+ * which settles it as of when it died, so its message goes in the same prune and its lane moves on.
426
+ * Marks stay: they are one row per scope and kind.
427
+ */
428
+ prune(now) {
429
+ this.sql.transaction(() => {
430
+ // #3474: each dead letter expiring now is counted, per (scope, channel, receiver).
431
+ const expiring = this.sql.all(`SELECT m.tenant_id, m.scope_id, m.kind, d.receiver, COUNT(*) AS n
432
+ FROM broker_deliveries d JOIN broker_messages m ON m.id = d.message_id
433
+ WHERE d.state = 'dead' AND d.dead_at <= ?
434
+ GROUP BY m.tenant_id, m.scope_id, m.kind, d.receiver`, now - this.timing.deadLetterRetentionMs);
435
+ addBrokerCounts(this.sql, expiring.map((r) => ({ tenantId: r.tenant_id, scopeId: r.scope_id, channel: r.kind, receiver: r.receiver, outcome: 'expired', n: Number(r.n) })), now);
436
+ pruneBrokerCounts(this.sql, now);
437
+ this.sql.run("UPDATE broker_deliveries SET state = 'expired', settled_at = dead_at WHERE state = 'dead' AND dead_at <= ?", now - this.timing.deadLetterRetentionMs);
438
+ const settled = this.sql.all(`SELECT message_id FROM broker_deliveries GROUP BY message_id
439
+ HAVING SUM(state IN ${OPEN}) = 0 AND MAX(settled_at) <= ? LIMIT ?`, now - this.timing.deliveredRetentionMs, PRUNE_BATCH);
440
+ if (settled.length) {
441
+ const ids = JSON.stringify(settled.map((s) => s.message_id));
442
+ this.sql.run('DELETE FROM broker_deliveries WHERE message_id IN (SELECT value FROM json_each(?))', ids);
443
+ this.sql.run('DELETE FROM broker_messages WHERE id IN (SELECT value FROM json_each(?))', ids);
444
+ }
445
+ this.pruneHeld(now);
446
+ });
447
+ }
448
+ /** Drop the held messages (no delivery row) past `heldRetentionMs`. */
449
+ pruneHeld(now) {
450
+ this.sql.run(`DELETE FROM broker_messages WHERE received_at <= ?
451
+ AND NOT EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = broker_messages.id)`, now - this.timing.heldRetentionMs);
452
+ }
453
+ /**
454
+ * #3474: which of `ids` the store already holds, so a receipt can tell a new message from a repeated
455
+ * handoff. Primary-key reads only, in chunks under the Durable Object's bound-parameter limit.
456
+ */
457
+ held(ids) {
458
+ const found = new Set();
459
+ for (let i = 0; i < ids.length; i += HELD_PROBE_CHUNK) {
460
+ const chunk = ids.slice(i, i + HELD_PROBE_CHUNK);
461
+ const rows = this.sql.all(`SELECT id FROM broker_messages WHERE id IN (${chunk.map(() => '?').join(', ')})`, ...chunk);
462
+ for (const r of rows)
463
+ found.add(r.id);
464
+ }
465
+ return found;
466
+ }
467
+ /**
468
+ * #3474: the broker's state in one read — what `pending()` counts and its oldest arrival, the
469
+ * receivers whose breaker is open, and the dead letters. Run once per wake and after each pass,
470
+ * never on a handoff.
471
+ */
472
+ stats() {
473
+ const row = this.sql.all(`SELECT COUNT(*) AS depth, MIN(m.received_at) AS oldest,
474
+ (SELECT COUNT(*) FROM broker_receivers WHERE open = 1) AS paused,
475
+ (SELECT COUNT(*) FROM broker_deliveries WHERE state = 'dead') AS dead
476
+ FROM broker_messages m
477
+ WHERE NOT EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id)
478
+ OR EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id AND d.state = 'pending')`)[0];
479
+ return {
480
+ depth: Number(row?.depth ?? 0),
481
+ oldestAt: row?.oldest ?? null,
482
+ pausedReceivers: Number(row?.paused ?? 0),
483
+ deadLetters: Number(row?.dead ?? 0),
484
+ };
485
+ }
486
+ /** #3474: whether a receiver's breaker is open (paused, as against slowed). One primary-key read. */
487
+ paused(receiver) {
488
+ return this.sql.all('SELECT open FROM broker_receivers WHERE receiver = ?', receiver)[0]?.open === 1;
489
+ }
490
+ /**
491
+ * #3474: when a delivery can next be attempted: its own `next_at`, or the receiver's pause or
492
+ * slow-down if that ends later; null when none is scheduled. Two primary-key reads in one statement.
493
+ */
494
+ nextAttemptAt(id, receiver) {
495
+ const row = this.sql.all(`SELECT d.next_at, r.blocked_until FROM broker_deliveries d
496
+ LEFT JOIN broker_receivers r ON r.receiver = d.receiver
497
+ WHERE d.message_id = ? AND d.receiver = ?`, id, receiver)[0];
498
+ if (row?.next_at == null)
499
+ return null;
500
+ return Math.max(row.next_at, row.blocked_until ?? 0);
501
+ }
502
+ /** #3474: the receivers whose breaker is open now, so a reporter that woke knows which pauses it inherits. */
503
+ openReceivers() {
504
+ return this.sql.all('SELECT receiver FROM broker_receivers WHERE open = 1').map((r) => r.receiver);
505
+ }
506
+ /** How many messages it holds that some receiver is still owed (held, or pending somewhere). */
507
+ pending() {
508
+ const row = this.sql.all(`SELECT COUNT(*) AS n FROM broker_messages m
509
+ WHERE NOT EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id)
510
+ OR EXISTS (SELECT 1 FROM broker_deliveries d WHERE d.message_id = m.id AND d.state = 'pending')`)[0];
511
+ return Number(row?.n ?? 0);
512
+ }
513
+ }
514
+ /** A delivery's key in a pass's `skip` list. */
515
+ const deliveryKey = (d) => `${d.message.id} ${d.receiver}`;
516
+ /**
517
+ * One delivery pass over a store, for both adapters: attempt each due delivery once, record the
518
+ * outcome, and say when the next is due. A receiver's throw is a failure of that delivery alone,
519
+ * read by `classifyFailure`. The pass re-reads what is due as it goes, so the message behind a lane's
520
+ * head goes in the same pass once the head landed, and a receiver that a failure paused (or a probe
521
+ * that failed) is sent nothing more in it. At most `limit` attempts. It prunes first (`prune`).
522
+ */
523
+ export async function runDeliveryPass(store, receivers, now, limit = BROKER_DELIVERY_BATCH, observer) {
524
+ let delivered = 0;
525
+ let failed = 0;
526
+ let deadLettered = 0;
527
+ // Attempted this pass. One `due` returned but no longer sendable is not in it: it may go later in
528
+ // the pass, once the head that overtook it has landed.
529
+ const tried = [];
530
+ // First, so a dead letter that expired releases its lane to this pass.
531
+ store.prune(now());
532
+ // `due` only returns what `sendable` admits, so a round attempts something unless a send raced it;
533
+ // the rounds are bounded all the same.
534
+ for (let round = 0; round < limit && tried.length < limit; round++) {
535
+ const batch = store.due(now(), limit - tried.length, tried);
536
+ if (!batch.length)
537
+ break;
538
+ for (const d of batch) {
539
+ if (tried.length >= limit)
540
+ break;
541
+ const receiver = receivers[d.receiver];
542
+ if (!receiver || !store.sendable(d.message.id, d.receiver, now()))
543
+ continue;
544
+ tried.push(deliveryKey(d));
545
+ // #3484: read again just before it goes. A delivery awaits its receiver, and an erasure can run
546
+ // meanwhile; the rest of a batch read before it must go as the store now holds it.
547
+ const message = store.current(d.message.id);
548
+ if (!message)
549
+ continue;
550
+ const startedAt = now();
551
+ try {
552
+ await receiver.deliver(message);
553
+ }
554
+ catch (err) {
555
+ const outcome = store.failed(d.message.id, d.receiver, classifyFailure(err), now());
556
+ if (outcome === 'dead')
557
+ deadLettered++;
558
+ else
559
+ failed++;
560
+ observer?.attempted(d, outcome, startedAt, now());
561
+ continue;
562
+ }
563
+ // Outside the receiver's `try`: a storage error here is the broker's, never the receiver's failure.
564
+ store.delivered(d.message.id, d.receiver, now());
565
+ delivered++;
566
+ observer?.attempted(d, 'delivered', startedAt, now());
567
+ }
568
+ }
569
+ return { delivered, failed, deadLettered, nextAt: store.nextWakeAt() };
570
+ }
571
+ //# sourceMappingURL=delivery-broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-broker.js","sourceRoot":"","sources":["../src/delivery-broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GAIjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,uB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