@substrat-run/adapter-cloudflare 0.214.0 → 0.215.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.
@@ -14,9 +14,19 @@ export interface KickProducer {
14
14
  tenantId: TenantId;
15
15
  scopeId: ScopeId;
16
16
  }
17
+ /**
18
+ * What the pass is asked to do, as the kicks since the last pass named it (K-69): `null` is
19
+ * everything, which is what a kick naming nothing asks for, as every kick did before kicks could
20
+ * name anything. Otherwise the union of the names the kicks gave.
21
+ */
22
+ export type KickWants = ReadonlySet<string> | null;
17
23
  /** The RPC surface a `defineKickCoalescerDO` class exposes over its stub. */
18
24
  export interface KickCoalescerDo {
19
- kick(tenantId: TenantId, scopeId: ScopeId): Promise<KickOutcome>;
25
+ /**
26
+ * `wants` (K-69): what this kick asks the pass for. Absent, everything. A pass is handed the union
27
+ * of what the kicks it covers asked for, so one kind of work never runs because another was asked.
28
+ */
29
+ kick(tenantId: TenantId, scopeId: ScopeId, wants?: readonly string[]): Promise<KickOutcome>;
20
30
  }
21
31
  export interface KickCoalescerConfig<Env> {
22
32
  /** Default {@link CROSS_VERTICAL_KICK_WINDOW_MS}. */
@@ -27,8 +37,8 @@ export interface KickCoalescerConfig<Env> {
27
37
  * authority lives: the deployment runs `runCrossVerticalFrom` here with the same reach and
28
38
  * gates as its sweep, so this object decides only WHEN, never what or for whom.
29
39
  */
30
- run(env: Env, producer: KickProducer): Promise<void | {
31
- more?: boolean;
40
+ run(env: Env, producer: KickProducer, wants: KickWants): Promise<void | {
41
+ more?: boolean | readonly string[];
32
42
  }>;
33
43
  /**
34
44
  * #3365: every pass runs from the alarm, never inside the kick. A kick only marks the producer
@@ -1 +1 @@
1
- {"version":3,"file":"kick-coalescer-do.d.ts","sourceRoot":"","sources":["../src/kick-coalescer-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,Q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CAE9E;AAuBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EACvC,MAAM,EAAE,mBAAmB,CAAC,GAAG,CAAC,GAC/B,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,KAAK,aAAa,CAAC,GAAG,CAAC,GAAG,eAAe,CAmFjF"}
@@ -10,6 +10,15 @@ export const CROSS_VERTICAL_KICK_WINDOW_MS = 5_000;
10
10
  export function kickCoalescerName(tenantId, scopeId) {
11
11
  return `${tenantId}:${scopeId}`;
12
12
  }
13
+ /** Fold one kick's ask into what the next pass is asked for. Everything absorbs any list. */
14
+ function wantsUnion(prior, wants) {
15
+ if (wants === null)
16
+ return null;
17
+ const known = prior.dirty ? prior.wants : [];
18
+ if (known === null || known === undefined)
19
+ return prior.dirty ? null : [...wants];
20
+ return [...new Set([...known, ...wants])].sort();
21
+ }
13
22
  /**
14
23
  * `defineKickCoalescerDO` — the global bound on the router kick (#1705 PR 2).
15
24
  *
@@ -35,9 +44,10 @@ export function defineKickCoalescerDO(config) {
35
44
  return class KickCoalescerDO extends DurableObject {
36
45
  /** The in-flight pass, when one is running. */
37
46
  #running = null;
38
- async kick(tenantId, scopeId) {
47
+ async kick(tenantId, scopeId, wants) {
39
48
  const prior = await this.ctx.storage.get('state');
40
- const state = prior ?? { producer: { tenantId, scopeId }, lastStartedAt: 0, dirty: false };
49
+ const base = prior ?? { producer: { tenantId, scopeId }, lastStartedAt: 0, dirty: false };
50
+ const state = { ...base, wants: wantsUnion(base, wants ?? null) };
41
51
  if (this.#running) {
42
52
  await this.ctx.storage.put('state', { ...state, dirty: true });
43
53
  return 'coalesced';
@@ -75,16 +85,20 @@ export function defineKickCoalescerDO(config) {
75
85
  }
76
86
  async #pass(state) {
77
87
  const startedAt = Date.now();
78
- await this.ctx.storage.put('state', { ...state, lastStartedAt: startedAt, dirty: false });
88
+ const wants = state.wants === null || state.wants === undefined ? null : new Set(state.wants);
89
+ await this.ctx.storage.put('state', { ...state, lastStartedAt: startedAt, dirty: false, wants: [] });
79
90
  this.#running = (async () => {
80
91
  try {
81
- const outcome = await config.run(this.env, state.producer);
92
+ const outcome = await config.run(this.env, state.producer, wants);
82
93
  // #3365: the pass stopped with work left (a deadline, its last round). Dirty again, so
83
94
  // the alarm at this window's end runs the next one, and so on until a pass finishes.
84
- if (outcome && outcome.more) {
95
+ // K-69: `more` may name the part that had more, and the next pass is asked for that part
96
+ // alone (beside whatever kicks arrived meanwhile); `true` asks for everything, as before.
97
+ const more = outcome?.more;
98
+ if (more === true || (Array.isArray(more) && more.length > 0)) {
85
99
  const now = await this.ctx.storage.get('state');
86
100
  if (now)
87
- await this.ctx.storage.put('state', { ...now, dirty: true });
101
+ await this.ctx.storage.put('state', { ...now, wants: wantsUnion(now, more === true ? null : more), dirty: true });
88
102
  }
89
103
  }
90
104
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"kick-coalescer-do.js","sourceRoot":"","sources":["../src/kick-coalescer-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAsCnD,oGAAoG;AACpG,MAAM,UAAU,iBAAiB,CAAC,QAAkB,EAAE,OAAgB;IACpE,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;AAClC,CAAC;AAUD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAgC;IAEhC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,6BAA6B,CAAC;IAClE,OAAO,MAAM,eAAgB,SAAQ,aAAkB;QACrD,+CAA+C;QAC/C,QAAQ,GAAyB,IAAI,CAAC;QAEtC,KAAK,CAAC,IAAI,CAAC,QAAkB,EAAE,OAAgB;YAC7C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAA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CAAC,QAAQ,CAAC;YACtB,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACrB,yFAAyF;gBACzF,kEAAkE;gBAClE,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QAED,mFAAmF;QACnF,KAAK,CAAC,OAAO,CAAC,SAAiB;YAC7B,MAAM,EAAE,GAAG,SAAS,GAAG,QAAQ,CAAC;YAChC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACnD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,GAAG,EAAE;gBAAE,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -51,6 +51,14 @@ export interface ScopeDoEnv {
51
51
  SUBSTRAT_VERTICAL?: string;
52
52
  /** #3316: `live` on the serving script, `preview` on a version's own script, as the upload says. */
53
53
  SUBSTRAT_SCRIPT_KIND?: string;
54
+ /**
55
+ * K-69: the control plane's origin and the platform secret, injected into every pushed vertical.
56
+ * With both, a scope that commits work for the platform (a pending intent, an unshipped event)
57
+ * arms its alarm and asks for its own drain (`scope-wake.ts`). Without them nothing is armed: a
58
+ * self-host or a test worker leaves the work to its sweep, as before.
59
+ */
60
+ CONTROL_PLANE_URL?: string;
61
+ PLATFORM_SECRET?: string;
54
62
  }
55
63
  /** #2016: how a tenant reads against a scope's record (`ScopeDO.tenantVerdict`). */
56
64
  export type TenantVerdict = 'recorded' | 'inferred' | 'foreign' | 'unknown';
@@ -1 +1 @@
1
- {"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EA0DL,KAAK,QAAQ,EAmBd,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AAG,IAAI,CAAA;KAAE,EAAE,CAAC;IACvG,cAAc,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClG,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AA8lBjG,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAQxD;AAgQD;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AAmBtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAOxD;AAED,gHAAgH;AAChH,OAAO,EAAE,kBAAkB,EAAE,CAAC;AA2B9B,wBAAgB,aAAa,CAC3B,OAAO,EAAE,kBAAkB,EAAE,EAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACzD;;;;GAIG;AACH,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,mBAAmB,CAAA;CAAO,GAClD,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,KAAK,aAAa,CAAC,UAAU,CAAC,CAilS7E"}
package/dist/scope-do.js CHANGED
@@ -14,6 +14,7 @@ import { COPY_RESTORE_FENCE_LAPSED, copyRestoreFenceLapsed, orphanSweepVersionRe
14
14
  import { createDoTupleChecker, createLocalControlPlaneReader, scopeTupleReader } from './checker.js';
15
15
  import { settlePlatformRequestIn } from '@substrat-run/kernel';
16
16
  import { loadDropsRowsOf, SCOPE_COPY_LEASE_MS, ulidTime } from '@substrat-run/kernel';
17
+ import { SCOPE_WAKE_KEY, keepRegisteredMeanwhile, kickControlPlane, runWake, wakeAfterCommit, wakeDueAt } from './scope-wake.js';
17
18
  import { CARRIED_AWAY_KEY, COPY_MARK_CLEARED_KEY, KEPT_COPY_REFUSAL, KEPT_DIVERGENT_KEY, LOAD_STAMP_KEY, STORE_LOCAL_META_KEYS, WRITE_REVISION_KEY, carriedAwayDump, isCopyMarkInsert, isWriteStatement, assertSpineTablesBuilt, clearCopyMarker, dumpRowsInsert, isSpineTable, markCopyOrigin, repointScopeGrants, settleCopiedWork, emittedHere, IS_COPY_SQL, CLEAN_ROOM_COPY_SQL, isCopyLoad, isLifecycleWrite, readLifecycle, settleLifecycleAfterLoad, writeLifecycle, spineColumnAdditions } from '@substrat-run/kernel';
18
19
  import { GRANT_CHILDREN_INDEX_DDL, SHAPE_MARKER_INDEX_DDL, grantedEntitiesForContext } from '@substrat-run/kernel';
19
20
  /** A scope's migration journal: `module@version` → the SQL digest it recorded (#2066). */
@@ -2962,14 +2963,97 @@ options = {}) {
2962
2963
  }
2963
2964
  if (earliest === undefined)
2964
2965
  return;
2965
- const at = Date.parse(earliest);
2966
+ await this.armAlarmBy(Date.parse(earliest));
2967
+ }
2968
+ /** The one alarm, moved only earlier: every user of it arms through here (#938, K-69). */
2969
+ async armAlarmBy(at) {
2966
2970
  const current = await this.ctx.storage.getAlarm();
2967
2971
  if (current === null || current > at)
2968
2972
  await this.ctx.storage.setAlarm(at);
2969
2973
  }
2970
- /** The live reaper's alarm (#938): close what has expired, then arm for what is next. */
2974
+ /**
2975
+ * The scope's alarm, shared by its two users: the live reaper (#938) closes what has expired, and
2976
+ * the scope's wake (K-69, `scope-wake.ts`) asks for the drains its pending work is waiting on.
2977
+ * Each re-arms for what it has next, earliest wins.
2978
+ */
2971
2979
  async alarm() {
2972
2980
  await this.armLiveExpiry();
2981
+ await this.runScopeWake();
2982
+ }
2983
+ /** K-69: a scope with the control plane's origin and secret asks for its own drains. */
2984
+ wakeTransport() {
2985
+ const url = this.env.CONTROL_PLANE_URL;
2986
+ const secret = this.env.PLATFORM_SECRET;
2987
+ return url && secret ? { controlPlaneUrl: url, secret } : null;
2988
+ }
2989
+ /**
2990
+ * K-69: what a commit left for the platform, read by index (`CommitWork`): the newest intent by
2991
+ * primary key, and whether an emitted event waits unshipped, by `_substrat_outbox_drained`.
2992
+ */
2993
+ commitWork() {
2994
+ const newest = this.sql
2995
+ .exec('SELECT id FROM _substrat_platform_requests ORDER BY id DESC LIMIT 1')
2996
+ .toArray()[0];
2997
+ const undrained = this.sql
2998
+ .exec(`SELECT 1 AS one FROM _substrat_outbox WHERE drained_at IS NULL AND ${emittedHere()} LIMIT 1`)
2999
+ .toArray();
3000
+ return { newestIntent: newest?.id ?? null, undrainedEvents: undrained.length > 0 };
3001
+ }
3002
+ /** K-69: at the alarm, also whether any intent is still pending — the drain's own listing scans the same rows. */
3003
+ wakeWork() {
3004
+ const pending = this.sql
3005
+ .exec(`SELECT 1 AS one FROM _substrat_platform_requests WHERE status = 'pending' LIMIT 1`)
3006
+ .toArray();
3007
+ return { ...this.commitWork(), pendingIntents: pending.length > 0 };
3008
+ }
3009
+ /**
3010
+ * K-69: after a commit, arm the scope's wake for the work it left. Never fails the commit it
3011
+ * follows: a wake not armed costs latency, and the pass (or its check) is the backstop.
3012
+ */
3013
+ async noteScopeWake(tenantId, scopeId) {
3014
+ if (!this.wakeTransport())
3015
+ return;
3016
+ try {
3017
+ const prior = (await this.ctx.storage.get(SCOPE_WAKE_KEY)) ?? null;
3018
+ const next = wakeAfterCommit(prior, { tenantId, scopeId }, this.commitWork(), Date.now());
3019
+ if (!next)
3020
+ return;
3021
+ await this.ctx.storage.put(SCOPE_WAKE_KEY, next);
3022
+ const at = wakeDueAt(next);
3023
+ if (at !== null)
3024
+ await this.armAlarmBy(at);
3025
+ }
3026
+ catch (err) {
3027
+ console.error('substrat: scope wake not armed after commit; the pass is the backstop', err);
3028
+ }
3029
+ }
3030
+ /** K-69: the wake's half of the alarm. Never throws: a thrown alarm is retried by the runtime. */
3031
+ async runScopeWake() {
3032
+ const transport = this.wakeTransport();
3033
+ try {
3034
+ const state = (await this.ctx.storage.get(SCOPE_WAKE_KEY)) ?? null;
3035
+ if (!state)
3036
+ return;
3037
+ if (!transport) {
3038
+ // The binding went away (a re-upload without it): nothing can be asked, so nothing is kept.
3039
+ await this.ctx.storage.delete(SCOPE_WAKE_KEY);
3040
+ return;
3041
+ }
3042
+ const ran = await runWake(state, Date.now(), () => this.wakeWork(), (body) => kickControlPlane(transport, body));
3043
+ // The object took other calls while the kick was out: keep what a commit stored meanwhile.
3044
+ const next = keepRegisteredMeanwhile(state, ran, (await this.ctx.storage.get(SCOPE_WAKE_KEY)) ?? null);
3045
+ if (!next) {
3046
+ await this.ctx.storage.delete(SCOPE_WAKE_KEY);
3047
+ return;
3048
+ }
3049
+ await this.ctx.storage.put(SCOPE_WAKE_KEY, next);
3050
+ const at = wakeDueAt(next);
3051
+ if (at !== null)
3052
+ await this.armAlarmBy(at);
3053
+ }
3054
+ catch (err) {
3055
+ console.error('substrat: scope wake failed; the pass is the backstop', err);
3056
+ }
2973
3057
  }
2974
3058
  /** The context a live subscriber's checks run in: its own principal, under `live.subscribe`. */
2975
3059
  liveContext(subscriber) {
@@ -3085,6 +3169,8 @@ options = {}) {
3085
3169
  */
3086
3170
  invocationId) {
3087
3171
  await this.dispatch(tenantId, scopeId, invocationId);
3172
+ // K-69: after the consumers, whose own emits and intents count too.
3173
+ await this.noteScopeWake(tenantId, scopeId);
3088
3174
  if (liveSince === null)
3089
3175
  return;
3090
3176
  try {
@@ -5571,7 +5657,7 @@ options = {}) {
5571
5657
  * `invocationId` is LAST, and defaulted, for the RPC-skew reason `recordExecutorAttempt`
5572
5658
  * states at length.
5573
5659
  */
5574
- routeExecutorEventToPlatform(eventId, deliveryId, kind, payload, requestedBy,
5660
+ async routeExecutorEventToPlatform(eventId, deliveryId, kind, payload, requestedBy,
5575
5661
  /**
5576
5662
  * #1525: the call this routing ran in, or null. On the hosted path this is the
5577
5663
  * dominant executor journal — every vertical is CP-less, so a connector delivery
@@ -5589,12 +5675,17 @@ options = {}) {
5589
5675
  // caused an outbound effect. Read here rather than passed over the RPC: the DO
5590
5676
  // owns the outbox, so a coordinator cannot claim a stamp or drop one.
5591
5677
  const source = this.sql
5592
- .exec('SELECT impersonation FROM _substrat_outbox WHERE id = ?', eventId)
5678
+ .exec('SELECT impersonation, tenant_id, scope_id FROM _substrat_outbox WHERE id = ?', eventId)
5593
5679
  .toArray()[0];
5594
5680
  this.sql.exec(`INSERT INTO _substrat_platform_requests
5595
5681
  (id, kind, payload, requested_by, impersonation, status, attempts, requested_at)
5596
5682
  VALUES (?, ?, ?, ?, ?, 'pending', 0, ?)`, id, kind, payload, requestedBy, source?.impersonation ?? null, instant.parse(new Date().toISOString()));
5597
5683
  this.recordExecutorAttempt(eventId, deliveryId, null, null, invocationId);
5684
+ // K-69: this intent is enqueued by the coordinator after the commit's own wake was armed, so
5685
+ // it arms one too, under the ids its source event carries. Both writes above are made before
5686
+ // this await, as one unit.
5687
+ if (source)
5688
+ await this.noteScopeWake(tenantIdOf.parse(source.tenant_id), scopeIdOf.parse(source.scope_id));
5598
5689
  return id;
5599
5690
  }
5600
5691
  /** #3365: the routed connector deliveries this scope holds pending — their own room. */