@usine/engine 0.3.0 → 0.5.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 (201) hide show
  1. package/LICENSE +661 -21
  2. package/README.md +112 -38
  3. package/dist/board-moves/board-moves.d.ts +20 -0
  4. package/dist/board-moves/board-moves.d.ts.map +1 -0
  5. package/dist/board-moves/board-moves.js +74 -0
  6. package/dist/board-moves/board-moves.js.map +1 -0
  7. package/dist/board-moves/model.d.ts +21 -0
  8. package/dist/board-moves/model.d.ts.map +1 -0
  9. package/dist/board-moves/model.js +22 -0
  10. package/dist/board-moves/model.js.map +1 -0
  11. package/dist/cursor/cursor.d.ts +2 -6
  12. package/dist/cursor/cursor.d.ts.map +1 -1
  13. package/dist/cursor/cursor.js +2 -6
  14. package/dist/cursor/cursor.js.map +1 -1
  15. package/dist/cycle-budget/cycle-budget.d.ts +14 -8
  16. package/dist/cycle-budget/cycle-budget.d.ts.map +1 -1
  17. package/dist/cycle-budget/cycle-budget.js +51 -10
  18. package/dist/cycle-budget/cycle-budget.js.map +1 -1
  19. package/dist/cycle-budget/model.d.ts +6 -2
  20. package/dist/cycle-budget/model.d.ts.map +1 -1
  21. package/dist/cycle-budget/model.js +5 -2
  22. package/dist/cycle-budget/model.js.map +1 -1
  23. package/dist/cycle-budget/queries.d.ts +1 -1
  24. package/dist/cycle-budget/queries.d.ts.map +1 -1
  25. package/dist/cycle-budget/queries.js +3 -3
  26. package/dist/cycle-budget/queries.js.map +1 -1
  27. package/dist/database/database.d.ts +1 -1
  28. package/dist/database/database.d.ts.map +1 -1
  29. package/dist/database/local-sqlite.d.ts +13 -10
  30. package/dist/database/local-sqlite.d.ts.map +1 -1
  31. package/dist/database/local-sqlite.js +22 -17
  32. package/dist/database/local-sqlite.js.map +1 -1
  33. package/dist/database/schema.d.ts +668 -36
  34. package/dist/database/schema.d.ts.map +1 -1
  35. package/dist/database/schema.js +123 -23
  36. package/dist/database/schema.js.map +1 -1
  37. package/dist/{workflow → engine}/admission.d.ts +2 -2
  38. package/dist/engine/admission.d.ts.map +1 -0
  39. package/dist/{workflow → engine}/admission.js +4 -4
  40. package/dist/engine/admission.js.map +1 -0
  41. package/dist/engine/checkout-recovery.d.ts +79 -0
  42. package/dist/engine/checkout-recovery.d.ts.map +1 -0
  43. package/dist/engine/checkout-recovery.js +238 -0
  44. package/dist/engine/checkout-recovery.js.map +1 -0
  45. package/dist/engine/engine.d.ts +67 -26
  46. package/dist/engine/engine.d.ts.map +1 -1
  47. package/dist/engine/engine.js +136 -129
  48. package/dist/engine/engine.js.map +1 -1
  49. package/dist/engine/error.d.ts +29 -10
  50. package/dist/engine/error.d.ts.map +1 -1
  51. package/dist/engine/error.js +28 -8
  52. package/dist/engine/error.js.map +1 -1
  53. package/dist/engine/lifecycle.d.ts +83 -28
  54. package/dist/engine/lifecycle.d.ts.map +1 -1
  55. package/dist/engine/lifecycle.js +94 -45
  56. package/dist/engine/lifecycle.js.map +1 -1
  57. package/dist/engine/retry.d.ts +16 -0
  58. package/dist/engine/retry.d.ts.map +1 -0
  59. package/dist/engine/retry.js +18 -0
  60. package/dist/engine/retry.js.map +1 -0
  61. package/dist/engine/run-again.d.ts +45 -0
  62. package/dist/engine/run-again.d.ts.map +1 -0
  63. package/dist/engine/run-again.js +56 -0
  64. package/dist/engine/run-again.js.map +1 -0
  65. package/dist/engine/run-driver.d.ts +68 -0
  66. package/dist/engine/run-driver.d.ts.map +1 -0
  67. package/dist/engine/run-driver.js +448 -0
  68. package/dist/engine/run-driver.js.map +1 -0
  69. package/dist/engine/shutdown.d.ts +3 -4
  70. package/dist/engine/shutdown.d.ts.map +1 -1
  71. package/dist/engine/shutdown.js +3 -4
  72. package/dist/engine/shutdown.js.map +1 -1
  73. package/dist/engine/submission.d.ts +31 -11
  74. package/dist/engine/submission.d.ts.map +1 -1
  75. package/dist/engine/submission.js +43 -12
  76. package/dist/engine/submission.js.map +1 -1
  77. package/dist/engine/unconfirmed-stops.d.ts +27 -0
  78. package/dist/engine/unconfirmed-stops.d.ts.map +1 -0
  79. package/dist/engine/unconfirmed-stops.js +26 -0
  80. package/dist/engine/unconfirmed-stops.js.map +1 -0
  81. package/dist/item-projection/item-projection.d.ts +14 -4
  82. package/dist/item-projection/item-projection.d.ts.map +1 -1
  83. package/dist/item-projection/item-projection.js +60 -14
  84. package/dist/item-projection/item-projection.js.map +1 -1
  85. package/dist/item-projection/model.d.ts +5 -1
  86. package/dist/item-projection/model.d.ts.map +1 -1
  87. package/dist/item-projection/model.js +6 -2
  88. package/dist/item-projection/model.js.map +1 -1
  89. package/dist/loop-control/loop-control.d.ts +5 -5
  90. package/dist/loop-control/loop-control.d.ts.map +1 -1
  91. package/dist/loop-control/loop-control.js +4 -4
  92. package/dist/loop-control/loop-control.js.map +1 -1
  93. package/dist/loop-control/model.d.ts +1 -1
  94. package/dist/loop-control/model.d.ts.map +1 -1
  95. package/dist/loop-control/model.js +1 -1
  96. package/dist/loop-control/model.js.map +1 -1
  97. package/dist/repository-label-projection/model.d.ts +2 -2
  98. package/dist/repository-label-projection/model.d.ts.map +1 -1
  99. package/dist/repository-label-projection/model.js +2 -2
  100. package/dist/repository-label-projection/model.js.map +1 -1
  101. package/dist/repository-label-projection/repository-label-projection.d.ts +1 -1
  102. package/dist/repository-label-projection/repository-label-projection.d.ts.map +1 -1
  103. package/dist/repository-label-projection/repository-label-projection.js +1 -1
  104. package/dist/repository-label-projection/repository-label-projection.js.map +1 -1
  105. package/dist/run-reader/model.d.ts +62 -4
  106. package/dist/run-reader/model.d.ts.map +1 -1
  107. package/dist/run-reader/model.js +66 -7
  108. package/dist/run-reader/model.js.map +1 -1
  109. package/dist/run-reader/run-reader.d.ts +25 -10
  110. package/dist/run-reader/run-reader.d.ts.map +1 -1
  111. package/dist/run-reader/run-reader.js +25 -7
  112. package/dist/run-reader/run-reader.js.map +1 -1
  113. package/dist/step-executor.d.ts +86 -13
  114. package/dist/step-executor.d.ts.map +1 -1
  115. package/dist/step-executor.js +10 -2
  116. package/dist/step-executor.js.map +1 -1
  117. package/dist/store/attempt-windows.d.ts +8 -0
  118. package/dist/store/attempt-windows.d.ts.map +1 -0
  119. package/dist/store/attempt-windows.js +53 -0
  120. package/dist/store/attempt-windows.js.map +1 -0
  121. package/dist/store/codec.d.ts +242 -43
  122. package/dist/store/codec.d.ts.map +1 -1
  123. package/dist/store/codec.js +61 -16
  124. package/dist/store/codec.js.map +1 -1
  125. package/dist/store/leftovers.d.ts +10 -0
  126. package/dist/store/leftovers.d.ts.map +1 -0
  127. package/dist/store/leftovers.js +43 -0
  128. package/dist/store/leftovers.js.map +1 -0
  129. package/dist/store/loop-items.d.ts +16 -0
  130. package/dist/store/loop-items.d.ts.map +1 -0
  131. package/dist/store/loop-items.js +185 -0
  132. package/dist/store/loop-items.js.map +1 -0
  133. package/dist/store/queries.d.ts +385 -36
  134. package/dist/store/queries.d.ts.map +1 -1
  135. package/dist/store/queries.js +355 -107
  136. package/dist/store/queries.js.map +1 -1
  137. package/dist/store/store.d.ts +106 -54
  138. package/dist/store/store.d.ts.map +1 -1
  139. package/dist/store/store.js +497 -190
  140. package/dist/store/store.js.map +1 -1
  141. package/dist/store/transcript.d.ts +3 -3
  142. package/dist/store/transcript.d.ts.map +1 -1
  143. package/dist/store/transcript.js +25 -6
  144. package/dist/store/transcript.js.map +1 -1
  145. package/dist/transcript.d.ts +19 -20
  146. package/dist/transcript.d.ts.map +1 -1
  147. package/dist/transcript.js +23 -21
  148. package/dist/transcript.js.map +1 -1
  149. package/dist/trigger-condition.d.ts +23 -0
  150. package/dist/trigger-condition.d.ts.map +1 -0
  151. package/dist/trigger-condition.js +8 -0
  152. package/dist/trigger-condition.js.map +1 -0
  153. package/drizzle/20260917071139_resolve_run_failure/migration.sql +1 -0
  154. package/drizzle/20260917071139_resolve_run_failure/snapshot.json +1471 -0
  155. package/drizzle/20260918032643_attempt_salvage/migration.sql +1 -0
  156. package/drizzle/20260918032643_attempt_salvage/snapshot.json +1481 -0
  157. package/drizzle/20261011153856_drop_workflow_tables/migration.sql +4 -0
  158. package/drizzle/20261011153856_drop_workflow_tables/snapshot.json +1433 -0
  159. package/drizzle/20261017155043_attempt_salvage_check/migration.sql +41 -0
  160. package/drizzle/20261017155043_attempt_salvage_check/snapshot.json +1421 -0
  161. package/drizzle/20261018162700_discard_attempt_leftovers/migration.sql +1 -0
  162. package/drizzle/20261018162700_discard_attempt_leftovers/snapshot.json +1431 -0
  163. package/drizzle/20261018172605_loop_items_and_reopenings/migration.sql +15 -0
  164. package/drizzle/20261018172605_loop_items_and_reopenings/snapshot.json +1574 -0
  165. package/drizzle/20261018180339_attempt_ended_at/migration.sql +1 -0
  166. package/drizzle/20261018180339_attempt_ended_at/snapshot.json +1584 -0
  167. package/drizzle/20261019104043_run_approval_source/migration.sql +15 -0
  168. package/drizzle/20261019104043_run_approval_source/snapshot.json +1610 -0
  169. package/drizzle/20261019133538_board_moves/migration.sql +14 -0
  170. package/drizzle/20261019133538_board_moves/snapshot.json +1731 -0
  171. package/drizzle/20261019170538_item_projection_gone/migration.sql +1 -0
  172. package/drizzle/20261019170538_item_projection_gone/snapshot.json +1741 -0
  173. package/drizzle/20261019180649_run_again_events/migration.sql +7 -0
  174. package/drizzle/20261019180649_run_again_events/snapshot.json +1804 -0
  175. package/drizzle/20261019185008_trigger_event_permissions/migration.sql +1 -0
  176. package/drizzle/20261019185008_trigger_event_permissions/snapshot.json +1814 -0
  177. package/drizzle/20261020103746_attempt_start/migration.sql +5 -0
  178. package/drizzle/20261020103746_attempt_start/snapshot.json +1844 -0
  179. package/drizzle/20261020125211_attempt_comments/migration.sql +1 -0
  180. package/drizzle/20261020125211_attempt_comments/snapshot.json +1854 -0
  181. package/drizzle/20261020191320_run_closed_at/migration.sql +6 -0
  182. package/drizzle/20261020191320_run_closed_at/snapshot.json +1864 -0
  183. package/drizzle/20261023091428_rename_loop_item_hold_to_suppression/migration.sql +2 -0
  184. package/drizzle/20261023091428_rename_loop_item_hold_to_suppression/snapshot.json +1867 -0
  185. package/drizzle/20261024162954_cycle_ask_closures/migration.sql +10 -0
  186. package/drizzle/20261024162954_cycle_ask_closures/snapshot.json +1948 -0
  187. package/drizzle/20261027104206_attempt_out_of_memory/migration.sql +1 -0
  188. package/drizzle/20261027104206_attempt_out_of_memory/snapshot.json +1958 -0
  189. package/drizzle/20261027191944_failure_resolution/migration.sql +1 -0
  190. package/drizzle/20261027191944_failure_resolution/snapshot.json +1968 -0
  191. package/package.json +22 -12
  192. package/dist/workflow/admission.d.ts.map +0 -1
  193. package/dist/workflow/admission.js.map +0 -1
  194. package/dist/workflow/command.d.ts +0 -13
  195. package/dist/workflow/command.d.ts.map +0 -1
  196. package/dist/workflow/command.js +0 -17
  197. package/dist/workflow/command.js.map +0 -1
  198. package/dist/workflow/workflow.d.ts +0 -18
  199. package/dist/workflow/workflow.d.ts.map +0 -1
  200. package/dist/workflow/workflow.js +0 -108
  201. package/dist/workflow/workflow.js.map +0 -1
@@ -1,9 +1,11 @@
1
+ import type { AttemptRecovery, RecoverySink } from "@usine/core/attempt/salvage";
1
2
  import { Agent } from "@usine/core/agent";
2
- import { Attempt, type AttemptId } from "@usine/core/attempt";
3
+ import { Attempt, type AttemptId, type StopReason } from "@usine/core/attempt";
4
+ import { SalvagePushed } from "@usine/core/attempt/salvage";
3
5
  import { Event } from "@usine/core/event";
4
- import { Run } from "@usine/core/run";
6
+ import { Run, type RunId } from "@usine/core/run";
5
7
  import { Step } from "@usine/core/step";
6
- import { Schema, Context, Effect } from "effect";
8
+ import { Schema, Context, Effect, type Option, type Result } from "effect";
7
9
  import type * as AttemptChannel from "@usine/core/attempt/channel";
8
10
  import type { AttemptFailure } from "@usine/core/attempt/failure";
9
11
  import type { WorkerName } from "@usine/core/worker";
@@ -19,26 +21,97 @@ declare const StepExecution_base: Schema.Class<StepExecution, Schema.Struct<{
19
21
  readonly task: Schema.brand<Schema.String, "AttemptTask">;
20
22
  readonly agent: typeof Agent;
21
23
  readonly parentModel: Schema.Option<Schema.brand<Schema.String, "ModelId">>;
24
+ /** The Attempt's access to `repository`, from the Run's Loop (ADR 0011). */
25
+ readonly permissions: Schema.Literals<readonly ["write", "read"]>;
26
+ /** The newest pushed salvage of an earlier Attempt of the Run, which the checkout resumes from. */
27
+ readonly resume: Schema.Option<typeof SalvagePushed>;
28
+ /** Whether to reattach to the Attempt's live parent task instead of starting it. */
29
+ readonly reattach: Schema.withConstructorDefault<Schema.Boolean>;
22
30
  }>, {}>;
23
- /** The saved Event, effective task and Agent, and Step being tried in one Attempt. */
31
+ /** The saved Event, effective task and Agent, and Step of one Attempt. */
24
32
  export declare class StepExecution extends StepExecution_base {
25
33
  }
26
- /** A reservation of one Worker's capacity for the length of an Attempt. Call `release` when the Attempt ends. */
34
+ /** A reservation of one Worker slot for an Attempt, freed by `release`. */
27
35
  export interface WorkerLease {
28
36
  readonly worker: WorkerName;
29
37
  readonly release: Effect.Effect<void>;
30
38
  }
39
+ /**
40
+ * The channel sink for one execution. The executor runs `checkoutAcquired` after preparing the
41
+ * checkout and before launching the Attempt; from then on, it salvages and releases the
42
+ * checkout. Before that, the engine reconciles a kept checkout through `StepExecutor.recover`
43
+ * (#180).
44
+ */
45
+ export interface ExecutionSink extends AttemptChannel.Sink {
46
+ readonly checkoutAcquired: Effect.Effect<void>;
47
+ }
31
48
  declare const StepExecutor_base: Context.ServiceClass<StepExecutor, "@usine/engine/StepExecutor", {
32
- /** Requests that the identified Attempt stop its current work. */
33
- readonly interrupt: (attemptId: AttemptId) => Effect.Effect<void, AttemptFailure>;
34
- /** Sends a nonterminal operator action to a live session in the identified Attempt. */
49
+ /**
50
+ * The configured Workers, plus each removed Worker until its last Attempt ends. The engine
51
+ * calls `recover` only for Attempts on these Workers.
52
+ */
53
+ readonly workers: Effect.Effect<ReadonlyArray<WorkerName>>;
54
+ /**
55
+ * Returns whether the Attempt's parent task survived an orchestrator restart: it still runs,
56
+ * or it finished and its result is still on the Worker.
57
+ */
58
+ readonly isLive: (attemptId: AttemptId) => Effect.Effect<boolean, AttemptFailure>;
59
+ /**
60
+ * Returns the result that an open Attempt's parent task stored before an orchestrator restart,
61
+ * or `None` if nothing was stored.
62
+ */
63
+ readonly outcome: (attemptId: AttemptId) => Effect.Effect<Option.Option<Result.Result<StepResult, AttemptFailure>>, AttemptFailure>;
64
+ /**
65
+ * Reconciles the checkout of an Attempt that no Run reattaches, recording its salvage before
66
+ * releasing it. Stops a live parent task first, and fails, leaving the checkout, if it can't
67
+ * confirm the stop. For an open Attempt whose parent task failed before a launch recorded it,
68
+ * also records the comments the Attempt posted on the Run's Item.
69
+ */
70
+ readonly recover: <E>(attempt: AttemptRecovery, record: RecoverySink<E>) => Effect.Effect<void, E | AttemptFailure>;
71
+ /**
72
+ * Stops the Attempt's work for `reason`, including a parent task that survived a restart. Fails
73
+ * if the parent task can't be confirmed stopped. The engine also calls it after `execute`
74
+ * fails, and keeps the Attempt's Worker slot while it fails (#512). Once a stop is confirmed,
75
+ * the executor salvages and removes a checkout that it kept while the stop was unconfirmed
76
+ * (#523).
77
+ */
78
+ readonly interrupt: (attemptId: AttemptId, reason: StopReason) => Effect.Effect<void, AttemptFailure>;
79
+ /** Sends a non-terminal operator action to a live session of the Attempt. */
35
80
  readonly intervene: (attemptId: AttemptId, intervention: AttemptChannel.Intervention) => Effect.Effect<void, AttemptFailure>;
36
- /** Waits for Worker capacity; the returned lease must be released after execution or cancellation. */
37
- readonly reserve: (submission: Submission) => Effect.Effect<WorkerLease, AttemptFailure>;
38
- /** Runs the reserved Attempt, recording channel activity through `io`, and waits for its result. */
39
- readonly execute: (execution: StepExecution, io: AttemptChannel.Sink) => Effect.Effect<StepResult, AttemptFailure>;
81
+ /**
82
+ * Waits for a Worker slot for the next Attempt of `runId` and returns its lease, which the
83
+ * caller releases. If `worker` is set, waits for a slot on that Worker only (#177).
84
+ */
85
+ readonly reserve: (runId: RunId, submission: Submission, worker: Option.Option<WorkerName>) => Effect.Effect<WorkerLease, AttemptFailure>;
86
+ /**
87
+ * Takes a slot on `worker` immediately for `attemptId`, an Attempt that already runs there,
88
+ * even if no slot is free, so the Worker can exceed its capacity until enough Attempts end
89
+ * (#177). On a Worker that creates a machine per Attempt, the lease holds that Attempt's
90
+ * machine (#550).
91
+ */
92
+ readonly occupy: (worker: WorkerName, attemptId: AttemptId) => Effect.Effect<WorkerLease>;
93
+ /**
94
+ * Removes the Worker resources that no Attempt holds, such as the machines that a provisioned
95
+ * Worker created for Attempts of an earlier process (#550), or the Codex homes that a crash
96
+ * left on an SSH Worker. The engine runs it after startup recovery and at each reconcile.
97
+ * Never fails; the executor logs what it couldn't remove.
98
+ */
99
+ readonly sweep: Effect.Effect<void>;
100
+ /**
101
+ * Removes what `attempts`, whose leftovers the operator discarded, left on `worker` outside
102
+ * their checkouts, such as their Codex homes on an SSH Worker. `worker` isn't in `workers`.
103
+ * The engine runs it after it stops tracking the Attempts. Never fails; the executor logs
104
+ * what it couldn't remove.
105
+ */
106
+ readonly discard: (worker: WorkerName, attempts: ReadonlyArray<AttemptId>) => Effect.Effect<void>;
107
+ /**
108
+ * Runs the reserved Attempt, or reattaches to it if `execution.reattach` is set, records channel
109
+ * activity through `io`, and returns its result. Runs `io.checkoutAcquired` after preparing the
110
+ * checkout, and never if preparation fails.
111
+ */
112
+ readonly execute: (execution: StepExecution, io: ExecutionSink) => Effect.Effect<StepResult, AttemptFailure>;
40
113
  }>;
41
- /** Runs one Attempt on a Worker: reserve capacity, execute the step, interrupt on cancel. */
114
+ /** The service that runs Attempts on Workers. */
42
115
  export declare class StepExecutor extends StepExecutor_base {
43
116
  }
44
117
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"step-executor.d.ts","sourceRoot":"","sources":["../src/step-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,m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;;;OAKG;sBACe,CAChB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,aAAa,CAAC,SAAS,CAAC,KAC/B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IACxB;;;;OAIG;sBACe,CAChB,SAAS,EAAE,aAAa,EACxB,EAAE,EAAE,aAAa,KACd,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC;;AAxFlD,iDAAiD;AACjD,qBAAa,YAAa,SAAQ,iBAyFD;CAAG"}
@@ -1,12 +1,14 @@
1
1
  import { Agent } from "@usine/core/agent";
2
2
  import { ModelId } from "@usine/core/agent/brain";
3
3
  import { Attempt, AttemptTask } from "@usine/core/attempt";
4
+ import { SalvagePushed } from "@usine/core/attempt/salvage";
4
5
  import { Event } from "@usine/core/event";
6
+ import { LoopPermissions } from "@usine/core/loop";
5
7
  import { RepositoryName, RepositoryRevision } from "@usine/core/repository";
6
8
  import { Run } from "@usine/core/run";
7
9
  import { Step } from "@usine/core/step";
8
10
  import { Schema, Context, Effect } from "effect";
9
- /** The saved Event, effective task and Agent, and Step being tried in one Attempt. */
11
+ /** The saved Event, effective task and Agent, and Step of one Attempt. */
10
12
  export class StepExecution extends Schema.Class("@usine/engine/StepExecution")({
11
13
  attempt: Attempt,
12
14
  event: Event,
@@ -17,9 +19,15 @@ export class StepExecution extends Schema.Class("@usine/engine/StepExecution")({
17
19
  task: AttemptTask,
18
20
  agent: Agent,
19
21
  parentModel: Schema.Option(ModelId),
22
+ /** The Attempt's access to `repository`, from the Run's Loop (ADR 0011). */
23
+ permissions: LoopPermissions,
24
+ /** The newest pushed salvage of an earlier Attempt of the Run, which the checkout resumes from. */
25
+ resume: Schema.Option(SalvagePushed),
26
+ /** Whether to reattach to the Attempt's live parent task instead of starting it. */
27
+ reattach: Schema.Boolean.pipe(Schema.withConstructorDefault(Effect.succeed(false))),
20
28
  }) {
21
29
  }
22
- /** Runs one Attempt on a Worker: reserve capacity, execute the step, interrupt on cancel. */
30
+ /** The service that runs Attempts on Workers. */
23
31
  export class StepExecutor extends Context.Service()("@usine/engine/StepExecutor") {
24
32
  }
25
33
  //# sourceMappingURL=step-executor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"step-executor.js","sourceRoot":"","sources":["../src/step-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOjD,sFAAsF;AACtF,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,KAAK,CAAgB,6BAA6B,CAAC,CAAC;IAC5F,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,cAAc;IAC1B,QAAQ,EAAE,kBAAkB;IAC5B,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,KAAK;IACZ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;CACpC,CAAC;CAAG;AAQL,6FAA6F;AAC7F,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,OAAO,EAkB9C,CAAC,4BAA4B,CAAC;CAAG"}
1
+ {"version":3,"file":"step-executor.js","sourceRoot":"","sources":["../src/step-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,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0 +1,8 @@
1
+ import { AttemptWindows } from "@usine/core/attempt";
2
+ import { Effect } from "effect";
3
+ import type { RunDatabaseClient } from "../database/database.ts";
4
+ /** Returns the Attempt window queries that run on the caller's transaction. */
5
+ export declare const attemptWindowQueries: (database: RunDatabaseClient) => {
6
+ readonly attemptWindows: (attemptId: string & import("effect/Brand").Brand<"AttemptId">) => Effect.Effect<AttemptWindows, import("drizzle-orm/effect-core").EffectDrizzleQueryError | import("effect/Schema").SchemaError, never>;
7
+ };
8
+ //# sourceMappingURL=attempt-windows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt-windows.d.ts","sourceRoot":"","sources":["../../src/store/attempt-windows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAE/F,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAKjE,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,aAAc,iBAAiB;;CAuD/D,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { AttemptWindows, windowOf, windowsOverlap } from "@usine/core/attempt";
2
+ import { and, eq, inArray, ne } from "drizzle-orm";
3
+ import { Effect, Option } from "effect";
4
+ import { attempts, runs, triggerEvents } from "../database/schema.js";
5
+ import { attemptFromRow, decodeAttemptRows } from "./codec.js";
6
+ import { attemptSelection } from "./queries.js";
7
+ /** Returns the Attempt window queries that run on the caller's transaction. */
8
+ export const attemptWindowQueries = (database) => {
9
+ /**
10
+ * Returns the window of `attemptId` and the overlapping windows of the same Agent's other
11
+ * Attempts on the Item. An Attempt that ended before end times were recorded has no window: for
12
+ * `attemptId` the result is empty, and other such Attempts are left out. Dies if `attemptId`
13
+ * isn't recorded.
14
+ */
15
+ const attemptWindows = Effect.fn("RunStoreQueries.attemptWindows")(function* (attemptId) {
16
+ yield* Effect.annotateCurrentSpan({ attemptId });
17
+ const [own] = yield* database
18
+ .select(attemptSelection)
19
+ .from(attempts)
20
+ .where(eq(attempts.attemptId, attemptId))
21
+ .execute()
22
+ .pipe(Effect.flatMap(decodeAttemptRows));
23
+ if (own === undefined)
24
+ return yield* Effect.die(new Error(`No attempt ${attemptId} recorded`));
25
+ const ownWindow = windowOf(attemptFromRow(own));
26
+ if (Option.isNone(ownWindow)) {
27
+ yield* Effect.logDebug("The Attempt ended before end times were recorded, so it has no window and none overlaps it", { attemptId });
28
+ return new AttemptWindows({ own: ownWindow, overlapping: [] });
29
+ }
30
+ const item = database
31
+ .select({ itemKey: triggerEvents.itemKey })
32
+ .from(runs)
33
+ .innerJoin(triggerEvents, eq(triggerEvents.eventId, runs.eventId))
34
+ .where(eq(runs.runId, own.runId));
35
+ const others = yield* database
36
+ .select(attemptSelection)
37
+ .from(attempts)
38
+ .innerJoin(runs, eq(runs.runId, attempts.runId))
39
+ .innerJoin(triggerEvents, eq(triggerEvents.eventId, runs.eventId))
40
+ .where(and(inArray(triggerEvents.itemKey, item), eq(attempts.agent, own.agent), ne(attempts.attemptId, attemptId)))
41
+ .orderBy(attempts.startedAt)
42
+ .execute()
43
+ .pipe(Effect.flatMap(decodeAttemptRows));
44
+ return new AttemptWindows({
45
+ own: ownWindow,
46
+ overlapping: others
47
+ .flatMap((row) => Option.toArray(windowOf(attemptFromRow(row))))
48
+ .filter((window) => windowsOverlap(ownWindow.value, window)),
49
+ });
50
+ });
51
+ return { attemptWindows };
52
+ };
53
+ //# sourceMappingURL=attempt-windows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt-windows.js","sourceRoot":"","sources":["../../src/store/attempt-windows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,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