@usine/engine 0.1.0 → 0.3.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 (156) hide show
  1. package/README.md +39 -12
  2. package/dist/cursor/{store.d.ts → cursor.d.ts} +9 -7
  3. package/dist/cursor/cursor.d.ts.map +1 -0
  4. package/dist/cursor/{store.js → cursor.js} +8 -7
  5. package/dist/cursor/cursor.js.map +1 -0
  6. package/dist/cycle-budget/cycle-budget.d.ts +25 -0
  7. package/dist/cycle-budget/cycle-budget.d.ts.map +1 -0
  8. package/dist/cycle-budget/cycle-budget.js +117 -0
  9. package/dist/cycle-budget/cycle-budget.js.map +1 -0
  10. package/dist/cycle-budget/model.d.ts +26 -0
  11. package/dist/cycle-budget/model.d.ts.map +1 -0
  12. package/dist/cycle-budget/model.js +20 -0
  13. package/dist/cycle-budget/model.js.map +1 -0
  14. package/dist/cycle-budget/queries.d.ts +27 -0
  15. package/dist/cycle-budget/queries.d.ts.map +1 -0
  16. package/dist/cycle-budget/queries.js +175 -0
  17. package/dist/cycle-budget/queries.js.map +1 -0
  18. package/dist/database/database.d.ts +1 -1
  19. package/dist/database/database.d.ts.map +1 -1
  20. package/dist/database/local-sqlite.d.ts +32 -12
  21. package/dist/database/local-sqlite.d.ts.map +1 -1
  22. package/dist/database/local-sqlite.js +121 -16
  23. package/dist/database/local-sqlite.js.map +1 -1
  24. package/dist/database/schema.d.ts +302 -9
  25. package/dist/database/schema.d.ts.map +1 -1
  26. package/dist/database/schema.js +69 -12
  27. package/dist/database/schema.js.map +1 -1
  28. package/dist/engine/engine.d.ts +59 -0
  29. package/dist/engine/engine.d.ts.map +1 -0
  30. package/dist/{engine.js → engine/engine.js} +80 -32
  31. package/dist/engine/engine.js.map +1 -0
  32. package/dist/engine/error.d.ts +45 -0
  33. package/dist/engine/error.d.ts.map +1 -0
  34. package/dist/engine/error.js +49 -0
  35. package/dist/engine/error.js.map +1 -0
  36. package/dist/engine/lifecycle.d.ts +112 -0
  37. package/dist/engine/lifecycle.d.ts.map +1 -0
  38. package/dist/engine/lifecycle.js +132 -0
  39. package/dist/engine/lifecycle.js.map +1 -0
  40. package/dist/engine/shutdown.d.ts +12 -0
  41. package/dist/engine/shutdown.d.ts.map +1 -0
  42. package/dist/engine/shutdown.js +10 -0
  43. package/dist/engine/shutdown.js.map +1 -0
  44. package/dist/engine/submission.d.ts +58 -0
  45. package/dist/engine/submission.d.ts.map +1 -0
  46. package/dist/engine/submission.js +54 -0
  47. package/dist/engine/submission.js.map +1 -0
  48. package/dist/item-projection/{service.d.ts → item-projection.d.ts} +6 -6
  49. package/dist/item-projection/item-projection.d.ts.map +1 -0
  50. package/dist/item-projection/{service.js → item-projection.js} +7 -5
  51. package/dist/item-projection/item-projection.js.map +1 -0
  52. package/dist/item-projection/model.d.ts +2 -5
  53. package/dist/item-projection/model.d.ts.map +1 -1
  54. package/dist/item-projection/model.js +5 -5
  55. package/dist/item-projection/model.js.map +1 -1
  56. package/dist/loop-control/loop-control.d.ts +21 -0
  57. package/dist/loop-control/loop-control.d.ts.map +1 -0
  58. package/dist/{loop-control.js → loop-control/loop-control.js} +7 -5
  59. package/dist/loop-control/loop-control.js.map +1 -0
  60. package/dist/loop-control/model.d.ts +10 -0
  61. package/dist/loop-control/model.d.ts.map +1 -0
  62. package/dist/loop-control/model.js +9 -0
  63. package/dist/loop-control/model.js.map +1 -0
  64. package/dist/repository-label-projection/model.d.ts +12 -3
  65. package/dist/repository-label-projection/model.d.ts.map +1 -1
  66. package/dist/repository-label-projection/model.js +14 -5
  67. package/dist/repository-label-projection/model.js.map +1 -1
  68. package/dist/repository-label-projection/{service.d.ts → repository-label-projection.d.ts} +5 -5
  69. package/dist/repository-label-projection/repository-label-projection.d.ts.map +1 -0
  70. package/dist/repository-label-projection/{service.js → repository-label-projection.js} +17 -7
  71. package/dist/repository-label-projection/repository-label-projection.js.map +1 -0
  72. package/dist/run-reader/model.d.ts +46 -0
  73. package/dist/run-reader/model.d.ts.map +1 -0
  74. package/dist/run-reader/model.js +44 -0
  75. package/dist/run-reader/model.js.map +1 -0
  76. package/dist/run-reader/run-reader.d.ts +29 -0
  77. package/dist/run-reader/run-reader.d.ts.map +1 -0
  78. package/dist/run-reader/run-reader.js +44 -0
  79. package/dist/run-reader/run-reader.js.map +1 -0
  80. package/dist/step-executor.d.ts +36 -12
  81. package/dist/step-executor.d.ts.map +1 -1
  82. package/dist/step-executor.js +22 -5
  83. package/dist/step-executor.js.map +1 -1
  84. package/dist/store/codec.d.ts +278 -40
  85. package/dist/store/codec.d.ts.map +1 -1
  86. package/dist/store/codec.js +72 -44
  87. package/dist/store/codec.js.map +1 -1
  88. package/dist/store/queries.d.ts +49 -16
  89. package/dist/store/queries.d.ts.map +1 -1
  90. package/dist/store/queries.js +104 -91
  91. package/dist/store/queries.js.map +1 -1
  92. package/dist/store/store.d.ts +44 -26
  93. package/dist/store/store.d.ts.map +1 -1
  94. package/dist/store/store.js +199 -128
  95. package/dist/store/store.js.map +1 -1
  96. package/dist/store/transcript.d.ts +9 -0
  97. package/dist/store/transcript.d.ts.map +1 -0
  98. package/dist/store/transcript.js +71 -0
  99. package/dist/store/transcript.js.map +1 -0
  100. package/dist/transcript.d.ts +86 -0
  101. package/dist/transcript.d.ts.map +1 -0
  102. package/dist/transcript.js +77 -0
  103. package/dist/transcript.js.map +1 -0
  104. package/dist/workflow/admission.d.ts +13 -0
  105. package/dist/workflow/admission.d.ts.map +1 -0
  106. package/dist/workflow/admission.js +55 -0
  107. package/dist/workflow/admission.js.map +1 -0
  108. package/dist/workflow/command.d.ts +13 -0
  109. package/dist/workflow/command.d.ts.map +1 -0
  110. package/dist/workflow/command.js +17 -0
  111. package/dist/workflow/command.js.map +1 -0
  112. package/dist/workflow/workflow.d.ts +18 -0
  113. package/dist/workflow/workflow.d.ts.map +1 -0
  114. package/dist/workflow/workflow.js +108 -0
  115. package/dist/workflow/workflow.js.map +1 -0
  116. package/drizzle/20260903091940_queued_approved_runs/migration.sql +3 -0
  117. package/drizzle/20260903091940_queued_approved_runs/snapshot.json +1147 -0
  118. package/drizzle/20260905150403_item_cycle_budgets/migration.sql +58 -0
  119. package/drizzle/20260905150403_item_cycle_budgets/snapshot.json +1417 -0
  120. package/drizzle/20260905174009_item_run_history/migration.sql +1 -0
  121. package/drizzle/20260905174009_item_run_history/snapshot.json +1431 -0
  122. package/drizzle/20260912111855_operator_intervention/migration.sql +42 -0
  123. package/drizzle/20260912111855_operator_intervention/snapshot.json +1461 -0
  124. package/package.json +41 -5
  125. package/dist/cursor/model.d.ts +0 -5
  126. package/dist/cursor/model.d.ts.map +0 -1
  127. package/dist/cursor/model.js +0 -4
  128. package/dist/cursor/model.js.map +0 -1
  129. package/dist/cursor/store.d.ts.map +0 -1
  130. package/dist/cursor/store.js.map +0 -1
  131. package/dist/engine.d.ts +0 -39
  132. package/dist/engine.d.ts.map +0 -1
  133. package/dist/engine.js.map +0 -1
  134. package/dist/index.d.ts +0 -20
  135. package/dist/index.d.ts.map +0 -1
  136. package/dist/index.js +0 -20
  137. package/dist/index.js.map +0 -1
  138. package/dist/item-projection/service.d.ts.map +0 -1
  139. package/dist/item-projection/service.js.map +0 -1
  140. package/dist/loop-control.d.ts +0 -16
  141. package/dist/loop-control.d.ts.map +0 -1
  142. package/dist/loop-control.js.map +0 -1
  143. package/dist/model.d.ts +0 -185
  144. package/dist/model.d.ts.map +0 -1
  145. package/dist/model.js +0 -174
  146. package/dist/model.js.map +0 -1
  147. package/dist/repository-label-projection/service.d.ts.map +0 -1
  148. package/dist/repository-label-projection/service.js.map +0 -1
  149. package/dist/run-reader.d.ts +0 -20
  150. package/dist/run-reader.d.ts.map +0 -1
  151. package/dist/run-reader.js +0 -19
  152. package/dist/run-reader.js.map +0 -1
  153. package/dist/workflow.d.ts +0 -14
  154. package/dist/workflow.d.ts.map +0 -1
  155. package/dist/workflow.js +0 -105
  156. package/dist/workflow.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.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,aAAa,EAAE,oBAAoB,YACzD,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,oBAAoB,CAAC,KAC5F,KAAK,CAAC,KAAK,CACV,WAAW,GACX,YAAY,GACZ,oBAAoB,GACpB,oBAAoB,GACpB,WAAW,GACX,+BAA+B,GAC/B,+BAA+B,GAC/B,SAAS,GACT,SAAS,EACX,cAAc,GAAG,aAAa,EAC9B,MAAM,CAAC,MAAM,GAAG,YAAY,GAAG,oBAAoB,CA8BpD,CAAC;AAEF,OAAO,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -1,21 +1,29 @@
1
- import { Event, Item, Loop, Run } from "@usine/core";
1
+ import { Event } from "@usine/core/event";
2
+ import { AttemptContext, AttemptId } from "@usine/core/attempt";
3
+ import { Intervention } from "@usine/core/attempt/channel";
4
+ import { ItemKey } from "@usine/core/item";
5
+ import { LoopName } from "@usine/core/loop";
6
+ import { RunId } from "@usine/core/run";
2
7
  import { Context, Crypto, Effect, Layer, Option, Result } from "effect";
3
8
  import { ClusterWorkflowEngine, SingleRunner } from "effect/unstable/cluster";
4
9
  import { SqlClient } from "effect/unstable/sql";
5
10
  import { DurableDeferred, WorkflowEngine } from "effect/unstable/workflow";
6
- import { RunDatabase } from "./database/database.js";
7
- import { AttemptCancellationError, } from "./model.js";
8
- import { RunStore } from "./store/store.js";
9
- import { RunReader } from "./run-reader.js";
10
- import { ItemProjectionReader, ItemProjectionWriter } from "./item-projection/service.js";
11
- import { RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter, } from "./repository-label-projection/service.js";
12
- import { ApprovalGate, DurableRun, continueWithNewest, durableRunLayer, runIdFor, } from "./workflow.js";
13
- import { StepExecutor } from "./step-executor.js";
14
- import { CursorStore } from "./cursor/store.js";
15
- import { LoopControl } from "./loop-control.js";
11
+ import { RunDatabase } from "../database/database.js";
12
+ import { AttemptCancellationError, RunInterventionRejectedError, } from "./error.js";
13
+ import { RunStore } from "../store/store.js";
14
+ import { RunReader } from "../run-reader/run-reader.js";
15
+ import { ItemProjectionReader, ItemProjectionWriter } from "../item-projection/item-projection.js";
16
+ import { RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter, } from "../repository-label-projection/repository-label-projection.js";
17
+ import { ApprovalGate, DurableRun, continueWithNewest, durableRunLayer, runIdFor, } from "../workflow/workflow.js";
18
+ import { StepExecutor } from "../step-executor.js";
19
+ import { CursorStore } from "../cursor/cursor.js";
20
+ import { LoopControl } from "../loop-control/loop-control.js";
21
+ import { CycleBudgets } from "../cycle-budget/cycle-budget.js";
22
+ import { AttemptAdmission } from "../workflow/admission.js";
16
23
  const MAX_SETTLEMENT_POLLS = 500;
17
24
  const makeRunEngine = Effect.gen(function* () {
18
25
  const store = yield* RunStore;
26
+ const admission = yield* AttemptAdmission;
19
27
  const stepExecutor = yield* StepExecutor;
20
28
  const workflowEngine = yield* WorkflowEngine.WorkflowEngine;
21
29
  const provideWorkflowEngine = (effect) => Effect.provideService(effect, WorkflowEngine.WorkflowEngine, workflowEngine);
@@ -38,10 +46,10 @@ const makeRunEngine = Effect.gen(function* () {
38
46
  yield* continueWithNewest(store, runId).pipe(provideWorkflowEngine);
39
47
  });
40
48
  const awaitWorkflowSettlement = Effect.fn("RunEngine.awaitWorkflowSettlement")(function* (runId) {
41
- // A Failed projection is committed before the workflow finishes suspending.
42
- // Poll across that short handover so an immediate operator retry is not
43
- // lost. A workflow still absent at the deadline is a corrupted instance
44
- // database, not a race — die loudly instead of hanging delivery forever.
49
+ // A Failed projection commits before the workflow finishes suspending, so
50
+ // poll across that handover or an immediate operator retry is lost. A
51
+ // workflow still absent at the deadline means a corrupted instance
52
+ // database, so fail loudly instead of hanging.
45
53
  for (let poll = 0; poll < MAX_SETTLEMENT_POLLS; poll += 1) {
46
54
  const status = yield* DurableRun.poll(runId).pipe(provideWorkflowEngine);
47
55
  if (Option.isSome(status))
@@ -82,13 +90,13 @@ const makeRunEngine = Effect.gen(function* () {
82
90
  yield* store.approve(runId, approval);
83
91
  yield* deliverApproval(runId);
84
92
  });
85
- const retry = Effect.fn("RunEngine.retry")(function* (runId) {
86
- yield* store.retry(runId);
93
+ const retry = Effect.fn("RunEngine.retry")(function* (runId, amendment = Option.none()) {
94
+ yield* store.retry(runId, amendment);
87
95
  yield* deliverResume(runId);
88
96
  });
89
97
  const cancel = Effect.fn("RunEngine.cancel")(function* (runId) {
90
98
  // The closing transaction decides both facts at once: whether the run was
91
- // still open, and which attempt (if any) was in flight when it closed.
99
+ // still open, and which attempt was in flight when it closed.
92
100
  const outcome = yield* store.cancel(runId);
93
101
  if (outcome._tag === "AlreadyClosed") {
94
102
  yield* Effect.logDebug("Cancel was a no-op; the run was already closed", { runId });
@@ -110,6 +118,37 @@ const makeRunEngine = Effect.gen(function* () {
110
118
  });
111
119
  }
112
120
  });
121
+ const intervene = Effect.fn("RunEngine.intervene")(function* (runId, attemptId, intervention) {
122
+ yield* Effect.annotateCurrentSpan({ runId, attemptId, action: intervention.action._tag });
123
+ const current = yield* store.snapshot(runId);
124
+ const active = current.attempts.at(-1);
125
+ if (current.run.state._tag !== "Running" ||
126
+ active?.id !== attemptId ||
127
+ Option.isSome(active.outcome)) {
128
+ yield* Effect.logInfo("Operator input rejected for an inactive Attempt", {
129
+ runId,
130
+ attemptId,
131
+ });
132
+ return yield* new RunInterventionRejectedError({
133
+ runId,
134
+ attemptId,
135
+ message: "This Attempt is no longer running",
136
+ });
137
+ }
138
+ yield* stepExecutor.intervene(attemptId, intervention).pipe(Effect.mapError((error) => new RunInterventionRejectedError({
139
+ runId,
140
+ attemptId,
141
+ message: error._tag === "RunawayFailure"
142
+ ? "The Attempt reached its runaway limit"
143
+ : error._tag === "ChildSessionBudgetFailure"
144
+ ? "The Attempt reached its child-session budget"
145
+ : error.message,
146
+ })), Effect.tapError((error) => Effect.logWarning("Operator input delivery failed", {
147
+ runId,
148
+ attemptId,
149
+ message: error.message,
150
+ })));
151
+ });
113
152
  const revoke = Effect.fn("RunEngine.revoke")(function* (loop, itemKey) {
114
153
  const revoked = yield* store.revoke(loop, itemKey);
115
154
  yield* Effect.forEach(revoked, deliverInterrupt, {
@@ -144,22 +183,27 @@ const makeRunEngine = Effect.gen(function* () {
144
183
  }), { concurrency: "unbounded", discard: true });
145
184
  });
146
185
  yield* reconcile();
147
- return { approve, cancel, inspect, reconcile, retry, revoke, submit, transcript };
186
+ return {
187
+ approve,
188
+ cancel,
189
+ drain: admission.drain,
190
+ inspect,
191
+ intervene,
192
+ reconcile,
193
+ retry,
194
+ revoke,
195
+ submit,
196
+ transcript,
197
+ };
148
198
  });
149
- /**
150
- * The public run-engine service. The interface below is the package's declared
151
- * API — widen it deliberately, never by letting an implementation change leak
152
- * through inference.
153
- */
199
+ /** Records Events and manages their Runs through approval, execution, retry, and cancellation. */
154
200
  export class RunEngine extends Context.Service()("@usine/engine/RunEngine") {
155
201
  }
156
202
  /**
157
- * Builds the durable runtime on a caller-selected SQLite-compatible database.
158
- * The adapter must provide both Drizzle's run database and the matching Effect
159
- * SQL client so run projections and cluster tables stay co-located. This entry
160
- * is platform-free: the deployment supplies its platform `Crypto` (the cluster
161
- * hashes over-length deduplication keys with it) next to the `StepExecutor`
162
- * port — see `database/local-sqlite.ts` for the Node composition.
203
+ * Provides Run execution and recovery on the supplied database.
204
+ * `database` must supply Drizzle and Effect SQL clients for the same database,
205
+ * so Run records and pending execution remain together across restarts.
206
+ * The deployment supplies `Crypto` and the Worker implementation through `StepExecutor`.
163
207
  */
164
208
  export const layerWithDatabase = (database) => {
165
209
  const store = RunStore.layer.pipe(Layer.provide(database));
@@ -172,8 +216,12 @@ export const layerWithDatabase = (database) => {
172
216
  },
173
217
  }).pipe(Layer.provide(database), Layer.orDie);
174
218
  const workflowEngine = ClusterWorkflowEngine.layer.pipe(Layer.provide(cluster));
175
- const runtime = durableRunLayer.pipe(Layer.provideMerge(workflowEngine), Layer.provideMerge(store));
219
+ const admission = AttemptAdmission.layer;
220
+ const runtime = durableRunLayer.pipe(Layer.provideMerge(workflowEngine), Layer.provideMerge(store), Layer.provideMerge(admission));
176
221
  const runEngine = Layer.effect(RunEngine, makeRunEngine).pipe(Layer.provide(runtime));
177
- return Layer.mergeAll(runEngine, RunReader.layer.pipe(Layer.provide(database)), CursorStore.layer.pipe(Layer.provide(database)), ItemProjectionReader.layer.pipe(Layer.provide(database)), ItemProjectionWriter.layer.pipe(Layer.provide(database)), RepositoryLabelProjectionReader.layer.pipe(Layer.provide(database)), RepositoryLabelProjectionWriter.layer.pipe(Layer.provide(database)), LoopControl.layer.pipe(Layer.provide(database)));
222
+ return Layer.mergeAll(runEngine, CycleBudgets.layer.pipe(Layer.provide(database)), RunReader.layer.pipe(Layer.provide(database)), CursorStore.layer.pipe(Layer.provide(database)), ItemProjectionReader.layer.pipe(Layer.provide(database)), ItemProjectionWriter.layer.pipe(Layer.provide(database)), RepositoryLabelProjectionReader.layer.pipe(Layer.provide(database)), RepositoryLabelProjectionWriter.layer.pipe(Layer.provide(database)), LoopControl.layer.pipe(Layer.provide(database)));
178
223
  };
224
+ export { Submission, Claimed, Queued, Ignored, CycleBlocked, IgnoreReason, SubmissionResult, } from "./submission.js";
225
+ export { RunEngineShutdown } from "./shutdown.js";
226
+ export { RunNotFoundError, RunOperationRejectedError, EnginePersistenceError, AttemptCancellationError, RunInterventionRejectedError, RunStoreError, RunEngineError, } from "./error.js";
179
227
  //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AAAA,OA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KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EACxD,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EACnE,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EACnE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAChD,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { Schema } from "effect";
2
+ declare const RunNotFoundError_base: Schema.Class<RunNotFoundError, Schema.TaggedStruct<"RunNotFoundError", {
3
+ readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
4
+ }>, import("effect/Cause").YieldableError>;
5
+ /** No Run with the requested identity exists in this instance's records. */
6
+ export declare class RunNotFoundError extends RunNotFoundError_base {
7
+ }
8
+ declare const RunOperationRejectedError_base: Schema.Class<RunOperationRejectedError, Schema.TaggedStruct<"RunOperationRejectedError", {
9
+ readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
10
+ readonly operation: Schema.Literals<readonly ["approve", "retry"]>;
11
+ readonly state: Schema.String;
12
+ }>, import("effect/Cause").YieldableError>;
13
+ /** The Run's current state does not allow the requested approval or retry. */
14
+ export declare class RunOperationRejectedError extends RunOperationRejectedError_base {
15
+ }
16
+ declare const EnginePersistenceError_base: Schema.Class<EnginePersistenceError, Schema.TaggedStruct<"EnginePersistenceError", {
17
+ readonly operation: Schema.String;
18
+ readonly cause: Schema.Defect;
19
+ }>, import("effect/Cause").YieldableError>;
20
+ /** An operation could not read or update the instance's durable records. */
21
+ export declare class EnginePersistenceError extends EnginePersistenceError_base {
22
+ }
23
+ declare const AttemptCancellationError_base: Schema.Class<AttemptCancellationError, Schema.TaggedStruct<"AttemptCancellationError", {
24
+ readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
25
+ readonly cause: Schema.Defect;
26
+ }>, import("effect/Cause").YieldableError>;
27
+ /** The Run is canceled, but interrupting its active Attempt failed. */
28
+ export declare class AttemptCancellationError extends AttemptCancellationError_base {
29
+ }
30
+ /** Everything the store itself can fail with. */
31
+ export declare const RunStoreError: Schema.Union<readonly [typeof RunNotFoundError, typeof RunOperationRejectedError, typeof EnginePersistenceError]>;
32
+ export type RunStoreError = typeof RunStoreError.Type;
33
+ declare const RunInterventionRejectedError_base: Schema.Class<RunInterventionRejectedError, Schema.TaggedStruct<"RunInterventionRejectedError", {
34
+ readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
35
+ readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
36
+ readonly message: Schema.NonEmptyString;
37
+ }>, import("effect/Cause").YieldableError>;
38
+ /** The requested Attempt is no longer live, or its channel could not accept operator input. */
39
+ export declare class RunInterventionRejectedError extends RunInterventionRejectedError_base {
40
+ }
41
+ /** The store's failures plus the cancellation handshake failure only the engine raises. */
42
+ export declare const RunEngineError: Schema.Union<readonly [typeof RunNotFoundError, typeof RunOperationRejectedError, typeof EnginePersistenceError, typeof AttemptCancellationError, typeof RunInterventionRejectedError]>;
43
+ export type RunEngineError = typeof RunEngineError.Type;
44
+ export {};
45
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/engine/error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAEhC,4EAA4E;AAC5E,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;;;;;;AAEL,8EAA8E;AAC9E,qBAAa,yBAA0B,SAAQ,8BAM7C;CAAG;;;;;AAEL,4EAA4E;AAC5E,qBAAa,sBAAuB,SAAQ,2BAK1C;CAAG;;;;;AAEL,uEAAuE;AACvE,qBAAa,wBAAyB,SAAQ,6BAK5C;CAAG;AAEL,iDAAiD;AACjD,eAAO,MAAM,aAAa,mHAIxB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;;;;;;AAEtD,+FAA+F;AAC/F,qBAAa,4BAA6B,SAAQ,iCAMhD;CAAG;AAEL,2FAA2F;AAC3F,eAAO,MAAM,cAAc,yLAMzB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { AttemptId } from "@usine/core/attempt";
2
+ import { RunId } from "@usine/core/run";
3
+ import { Schema } from "effect";
4
+ /** No Run with the requested identity exists in this instance's records. */
5
+ export class RunNotFoundError extends Schema.TaggedError("@usine/engine/RunNotFoundError")("RunNotFoundError", {
6
+ runId: RunId,
7
+ }) {
8
+ }
9
+ /** The Run's current state does not allow the requested approval or retry. */
10
+ export class RunOperationRejectedError extends Schema.TaggedError("@usine/engine/RunOperationRejectedError")("RunOperationRejectedError", {
11
+ runId: RunId,
12
+ operation: Schema.Literals(["approve", "retry"]),
13
+ state: Schema.String,
14
+ }) {
15
+ }
16
+ /** An operation could not read or update the instance's durable records. */
17
+ export class EnginePersistenceError extends Schema.TaggedError("@usine/engine/EnginePersistenceError")("EnginePersistenceError", {
18
+ operation: Schema.String,
19
+ cause: Schema.Defect(),
20
+ }) {
21
+ }
22
+ /** The Run is canceled, but interrupting its active Attempt failed. */
23
+ export class AttemptCancellationError extends Schema.TaggedError("@usine/engine/AttemptCancellationError")("AttemptCancellationError", {
24
+ attemptId: AttemptId,
25
+ cause: Schema.Defect(),
26
+ }) {
27
+ }
28
+ /** Everything the store itself can fail with. */
29
+ export const RunStoreError = Schema.Union([
30
+ RunNotFoundError,
31
+ RunOperationRejectedError,
32
+ EnginePersistenceError,
33
+ ]);
34
+ /** The requested Attempt is no longer live, or its channel could not accept operator input. */
35
+ export class RunInterventionRejectedError extends Schema.TaggedError("@usine/engine/RunInterventionRejectedError")("RunInterventionRejectedError", {
36
+ runId: RunId,
37
+ attemptId: AttemptId,
38
+ message: Schema.NonEmptyString,
39
+ }) {
40
+ }
41
+ /** The store's failures plus the cancellation handshake failure only the engine raises. */
42
+ export const RunEngineError = Schema.Union([
43
+ RunNotFoundError,
44
+ RunOperationRejectedError,
45
+ EnginePersistenceError,
46
+ AttemptCancellationError,
47
+ RunInterventionRejectedError,
48
+ ]);
49
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/engine/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,4EAA4E;AAC5E,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CACtD,gCAAgC,CACjC,CAAC,kBAAkB,EAAE;IACpB,KAAK,EAAE,KAAK;CACb,CAAC;CAAG;AAEL,8EAA8E;AAC9E,MAAM,OAAO,yBAA0B,SAAQ,MAAM,CAAC,WAAW,CAC/D,yCAAyC,CAC1C,CAAC,2BAA2B,EAAE;IAC7B,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChD,KAAK,EAAE,MAAM,CAAC,MAAM;CACrB,CAAC;CAAG;AAEL,4EAA4E;AAC5E,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,WAAW,CAC5D,sCAAsC,CACvC,CAAC,wBAAwB,EAAE;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;CACvB,CAAC;CAAG;AAEL,uEAAuE;AACvE,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,WAAW,CAC9D,wCAAwC,CACzC,CAAC,0BAA0B,EAAE;IAC5B,SAAS,EAAE,SAAS;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;CACvB,CAAC;CAAG;AAEL,iDAAiD;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;IACxC,gBAAgB;IAChB,yBAAyB;IACzB,sBAAsB;CACvB,CAAC,CAAC;AAIH,+FAA+F;AAC/F,MAAM,OAAO,4BAA6B,SAAQ,MAAM,CAAC,WAAW,CAClE,4CAA4C,CAC7C,CAAC,8BAA8B,EAAE;IAChC,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,SAAS;IACpB,OAAO,EAAE,MAAM,CAAC,cAAc;CAC/B,CAAC;CAAG;AAEL,2FAA2F;AAC3F,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC;IACzC,gBAAgB;IAChB,yBAAyB;IACzB,sBAAsB;IACtB,wBAAwB;IACxB,4BAA4B;CAC7B,CAAC,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { Attempt, AttemptId, AttemptNumber } from "@usine/core/attempt";
2
+ import { AttemptFailure, InfraFailure } from "@usine/core/attempt/failure";
3
+ import { AttemptCanceled, AttemptFailed, AttemptSucceeded } from "@usine/core/attempt/outcome";
4
+ import { EventId } from "@usine/core/event";
5
+ import { Run, RunId } from "@usine/core/run";
6
+ import * as RunState from "@usine/core/run/state";
7
+ import { StepResult } from "@usine/core/step/result";
8
+ import { Option, Result } from "effect";
9
+ import type { WorkflowCommand } from "../workflow/command.ts";
10
+ /** A Run and its Attempts in ascending attempt-number order, read together. */
11
+ interface RunProgress {
12
+ readonly run: Run;
13
+ readonly attempts: ReadonlyArray<Attempt>;
14
+ }
15
+ type Unchanged = {
16
+ readonly _tag: "Unchanged";
17
+ readonly reason: "RunNotRunning" | "NoOpenAttempt" | "AttemptReplaced";
18
+ };
19
+ type RetryAttempt = {
20
+ readonly _tag: "RetryAttempt";
21
+ readonly attempt: Attempt;
22
+ readonly outcome: AttemptFailed;
23
+ };
24
+ type RunFailed = {
25
+ readonly _tag: "RunFailed";
26
+ readonly attempt: Attempt;
27
+ readonly outcome: AttemptFailed;
28
+ readonly state: RunState.Failed;
29
+ };
30
+ type RunSucceeded = {
31
+ readonly _tag: "RunSucceeded";
32
+ readonly attempt: Attempt;
33
+ readonly outcome: AttemptSucceeded;
34
+ readonly state: RunState.Succeeded;
35
+ readonly result: StepResult;
36
+ };
37
+ /** Changes that must commit together when an Attempt finishes. Only success stores a Step result. */
38
+ export type FinishDecision = RetryAttempt | RunFailed | RunSucceeded | Unchanged;
39
+ /**
40
+ * Settles the current Attempt from its executor result. Infrastructure failure
41
+ * can retry up to three total Attempts; a late or repeated completion changes nothing.
42
+ */
43
+ export declare const finishAttempt: (current: RunProgress, attemptId: AttemptId, result: Result.Result<StepResult, AttemptFailure>) => FinishDecision;
44
+ /**
45
+ * Repairs an open Attempt from a final durable result. The workflow has already
46
+ * ended, so even an infrastructure failure closes the Run without auto-retry.
47
+ * The runtime must first translate its completion into a typed result; defects
48
+ * and suspension are not Attempt outcomes here (ADRs 0003 and 0010).
49
+ */
50
+ export declare const reconcileAttempt: (current: RunProgress, result: Result.Result<StepResult, AttemptFailure>) => FinishDecision;
51
+ type StartDecision = {
52
+ readonly _tag: "StartAttempt";
53
+ readonly state: RunState.Running;
54
+ readonly number: AttemptNumber;
55
+ readonly interrupted: Option.Option<RetryAttempt>;
56
+ } | RunFailed | {
57
+ readonly _tag: "RunClosed";
58
+ readonly state: RunState.RunState;
59
+ };
60
+ /**
61
+ * Admits the next Attempt after a Worker reservation. An unfinished previous
62
+ * Attempt indicates a restart and counts against the same retry cap as ordinary
63
+ * infrastructure failure. `interruption` records the runtime's explanation.
64
+ * The caller creates the new Attempt's identity and timestamp only when admitted.
65
+ */
66
+ export declare const beginAttempt: (current: RunProgress, interruption: InfraFailure) => StartDecision;
67
+ type CancelDecision = {
68
+ readonly _tag: "AlreadyClosed";
69
+ } | {
70
+ readonly _tag: "Canceled";
71
+ readonly state: RunState.Canceled;
72
+ readonly attempt: Option.Option<{
73
+ readonly id: AttemptId;
74
+ readonly outcome: AttemptCanceled;
75
+ }>;
76
+ };
77
+ /**
78
+ * Cancels open work and, if executing, its unfinished Attempt. A Run awaiting
79
+ * capacity may have no Attempt, or only the closed Attempt preceding a retry.
80
+ */
81
+ export declare const cancelRun: (current: RunProgress) => CancelDecision;
82
+ type RetryDecision = {
83
+ readonly _tag: "Resume";
84
+ readonly state: RunState.Running;
85
+ } | {
86
+ readonly _tag: "ResumePending";
87
+ } | {
88
+ readonly _tag: "RetryRejected";
89
+ };
90
+ /**
91
+ * Reopens a failed Run for operator retry regardless of its Attempt count.
92
+ * Repeating the request is accepted while its Resume command remains pending;
93
+ * after delivery, retrying a Running Run is rejected.
94
+ */
95
+ export declare const retryRun: (state: RunState.RunState, pendingCommands: ReadonlyArray<WorkflowCommand>) => RetryDecision;
96
+ type ClaimDecision = {
97
+ readonly _tag: "OpenRun";
98
+ } | {
99
+ readonly _tag: "QueueEvent";
100
+ } | {
101
+ readonly _tag: "SupersedeRun";
102
+ readonly runId: RunId;
103
+ readonly state: RunState.Canceled;
104
+ };
105
+ /**
106
+ * Places a previously unclaimed Event behind its Item's running work, or
107
+ * replaces unstarted work. The ledger must resolve permanent deduplication and
108
+ * ignored Events before this decision; running Attempts always finish (ADR 0007).
109
+ */
110
+ export declare const claimRun: (blocking: Option.Option<Run>, eventId: EventId) => ClaimDecision;
111
+ export {};
112
+ //# sourceMappingURL=lifecycle.d.ts.map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 import { AttemptFailure, InfraFailure } from "@usine/core/attempt/failure";
3
+ import { AttemptCanceled, AttemptFailed, AttemptSucceeded } from "@usine/core/attempt/outcome";
4
+ import { EventId } from "@usine/core/event";
5
+ import { Run, RunId } from "@usine/core/run";
6
+ import * as RunState from "@usine/core/run/state";
7
+ import { StepResult } from "@usine/core/step/result";
8
+ import { Option, Result } from "effect";
9
+ // Engine policy, not a limit imposed on consumers of the core Attempt model.
10
+ const MAX_AUTO_ATTEMPTS = AttemptNumber.make(3);
11
+ const openAttempt = (current) => Option.fromNullishOr(current.attempts.at(-1)).pipe(Option.filter((attempt) => Option.isNone(attempt.outcome)));
12
+ const failRunningAttempt = (state, attempt, failure, policy) => {
13
+ const outcome = new AttemptFailed({ failure });
14
+ if (policy === "Execution" &&
15
+ shouldAutoRetry({ failure, number: attempt.number, maxAutoAttempts: MAX_AUTO_ATTEMPTS })) {
16
+ return { _tag: "RetryAttempt", attempt, outcome };
17
+ }
18
+ return { _tag: "RunFailed", attempt, outcome, state: RunState.fail(state) };
19
+ };
20
+ const finish = (current, attemptId, result, policy) => {
21
+ if (current.run.state._tag !== "Running") {
22
+ return { _tag: "Unchanged", reason: "RunNotRunning" };
23
+ }
24
+ const attempt = openAttempt(current);
25
+ if (Option.isNone(attempt))
26
+ return { _tag: "Unchanged", reason: "NoOpenAttempt" };
27
+ // A completion from before restart or operator retry cannot settle the
28
+ // replacement Attempt, even though the Run is Running again.
29
+ if (attempt.value.id !== attemptId)
30
+ return { _tag: "Unchanged", reason: "AttemptReplaced" };
31
+ if (Result.isFailure(result)) {
32
+ return failRunningAttempt(current.run.state, attempt.value, result.failure, policy);
33
+ }
34
+ return {
35
+ _tag: "RunSucceeded",
36
+ attempt: attempt.value,
37
+ outcome: new AttemptSucceeded(),
38
+ state: RunState.succeed(current.run.state),
39
+ result: result.success,
40
+ };
41
+ };
42
+ /**
43
+ * Settles the current Attempt from its executor result. Infrastructure failure
44
+ * can retry up to three total Attempts; a late or repeated completion changes nothing.
45
+ */
46
+ export const finishAttempt = (current, attemptId, result) => finish(current, attemptId, result, "Execution");
47
+ /**
48
+ * Repairs an open Attempt from a final durable result. The workflow has already
49
+ * ended, so even an infrastructure failure closes the Run without auto-retry.
50
+ * The runtime must first translate its completion into a typed result; defects
51
+ * and suspension are not Attempt outcomes here (ADRs 0003 and 0010).
52
+ */
53
+ export const reconcileAttempt = (current, result) => {
54
+ const attempt = openAttempt(current);
55
+ return Option.isNone(attempt)
56
+ ? { _tag: "Unchanged", reason: "NoOpenAttempt" }
57
+ : finish(current, attempt.value.id, result, "FinalReconciliation");
58
+ };
59
+ /**
60
+ * Admits the next Attempt after a Worker reservation. An unfinished previous
61
+ * Attempt indicates a restart and counts against the same retry cap as ordinary
62
+ * infrastructure failure. `interruption` records the runtime's explanation.
63
+ * The caller creates the new Attempt's identity and timestamp only when admitted.
64
+ */
65
+ export const beginAttempt = (current, interruption) => {
66
+ const state = current.run.state;
67
+ if (!RunState.isStartable(state) && state._tag !== "Running") {
68
+ return { _tag: "RunClosed", state };
69
+ }
70
+ let interrupted = Option.none();
71
+ const attempt = openAttempt(current);
72
+ if (state._tag === "Running" && Option.isSome(attempt)) {
73
+ const recovery = failRunningAttempt(state, attempt.value, interruption, "Execution");
74
+ if (recovery._tag === "RunFailed")
75
+ return recovery;
76
+ interrupted = Option.some(recovery);
77
+ }
78
+ return {
79
+ _tag: "StartAttempt",
80
+ state: state._tag === "Running" ? state : RunState.start(state),
81
+ number: AttemptNumber.make((current.attempts.at(-1)?.number ?? 0) + 1),
82
+ interrupted,
83
+ };
84
+ };
85
+ /**
86
+ * Cancels open work and, if executing, its unfinished Attempt. A Run awaiting
87
+ * capacity may have no Attempt, or only the closed Attempt preceding a retry.
88
+ */
89
+ export const cancelRun = (current) => {
90
+ if (!RunState.isOpen(current.run.state))
91
+ return { _tag: "AlreadyClosed" };
92
+ return {
93
+ _tag: "Canceled",
94
+ state: RunState.cancelByOperator(current.run.state),
95
+ attempt: current.run.state._tag === "Running"
96
+ ? Option.map(openAttempt(current), (attempt) => ({
97
+ id: attempt.id,
98
+ outcome: new AttemptCanceled(),
99
+ }))
100
+ : Option.none(),
101
+ };
102
+ };
103
+ /**
104
+ * Reopens a failed Run for operator retry regardless of its Attempt count.
105
+ * Repeating the request is accepted while its Resume command remains pending;
106
+ * after delivery, retrying a Running Run is rejected.
107
+ */
108
+ export const retryRun = (state, pendingCommands) => {
109
+ if (state._tag === "Failed")
110
+ return { _tag: "Resume", state: RunState.retry(state) };
111
+ if (state._tag === "Running" && pendingCommands.includes("Resume")) {
112
+ return { _tag: "ResumePending" };
113
+ }
114
+ return { _tag: "RetryRejected" };
115
+ };
116
+ /**
117
+ * Places a previously unclaimed Event behind its Item's running work, or
118
+ * replaces unstarted work. The ledger must resolve permanent deduplication and
119
+ * ignored Events before this decision; running Attempts always finish (ADR 0007).
120
+ */
121
+ export const claimRun = (blocking, eventId) => {
122
+ if (Option.isNone(blocking))
123
+ return { _tag: "OpenRun" };
124
+ const run = blocking.value;
125
+ if (run.state._tag === "Running")
126
+ return { _tag: "QueueEvent" };
127
+ if (RunState.isUnstarted(run.state)) {
128
+ return { _tag: "SupersedeRun", runId: run.id, state: RunState.supersede(run.state, eventId) };
129
+ }
130
+ return { _tag: "OpenRun" };
131
+ };
132
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/engine/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE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I,EAAE,eAAe,EAAE,CAAC;AACnC,CAAC,CAAC;AAOF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,QAA4B,EAAE,OAAgB,EAAiB,EAAE;IACxF,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC3B,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAChE,IAAI,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Context, Deferred } from "effect";
2
+ declare const RunEngineShutdown_base: Context.ServiceClass<RunEngineShutdown, "@usine/engine/RunEngineShutdown", Deferred.Deferred<void, never>>;
3
+ /**
4
+ * Optional host-owned shutdown latch, provided before building an engine runtime.
5
+ * Completing it closes Attempt admission even while startup recovery is running.
6
+ * After startup, RunEngine.drain waits for admitted Attempts to persist their outcomes.
7
+ * Allocate a fresh latch for each runtime; it cannot be reopened (ADR 0023).
8
+ */
9
+ export declare class RunEngineShutdown extends RunEngineShutdown_base {
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;;AAE3C;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAGD;CAAG"}
@@ -0,0 +1,10 @@
1
+ import { Context, Deferred } from "effect";
2
+ /**
3
+ * Optional host-owned shutdown latch, provided before building an engine runtime.
4
+ * Completing it closes Attempt admission even while startup recovery is running.
5
+ * After startup, RunEngine.drain waits for admitted Attempts to persist their outcomes.
6
+ * Allocate a fresh latch for each runtime; it cannot be reopened (ADR 0023).
7
+ */
8
+ export class RunEngineShutdown extends Context.Service()("@usine/engine/RunEngineShutdown") {
9
+ }
10
+ //# sourceMappingURL=shutdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,OAAO,CAAC,OAAO,EAGnD,CAAC,iCAAiC,CAAC;CAAG"}