@oona/vlo 0.0.0-stage → 0.1.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.
@@ -0,0 +1,746 @@
1
+ /** The run row as the kernel needs it to prepare or reduce an event. */
2
+ interface RunRef {
3
+ /** Run id. */
4
+ run_id: string;
5
+ /** Workflow name. */
6
+ workflow: string;
7
+ /** Digest of the workflow the run pinned when it started. */
8
+ bundle_digest: string;
9
+ /** Current run status. */
10
+ status: RunStatus;
11
+ /** Sequence number of the last journaled event; `0` before `started`. */
12
+ last_seq: number;
13
+ /** Parent run, for a child run. */
14
+ parent_run_id?: string;
15
+ /** The parent's `spawn` step, for a child run. */
16
+ parent_step_id?: string;
17
+ }
18
+ /** Columns of the run row the transition updates. */
19
+ interface RunPatch {
20
+ /** Run status after the event. */
21
+ status: RunStatus;
22
+ /** Sequence number of the event just applied. */
23
+ last_seq: number;
24
+ }
25
+ /** A task row to insert: the outbox entry a worker will receive. */
26
+ interface NewTask {
27
+ /** Deterministic task id, derived from run, step and attempt. */
28
+ task_id: string;
29
+ /** Step id inside the run. */
30
+ step_id: string;
31
+ /** Attempt number, starting at 1. */
32
+ attempt: number;
33
+ /** Activity name. */
34
+ activity: string;
35
+ /** Queue the task is pushed to or polled from. */
36
+ queue: string;
37
+ /** Schema reference for input validation, when the activity declares one. */
38
+ schema_ref?: string;
39
+ /** Task input. */
40
+ input: Json;
41
+ /** Idempotency key the worker echoes so a duplicate push is harmless. */
42
+ idempotency_key: string;
43
+ /** Retry policy the host applies on failure. */
44
+ retry: RetryPolicy;
45
+ /** Lease duration in milliseconds; the reaper reclaims a task past it. */
46
+ lease_ttl_ms: number;
47
+ /** Execution timeout in milliseconds; absent means no timeout. */
48
+ timeout_ms?: number;
49
+ }
50
+ /** A status change on an existing task row. */
51
+ interface TaskUpdate {
52
+ /** Task id. */
53
+ task_id: string;
54
+ /** Attempt the update applies to. */
55
+ attempt: number;
56
+ /** New task status. */
57
+ status: Status;
58
+ /** Earliest time in milliseconds the task may run again; set on a retry. */
59
+ not_before_ms?: number;
60
+ }
61
+ /** A timer row to insert. */
62
+ interface NewTimer {
63
+ /** Step id inside the run. */
64
+ step_id: string;
65
+ /** When the timer fires, in milliseconds since the epoch. */
66
+ fire_at_ms: number;
67
+ }
68
+ /** A child run to start. */
69
+ interface NewSpawn {
70
+ /** The parent's step id. */
71
+ step_id: string;
72
+ /** Deterministic id of the child run. */
73
+ child_run_id: string;
74
+ /** Workflow the child runs. */
75
+ workflow: string;
76
+ /** The child's start input. */
77
+ input: Json;
78
+ }
79
+ /** A signal wait row to insert: the run is parked until a signal with this name arrives. */
80
+ interface SignalWait {
81
+ /** Step id inside the run. */
82
+ step_id: string;
83
+ /** Signal name. */
84
+ name: string;
85
+ /** Schema reference for payload validation, when the signal declares one. */
86
+ schema_ref?: string;
87
+ /** Deadline in milliseconds since the epoch; absent means wait forever. */
88
+ expires_at_ms?: number;
89
+ }
90
+ /** A side-channel emission; delivered in memory, never journaled. */
91
+ interface Emit {
92
+ /** Channel name. */
93
+ channel: string;
94
+ /** Payload. */
95
+ data: Json;
96
+ }
97
+ /** The run's terminal outcome, present when the event closed the run. */
98
+ interface Completion {
99
+ /** Terminal status. */
100
+ status: RunStatus;
101
+ /** Output, when the run completed. */
102
+ output?: Json;
103
+ }
104
+ /** The write-set. Journals apply it atomically and never interpret commands. */
105
+ interface Transition {
106
+ /** Run row patch. */
107
+ run: RunPatch;
108
+ /** Kernel state after the event. */
109
+ kernel_state: KernelState;
110
+ /** User state after the event, byte-exact JSON. */
111
+ state: string;
112
+ /** Hash of kernel state plus user state. */
113
+ state_hash: string;
114
+ /** Whether `state` is stored inline or offloaded to the blob store. */
115
+ state_inline: boolean;
116
+ /** Events to append: the triggering event plus any markers. */
117
+ events: Envelope[];
118
+ /** Tasks to insert. */
119
+ tasks: NewTask[];
120
+ /** Task rows to update. */
121
+ task_updates: TaskUpdate[];
122
+ /** Timers to insert. */
123
+ timers: NewTimer[];
124
+ /** Child runs to start. */
125
+ spawns: NewSpawn[];
126
+ /** Signal waits to open. */
127
+ signal_waits: SignalWait[];
128
+ /** Side-channel emissions. */
129
+ emits: Emit[];
130
+ /** Present when the run reached a terminal status. */
131
+ completion?: Completion;
132
+ /** Present when the run continued as new; carries the successor's input. */
133
+ continue_as_new?: {
134
+ input: Json;
135
+ };
136
+ }
137
+ type Kind = "task" | "timer" | "signal" | "child" | "marker";
138
+ /**
139
+ * Status of one step (a task, timer, signal wait or child), as carried on every event.
140
+ * `scheduled` → `running` → `succeeded` | `failed` | `retrying` | `cancelled`;
141
+ * `awaiting_signal` is a parked wait. `succeeded`, `failed` and `cancelled` are terminal.
142
+ */
143
+ type Status = "scheduled" | "running" | "succeeded" | "failed" | "retrying" | "cancelled" | "awaiting_signal";
144
+ /**
145
+ * Why a step or run failed. `timeout`: the attempt ran past `timeout_ms`; `heartbeat_lost`:
146
+ * the lease expired; `app_error`: the handler or reducer threw; `user_cancel`: cancelled
147
+ * through the API; `schema_violation`: a worker's output failed the output schema;
148
+ * `nondeterminism_detected`: a re-fold diverged from the journal. The last three never retry.
149
+ */
150
+ type Cause = "timeout" | "heartbeat_lost" | "app_error" | "user_cancel" | "schema_violation" | "nondeterminism_detected";
151
+ /**
152
+ * Status of a run. `created` until `started` is folded, then `running` or
153
+ * `awaiting_signal`; `completed`, `failed`, `cancelled` and `continued` are terminal.
154
+ */
155
+ type RunStatus = "created" | "running" | "awaiting_signal" | "completed" | "failed" | "cancelled" | "continued";
156
+ /**
157
+ * Resources an attempt consumed, as banked by the kernel. Integers only, never negative:
158
+ * the total is hashed into the kernel state.
159
+ */
160
+ interface Usage {
161
+ /** CPU time in milliseconds. */
162
+ cpu_ms: number;
163
+ /** Model tokens, prompt and completion together. */
164
+ tokens: number;
165
+ /** Cost in millionths of a US dollar. */
166
+ cost_micro_usd: number;
167
+ }
168
+ /** Any JSON value. Inputs, outputs, payloads and workflow state are all `Json` on the wire. */
169
+ type Json = null | boolean | number | string | Json[] | {
170
+ [key: string]: Json;
171
+ };
172
+ /** An event as the host submits it, before `seq` and `state_hash` are assigned. */
173
+ interface EventInput {
174
+ run_id: string;
175
+ step_id: string;
176
+ attempt: number;
177
+ kind: Kind;
178
+ status: Status;
179
+ cause?: Cause;
180
+ usage?: Usage;
181
+ ts_ms: number;
182
+ /** 32 hex chars of host-generated randomness, journaled. */
183
+ random: string;
184
+ schema_ref?: string;
185
+ /** Inline JSON payload, byte-exact. Exactly one of payload / payload_ref. */
186
+ payload?: string;
187
+ payload_ref?: string;
188
+ error?: string;
189
+ }
190
+ /** A journaled event. */
191
+ interface Envelope extends EventInput {
192
+ seq: number;
193
+ parent_run_id?: string;
194
+ parent_step_id?: string;
195
+ state_hash: string;
196
+ }
197
+ /** `fixed` repeats `initial_ms`; `exponential` multiplies it by `factor` per attempt. */
198
+ type Backoff = "fixed" | "exponential";
199
+ /** `full` scales each delay by a journaled random fraction in [0, 1); `none` leaves it. */
200
+ type Jitter = "none" | "full";
201
+ /**
202
+ * Wire form of a retry policy; the authoring form is `RetryOptions`. The delay before
203
+ * attempt `n + 1` is `initial_ms` (fixed) or `initial_ms · factor^(n − 1)` (exponential),
204
+ * capped at `max_ms`, then jittered. Retrying stops at `max_attempts` or on a cause that
205
+ * never retries.
206
+ */
207
+ interface RetryPolicy {
208
+ /** Attempts in total, the first one included. */
209
+ max_attempts: number;
210
+ /** Delay growth strategy. */
211
+ backoff: Backoff;
212
+ /** Delay before the second attempt, in milliseconds. */
213
+ initial_ms: number;
214
+ /** Ceiling on any single delay, in milliseconds. */
215
+ max_ms: number;
216
+ /** Growth multiplier for exponential backoff; ≤ 1 behaves like fixed. */
217
+ factor: number;
218
+ /** Jitter applied to every delay. */
219
+ jitter: Jitter;
220
+ }
221
+ /**
222
+ * A command as a reducer returns it and the kernel validates it. Build them with `cmd.*`.
223
+ * `task`, `timer`, `spawn` and `await_signal` open a step and take an optional step `id`
224
+ * (default: kernel-derived, `${type}#${step_no}`); `complete` and `continue_as_new` must be last.
225
+ */
226
+ type Command = {
227
+ /** Run an activity. */
228
+ type: "task";
229
+ /** Activity name. */
230
+ activity: string;
231
+ /** `name@hash` of the activity, recorded on the step's events. */
232
+ schema_ref?: string;
233
+ /** Validated task input. */
234
+ input: Json;
235
+ /** Queue to dispatch on. Default `"default"`. */
236
+ queue?: string;
237
+ /** Retry policy. Default: the kernel's own. */
238
+ retry?: RetryPolicy;
239
+ /** Lease per attempt, in milliseconds. Default: the kernel's own. */
240
+ lease_ttl_ms?: number;
241
+ /** Wall-clock budget for one attempt: the worker aborts at it, the host reaps past it. */
242
+ timeout_ms?: number;
243
+ /** Explicit step id. */
244
+ id?: string;
245
+ } | {
246
+ /** Fire a `timer` event. Exactly one of `fire_in_ms` / `fire_at_ms`. */
247
+ type: "timer";
248
+ /** Delay from the reduced event's `ts_ms`, in milliseconds. */
249
+ fire_in_ms?: number;
250
+ /** Absolute epoch time, in milliseconds. */
251
+ fire_at_ms?: number;
252
+ /** Explicit step id. */
253
+ id?: string;
254
+ } | {
255
+ /** Start a child run. */
256
+ type: "spawn";
257
+ /** Workflow name. */
258
+ workflow: string;
259
+ /** The child's start input. */
260
+ input: Json;
261
+ /** Explicit step id. */
262
+ id?: string;
263
+ } | {
264
+ /** Park until a signal is delivered. */
265
+ type: "await_signal";
266
+ /** Signal name. */
267
+ name: string;
268
+ /** `name@hash` of the signal. */
269
+ schema_ref?: string;
270
+ /** Recorded as the wait's `expires_at_ms`; not enforced by the host. */
271
+ timeout_ms?: number;
272
+ /** Explicit step id. */
273
+ id?: string;
274
+ } | {
275
+ /** Publish on a side channel; never journaled. */
276
+ type: "emit";
277
+ /** Channel name. */
278
+ channel: string;
279
+ /** The payload. */
280
+ data: Json;
281
+ } | {
282
+ /** Close the run as `completed`. */
283
+ type: "complete";
284
+ /** The run's output. */
285
+ output: Json;
286
+ } | {
287
+ /** Close the run as `continued`. */
288
+ type: "continue_as_new";
289
+ /** Start input for the successor run. */
290
+ input: Json;
291
+ };
292
+ interface Reduction {
293
+ /** User state, byte-exact JSON. */
294
+ state: string;
295
+ commands: Command[];
296
+ }
297
+ interface StepState {
298
+ kind: Kind;
299
+ status: Status;
300
+ attempt: number;
301
+ activity?: string;
302
+ queue?: string;
303
+ retry?: RetryPolicy;
304
+ child_run_id?: string;
305
+ signal?: string;
306
+ fire_at_ms?: number;
307
+ }
308
+ interface KernelState {
309
+ v: number;
310
+ status: RunStatus;
311
+ step_no: number;
312
+ steps: Record<string, StepState>;
313
+ closed_steps: number;
314
+ usage_total: Usage;
315
+ }
316
+ /**
317
+ * `usage_total` rides on every variant: the run's banked total *including* this event, so a
318
+ * reducer can decide on a budget without keeping its own tally.
319
+ */
320
+ type ReducerEvent = {
321
+ /** The run's first event. */
322
+ type: "started";
323
+ /** Journaled event time, epoch milliseconds — the reducer's only clock. */
324
+ ts_ms: number;
325
+ /** 32 hex chars of journaled randomness — the reducer's only entropy. */
326
+ random: string;
327
+ /** The start input, as given to `init`. */
328
+ input: Json;
329
+ /** The run's banked usage including this event. */
330
+ usage_total: Usage;
331
+ } | {
332
+ /** A task reached a terminal status. */
333
+ type: "task_done";
334
+ /** Journaled event time, epoch milliseconds. */
335
+ ts_ms: number;
336
+ /** 32 hex chars of journaled randomness. */
337
+ random: string;
338
+ /** Step id of the task. */
339
+ step_id: string;
340
+ /** The attempt that produced this result. */
341
+ attempt: number;
342
+ /** Activity name. */
343
+ activity: string;
344
+ /** `succeeded`, `failed` or `cancelled`. */
345
+ status: Status;
346
+ /** Validated output; present when `succeeded`. */
347
+ output?: Json;
348
+ /** Why it did not succeed. */
349
+ cause?: Cause;
350
+ /** Error message from the worker or host. */
351
+ error?: string;
352
+ /** What this attempt itself consumed; zeroed when the worker reported none. */
353
+ usage: Usage;
354
+ /** The run's banked usage including this event. */
355
+ usage_total: Usage;
356
+ } | {
357
+ /** A signal the run was waiting on was delivered. */
358
+ type: "signal";
359
+ /** Journaled event time, epoch milliseconds. */
360
+ ts_ms: number;
361
+ /** 32 hex chars of journaled randomness. */
362
+ random: string;
363
+ /** Step id of the wait. */
364
+ step_id: string;
365
+ /** Signal name. */
366
+ name: string;
367
+ /** Validated payload. */
368
+ payload: Json;
369
+ /** The run's banked usage including this event. */
370
+ usage_total: Usage;
371
+ } | {
372
+ /** A timer fired. */
373
+ type: "timer";
374
+ /** Journaled event time, epoch milliseconds. */
375
+ ts_ms: number;
376
+ /** 32 hex chars of journaled randomness. */
377
+ random: string;
378
+ /** Step id of the timer. */
379
+ step_id: string;
380
+ /** The run's banked usage including this event. */
381
+ usage_total: Usage;
382
+ } | {
383
+ /** A child run closed. */
384
+ type: "child_done";
385
+ /** Journaled event time, epoch milliseconds. */
386
+ ts_ms: number;
387
+ /** 32 hex chars of journaled randomness. */
388
+ random: string;
389
+ /** Step id of the spawn. */
390
+ step_id: string;
391
+ /** The child's run id. */
392
+ child_run_id: string;
393
+ /** `succeeded`, `failed` or `cancelled`, mapped from the child's run status. */
394
+ status: Status;
395
+ /** The child's output; present when it completed. */
396
+ output?: Json;
397
+ /** The run's banked usage including this event. */
398
+ usage_total: Usage;
399
+ };
400
+ /** One row of `runs`. */
401
+ interface RunRow {
402
+ /** Primary key. */
403
+ run_id: string;
404
+ /** Namespace the run was created in. */
405
+ namespace: string;
406
+ /** Workflow name. */
407
+ workflow: string;
408
+ /** Digest of the workflow bundle the run was started with; a checkpoint from another digest is rebuilt. */
409
+ component_digest: string;
410
+ /** Current status. */
411
+ status: RunStatus;
412
+ /** Seq of the last journaled event; 0 before `started`. */
413
+ last_seq: number;
414
+ /** Parent run, for a spawned child. */
415
+ parent_run_id?: string;
416
+ /** The parent's step that spawned this run. */
417
+ parent_step_id?: string;
418
+ /** The run this one continued from (`continue_as_new`). */
419
+ continued_from?: string;
420
+ /** The successor run a `continued` run handed its input to; set with the `continue` marker. */
421
+ continued_to?: string;
422
+ /** Inline start input, byte-exact JSON. */
423
+ input?: string;
424
+ /** Blob reference for an offloaded start input. */
425
+ input_ref?: string;
426
+ /** Inline completion output, byte-exact JSON. */
427
+ output?: string;
428
+ /** Blob reference for an offloaded completion output. */
429
+ output_ref?: string;
430
+ /** Caller-supplied search attributes. */
431
+ search: Record<string, Json>;
432
+ /** Free-form assignee, for human-facing queues. Unused by the host. */
433
+ assignee?: string;
434
+ /** Row creation, epoch milliseconds. */
435
+ created_at_ms: number;
436
+ /** Last change, epoch milliseconds. */
437
+ updated_at_ms: number;
438
+ /** When the `started` event was folded, epoch milliseconds. */
439
+ started_at_ms?: number;
440
+ /** When the run reached a terminal status, epoch milliseconds. */
441
+ closed_at_ms?: number;
442
+ /** When the parent received this child's `child` event, epoch milliseconds. */
443
+ parent_notified_at_ms?: number;
444
+ /** Outbox claim held by the "start runs" stage. */
445
+ start_claimed_until_ms?: number;
446
+ /** Outbox claim held by the "notify parents" stage. */
447
+ notify_claimed_until_ms?: number;
448
+ }
449
+ /** The checkpoint: rewritten on every transition, in the transition's own transaction. */
450
+ interface StateRow {
451
+ /** The run this checkpoint belongs to; one row per run. */
452
+ run_id: string;
453
+ /** Seq of the last event folded into it. */
454
+ seq: number;
455
+ /** Digest of the bundle that produced it. */
456
+ bundle_digest: string;
457
+ /** Kernel-owned state, byte-exact JSON text. */
458
+ kernel_state: string;
459
+ /** User state, byte-exact JSON text. Exactly one of `state` / `state_ref`. */
460
+ state?: string;
461
+ /** Blob reference for an offloaded user state. */
462
+ state_ref?: string;
463
+ /** Kernel hash of `(kernel_state, state)`; checked before every fold. */
464
+ state_hash: string;
465
+ }
466
+ /** One row of `tasks`: a scheduled activity attempt and its outbox and lease bookkeeping. */
467
+ interface TaskRow {
468
+ /** Primary key, derived by the kernel from `(run_id, step_id)`. */
469
+ task_id: string;
470
+ /** The run that scheduled it. */
471
+ run_id: string;
472
+ /** The workflow step. */
473
+ step_id: string;
474
+ /** Current attempt, starting at 1. */
475
+ attempt: number;
476
+ /** Activity name. */
477
+ activity: string;
478
+ /** Registered schema version the output is checked against. */
479
+ schema_ref?: string;
480
+ /** Queue the task is delivered on. */
481
+ queue: string;
482
+ /** Inline input, byte-exact JSON. */
483
+ input?: string;
484
+ /** Blob reference for an offloaded input. */
485
+ input_ref?: string;
486
+ /** Retry policy the kernel plans retries with. */
487
+ retry_policy: RetryPolicy;
488
+ /** Task status: `scheduled`, `running`, `retrying`, `succeeded`, `failed` or `cancelled`. */
489
+ status: Status;
490
+ /** Stable per attempt; the worker dedupes on it. */
491
+ idempotency_key: string;
492
+ /** Earliest dispatch time, epoch milliseconds; pushed back by retries and deferrals. */
493
+ not_before_ms: number;
494
+ /** When this attempt was handed to a worker, epoch milliseconds. */
495
+ dispatched_at_ms?: number;
496
+ /** Pushes tried for this attempt; drives the backoff. */
497
+ dispatch_attempts: number;
498
+ /** Outbox claim held by the push stage, epoch milliseconds. */
499
+ dispatch_claimed_until_ms?: number;
500
+ /** Lease length in milliseconds; a heartbeat extends the lease by this much. */
501
+ lease_ttl_ms: number;
502
+ /** Wall-clock budget for one attempt, measured from `dispatched_at_ms`. */
503
+ timeout_ms?: number;
504
+ /** When the current lease lapses, epoch milliseconds. */
505
+ lease_until_ms?: number;
506
+ /** Worker id recorded at dispatch. */
507
+ worker_id?: string;
508
+ /** Last heartbeat, epoch milliseconds. */
509
+ heartbeat_at_ms?: number;
510
+ /** Row creation, epoch milliseconds. */
511
+ created_at_ms: number;
512
+ /** Last change, epoch milliseconds. */
513
+ updated_at_ms: number;
514
+ }
515
+ /** One row of `timers`. Keyed by `(run_id, step_id)`. */
516
+ interface TimerRow {
517
+ /** The run that set it. */
518
+ run_id: string;
519
+ /** The workflow step. */
520
+ step_id: string;
521
+ /** When it is due, epoch milliseconds. */
522
+ fire_at_ms: number;
523
+ /** When it fired, epoch milliseconds; set exactly once. */
524
+ fired_at_ms?: number;
525
+ /** Outbox claim held by the fire-timers stage, epoch milliseconds. */
526
+ claimed_until_ms?: number;
527
+ }
528
+ /** One row of `signal_waits`: a step parked on a named signal. */
529
+ interface SignalWaitRow {
530
+ /** The waiting run. */
531
+ run_id: string;
532
+ /** The waiting step. */
533
+ step_id: string;
534
+ /** Signal name waited for. */
535
+ name: string;
536
+ /** Registered schema version of the signal. */
537
+ schema_ref?: string;
538
+ /** Wait deadline, epoch milliseconds. */
539
+ expires_at_ms?: number;
540
+ }
541
+ /** One row of `signals`: a delivered or buffered signal. */
542
+ interface SignalRow {
543
+ /** Primary key. */
544
+ signal_id: string;
545
+ /** The run it was sent to. */
546
+ run_id: string;
547
+ /** Signal name. */
548
+ name: string;
549
+ /** Inline payload, byte-exact JSON. */
550
+ payload?: string;
551
+ /** Blob reference for an offloaded payload. */
552
+ payload_ref?: string;
553
+ /** Free-form sender. Unused by the host. */
554
+ sender?: string;
555
+ /** Row creation, epoch milliseconds. */
556
+ created_at_ms: number;
557
+ /** When it was folded into the run, epoch milliseconds; absent while buffered. */
558
+ delivered_at_ms?: number;
559
+ /** The step it was delivered to. */
560
+ delivered_step_id?: string;
561
+ }
562
+ /** One row of `schemas`: an activity or signal definition, keyed by `(name, version)`. */
563
+ interface SchemaRow {
564
+ /** Activity or signal name. */
565
+ name: string;
566
+ /** Content hash of the definition. */
567
+ version: string;
568
+ /** JSON Schema text. */
569
+ json_schema: string;
570
+ /** Byte-exact JSON: it is part of the activity content hash. */
571
+ retry_policy?: string;
572
+ }
573
+ /** What `createRun` inserts; timestamps and counters are filled by the journal. */
574
+ interface NewRunRow {
575
+ /** Primary key. */
576
+ run_id: string;
577
+ /** Namespace. Default `"default"`. */
578
+ namespace?: string;
579
+ /** Workflow name. */
580
+ workflow: string;
581
+ /** Digest of the workflow bundle. */
582
+ component_digest: string;
583
+ /** Always `created`; the outbox starts the run. */
584
+ status: "created";
585
+ /** Parent run, for a spawned child. */
586
+ parent_run_id?: string;
587
+ /** The parent's spawning step. */
588
+ parent_step_id?: string;
589
+ /** The run this one continues from. */
590
+ continued_from?: string;
591
+ /** Inline start input, byte-exact JSON. */
592
+ input?: string;
593
+ /** Blob reference for an offloaded start input. */
594
+ input_ref?: string;
595
+ /** Caller-supplied search attributes. */
596
+ search?: Record<string, Json>;
597
+ }
598
+ /** What `putSignal` inserts. */
599
+ interface NewSignalRow {
600
+ /** Primary key. */
601
+ signal_id: string;
602
+ /** The run it is sent to. */
603
+ run_id: string;
604
+ /** Signal name. */
605
+ name: string;
606
+ /** Inline payload, byte-exact JSON. */
607
+ payload?: string;
608
+ /** Blob reference for an offloaded payload. */
609
+ payload_ref?: string;
610
+ /** Free-form sender. */
611
+ sender?: string;
612
+ }
613
+ /** Host-side decisions `applyTransition` needs on top of the kernel's write-set. */
614
+ interface ApplyTransitionOptions {
615
+ /** Timestamp for every row written, epoch milliseconds. */
616
+ nowMs: number;
617
+ /** Set when the user state was offloaded to the blob store; stores `state_ref`. */
618
+ stateRef?: string;
619
+ /** Set when the completion output was offloaded; stores `output_ref`. */
620
+ outputRef?: string;
621
+ /** Defaults to the run's `component_digest`. */
622
+ bundleDigest?: string;
623
+ /** Child runs the host derived from `transition.spawns`; journals never interpret commands. */
624
+ childRuns?: NewRunRow[];
625
+ /**
626
+ * The successor the host derived from `transition.continue_as_new`. Inserted as a `created`
627
+ * row and linked back by setting `continued_to` on the run being closed, in the same
628
+ * transaction.
629
+ */
630
+ successorRun?: NewRunRow;
631
+ }
632
+ /** Filters for `Journal.query`. All optional; every given field must match. */
633
+ interface RunQuery {
634
+ /** Namespace to list. */
635
+ namespace?: string;
636
+ /** Status to match. */
637
+ status?: RunStatus;
638
+ /** Workflow name to match. */
639
+ workflow?: string;
640
+ /** Maximum rows, newest first. */
641
+ limit?: number;
642
+ }
643
+ /**
644
+ * Which queues a task claim may take. `queue` is what a puller asks for; `excludeQueues`
645
+ * is what the push dispatcher leaves alone because pollers own those queues.
646
+ */
647
+ interface TaskClaimFilter {
648
+ /** Only this queue. */
649
+ queue?: string;
650
+ /** Every queue but these. */
651
+ excludeQueues?: readonly string[];
652
+ }
653
+ /** Reads outside a transaction, plus the transaction entry point. */
654
+ interface Journal {
655
+ /** Idempotent, safe to run from several processes at once. */
656
+ migrate(): Promise<void>;
657
+ /** Runs `fn` in one transaction: committed when it resolves, rolled back when it rejects. */
658
+ transaction<T>(fn: (tx: JournalTx) => Promise<T>): Promise<T>;
659
+ /** Events with `seq > sinceSeq`, ascending. */
660
+ readEvents(runId: string, sinceSeq?: number): Promise<Envelope[]>;
661
+ /** The run row, or null. */
662
+ getRun(runId: string): Promise<RunRow | null>;
663
+ /** The run's checkpoint, or null before its first fold. */
664
+ getState(runId: string): Promise<StateRow | null>;
665
+ /** The task row, or null. */
666
+ getTask(taskId: string): Promise<TaskRow | null>;
667
+ /** Every task of a run. */
668
+ listTasks(runId: string): Promise<TaskRow[]>;
669
+ /** Runs matching the query. */
670
+ query(q: RunQuery): Promise<RunRow[]>;
671
+ /** Unfired timers with `fire_at_ms <= nowMs`. Read-only; the dispatcher claims via `claimDueTimers`. */
672
+ dueTimers(nowMs: number, limit: number): Promise<TimerRow[]>;
673
+ /** Running attempts whose `lease_until_ms` has passed. */
674
+ expiredLeases(nowMs: number, limit: number): Promise<TaskRow[]>;
675
+ /**
676
+ * Running attempts past their `timeout_ms`. The backstop for a worker that never answers:
677
+ * the worker's own timer covers the case where it is alive enough to report.
678
+ */
679
+ expiredTimeouts(nowMs: number, limit: number): Promise<TaskRow[]>;
680
+ /** Releases the connection(s). Idempotent; every call afterwards throws {@link JournalClosed}. */
681
+ close(): Promise<void>;
682
+ }
683
+ /**
684
+ * Thrown by every journal call made after `close()`.
685
+ *
686
+ * Shutdown is inherently racy: a worker reporting a result, a stage finishing its pass. The
687
+ * contract is that those calls fail with this, one recognisable error, instead of whatever
688
+ * the driver does to a closed handle — `node:sqlite` raises `ERR_INVALID_STATE` from a
689
+ * finalized statement, which surfaces as a crash rather than as "the host is stopping".
690
+ */
691
+ declare class JournalClosed extends Error {
692
+ /** Always `journal_closed`. */
693
+ readonly code = "journal_closed";
694
+ /** `dialect` names the implementation, e.g. `sqlite` or `postgres`. */
695
+ constructor(dialect: string);
696
+ }
697
+ /** One transaction. Every method is serialised against the run it touches. */
698
+ interface JournalTx {
699
+ /** Takes the per-run write lock for the rest of the transaction, then reads the run. */
700
+ lockRun(runId: string): Promise<RunRow | null>;
701
+ /** Idempotent on `run_id`. */
702
+ createRun(row: NewRunRow, nowMs: number): Promise<void>;
703
+ /** The run's checkpoint, or null before its first fold. */
704
+ getState(runId: string): Promise<StateRow | null>;
705
+ /** Events with `seq > sinceSeq`, ascending. */
706
+ readEvents(runId: string, sinceSeq?: number): Promise<Envelope[]>;
707
+ /**
708
+ * Applies a kernel write-set atomically: events (seq taken from each envelope,
709
+ * with the `(run_id, seq)` primary key as the backstop), the checkpoint, new
710
+ * tasks, task updates, timers, signal waits, child runs, the successor run and the run row.
711
+ */
712
+ applyTransition(runId: string, t: Transition, opts: ApplyTransitionOptions): Promise<void>;
713
+ /** Claims schedulable, undispatched tasks for `holdMs`; concurrent claimers get disjoint sets. */
714
+ claimUndispatchedTasks(nowMs: number, limit: number, holdMs: number, filter?: TaskClaimFilter): Promise<TaskRow[]>;
715
+ /** False when the attempt moved on or the task is no longer scheduled. */
716
+ markDispatched(taskId: string, attempt: number, nowMs: number, leaseUntilMs: number, workerId?: string): Promise<boolean>;
717
+ /** Releases the dispatch claim and backs the task off to `notBeforeMs`. */
718
+ deferDispatch(taskId: string, attempt: number, notBeforeMs: number): Promise<void>;
719
+ /** False unless the task is running at that attempt. */
720
+ heartbeat(taskId: string, attempt: number, leaseUntilMs: number, nowMs: number): Promise<boolean>;
721
+ /** `created` runs not yet started, claimed for `holdMs`; concurrent claimers get disjoint sets. */
722
+ claimCreatedRuns(nowMs: number, limit: number, holdMs: number): Promise<RunRow[]>;
723
+ /** Closed child runs whose parent has not been told yet, claimed for `holdMs`. */
724
+ claimClosedUnnotified(nowMs: number, limit: number, holdMs: number): Promise<RunRow[]>;
725
+ /** Sets `parent_notified_at_ms`, so the child is never claimed again. */
726
+ markParentNotified(runId: string, nowMs: number): Promise<void>;
727
+ /** Due, unfired timers, claimed for `holdMs`; concurrent claimers get disjoint sets. */
728
+ claimDueTimers(nowMs: number, limit: number, holdMs: number): Promise<TimerRow[]>;
729
+ /** False when the timer already fired; timers are deduped by `step_id`. */
730
+ markTimerFired(runId: string, stepId: string, nowMs: number): Promise<boolean>;
731
+ /** Stores a signal, undelivered. */
732
+ putSignal(row: NewSignalRow, nowMs: number): Promise<void>;
733
+ /** Oldest undelivered signal of that name. Does not mark it delivered. */
734
+ takeSignal(runId: string, name: string): Promise<SignalRow | null>;
735
+ /** Records which step consumed the signal. */
736
+ markSignalDelivered(signalId: string, stepId: string, nowMs: number): Promise<void>;
737
+ /** Steps of the run currently parked on a signal. */
738
+ getSignalWaits(runId: string): Promise<SignalWaitRow[]>;
739
+ /** Drops a wait once its signal was delivered. */
740
+ removeSignalWait(runId: string, stepId: string): Promise<void>;
741
+ /** Inserts the schema; a row with the same `(name, version)` is left untouched. */
742
+ upsertSchema(row: SchemaRow, nowMs: number): Promise<void>;
743
+ /** The schema row, or null. */
744
+ getSchema(name: string, version: string): Promise<SchemaRow | null>;
745
+ }
746
+ export { StepState as A, TaskUpdate as B, KernelState as C, RetryPolicy as D, Reduction as E, NewTask as F, NewTimer as I, RunPatch as L, Completion as M, Emit as N, RunStatus as O, NewSpawn as P, RunRef as R, Json as S, ReducerEvent as T, Transition as V, Cause as _, NewRunRow as a, EventInput as b, RunRow as c, SignalWaitRow as d, StateRow as f, Backoff as g, TimerRow as h, JournalTx as i, Usage as j, Status as k, SchemaRow as l, TaskRow as m, Journal as n, NewSignalRow as o, TaskClaimFilter as p, JournalClosed as r, RunQuery as s, ApplyTransitionOptions as t, SignalRow as u, Command as v, Kind as w, Jitter as x, Envelope as y, SignalWait as z };