@substrat-run/adapter-cloudflare 0.228.0 → 0.230.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 (102) hide show
  1. package/dist/broker-lake.d.ts +26 -2
  2. package/dist/broker-lake.d.ts.map +1 -1
  3. package/dist/broker-lake.js +56 -3
  4. package/dist/broker-lake.js.map +1 -1
  5. package/dist/control-plane-do.d.ts +50 -13
  6. package/dist/control-plane-do.d.ts.map +1 -1
  7. package/dist/control-plane-do.js +128 -52
  8. package/dist/control-plane-do.js.map +1 -1
  9. package/dist/delivery-broker-do.d.ts +26 -1
  10. package/dist/delivery-broker-do.d.ts.map +1 -1
  11. package/dist/delivery-broker-do.js +50 -3
  12. package/dist/delivery-broker-do.js.map +1 -1
  13. package/dist/delivery-broker-platform.d.ts +24 -2
  14. package/dist/delivery-broker-platform.d.ts.map +1 -1
  15. package/dist/delivery-broker-platform.js +43 -2
  16. package/dist/delivery-broker-platform.js.map +1 -1
  17. package/dist/delivery-handoff.d.ts +8 -1
  18. package/dist/delivery-handoff.d.ts.map +1 -1
  19. package/dist/delivery-handoff.js +8 -5
  20. package/dist/delivery-handoff.js.map +1 -1
  21. package/dist/directory-cutover.d.ts +93 -1
  22. package/dist/directory-cutover.d.ts.map +1 -1
  23. package/dist/directory-cutover.js +85 -2
  24. package/dist/directory-cutover.js.map +1 -1
  25. package/dist/directory-objects.d.ts +12 -0
  26. package/dist/directory-objects.d.ts.map +1 -1
  27. package/dist/directory-objects.js +8 -1
  28. package/dist/directory-objects.js.map +1 -1
  29. package/dist/directory-placement.d.ts.map +1 -1
  30. package/dist/directory-placement.js +1 -0
  31. package/dist/directory-placement.js.map +1 -1
  32. package/dist/directory-tenant-identities.d.ts +30 -0
  33. package/dist/directory-tenant-identities.d.ts.map +1 -0
  34. package/dist/directory-tenant-identities.js +64 -0
  35. package/dist/directory-tenant-identities.js.map +1 -0
  36. package/dist/directory-tenant-tuples.d.ts +30 -3
  37. package/dist/directory-tenant-tuples.d.ts.map +1 -1
  38. package/dist/directory-tenant-tuples.js +27 -0
  39. package/dist/directory-tenant-tuples.js.map +1 -1
  40. package/dist/host.d.ts +35 -5
  41. package/dist/host.d.ts.map +1 -1
  42. package/dist/host.js +110 -19
  43. package/dist/host.js.map +1 -1
  44. package/dist/index.d.ts +7 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +9 -2
  47. package/dist/index.js.map +1 -1
  48. package/dist/peer-call-target.d.ts +16 -2
  49. package/dist/peer-call-target.d.ts.map +1 -1
  50. package/dist/peer-call-target.js +36 -6
  51. package/dist/peer-call-target.js.map +1 -1
  52. package/dist/reconcile-on-wake.d.ts +17 -1
  53. package/dist/reconcile-on-wake.d.ts.map +1 -1
  54. package/dist/reconcile-on-wake.js +84 -12
  55. package/dist/reconcile-on-wake.js.map +1 -1
  56. package/dist/route-read-model-publisher.d.ts.map +1 -1
  57. package/dist/route-read-model-publisher.js +4 -0
  58. package/dist/route-read-model-publisher.js.map +1 -1
  59. package/dist/route-resolver.d.ts +19 -2
  60. package/dist/route-resolver.d.ts.map +1 -1
  61. package/dist/route-resolver.js +25 -5
  62. package/dist/route-resolver.js.map +1 -1
  63. package/dist/scope-do.d.ts +19 -0
  64. package/dist/scope-do.d.ts.map +1 -1
  65. package/dist/scope-do.js +398 -25
  66. package/dist/scope-do.js.map +1 -1
  67. package/dist/scope-facets.d.ts +121 -0
  68. package/dist/scope-facets.d.ts.map +1 -0
  69. package/dist/scope-facets.js +98 -0
  70. package/dist/scope-facets.js.map +1 -0
  71. package/dist/scope-supervisor-do.d.ts +93 -0
  72. package/dist/scope-supervisor-do.d.ts.map +1 -0
  73. package/dist/scope-supervisor-do.js +504 -0
  74. package/dist/scope-supervisor-do.js.map +1 -0
  75. package/dist/scope-sweeper-do.d.ts +7 -1
  76. package/dist/scope-sweeper-do.d.ts.map +1 -1
  77. package/dist/scope-sweeper-do.js +17 -1
  78. package/dist/scope-sweeper-do.js.map +1 -1
  79. package/dist/scope-wake.d.ts +5 -0
  80. package/dist/scope-wake.d.ts.map +1 -1
  81. package/dist/scope-wake.js +2 -0
  82. package/dist/scope-wake.js.map +1 -1
  83. package/dist/scope-work.d.ts +1 -1
  84. package/dist/scope-work.js +1 -1
  85. package/dist/scope-work.js.map +1 -1
  86. package/dist/supplied-pass-box.d.ts +77 -0
  87. package/dist/supplied-pass-box.d.ts.map +1 -0
  88. package/dist/supplied-pass-box.js +265 -0
  89. package/dist/supplied-pass-box.js.map +1 -0
  90. package/dist/tenant-due-index-do.d.ts +76 -0
  91. package/dist/tenant-due-index-do.d.ts.map +1 -0
  92. package/dist/tenant-due-index-do.js +90 -0
  93. package/dist/tenant-due-index-do.js.map +1 -0
  94. package/dist/tenant-due-nudge.d.ts +66 -0
  95. package/dist/tenant-due-nudge.d.ts.map +1 -0
  96. package/dist/tenant-due-nudge.js +77 -0
  97. package/dist/tenant-due-nudge.js.map +1 -0
  98. package/dist/tenant-due-work-do.d.ts +26 -0
  99. package/dist/tenant-due-work-do.d.ts.map +1 -1
  100. package/dist/tenant-due-work-do.js +69 -5
  101. package/dist/tenant-due-work-do.js.map +1 -1
  102. package/package.json +12 -12
@@ -0,0 +1,504 @@
1
+ /**
2
+ * Track B (broker RFC §6, #3466): the scope supervisor — the one class a script executes for its
3
+ * scopes when scopes run as facets. Platform code only. Switched: nothing on `main` exports it as a
4
+ * deployed script's scope class, so every scope still runs `defineScopeDO` as its own object.
5
+ *
6
+ * One object per scope, as today, in two layers (`docs/architecture/scope-facets.md`):
7
+ *
8
+ * - **This supervisor** receives every call, holds the alarm and the live-read sockets, and keeps a
9
+ * table of its own, `_substrat_supervisor` (`SUPERVISOR_MARKER_TABLE`), in the object's storage.
10
+ * Its SQL names that table literally, so `lint:attachment-writers` can see no write here reaches
11
+ * attachment rows.
12
+ * - **The facet** holds the kernel, the app's modules and the scope's data. Its code arrives inert
13
+ * (`ScopeSupervisorOptions.code`, the `defineScopeFacet` class bundled as text), is loaded through
14
+ * the Worker Loader with `globalOutbound: null` and an empty env, and runs as the facet `scope`
15
+ * with a SQLite database of its own the supervisor never reads.
16
+ *
17
+ * **The isolate id** is `(release, tenant, app)` (RFC §6.3): two tenants never share one. A scope
18
+ * is not provisioned for a tenant until its first provision has run in the facet, so until the
19
+ * facet reports its tenant the id names this object instead (`unbound-<object id>`), which shares
20
+ * an isolate with nobody. The first idle moment after the tenant is known, the facet is restarted
21
+ * under the tenant's id; its storage stays, as the spikes showed it does across a restart.
22
+ *
23
+ * **The alarm** (`spikes/scope-facet-wakeups`): a facet cannot set one, and the supervisor's lives
24
+ * in another database than the facet's rows, so no single commit holds both. What holds instead:
25
+ * before ANY call into the facet, the supervisor arms its alarm no later than `prearmMs` from now
26
+ * and waits for `storage.sync()`, so a row the facet commits can never be left without a wake,
27
+ * whatever resets after it. After the call it moves the alarm to what the facet asked for, but only
28
+ * once no other call is in flight, since each in-flight call's commit is protected by that same
29
+ * pre-arm. A call that throws leaves a wake `prearmMs` out. The alarm handler arms again first,
30
+ * then forwards the alarm, so a drain that fails is retried by this alarm, not by the runtime's cap.
31
+ *
32
+ * **The sockets** (`spikes/scope-facet-wakeups` §3): accepted here, hibernatable, each carrying its
33
+ * subscription and a cursor — the last outbox event its walk has passed. After every call and on
34
+ * every alarm the facet decides what each socket is owed since its cursor and the supervisor sends
35
+ * it. A socket survives a facet restart (a rollout), and a revived supervisor rebuilds its roster
36
+ * from `getWebSockets()`. A reset closes every socket (1006); the client opens a new one naming the
37
+ * last event it heard (`LIVE_RESUME_HEADER`), and the walk resumes from there. A committed change
38
+ * is never skipped for a socket; it may be pushed twice.
39
+ */
40
+ import { DurableObject, RpcTarget } from 'cloudflare:workers';
41
+ import { isUpgradeRequest, readSubscription, LIVE_CLOSE, LIVE_SOCKETS_PER_PRINCIPAL, LIVE_SUBSCRIBE_PATH, } from './live-reads.js';
42
+ import { defineScopeDO } from './scope-do.js';
43
+ import { holdsScopeData, scopeRpcMethods, servedBySupervisor, ScopeFacetFenced, LIVE_RESUME_HEADER, } from './scope-facets.js';
44
+ /** See `ScopeSupervisorOptions.prearmMs`. */
45
+ export const DEFAULT_PREARM_MS = 30_000;
46
+ /** How many catch-up passes one trigger runs before it leaves the rest to an alarm armed now. */
47
+ const LIVE_CATCHUP_PASSES = 8;
48
+ /** The facet's name inside this object. One facet: the scope. */
49
+ const FACET = 'scope';
50
+ /** The generated module the supervisor puts in front of the bundle, so the env stays empty. */
51
+ const FACET_ENTRY_MODULE = 'substrat-scope-facet.js';
52
+ /** The marker table's keys. */
53
+ const KEY_SERVED_SINCE = 'served_since';
54
+ const KEY_TENANT = 'tenant';
55
+ /**
56
+ * Where the platform names the tenant in a call it forwards: `invoke(operation, input, principal,
57
+ * tenantId, …)`. The host resolved that tenant, and the scope pair-checks it against its receipt.
58
+ * The isolate id's tenant is pinned only from here, and only when the facet's receipt agrees: a
59
+ * facet is the app's code, so its reply alone never picks an isolate (#3784 review). Until both
60
+ * agree, the scope keeps an isolate of its own object.
61
+ */
62
+ const PLATFORM_TENANT_ARG = { invoke: 3 };
63
+ const KEY_WANT_AT = 'want_at';
64
+ /** An event id as the outbox mints it (a ULID): what a resume header may name. */
65
+ const EVENT_ID = /^[0-9A-HJKMNP-TV-Z]{26}$/;
66
+ /**
67
+ * The module the facet is loaded through: the bundle's class, constructed with the release and the
68
+ * app as constants compiled into code. The Worker Loader's env stays `{}`, so no binding and no
69
+ * secret reaches the facet, and a per-scope value never rides the loader's cache by id (the env
70
+ * trap in `spikes/scope-no-network`). Exported for the test that reads it.
71
+ */
72
+ export function facetEntrySource(mainModule, className, constants) {
73
+ return [
74
+ `import * as bundle from ${JSON.stringify(`./${mainModule}`)};`,
75
+ `const constants = Object.freeze(${JSON.stringify(constants)});`,
76
+ `const Facet = bundle[${JSON.stringify(className)}];`,
77
+ `if (typeof Facet !== 'function') throw new Error(${JSON.stringify(`scope bundle: no export '${className}'`)});`,
78
+ `export class ScopeFacet extends Facet {`,
79
+ ` constructor(ctx, env) { super(ctx, { ...constants }); }`,
80
+ `}`,
81
+ ].join('\n');
82
+ }
83
+ /** The facet sends and closes through this, on the supervisor's own sockets, by tag. */
84
+ class LiveSockets extends RpcTarget {
85
+ #ctx;
86
+ constructor(ctx) {
87
+ super();
88
+ this.#ctx = ctx;
89
+ }
90
+ liveSend(sid, frame) {
91
+ for (const ws of this.#ctx.getWebSockets(sid)) {
92
+ try {
93
+ ws.send(frame);
94
+ }
95
+ catch {
96
+ // Gone between the decision and the send: the runtime delivers its close.
97
+ }
98
+ }
99
+ }
100
+ liveClose(sid, code, reason) {
101
+ for (const ws of this.#ctx.getWebSockets(sid)) {
102
+ try {
103
+ ws.close(code, reason);
104
+ }
105
+ catch {
106
+ // Already closed.
107
+ }
108
+ }
109
+ }
110
+ }
111
+ const FORWARD = Symbol('scope supervisor forward');
112
+ export function defineScopeSupervisorDO(options) {
113
+ const prearmMs = options.prearmMs ?? DEFAULT_PREARM_MS;
114
+ if (!(prearmMs > 0))
115
+ throw new Error('scope supervisor: prearmMs must be positive');
116
+ // The platform's own class, with no module: its surface is the scope's RPC surface, whatever any
117
+ // bundle adds. No app code is read to decide what is forwarded.
118
+ const forwarded = new Set([...scopeRpcMethods(defineScopeDO([], {}).prototype), ...(options.forward ?? [])]);
119
+ class ScopeSupervisor extends DurableObject {
120
+ /** Calls into the facet that have armed and not yet settled: the pre-arm is theirs while > 0. */
121
+ #inflight = 0;
122
+ /**
123
+ * Every call inside the facet right now, whoever made it: forwarded calls, the alarm, catch-up
124
+ * passes and plain fetches. Separate from `#inflight`, which only the calls that pre-arm count,
125
+ * because a restart must wait for all of them (#3784 review).
126
+ */
127
+ #inFacet = 0;
128
+ /** Why this object refuses every call (the forward fence), or null. */
129
+ #fenced;
130
+ /** The isolate id the running facet was started under, or null before the first start. */
131
+ #loaded = null;
132
+ /** One catch-up pass at a time, in order. */
133
+ #live = Promise.resolve();
134
+ #sockets;
135
+ constructor(ctx, env) {
136
+ super(ctx, env);
137
+ ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair('ping', 'pong'));
138
+ this.#sockets = new LiveSockets(ctx);
139
+ const storage = ctx.storage;
140
+ // The forward fence: an object that held a scope's rows before it was supervised stays as it
141
+ // is. Facet mode is for new scopes; moving one is parked (RFC §6.6). Nothing is written.
142
+ if (!servedBySupervisor(storage) && holdsScopeData(storage)) {
143
+ this.#fenced =
144
+ 'ScopeFacetFenced: this scope holds data in its own object storage (it ran before scopes ' +
145
+ 'became facets). The scope supervisor serves new scopes only, and moving a scope into a ' +
146
+ 'facet is not built: serve this script with the scope class as an object';
147
+ return;
148
+ }
149
+ this.#fenced = null;
150
+ // The rollback fence's marker, before any call can reach the facet (`assertNotSupervised`).
151
+ storage.sql.exec(`CREATE TABLE IF NOT EXISTS _substrat_supervisor (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
152
+ storage.sql.exec(`INSERT OR IGNORE INTO _substrat_supervisor (key, value) VALUES (?, ?)`, KEY_SERVED_SINCE, new Date().toISOString());
153
+ }
154
+ // -- the supervisor's own table ---------------------------------------------------------
155
+ #read(key) {
156
+ const row = this.ctx.storage.sql
157
+ .exec(`SELECT value FROM _substrat_supervisor WHERE key = ?`, key)
158
+ .toArray()[0];
159
+ return row?.value ?? null;
160
+ }
161
+ #write(key, value) {
162
+ if (value === null)
163
+ this.ctx.storage.sql.exec(`DELETE FROM _substrat_supervisor WHERE key = ?`, key);
164
+ else
165
+ this.ctx.storage.sql.exec(`INSERT OR REPLACE INTO _substrat_supervisor (key, value) VALUES (?, ?)`, key, value);
166
+ }
167
+ /** The earliest wake the facet asked for that has not come due, durable across resets. */
168
+ #wantAt() {
169
+ const v = this.#read(KEY_WANT_AT);
170
+ return v === null ? null : Number(v);
171
+ }
172
+ #want(at) {
173
+ const current = this.#wantAt();
174
+ if (current === null || at < current)
175
+ this.#write(KEY_WANT_AT, String(at));
176
+ }
177
+ // -- the facet --------------------------------------------------------------------------
178
+ #refuseIfFenced() {
179
+ if (this.#fenced !== null)
180
+ throw new ScopeFacetFenced(this.#fenced);
181
+ }
182
+ #release() {
183
+ return this.env.SUBSTRAT_VERSION_ID ?? 'unversioned';
184
+ }
185
+ #app() {
186
+ return this.env.SUBSTRAT_VERTICAL ?? options.app;
187
+ }
188
+ /** `(release, tenant, app)`, or this object alone until the facet has reported its tenant. */
189
+ #isolateId() {
190
+ const tenant = this.#read(KEY_TENANT);
191
+ return `${this.#release()}:${tenant ?? `unbound-${this.ctx.id.toString()}`}:${this.#app()}`;
192
+ }
193
+ /**
194
+ * Run one call inside the facet. Every call goes through here, so a restart sees every call
195
+ * already inside, and never aborts one.
196
+ */
197
+ async #inside(call) {
198
+ const facet = this.#facet();
199
+ this.#inFacet += 1;
200
+ try {
201
+ return await call(facet);
202
+ }
203
+ finally {
204
+ this.#inFacet -= 1;
205
+ }
206
+ }
207
+ #facet() {
208
+ const id = this.#isolateId();
209
+ // A new id (a tenant now known, a release this instance had not loaded) restarts the facet,
210
+ // but only when no call is inside it: aborting would fail calls already running. Otherwise
211
+ // the running facet serves this call too, and a later call restarts it.
212
+ if (this.#loaded !== null && this.#loaded !== id && this.#inFacet === 0) {
213
+ this.ctx.facets.abort(FACET, new Error(`scope supervisor: restarting the facet under ${id}`));
214
+ this.#loaded = null;
215
+ }
216
+ const stub = this.ctx.facets.get(FACET, () => {
217
+ const worker = this.env.SCOPE_LOADER.get(id, () => this.#code());
218
+ this.#loaded = id;
219
+ return { class: worker.getDurableObjectClass('ScopeFacet') };
220
+ });
221
+ return stub;
222
+ }
223
+ #code() {
224
+ const code = typeof options.code === 'function' ? options.code(this.env) : options.code;
225
+ const constants = { SUBSTRAT_VERTICAL: this.#app() };
226
+ if (this.env.SUBSTRAT_VERSION_ID !== undefined)
227
+ constants.SUBSTRAT_VERSION_ID = this.env.SUBSTRAT_VERSION_ID;
228
+ if (FACET_ENTRY_MODULE in code.modules)
229
+ throw new Error(`scope bundle: '${FACET_ENTRY_MODULE}' is the supervisor's`);
230
+ return {
231
+ compatibilityDate: code.compatibilityDate,
232
+ ...(code.compatibilityFlags ? { compatibilityFlags: [...code.compatibilityFlags] } : {}),
233
+ mainModule: FACET_ENTRY_MODULE,
234
+ modules: {
235
+ ...code.modules,
236
+ [FACET_ENTRY_MODULE]: facetEntrySource(code.mainModule, code.className ?? 'ScopeFacet', constants),
237
+ },
238
+ env: {},
239
+ globalOutbound: null,
240
+ ...(options.limits ? { limits: { ...options.limits } } : {}),
241
+ };
242
+ }
243
+ // -- the alarm --------------------------------------------------------------------------
244
+ /** Arm no later than `prearmMs` from now, and wait until that is durable. */
245
+ async #preArm() {
246
+ const at = Date.now() + prearmMs;
247
+ const current = await this.ctx.storage.getAlarm();
248
+ if (current === null || current > at)
249
+ await this.ctx.storage.setAlarm(at);
250
+ await this.ctx.storage.sync();
251
+ }
252
+ /**
253
+ * Move the alarm to what is wanted: the facet's earliest wake and the earliest session end among
254
+ * the sockets. While a call is in flight the pre-arm stays, earlier if something wants earlier.
255
+ */
256
+ async #settleAlarm() {
257
+ let target = this.#wantAt();
258
+ for (const held of this.#held()) {
259
+ const ends = held.subscription.expiresAt === undefined ? null : Date.parse(held.subscription.expiresAt);
260
+ if (ends !== null && (target === null || ends < target))
261
+ target = ends;
262
+ }
263
+ const current = await this.ctx.storage.getAlarm();
264
+ if (this.#inflight > 0) {
265
+ if (target !== null && (current === null || target < current))
266
+ await this.ctx.storage.setAlarm(target);
267
+ return;
268
+ }
269
+ if (target === null) {
270
+ if (current !== null)
271
+ await this.ctx.storage.deleteAlarm();
272
+ }
273
+ else if (current !== target) {
274
+ await this.ctx.storage.setAlarm(target);
275
+ }
276
+ }
277
+ /** What a settled call tells the supervisor: its tenant, its wake, or that it failed. */
278
+ #note(reply, platformTenant) {
279
+ if (reply === undefined) {
280
+ // Failed: whatever it committed before it threw is woken for within `prearmMs`, and the
281
+ // facet's alarm users re-arm from the store when it fires.
282
+ this.#want(Date.now() + prearmMs);
283
+ return;
284
+ }
285
+ this.#pinTenant(reply.tenant, platformTenant);
286
+ if (reply.wakeAt !== null)
287
+ this.#want(reply.wakeAt);
288
+ }
289
+ /**
290
+ * Record the tenant half of the isolate id once, from the platform's own argument, when the
291
+ * facet's receipt names the same tenant. Anything else pins nothing: a reply naming another
292
+ * tenant, a call that names none, a tenant already pinned. Failing closed leaves the isolate
293
+ * per object (`unbound-<id>`), which shares with no other scope at all.
294
+ */
295
+ #pinTenant(reported, platformTenant) {
296
+ const pinned = this.#read(KEY_TENANT);
297
+ if (pinned !== null) {
298
+ if (reported !== null && reported !== pinned) {
299
+ console.error(`substrat: scope facet reported tenant '${reported}', pinned '${pinned}'; kept`);
300
+ }
301
+ return;
302
+ }
303
+ if (platformTenant === undefined || reported === null)
304
+ return;
305
+ if (reported !== platformTenant) {
306
+ console.error(`substrat: scope facet reported tenant '${reported}' for a call naming '${platformTenant}'; not pinned`);
307
+ return;
308
+ }
309
+ this.#write(KEY_TENANT, platformTenant);
310
+ }
311
+ /** One call into the facet, under the pre-arm. */
312
+ async [FORWARD](method, args) {
313
+ this.#refuseIfFenced();
314
+ if (method !== 'liveAdmit' && !forwarded.has(method))
315
+ throw new Error(`scope supervisor: '${method}' is not forwarded`);
316
+ this.#inflight += 1;
317
+ let reply;
318
+ try {
319
+ await this.#preArm();
320
+ reply = await this.#inside((facet) => facet.supervisedCall(method, args));
321
+ return reply.value;
322
+ }
323
+ finally {
324
+ this.#inflight -= 1;
325
+ try {
326
+ const at = Object.hasOwn(PLATFORM_TENANT_ARG, method) ? PLATFORM_TENANT_ARG[method] : undefined;
327
+ const named = at === undefined ? undefined : args[at];
328
+ this.#note(reply, typeof named === 'string' ? named : undefined);
329
+ await this.#settleAlarm();
330
+ }
331
+ catch (err) {
332
+ // The pre-arm stands, so a failure here costs an early alarm, never a lost one.
333
+ console.error('substrat: scope supervisor could not settle its alarm', err);
334
+ }
335
+ await this.#catchUp();
336
+ }
337
+ }
338
+ async alarm() {
339
+ if (this.#fenced !== null)
340
+ return;
341
+ this.#inflight += 1;
342
+ let reply;
343
+ try {
344
+ // Arm again first, so this wake's own work is covered whatever happens below.
345
+ await this.#preArm();
346
+ const want = this.#wantAt();
347
+ if (want !== null && want <= Date.now())
348
+ this.#write(KEY_WANT_AT, null);
349
+ this.#closeEnded();
350
+ reply = await this.#inside((facet) => facet.supervisedCall('alarm', []));
351
+ }
352
+ catch (err) {
353
+ console.error('substrat: scope facet alarm failed; armed again', err);
354
+ }
355
+ finally {
356
+ this.#inflight -= 1;
357
+ try {
358
+ this.#note(reply);
359
+ await this.#settleAlarm();
360
+ }
361
+ catch (err) {
362
+ console.error('substrat: scope supervisor could not settle its alarm', err);
363
+ }
364
+ await this.#catchUp();
365
+ }
366
+ }
367
+ // -- live reads -------------------------------------------------------------------------
368
+ /** Every socket with a usable attachment, as the roster a revived supervisor rebuilds. */
369
+ #held() {
370
+ const held = [];
371
+ for (const ws of this.ctx.getWebSockets()) {
372
+ let attachment;
373
+ try {
374
+ attachment = ws.deserializeAttachment();
375
+ }
376
+ catch {
377
+ continue;
378
+ }
379
+ const subscription = readSubscription(attachment);
380
+ const a = attachment;
381
+ if (!subscription || typeof a?.sid !== 'string' || typeof a.cursor !== 'string')
382
+ continue;
383
+ held.push({ ws, sid: a.sid, cursor: a.cursor, attachment: attachment, subscription });
384
+ }
385
+ return held;
386
+ }
387
+ /** Close every socket whose session has ended; return the rest. */
388
+ #closeEnded(now = new Date().toISOString()) {
389
+ const live = [];
390
+ for (const held of this.#held()) {
391
+ if (held.subscription.expiresAt !== undefined && held.subscription.expiresAt <= now) {
392
+ try {
393
+ held.ws.close(LIVE_CLOSE.revoked, 'the session that opened this subscription has ended');
394
+ }
395
+ catch {
396
+ // Already gone.
397
+ }
398
+ continue;
399
+ }
400
+ live.push(held);
401
+ }
402
+ return live;
403
+ }
404
+ /** Run catch-up passes after a call, one chain at a time. Never throws: a push is a hint. */
405
+ #catchUp() {
406
+ if (this.#fenced !== null || this.ctx.getWebSockets().length === 0)
407
+ return this.#live;
408
+ this.#live = this.#live.then(() => this.#catchUpPasses(), () => this.#catchUpPasses()).catch((err) => {
409
+ console.error('substrat: scope supervisor live catch-up failed', err);
410
+ });
411
+ return this.#live;
412
+ }
413
+ async #catchUpPasses() {
414
+ for (let pass = 0; pass < LIVE_CATCHUP_PASSES; pass++) {
415
+ const held = this.#closeEnded();
416
+ if (held.length === 0)
417
+ return;
418
+ const answer = await this.#inside((facet) => facet.liveCatchUp(held.map((h) => ({ sid: h.sid, attachment: h.attachment, cursor: h.cursor })), this.#sockets));
419
+ for (const h of held) {
420
+ const next = answer.cursors[h.sid];
421
+ if (next === undefined || next <= h.cursor)
422
+ continue;
423
+ try {
424
+ h.ws.serializeAttachment({ ...h.attachment, cursor: next });
425
+ }
426
+ catch {
427
+ // Closed meanwhile.
428
+ }
429
+ }
430
+ if (!answer.behind)
431
+ return;
432
+ }
433
+ // Still behind: the rest is an alarm away, not a longer hold on this object.
434
+ this.#want(Date.now());
435
+ await this.#settleAlarm();
436
+ }
437
+ async #subscribe(request) {
438
+ const asked = { url: request.url, headers: [...request.headers] };
439
+ const admission = (await this[FORWARD]('liveAdmit', [asked]));
440
+ if (!admission.admitted) {
441
+ return new Response(admission.body, { status: admission.status, headers: admission.headers });
442
+ }
443
+ const principal = admission.subscription.principal;
444
+ const pair = new WebSocketPair();
445
+ const [client, server] = Object.values(pair);
446
+ // The object's cap (#938), counted over the sockets still live.
447
+ if (this.#closeEnded().filter((h) => h.subscription.principal === principal).length >= LIVE_SOCKETS_PER_PRINCIPAL) {
448
+ server.accept();
449
+ server.close(LIVE_CLOSE.tooMany, 'too many live subscriptions for this principal; poll instead');
450
+ return new Response(null, { status: 101, webSocket: client });
451
+ }
452
+ // A resume names the last event the client heard: the walk starts there, never later than
453
+ // the mark the facet admitted at. Anything else in the header is ignored, not trusted.
454
+ const resume = request.headers.get(LIVE_RESUME_HEADER);
455
+ const cursor = resume !== null && EVENT_ID.test(resume) && resume < admission.cursor ? resume : admission.cursor;
456
+ const sid = crypto.randomUUID();
457
+ this.ctx.acceptWebSocket(server, [sid]);
458
+ server.serializeAttachment({ ...admission.subscription, sid, cursor });
459
+ if (typeof admission.subscription.expiresAt === 'string')
460
+ await this.#settleAlarm();
461
+ if (cursor < admission.cursor)
462
+ void this.#catchUp();
463
+ return new Response(null, { status: 101, webSocket: client });
464
+ }
465
+ async fetch(request) {
466
+ this.#refuseIfFenced();
467
+ const url = new URL(request.url);
468
+ if (url.pathname === LIVE_SUBSCRIBE_PATH && isUpgradeRequest(request))
469
+ return this.#subscribe(request);
470
+ // The facet's answer to anything else (no such surface, not an upgrade). Nothing there writes.
471
+ return this.#inside((facet) => facet.fetch(request));
472
+ }
473
+ webSocketMessage(ws, message) {
474
+ // The scope class's protocol: `ping`/`pong` only, answered by the auto-response normally.
475
+ if (message === 'ping')
476
+ ws.send('pong');
477
+ }
478
+ webSocketClose(ws, code) {
479
+ try {
480
+ ws.close(code === 1006 ? 1000 : code, 'scope closing the subscription');
481
+ }
482
+ catch {
483
+ // Already gone.
484
+ }
485
+ }
486
+ webSocketError(_ws, error) {
487
+ console.error('substrat: live-read socket error', error);
488
+ }
489
+ }
490
+ // The scope's RPC surface, each method a call into the facet under the pre-arm.
491
+ for (const name of forwarded) {
492
+ if (Object.prototype.hasOwnProperty.call(ScopeSupervisor.prototype, name))
493
+ continue;
494
+ Object.defineProperty(ScopeSupervisor.prototype, name, {
495
+ value: function (...args) {
496
+ return this[FORWARD](name, args);
497
+ },
498
+ writable: true,
499
+ configurable: true,
500
+ });
501
+ }
502
+ return ScopeSupervisor;
503
+ }
504
+ //# sourceMappingURL=scope-supervisor-do.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-supervisor-do.js","sourceRoot":"","sources":["../src/scope-supervisor-do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,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nC,CAAC;YACD,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -54,10 +54,16 @@ export interface ScopeSweepReport {
54
54
  * scope this deployment does not serve), its lifecycle holds it, or its module's schedules are switched
55
55
  * off — so the scope does not re-arm, and the pass re-arms it once its schedules run again.
56
56
  */
57
- export type ScopePurgeAnswer = {
57
+ export type ScopePurgeAnswer =
58
+ /**
59
+ * `progressed` (D-85): a job pass committed with its run still going, so the scope has work due at
60
+ * once and its alarm re-arms without the minimum gap, as for a purge lap left open.
61
+ */
62
+ {
58
63
  ran: number;
59
64
  failed: number;
60
65
  skipped: number;
66
+ progressed?: boolean;
61
67
  } | {
62
68
  held: string;
63
69
  };
@@ -1 +1 @@
1
- {"version":3,"file":"scope-sweeper-do.d.ts","sourceRoot":"","sources":["../src/scope-sweeper-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,QAA6B,CAAC;AAarD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,WAAW,EAAE,mBAAmB,CAAC;IACjC;;;;OAIG;IACH,SAAS,EAAE,mBAAmB,CAAC;IAC/B,sEAAsE;IACtE,IAAI,CAA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C;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5D,gEAAgE;IAChE,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACvC;;;OAGG;IACH,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAChF;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EACtC,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAChC,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,KAAK,aAAa,CAAC,GAAG,CAAC,GAAG,cAAc,CAwShF;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,cAAc,EACpB,CAAC,EAAE,QAAQ,EACX,CAAC,EAAE,OAAO,EACV,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,iBAAiB,EAAE,MAAM,IAAI,CAAA;CAAE,GACnE,OAAO,CAAC,gBAAgB,CAAC,CA2D3B;AAED,8GAA8G;AAC9G,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ1G"}
@@ -426,6 +426,22 @@ export async function runScopeDueWork(host, t, s, schedules, options) {
426
426
  answer.failed += 1;
427
427
  }
428
428
  }
429
+ // D-85: the scope's due job runs, when the alarm runs its due work (`schedules`): a run started by
430
+ // `ctx.jobs.start` armed this alarm, and is driven here rather than by a pass over scopes (K-69).
431
+ // One pass per run, as a sweep drives it; a failure is on the run's own record. A run that advanced
432
+ // is due again at once, which `progressed` says.
433
+ let progressed = false;
434
+ if (schedules) {
435
+ try {
436
+ const r = await host.runDueJobs(t, s);
437
+ answer.ran += r.completed + r.advanced;
438
+ answer.failed += r.failed;
439
+ progressed = r.advanced > 0;
440
+ }
441
+ catch {
442
+ answer.failed += 1;
443
+ }
444
+ }
429
445
  if (passRuns.length > 0 && host.enqueueSweepRuns) {
430
446
  try {
431
447
  await host.enqueueSweepRuns(s, { version: options.versionId, entries: passRuns.slice(0, 64) });
@@ -436,7 +452,7 @@ export async function runScopeDueWork(host, t, s, schedules, options) {
436
452
  }
437
453
  if (needsPlatformDrain)
438
454
  options.kickPlatformDrain();
439
- return heldBy !== null && answer.ran === 0 && answer.failed === 0 ? { held: heldBy } : answer;
455
+ return heldBy !== null && answer.ran === 0 && answer.failed === 0 ? { held: heldBy } : { ...answer, ...(progressed ? { progressed } : {}) };
440
456
  }
441
457
  /** The router's existing per-scope drain call, also used after an unattended pass and a scope's due alarm. */
442
458
  export async function kickPlatformDrain(env, tenantId, scopeId) {