@listen-fire/engine 0.12.3 → 0.12.5

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.
@@ -16,7 +16,7 @@ export interface InboundSubscription {
16
16
  /** Existed before signed inbound became the rule for its provider: while it
17
17
  * holds no usable secret it is verified as its provider's door always did. */
18
18
  grandfatheredUnsigned: boolean;
19
- checkpoint: unknown;
19
+ checkpoint?: unknown;
20
20
  }
21
21
  /** How a subscription's deliveries are checked and read. */
22
22
  export interface InboundSource {
@@ -80,7 +80,7 @@ export interface ParkSink {
80
80
  frameAddress: string;
81
81
  branchAddress: string;
82
82
  branchIndex: number;
83
- exports: unknown;
83
+ exports?: unknown;
84
84
  }): Promise<void>;
85
85
  /** Collect all branches' persisted exports for a frame, ordered by branchIndex (§12.4). */
86
86
  collectBranchExports(input: {
@@ -88,7 +88,7 @@ export interface ParkSink {
88
88
  }): Promise<Array<{
89
89
  branchAddress: string;
90
90
  branchIndex: number;
91
- exports: unknown;
91
+ exports?: unknown;
92
92
  }>>;
93
93
  /**
94
94
  * Cancel every park under the given subtree prefixes (asks-as-adapter chunk C
@@ -62,7 +62,7 @@ export interface DeliveryContractBackend {
62
62
  checkpoint(input: {
63
63
  subscriptionId: string;
64
64
  }): Promise<{
65
- checkpoint: unknown;
65
+ checkpoint?: unknown;
66
66
  } | null>;
67
67
  startRun(input: {
68
68
  id: string;
@@ -106,6 +106,34 @@ exports.runHostContractCases = [
106
106
  await store.work.complete(claimed);
107
107
  },
108
108
  },
109
+ {
110
+ name: 'work: a key queued if absent is queued once; a row there, due later or leased, is left as it was',
111
+ async run({ store }) {
112
+ const key = uniqueKey('poll_listen');
113
+ strict_1.default.equal(await store.work.enqueueIfAbsent({ kind: 'poll_listen', key, payload: { n: 1 }, dueAt: FUTURE(10) }), true);
114
+ strict_1.default.equal(await store.work.enqueueIfAbsent({ kind: 'poll_listen', key, payload: { n: 2 }, dueAt: PAST(1) }), false);
115
+ strict_1.default.equal(await claimKey(store, key), undefined, 'still due later: the second arm moved nothing');
116
+ await store.work.enqueue({ kind: 'poll_listen', key, payload: { n: 3 }, dueAt: PAST(1) });
117
+ const held = await claimKey(store, key);
118
+ strict_1.default.deepEqual(held?.payload, { n: 3 });
119
+ strict_1.default.ok(held);
120
+ // Another worker arms the same listen while the row is held: nothing changes,
121
+ // so the holder's release decides when it is next due.
122
+ strict_1.default.equal(await store.work.enqueueIfAbsent({ kind: 'poll_listen', key, payload: { n: 4 }, dueAt: PAST(1) }), false);
123
+ await store.work.release({ ...held, dueAt: FUTURE(30) });
124
+ strict_1.default.equal(await claimKey(store, key), undefined, 'due at the release time, not polled again at once');
125
+ const later = await store.work.claimDue({ limit: 1000, leaseMs: 60_000, dueBy: FUTURE(31) });
126
+ const again = later.find((w) => w.key === key);
127
+ strict_1.default.deepEqual(again?.payload, { n: 3 }, 'the payload the row had');
128
+ for (const w of later)
129
+ if (w.key === key)
130
+ await store.work.complete(w);
131
+ strict_1.default.equal(await store.work.enqueueIfAbsent({ kind: 'poll_listen', key, payload: { n: 5 }, dueAt: PAST(1) }), true, 'completed and gone, it is queued again');
132
+ const last = await claimKey(store, key);
133
+ if (last)
134
+ await store.work.complete(last);
135
+ },
136
+ },
109
137
  {
110
138
  name: 'work: only due, unleased rows are claimed; a live lease blocks a second claim',
111
139
  async run({ store }) {
@@ -200,6 +200,12 @@ function memoryRunHostStore(options = {}) {
200
200
  row.teamId = teamId;
201
201
  row.armed += 1;
202
202
  },
203
+ async enqueueIfAbsent({ kind, key, payload, dueAt, teamId }) {
204
+ if (work.has(key))
205
+ return false;
206
+ work.set(key, { id: (0, node_crypto_1.randomUUID)(), kind, key, payload: stored(payload), dueAt: dueAt !== undefined ? Date.parse(dueAt) : now(), teamId, claim: undefined, leasedUntil: 0, armed: 0, armedAtClaim: 0 });
207
+ return true;
208
+ },
203
209
  async claimDue({ limit, leaseMs, dueBy, kinds }) {
204
210
  const by = dueBy !== undefined ? Date.parse(dueBy) : now();
205
211
  const claimed = [];
@@ -106,7 +106,7 @@ export declare class RpcStoreBackend {
106
106
  checkpoint(input: {
107
107
  subscriptionId: string;
108
108
  }): Promise<{
109
- checkpoint: unknown;
109
+ checkpoint?: unknown;
110
110
  } | null>;
111
111
  /** An operator asks to cancel the run (the records contract's `requestCancel`). */
112
112
  requestCancel(input: {
@@ -26,16 +26,16 @@ const Leaf = zod_1.z.object({
26
26
  status: zod_1.z.enum(['parked', 'resuming']),
27
27
  wakeAt: zod_1.z.string().nullable(),
28
28
  });
29
- const Claimed = zod_1.z.object({ reason: zod_1.z.string(), state: zod_1.z.unknown() }).nullable();
29
+ const Claimed = zod_1.z.object({ reason: zod_1.z.string(), state: zod_1.z.unknown().optional() }).nullable();
30
30
  const Correlated = zod_1.z.object({ runId: zod_1.z.string(), teamId: zod_1.z.string(), address: zod_1.z.string() });
31
- const Work = zod_1.z.object({ id: zod_1.z.string(), kind: zod_1.z.string(), key: zod_1.z.string(), payload: zod_1.z.unknown(), claim: zod_1.z.string() });
31
+ const Work = zod_1.z.object({ id: zod_1.z.string(), kind: zod_1.z.string(), key: zod_1.z.string(), payload: zod_1.z.unknown().optional(), claim: zod_1.z.string() });
32
32
  const Callback = zod_1.z.object({
33
33
  id: zod_1.z.string(),
34
34
  teamId: zod_1.z.string(),
35
35
  runId: zod_1.z.string(),
36
36
  address: zod_1.z.string(),
37
37
  params: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), type: zod_1.z.enum(engine_contracts_1.CALLBACK_PARAM_TYPES) })),
38
- state: zod_1.z.unknown(),
38
+ state: zod_1.z.unknown().optional(),
39
39
  calls: zod_1.z.array(zod_1.z.object({ at: zod_1.z.string(), values: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()), bodyStartedAt: zod_1.z.string().optional() })),
40
40
  singleUse: zod_1.z.boolean(),
41
41
  expiresAt: zod_1.z.string().nullable(),
@@ -145,7 +145,7 @@ class RpcStoreBackend {
145
145
  }
146
146
  /** A subscription's saved pull cursor (`inbound.checkpoint`). */
147
147
  checkpoint(input) {
148
- return this.call('inbound.checkpoint', input, zod_1.z.object({ checkpoint: zod_1.z.unknown() }).nullable());
148
+ return this.call('inbound.checkpoint', input, zod_1.z.object({ checkpoint: zod_1.z.unknown().optional() }).nullable());
149
149
  }
150
150
  /** An operator asks to cancel the run (the records contract's `requestCancel`). */
151
151
  async requestCancel(input) {
@@ -213,7 +213,7 @@ class RpcStoreBackend {
213
213
  persistBranchExport: async (input) => {
214
214
  await call('joins.persistBranchExport', input, Nothing);
215
215
  },
216
- collectBranchExports: (input) => call('joins.collectBranchExports', input, zod_1.z.array(zod_1.z.object({ branchAddress: zod_1.z.string(), branchIndex: zod_1.z.number(), exports: zod_1.z.unknown() }))),
216
+ collectBranchExports: (input) => call('joins.collectBranchExports', input, zod_1.z.array(zod_1.z.object({ branchAddress: zod_1.z.string(), branchIndex: zod_1.z.number(), exports: zod_1.z.unknown().optional() }))),
217
217
  hasPendingJoins: (input) => call('joins.hasPendingJoins', input, zod_1.z.boolean()),
218
218
  frames: (input) => call('joins.frames', input, zod_1.z.array(zod_1.z.string())),
219
219
  deleteFrames: async (input) => {
@@ -245,6 +245,7 @@ class RpcStoreBackend {
245
245
  enqueue: async (input) => {
246
246
  await call('work.enqueue', input, Nothing);
247
247
  },
248
+ enqueueIfAbsent: (input) => call('work.enqueueIfAbsent', input, zod_1.z.boolean()),
248
249
  claimDue: (input) => call('work.claimDue', input, zod_1.z.array(Work)),
249
250
  complete: async (work) => {
250
251
  await call('work.complete', claimOf(work), Nothing);
@@ -23,7 +23,7 @@ export interface ParkStore {
23
23
  address: string;
24
24
  reason: CoreParkReason;
25
25
  wakeAt: string | null;
26
- state: unknown;
26
+ state?: unknown;
27
27
  rewritten?: boolean;
28
28
  fence?: string;
29
29
  }): Promise<void>;
@@ -34,7 +34,7 @@ export interface ParkStore {
34
34
  address: string;
35
35
  reason?: ParkReason;
36
36
  }): Promise<{
37
- state: unknown;
37
+ state?: unknown;
38
38
  reason: ParkReason;
39
39
  } | null>;
40
40
  /** The claimed leaf is done with: delete it unless its step parked it again
@@ -93,7 +93,7 @@ export interface JoinStore {
93
93
  }): Promise<Array<{
94
94
  branchAddress: string;
95
95
  branchIndex: number;
96
- exports: unknown;
96
+ exports?: unknown;
97
97
  }>>;
98
98
  /** Whether any join of the run still waits on a branch (a closed frame does not). */
99
99
  hasPendingJoins(input: {
@@ -200,7 +200,7 @@ export interface ClaimedWork {
200
200
  id: string;
201
201
  kind: string;
202
202
  key: string;
203
- payload: unknown;
203
+ payload?: unknown;
204
204
  claim: string;
205
205
  }
206
206
  export interface WorkQueue {
@@ -214,6 +214,17 @@ export interface WorkQueue {
214
214
  dueAt?: string;
215
215
  teamId?: string;
216
216
  }): Promise<void>;
217
+ /** Insert when no row has the key, in one write; a row there in any state
218
+ * (due, leased, buried) is left as it is. Whether it was queued: arming a
219
+ * listen's standing row from several workers queues it once, and never
220
+ * moves the due time of a row another worker holds. */
221
+ enqueueIfAbsent(input: {
222
+ kind: string;
223
+ key: string;
224
+ payload: unknown;
225
+ dueAt?: string;
226
+ teamId?: string;
227
+ }): Promise<boolean>;
217
228
  /** Lease up to `limit` rows due by `dueBy`, unleased or with a lapsed lease;
218
229
  * only rows of `kinds` when it is given (a drain pool's), else every kind. */
219
230
  claimDue(input: {
@@ -283,7 +294,7 @@ export interface CallbackRecord {
283
294
  * call's body resumes. */
284
295
  address: string;
285
296
  params: CallbackParamSpec[];
286
- state: unknown;
297
+ state?: unknown;
287
298
  calls: LedgerCall[];
288
299
  singleUse: boolean;
289
300
  /** When it stops taking calls (ISO 8601); null for never. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@listen-fire/engine",
3
3
  "license": "Apache-2.0",
4
- "version": "0.12.3",
4
+ "version": "0.12.5",
5
5
  "description": "The movement engine for this release's language and its host contract: the Rust engine's shim, the EngineHost families, the run host, the embed kit, and the adapter and model types they reach. Every shell (the hosted product, the `lf` command line, an embedder) runs the same engine. A run pinned to a release this one does not read is refused by name. Embedders reach it only through public/* (the exports map); the internals resolve only under the `movement-engine-internals` condition, which only test runners set",
6
6
  "engines": {
7
7
  "node": ">=22.23.4 <23"
@@ -17,9 +17,9 @@
17
17
  "dependencies": {
18
18
  "safe-stable-stringify": "2.5.0",
19
19
  "zod": "4.1.12",
20
- "@listen-fire/module-runtime": "^0.12.3",
21
- "@listen-fire/engine-contracts": "^0.12.3",
22
- "@listen-fire/movement-lang": "^0.12.3"
20
+ "@listen-fire/module-runtime": "^0.12.5",
21
+ "@listen-fire/engine-contracts": "^0.12.5",
22
+ "@listen-fire/movement-lang": "^0.12.5"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/jest": "29.5.14",