@usine/orchestrator 0.0.1 → 0.2.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 (114) hide show
  1. package/README.md +146 -2
  2. package/dist/board/items.d.ts +18 -0
  3. package/dist/board/items.d.ts.map +1 -0
  4. package/dist/board/items.js +46 -0
  5. package/dist/board/items.js.map +1 -0
  6. package/dist/board/projection.d.ts +9 -0
  7. package/dist/board/projection.d.ts.map +1 -0
  8. package/dist/board/projection.js +111 -0
  9. package/dist/board/projection.js.map +1 -0
  10. package/dist/board/tasks.d.ts +8 -0
  11. package/dist/board/tasks.d.ts.map +1 -0
  12. package/dist/board/tasks.js +86 -0
  13. package/dist/board/tasks.js.map +1 -0
  14. package/dist/credentials.d.ts +12 -0
  15. package/dist/credentials.d.ts.map +1 -0
  16. package/dist/credentials.js +62 -0
  17. package/dist/credentials.js.map +1 -0
  18. package/dist/exe-dev.d.ts +8 -0
  19. package/dist/exe-dev.d.ts.map +1 -0
  20. package/dist/exe-dev.js +17 -0
  21. package/dist/exe-dev.js.map +1 -0
  22. package/dist/idle-triggers.d.ts +6 -0
  23. package/dist/idle-triggers.d.ts.map +1 -0
  24. package/dist/idle-triggers.js +31 -0
  25. package/dist/idle-triggers.js.map +1 -0
  26. package/dist/label-reconciler.d.ts +30 -0
  27. package/dist/label-reconciler.d.ts.map +1 -0
  28. package/dist/label-reconciler.js +119 -0
  29. package/dist/label-reconciler.js.map +1 -0
  30. package/dist/local.d.ts +25 -0
  31. package/dist/local.d.ts.map +1 -0
  32. package/dist/local.js +53 -0
  33. package/dist/local.js.map +1 -0
  34. package/dist/operator/attempt.d.ts +66 -0
  35. package/dist/operator/attempt.d.ts.map +1 -0
  36. package/dist/operator/attempt.js +58 -0
  37. package/dist/operator/attempt.js.map +1 -0
  38. package/dist/operator/board.d.ts +119 -0
  39. package/dist/operator/board.d.ts.map +1 -0
  40. package/dist/operator/board.js +101 -0
  41. package/dist/operator/board.js.map +1 -0
  42. package/dist/operator/http.d.ts +114 -0
  43. package/dist/operator/http.d.ts.map +1 -0
  44. package/dist/operator/http.js +139 -0
  45. package/dist/operator/http.js.map +1 -0
  46. package/dist/operator/need.d.ts +66 -0
  47. package/dist/operator/need.d.ts.map +1 -0
  48. package/dist/operator/need.js +70 -0
  49. package/dist/operator/need.js.map +1 -0
  50. package/dist/operator/operator.d.ts +64 -0
  51. package/dist/operator/operator.d.ts.map +1 -0
  52. package/dist/operator/operator.js +363 -0
  53. package/dist/operator/operator.js.map +1 -0
  54. package/dist/operator/overview.d.ts +51 -0
  55. package/dist/operator/overview.d.ts.map +1 -0
  56. package/dist/operator/overview.js +48 -0
  57. package/dist/operator/overview.js.map +1 -0
  58. package/dist/operator/projection.d.ts +17 -0
  59. package/dist/operator/projection.d.ts.map +1 -0
  60. package/dist/operator/projection.js +138 -0
  61. package/dist/operator/projection.js.map +1 -0
  62. package/dist/operator/run.d.ts +38 -0
  63. package/dist/operator/run.d.ts.map +1 -0
  64. package/dist/operator/run.js +41 -0
  65. package/dist/operator/run.js.map +1 -0
  66. package/dist/operator/transcript.d.ts +57 -0
  67. package/dist/operator/transcript.d.ts.map +1 -0
  68. package/dist/operator/transcript.js +59 -0
  69. package/dist/operator/transcript.js.map +1 -0
  70. package/dist/orchestrator.d.ts +14 -0
  71. package/dist/orchestrator.d.ts.map +1 -0
  72. package/dist/orchestrator.js +14 -0
  73. package/dist/orchestrator.js.map +1 -0
  74. package/dist/polling/cycle.d.ts +51 -0
  75. package/dist/polling/cycle.d.ts.map +1 -0
  76. package/dist/polling/cycle.js +44 -0
  77. package/dist/polling/cycle.js.map +1 -0
  78. package/dist/polling/hints.d.ts +20 -0
  79. package/dist/polling/hints.d.ts.map +1 -0
  80. package/dist/polling/hints.js +54 -0
  81. package/dist/polling/hints.js.map +1 -0
  82. package/dist/polling/loop-evaluation.d.ts +21 -0
  83. package/dist/polling/loop-evaluation.d.ts.map +1 -0
  84. package/dist/polling/loop-evaluation.js +131 -0
  85. package/dist/polling/loop-evaluation.js.map +1 -0
  86. package/dist/polling/polling.d.ts +36 -0
  87. package/dist/polling/polling.d.ts.map +1 -0
  88. package/dist/polling/polling.js +296 -0
  89. package/dist/polling/polling.js.map +1 -0
  90. package/dist/polling/repository-sync.d.ts +45 -0
  91. package/dist/polling/repository-sync.d.ts.map +1 -0
  92. package/dist/polling/repository-sync.js +169 -0
  93. package/dist/polling/repository-sync.js.map +1 -0
  94. package/dist/polling-triggers.d.ts +4 -0
  95. package/dist/polling-triggers.d.ts.map +1 -0
  96. package/dist/polling-triggers.js +4 -0
  97. package/dist/polling-triggers.js.map +1 -0
  98. package/dist/schedule-triggers.d.ts +67 -0
  99. package/dist/schedule-triggers.d.ts.map +1 -0
  100. package/dist/schedule-triggers.js +401 -0
  101. package/dist/schedule-triggers.js.map +1 -0
  102. package/dist/scheduler.d.ts +15 -0
  103. package/dist/scheduler.d.ts.map +1 -0
  104. package/dist/scheduler.js +107 -0
  105. package/dist/scheduler.js.map +1 -0
  106. package/dist/trigger-submission.d.ts +69 -0
  107. package/dist/trigger-submission.d.ts.map +1 -0
  108. package/dist/trigger-submission.js +108 -0
  109. package/dist/trigger-submission.js.map +1 -0
  110. package/package.json +67 -5
  111. package/dist/index.d.ts +0 -8
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js +0 -8
  114. package/dist/index.js.map +0 -1
@@ -0,0 +1,401 @@
1
+ import { CycleGeneration } from "@usine/core/cycle-budget";
2
+ import { ConfigParser } from "@usine/config/parser";
3
+ import { environmentFor, repositoryContext } from "@usine/config/payload-slices";
4
+ import { matchesSelector } from "@usine/config/selector";
5
+ import { AttemptTask } from "@usine/core/attempt";
6
+ import { AgentName } from "@usine/core/agent";
7
+ import { DedupKey } from "@usine/core/event";
8
+ import { ItemKey } from "@usine/core/item";
9
+ import { LoopName } from "@usine/core/loop";
10
+ import { RepositoryName, canonicalRepositoryName } from "@usine/core/repository";
11
+ import { RunEngine, SubmissionResult, } from "@usine/engine/engine";
12
+ import { LoopControl } from "@usine/engine/loop-control";
13
+ import { ExpressionEngine } from "@usine/expression/expression-engine";
14
+ import { Clock, Context, Cron, DateTime, Duration, Effect, Layer, Option, Ref, Result, Schema, } from "effect";
15
+ import { configFileErrorLogFields, DEFAULT_BRANCH_REVISION, resolveTriggerLoop, submissionLogFields, triggerSubmission, } from "./trigger-submission.js";
16
+ /** Fanout submits into local SQLite, so it stays small to keep write transactions from piling up. */
17
+ const FANOUT_CONCURRENCY = 4;
18
+ /** How often the loop wakes when no schedule can name its next boundary. */
19
+ const IDLE_WAKE_MILLIS = 60_000;
20
+ const scheduleFailureLogFields = (error) => {
21
+ const common = { errorTag: error._tag, message: error.message };
22
+ if (error._tag === "ConfigFileError") {
23
+ return { ...common, ...configFileErrorLogFields(error) };
24
+ }
25
+ if (error._tag === "ExpressionCheckError" || error._tag === "ExpressionEvaluationError") {
26
+ return { ...common, expression: error.source };
27
+ }
28
+ return common;
29
+ };
30
+ /** A schedule loop whose agent is no longer in the loaded roster. */
31
+ export class ScheduleAgentFailure extends Schema.TaggedClass("@usine/orchestrator/ScheduleAgentFailure")("ScheduleAgentFailure", {
32
+ loop: LoopName,
33
+ agent: AgentName,
34
+ message: Schema.String,
35
+ }) {
36
+ }
37
+ /** A selected repository whose Tick could not be evaluated or submitted. */
38
+ export class ScheduleTickFailure extends Schema.TaggedClass("@usine/orchestrator/ScheduleTickFailure")("ScheduleTickFailure", {
39
+ loop: LoopName,
40
+ repository: RepositoryName,
41
+ scheduledAt: Schema.DateTimeUtc,
42
+ errorTag: Schema.NonEmptyString,
43
+ message: Schema.String,
44
+ }) {
45
+ }
46
+ /**
47
+ * A schedule whose cron boundaries could not be computed at this instant.
48
+ * Cron.prev and Cron.next fail inside a DST spring-forward gap even for a cron
49
+ * that parsed; the schedule retries next cycle and its siblings run.
50
+ */
51
+ export class ScheduleCronFailure extends Schema.TaggedClass("@usine/orchestrator/ScheduleCronFailure")("ScheduleCronFailure", {
52
+ loop: LoopName,
53
+ cron: Schema.String,
54
+ tz: Schema.String,
55
+ message: Schema.String,
56
+ }) {
57
+ }
58
+ export const ScheduleFailure = Schema.Union([
59
+ ScheduleAgentFailure,
60
+ ScheduleCronFailure,
61
+ ScheduleTickFailure,
62
+ ]);
63
+ /** The result of evaluating every schedule loop at one instant. */
64
+ export class ScheduleCycle extends Schema.Class("@usine/orchestrator/ScheduleCycle")({
65
+ loops: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
66
+ fanout: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
67
+ submissions: Schema.Array(SubmissionResult),
68
+ skipped: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
69
+ alreadyFired: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
70
+ failures: Schema.Array(ScheduleFailure),
71
+ nextTickAt: Schema.Option(Schema.DateTimeUtc),
72
+ }) {
73
+ }
74
+ const watchedSchedules = (instance) => instance.loops.flatMap((loop) => {
75
+ const trigger = loop.trigger;
76
+ if (trigger.on !== "schedule")
77
+ return [];
78
+ return [
79
+ {
80
+ loop,
81
+ repositories: instance.config.repos.filter((repository) => matchesSelector(loop.selector, repository)),
82
+ trigger,
83
+ },
84
+ ];
85
+ });
86
+ /**
87
+ * The latest occurrence at or before `now`; Cron.prev alone excludes an exact
88
+ * match. Across a DST fall-back one local time maps to two UTC instants and
89
+ * both are boundaries: the payload's zone-local time tells them apart in logs
90
+ * and the dedup ledger keeps each a single fact.
91
+ */
92
+ const latestScheduledAt = (cron, now) => {
93
+ const minuteBoundary = DateTime.toDateUtc(now);
94
+ minuteBoundary.setUTCSeconds(0, 0);
95
+ return DateTime.fromDateUnsafe(Cron.match(cron, minuteBoundary) ? minuteBoundary : Cron.prev(cron, minuteBoundary));
96
+ };
97
+ const nextScheduledAt = (cron, now) => DateTime.fromDateUnsafe(Cron.next(cron, DateTime.toDateUtc(now)));
98
+ const localTime = (scheduledAt, tz) => Option.match(DateTime.setZoneNamed(scheduledAt, tz), {
99
+ onNone: () => DateTime.formatIso(scheduledAt),
100
+ onSome: DateTime.formatIsoZoned,
101
+ });
102
+ const earliest = (values) => {
103
+ if (values.length === 0)
104
+ return Option.none();
105
+ return DateTime.make(Math.min(...values.map(DateTime.toEpochMillis)));
106
+ };
107
+ const itemKey = (repository) => ItemKey.make(JSON.stringify(["github", canonicalRepositoryName(repository.name)]));
108
+ const eventKey = (loop, repository, scheduledAt) => DedupKey.make(JSON.stringify([
109
+ loop.name,
110
+ canonicalRepositoryName(repository.name),
111
+ DateTime.formatIso(scheduledAt),
112
+ ]));
113
+ const tickPayload = (due) => ({
114
+ tick: {
115
+ scheduledAt: DateTime.formatIso(due.scheduledAt),
116
+ scheduledAtLocal: due.scheduledAtLocal,
117
+ cron: due.trigger.cron,
118
+ tz: due.trigger.tz,
119
+ },
120
+ });
121
+ /** Turns due schedule ticks into one Event per selected repository. */
122
+ export class ScheduleTriggers extends Context.Service()("@usine/orchestrator/ScheduleTriggers") {
123
+ static layer = Layer.effect(ScheduleTriggers, Effect.gen(function* () {
124
+ const config = yield* ConfigParser;
125
+ const expressions = yield* ExpressionEngine;
126
+ const runs = yield* RunEngine;
127
+ const loops = yield* LoopControl;
128
+ const latestCycle = yield* Ref.make(Option.none());
129
+ // Remembers fired ticks to skip repeat work. An empty map after a restart
130
+ // fires the latest missed tick (ADR 0007); the dedup ledger stays the
131
+ // correctness guarantee.
132
+ const lastFired = yield* Ref.make(new Map());
133
+ // Cron sources were validated at the config boundary, so parseUnsafe is
134
+ // safe and the result is cached instead of re-parsed each cycle.
135
+ const parsedCrons = new WeakMap();
136
+ const cronFor = (trigger) => {
137
+ const cached = parsedCrons.get(trigger);
138
+ if (cached !== undefined)
139
+ return cached;
140
+ const parsed = Cron.parseUnsafe(trigger.cron, trigger.tz);
141
+ parsedCrons.set(trigger, parsed);
142
+ return parsed;
143
+ };
144
+ const submitTick = Effect.fn("ScheduleTriggers.submitTick")(function* (due, receivedAt) {
145
+ yield* Effect.annotateCurrentSpan({
146
+ loop: due.loop.name,
147
+ repository: due.repository.name,
148
+ agent: due.agent.name,
149
+ scheduledAt: DateTime.formatIso(due.scheduledAt),
150
+ });
151
+ const payload = tickPayload(due);
152
+ const context = { repo: repositoryContext(due.repository), item: payload };
153
+ const matches = yield* expressions.evaluateBoolean(due.trigger.if, environmentFor("schedule"), context);
154
+ if (!matches) {
155
+ yield* Effect.logDebug("Scheduled Tick did not match its expression", {
156
+ loop: due.loop.name,
157
+ repository: due.repository.name,
158
+ agent: due.agent.name,
159
+ scheduledAt: DateTime.formatIso(due.scheduledAt),
160
+ });
161
+ return Option.none();
162
+ }
163
+ const dedupKey = eventKey(due.loop, due.repository, due.scheduledAt);
164
+ const task = yield* config.renderPrompt(due.loop, context);
165
+ const submitted = yield* runs.submit(triggerSubmission({
166
+ cycleGeneration: CycleGeneration.make(0),
167
+ agent: due.agent,
168
+ dedupKey,
169
+ itemKey: itemKey(due.repository),
170
+ loop: due.loop,
171
+ payload,
172
+ receivedAt,
173
+ repository: due.repository,
174
+ revision: DEFAULT_BRANCH_REVISION,
175
+ task: AttemptTask.make(task),
176
+ parentModel: due.parentModel,
177
+ }));
178
+ yield* Effect.logInfo("Submitted scheduled Tick", {
179
+ loop: due.loop.name,
180
+ repository: due.repository.name,
181
+ agent: due.agent.name,
182
+ scheduledAt: DateTime.formatIso(due.scheduledAt),
183
+ scheduledAtLocal: due.scheduledAtLocal,
184
+ result: submitted._tag,
185
+ ...submissionLogFields(submitted),
186
+ });
187
+ return Option.some(submitted);
188
+ });
189
+ const tick = Effect.fn("ScheduleTriggers.tick")(function* (instance) {
190
+ const now = yield* DateTime.now;
191
+ const paused = new Set((yield* loops.states).filter((state) => state.paused).map((state) => state.loop));
192
+ for (const loop of instance.loops) {
193
+ if (loop.trigger.on === "schedule" && paused.has(loop.name)) {
194
+ yield* Effect.logDebug("Paused Loop skipped during schedule evaluation", {
195
+ loop: loop.name,
196
+ });
197
+ }
198
+ }
199
+ const schedules = watchedSchedules(instance).filter(({ loop }) => !paused.has(loop.name));
200
+ const fired = yield* Ref.get(lastFired);
201
+ const due = [];
202
+ const agentFailures = [];
203
+ const cronFailures = [];
204
+ const boundariesByLoop = new Map();
205
+ const nexts = [];
206
+ let alreadyFired = 0;
207
+ for (const schedule of schedules) {
208
+ if (schedule.repositories.length === 0) {
209
+ yield* Effect.logWarning("Schedule loop selected no repositories", {
210
+ loop: schedule.loop.name,
211
+ });
212
+ }
213
+ // Cron evaluation throws inside a DST spring-forward gap even though
214
+ // the expression parsed; one schedule's bad instant must not stop the
215
+ // stream.
216
+ const computed = yield* Effect.try({
217
+ try: () => {
218
+ const cron = cronFor(schedule.trigger);
219
+ const latest = latestScheduledAt(cron, now);
220
+ return {
221
+ latest,
222
+ latestLocal: localTime(latest, schedule.trigger.tz),
223
+ next: nextScheduledAt(cron, now),
224
+ };
225
+ },
226
+ catch: (cause) => cause,
227
+ }).pipe(Effect.result);
228
+ if (Result.isFailure(computed)) {
229
+ yield* Effect.logError("Schedule cron boundaries could not be computed", {
230
+ loop: schedule.loop.name,
231
+ cron: schedule.trigger.cron,
232
+ tz: schedule.trigger.tz,
233
+ message: String(computed.failure),
234
+ });
235
+ cronFailures.push(new ScheduleCronFailure({
236
+ loop: schedule.loop.name,
237
+ cron: schedule.trigger.cron,
238
+ tz: schedule.trigger.tz,
239
+ message: String(computed.failure),
240
+ }));
241
+ continue;
242
+ }
243
+ const boundaries = computed.success;
244
+ nexts.push(boundaries.next);
245
+ const latestEpoch = DateTime.toEpochMillis(boundaries.latest);
246
+ const last = fired.get(schedule.loop.name);
247
+ if (last !== undefined && last >= latestEpoch) {
248
+ alreadyFired += 1;
249
+ yield* Effect.logDebug("Tick already fired", {
250
+ loop: schedule.loop.name,
251
+ scheduledAt: DateTime.formatIso(boundaries.latest),
252
+ });
253
+ continue;
254
+ }
255
+ const resolved = yield* Effect.result(resolveTriggerLoop(instance, schedule.loop));
256
+ if (Result.isFailure(resolved)) {
257
+ const error = resolved.failure;
258
+ yield* Effect.logError("Schedule loop could not resolve its Agent", {
259
+ loop: error.loop,
260
+ agent: error.agent,
261
+ errorTag: error._tag,
262
+ message: error.message,
263
+ });
264
+ agentFailures.push(new ScheduleAgentFailure({
265
+ loop: error.loop,
266
+ agent: error.agent,
267
+ message: error.message,
268
+ }));
269
+ continue;
270
+ }
271
+ if (schedule.repositories.length === 0)
272
+ continue;
273
+ boundariesByLoop.set(schedule.loop.name, latestEpoch);
274
+ yield* Effect.logInfo("Schedule tick due", {
275
+ loop: schedule.loop.name,
276
+ agent: resolved.success.agent.name,
277
+ cron: schedule.trigger.cron,
278
+ tz: schedule.trigger.tz,
279
+ scheduledAt: DateTime.formatIso(boundaries.latest),
280
+ scheduledAtLocal: boundaries.latestLocal,
281
+ repositories: schedule.repositories.length,
282
+ nextTickAt: DateTime.formatIso(boundaries.next),
283
+ });
284
+ for (const repository of schedule.repositories) {
285
+ due.push({
286
+ agent: resolved.success.agent,
287
+ loop: schedule.loop,
288
+ parentModel: resolved.success.parentModel,
289
+ repository,
290
+ scheduledAt: boundaries.latest,
291
+ scheduledAtLocal: boundaries.latestLocal,
292
+ trigger: schedule.trigger,
293
+ });
294
+ }
295
+ }
296
+ yield* Effect.annotateCurrentSpan({ schedules: schedules.length, fanout: due.length });
297
+ const settled = yield* Effect.forEach(due, (candidate) => Effect.result(submitTick(candidate, now)).pipe(Effect.map((result) => ({ candidate, result }))), { concurrency: FANOUT_CONCURRENCY });
298
+ const submissions = [];
299
+ const tickFailures = [];
300
+ const submittedLoops = new Set();
301
+ const failedLoops = new Set();
302
+ let skipped = 0;
303
+ for (const { candidate, result } of settled) {
304
+ if (Result.isSuccess(result)) {
305
+ if (Option.isSome(result.success)) {
306
+ submissions.push(result.success.value);
307
+ submittedLoops.add(candidate.loop.name);
308
+ }
309
+ else
310
+ skipped += 1;
311
+ continue;
312
+ }
313
+ const error = result.failure;
314
+ failedLoops.add(candidate.loop.name);
315
+ yield* Effect.logError("Scheduled Tick failed; sibling fanout was unaffected", {
316
+ loop: candidate.loop.name,
317
+ repository: candidate.repository.name,
318
+ agent: candidate.agent.name,
319
+ scheduledAt: DateTime.formatIso(candidate.scheduledAt),
320
+ ...scheduleFailureLogFields(error),
321
+ });
322
+ tickFailures.push(new ScheduleTickFailure({
323
+ loop: candidate.loop.name,
324
+ repository: candidate.repository.name,
325
+ scheduledAt: candidate.scheduledAt,
326
+ errorTag: error._tag,
327
+ message: error.message,
328
+ }));
329
+ }
330
+ // Only loops that submitted without a failure advance the fired-tick
331
+ // memory: an all-unmatched tick keeps re-evaluating so a fixed `if:`
332
+ // still fires it, a failed loop retries every repository next cycle, and
333
+ // the dedup ledger absorbs the submissions that already landed.
334
+ yield* Ref.update(lastFired, (current) => {
335
+ const next = new Map(current);
336
+ for (const [loop, latestEpoch] of boundariesByLoop) {
337
+ if (submittedLoops.has(loop) && !failedLoops.has(loop)) {
338
+ next.set(loop, latestEpoch);
339
+ }
340
+ }
341
+ return next;
342
+ });
343
+ const cycle = new ScheduleCycle({
344
+ loops: schedules.length,
345
+ fanout: due.length,
346
+ submissions,
347
+ skipped,
348
+ alreadyFired,
349
+ failures: [...agentFailures, ...cronFailures, ...tickFailures],
350
+ nextTickAt: earliest(nexts),
351
+ });
352
+ yield* Ref.set(latestCycle, Option.some(cycle));
353
+ return cycle;
354
+ });
355
+ // `run` never returns, so wrapping it in Effect.fn would open a span that
356
+ // never closes; `tick` opens the span for each cycle.
357
+ const run = (instance) => Effect.gen(function* () {
358
+ const result = yield* Effect.result(tick(instance));
359
+ if (Result.isFailure(result)) {
360
+ yield* Effect.logError("Schedule cycle could not read Loop runtime state; retrying", {
361
+ errorTag: result.failure._tag,
362
+ message: result.failure.message,
363
+ operation: result.failure.operation,
364
+ sleepMs: IDLE_WAKE_MILLIS,
365
+ });
366
+ yield* Effect.sleep(Duration.millis(IDLE_WAKE_MILLIS));
367
+ return;
368
+ }
369
+ const cycle = result.success;
370
+ const now = yield* Clock.currentTimeMillis;
371
+ const target = Option.match(cycle.nextTickAt, {
372
+ onNone: () => now + IDLE_WAKE_MILLIS,
373
+ onSome: DateTime.toEpochMillis,
374
+ });
375
+ const sleepMs = Math.min(IDLE_WAKE_MILLIS, Math.max(0, target - now));
376
+ const summary = {
377
+ loops: cycle.loops,
378
+ fanout: cycle.fanout,
379
+ submissions: cycle.submissions.length,
380
+ skipped: cycle.skipped,
381
+ alreadyFired: cycle.alreadyFired,
382
+ failures: cycle.failures.length,
383
+ nextTickAt: Option.match(cycle.nextTickAt, {
384
+ onNone: () => "none",
385
+ onSome: DateTime.formatIso,
386
+ }),
387
+ sleepMs,
388
+ };
389
+ // Quiet cycles log at Debug; cycles that acted or failed log at Info.
390
+ if (cycle.fanout === 0 && cycle.failures.length === 0) {
391
+ yield* Effect.logDebug("Schedule cycle complete", summary);
392
+ }
393
+ else {
394
+ yield* Effect.logInfo("Schedule cycle complete", summary);
395
+ }
396
+ yield* Effect.sleep(Duration.millis(sleepMs));
397
+ }).pipe(Effect.forever);
398
+ return { latest: Ref.get(latestCycle), run, tick };
399
+ }));
400
+ }
401
+ //# sourceMappingURL=schedule-triggers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule-triggers.js","sourceRoot":"","sources":["../src/schedule-triggers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAM3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,M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5D,CAAC;YACD,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACrD,CAAC,CAAC,CACH,CAAC;CACH"}
@@ -0,0 +1,15 @@
1
+ import type { UsineConfig } from "@usine/config/factory";
2
+ import type { BrainSpec } from "@usine/core/agent/brain";
3
+ import { Executor, ExecutorError } from "@usine/executor";
4
+ import { StepExecutor } from "@usine/engine/step-executor";
5
+ import { Layer, Schema } from "effect";
6
+ declare const UnsupportedWorkerError_base: Schema.Class<UnsupportedWorkerError, Schema.TaggedStruct<"UnsupportedWorkerError", {
7
+ readonly worker: Schema.brand<Schema.String, "WorkerName">;
8
+ readonly kind: Schema.String;
9
+ }>, import("effect/Cause").YieldableError>;
10
+ export declare class UnsupportedWorkerError extends UnsupportedWorkerError_base {
11
+ }
12
+ /** Schedules Attempts FIFO over the configured Workers and adapts the Executor to the engine's StepExecutor port. */
13
+ export declare const stepExecutorLayer: (config: UsineConfig, brains: ReadonlyArray<BrainSpec>) => Layer.Layer<StepExecutor, ExecutorError | UnsupportedWorkerError, Executor>;
14
+ export {};
15
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA0B,MAAM,uBAAuB,CAAC;AAEjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAEL,QAAQ,EACR,aAAa,EAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAIL,KAAK,EAKL,MAAM,EAEP,MAAM,QAAQ,CAAC;;;;;AAEhB,qBAAa,sBAAuB,SAAQ,2BAK1C;CAAG;AAsDL,qHAAqH;AACrH,eAAO,MAAM,iBAAiB,WACpB,WAAW,UACX,aAAa,CAAC,SAAS,CAAC,KAC/B,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,GAAG,sBAAsB,EAAE,QAAQ,CA2G1E,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { resolveParentEffort } from "@usine/core/agent";
2
+ import { AgentFailure, InfraFailure } from "@usine/core/attempt/failure";
3
+ import { WorkerName } from "@usine/core/worker";
4
+ import { CheckoutRequest, Executor, ExecutorError, } from "@usine/executor";
5
+ import { StepExecutor } from "@usine/engine/step-executor";
6
+ import { DateTime, Deferred, Effect, Layer, Option, Order, Queue, Ref, Schema, TxPriorityQueue, } from "effect";
7
+ export class UnsupportedWorkerError extends Schema.TaggedError("@usine/orchestrator/UnsupportedWorkerError")("UnsupportedWorkerError", {
8
+ worker: WorkerName,
9
+ kind: Schema.String,
10
+ }) {
11
+ }
12
+ const reservationOrder = Order.combine(Order.mapInput(Order.Number, (reservation) => reservation.eventTime), Order.mapInput(Order.Number, (reservation) => reservation.order));
13
+ const asAttemptFailure = (error) => error._tag === "WorkerCapabilityError"
14
+ ? new AgentFailure({ message: error.message })
15
+ : new InfraFailure({
16
+ message: error._tag === "ExecutorOperationError"
17
+ ? `Executor ${error.operation} failed: ${error.message}`
18
+ : error.message,
19
+ cause: error,
20
+ });
21
+ const makeLease = Effect.fn("WorkerScheduler.makeLease")(function* (worker, available) {
22
+ const released = yield* Ref.make(false);
23
+ return {
24
+ worker,
25
+ release: Ref.modify(released, (done) => [!done, true]).pipe(Effect.flatMap((first) => (first ? Queue.offer(available, worker) : Effect.void)), Effect.asVoid),
26
+ };
27
+ });
28
+ const validateWorkers = (kind, workers) => {
29
+ const unsupported = workers.find((worker) => worker.kind !== kind);
30
+ return unsupported === undefined
31
+ ? Effect.succeed(workers)
32
+ : new UnsupportedWorkerError({ worker: unsupported.name, kind: unsupported.kind });
33
+ };
34
+ /** Schedules Attempts FIFO over the configured Workers and adapts the Executor to the engine's StepExecutor port. */
35
+ export const stepExecutorLayer = (config, brains) => Layer.effect(StepExecutor, Effect.gen(function* () {
36
+ const executor = yield* Executor;
37
+ const workers = yield* validateWorkers(executor.kind, config.workers);
38
+ yield* Effect.forEach(workers, ({ name }) => executor.preflight(name, brains), {
39
+ concurrency: "unbounded",
40
+ discard: true,
41
+ });
42
+ const available = yield* Queue.make();
43
+ yield* Queue.offerAll(available, workers.flatMap(({ maxConcurrentAttempts, name }) => Array.from({ length: maxConcurrentAttempts }, () => name)));
44
+ const pending = yield* TxPriorityQueue.empty(reservationOrder);
45
+ const nextOrder = yield* Ref.make(0);
46
+ const dispatch = Effect.forever(Effect.gen(function* () {
47
+ const worker = yield* Queue.take(available);
48
+ const reservation = yield* TxPriorityQueue.take(pending);
49
+ const lease = yield* makeLease(worker, available);
50
+ const assign = yield* Ref.modify(reservation.state, (state) => state._tag === "Pending"
51
+ ? [true, { _tag: "Assigned", lease }]
52
+ : [false, state]);
53
+ if (assign) {
54
+ yield* Effect.logDebug("Worker slot assigned", { worker });
55
+ yield* Deferred.succeed(reservation.deferred, lease);
56
+ }
57
+ else {
58
+ yield* lease.release;
59
+ }
60
+ }));
61
+ yield* Effect.forkScoped(dispatch);
62
+ const reserve = Effect.fn("WorkerScheduler.reserve")(function* (submission) {
63
+ const deferred = yield* Deferred.make();
64
+ const state = yield* Ref.make({ _tag: "Pending" });
65
+ const reservation = {
66
+ deferred,
67
+ eventTime: DateTime.toEpochMillis(submission.event.receivedAt),
68
+ order: yield* Ref.getAndUpdate(nextOrder, (value) => value + 1),
69
+ state,
70
+ };
71
+ yield* TxPriorityQueue.offer(pending, reservation);
72
+ yield* Effect.logInfo("Run waits for a worker slot", {
73
+ loop: submission.loop,
74
+ itemKey: submission.itemKey,
75
+ queued: yield* TxPriorityQueue.size(pending),
76
+ });
77
+ return yield* Deferred.await(deferred).pipe(Effect.onInterrupt(() => Ref.modify(state, (current) => current._tag === "Assigned"
78
+ ? [Option.some(current.lease), { _tag: "Canceled" }]
79
+ : [Option.none(), { _tag: "Canceled" }]).pipe(Effect.flatMap(Option.match({ onNone: () => Effect.void, onSome: (lease) => lease.release })))));
80
+ });
81
+ const execute = Effect.fn("WorkerScheduler.execute")(function* (execution, io) {
82
+ yield* Effect.annotateCurrentSpan({
83
+ attemptId: execution.attempt.id,
84
+ runId: execution.run.id,
85
+ worker: execution.attempt.worker,
86
+ });
87
+ const prepared = yield* executor
88
+ .prepare(new CheckoutRequest({
89
+ attemptId: execution.attempt.id,
90
+ worker: execution.attempt.worker,
91
+ repository: execution.repository,
92
+ revision: execution.revision,
93
+ payload: execution.event.payload,
94
+ task: execution.task,
95
+ agent: execution.agent,
96
+ parentModel: execution.parentModel,
97
+ maxChildren: config.settings.maxChildren,
98
+ maxAttemptMinutes: config.settings.maxAttemptMinutes,
99
+ parentEffort: resolveParentEffort(execution.agent, config.settings.parentEffort),
100
+ }))
101
+ .pipe(Effect.mapError(asAttemptFailure));
102
+ return yield* prepared.launch(io);
103
+ }, Effect.scoped);
104
+ const interrupt = (attemptId) => executor.cancel(attemptId).pipe(Effect.mapError(asAttemptFailure));
105
+ return StepExecutor.of({ execute, interrupt, reserve });
106
+ }));
107
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,QAAQ,EACR,aAAa,GAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YA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MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM;YAChC,UAAU,EAAE,SAAS,CAAC,UAAU;YAChC,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,OAAO;YAChC,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,WAAW,EAAE,SAAS,CAAC,WAAW;YAClC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW;YACxC,iBAAiB,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB;YACpD,YAAY,EAAE,mBAAmB,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC;SACjF,CAAC,CACH;aACA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC3C,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC,EACD,MAAM,CAAC,MAAM,CACd,CAAC;IAEF,MAAM,SAAS,GAAyC,CAAC,SAAS,EAAE,EAAE,CACpE,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAErE,OAAO,YAAY,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { ConfigFileError } from "@usine/config/file";
2
+ import type { LoadedInstance } from "@usine/config/instance";
3
+ import type { LoopFile } from "@usine/config/loop";
4
+ import type { ManagedRepo } from "@usine/config/factory";
5
+ import { Agent } from "@usine/core/agent";
6
+ import { ModelId } from "@usine/core/agent/brain";
7
+ import { AttemptTask } from "@usine/core/attempt";
8
+ import { DedupKey } from "@usine/core/event";
9
+ import { CycleGeneration } from "@usine/core/cycle-budget";
10
+ import { ItemKey } from "@usine/core/item";
11
+ import { RepositoryRevision } from "@usine/core/repository";
12
+ import { Submission, type SubmissionResult } from "@usine/engine/engine";
13
+ import { type DateTime, Effect, Option, Schema } from "effect";
14
+ /** Issue and schedule Attempts resolve the remote's default branch at prepare time. */
15
+ export declare const DEFAULT_BRANCH_REVISION: string & import("effect/Brand").Brand<"RepositoryRevision">;
16
+ export interface ResolvedLoop {
17
+ readonly agent: Agent;
18
+ readonly loop: LoopFile;
19
+ readonly parentModel: Option.Option<ModelId>;
20
+ }
21
+ declare const LoopAgentResolutionError_base: Schema.Class<LoopAgentResolutionError, Schema.TaggedStruct<"LoopAgentResolutionError", {
22
+ readonly loop: Schema.brand<Schema.NonEmptyString, "LoopName">;
23
+ readonly agent: Schema.brand<Schema.String, "AgentName">;
24
+ readonly message: Schema.NonEmptyString;
25
+ }>, import("effect/Cause").YieldableError>;
26
+ /** The agent a loaded loop names is no longer in the roster. */
27
+ export declare class LoopAgentResolutionError extends LoopAgentResolutionError_base {
28
+ }
29
+ /** Resolves one loop's roster agent and effective parent model. */
30
+ export declare const resolveTriggerLoop: (instance: LoadedInstance, loop: LoopFile) => Effect.Effect<{
31
+ agent: Agent;
32
+ loop: LoopFile;
33
+ parentModel: Option.Option<string & import("effect/Brand").Brand<"ModelId">>;
34
+ }, LoopAgentResolutionError, never>;
35
+ /**
36
+ * Resolves every loaded loop's agent. `InstanceFolder.load` already quarantines
37
+ * loops that name unknown agents, so a miss here means a hand-assembled
38
+ * instance drifted: the loop is skipped with a log each cycle and its siblings
39
+ * keep running.
40
+ */
41
+ export declare const resolveTriggerLoops: (instance: LoadedInstance) => Effect.Effect<ResolvedLoop[], never, never>;
42
+ interface TriggerSubmissionOptions {
43
+ readonly agent: Agent;
44
+ readonly dedupKey: DedupKey;
45
+ readonly cycleGeneration: CycleGeneration;
46
+ readonly itemKey: ItemKey;
47
+ readonly loop: LoopFile;
48
+ readonly payload: Schema.Json;
49
+ readonly receivedAt: DateTime.Utc;
50
+ readonly repository: ManagedRepo;
51
+ readonly revision: RepositoryRevision;
52
+ readonly task: AttemptTask;
53
+ readonly parentModel: Option.Option<ModelId>;
54
+ }
55
+ /** Builds the Submission every trigger stream hands to the engine. */
56
+ export declare const triggerSubmission: (options: TriggerSubmissionOptions) => Submission;
57
+ /** The log fields for a submission outcome: the run id for a claim, the reason for an ignore. */
58
+ export declare const submissionLogFields: (submission: SubmissionResult) => Record<string, string>;
59
+ /** Log fields for a config failure met while triggering. */
60
+ export declare const configFileErrorLogFields: (error: ConfigFileError) => {
61
+ configFile: string & import("effect/Brand").Brand<"InstancePath">;
62
+ configStage: "expression" | "frontmatter" | "read" | "reference" | "schema" | "yaml";
63
+ } | {
64
+ configFile: string & import("effect/Brand").Brand<"InstancePath">;
65
+ configStage: "expression" | "frontmatter" | "read" | "reference" | "schema" | "yaml";
66
+ expression: string & import("effect/Brand").Brand<"ExpressionSource">;
67
+ };
68
+ export {};
69
+ //# sourceMappingURL=trigger-submission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-submission.d.ts","sourceRoot":"","sources":["../src/trigger-submission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAiC,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAa,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAS,QAAQ,EAAW,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA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