@usine/orchestrator 0.2.1 → 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 (173) hide show
  1. package/README.md +151 -52
  2. package/dist/board/items.d.ts +9 -1
  3. package/dist/board/items.d.ts.map +1 -1
  4. package/dist/board/items.js +16 -4
  5. package/dist/board/items.js.map +1 -1
  6. package/dist/board/projection.d.ts +7 -1
  7. package/dist/board/projection.d.ts.map +1 -1
  8. package/dist/board/projection.js +53 -14
  9. package/dist/board/projection.js.map +1 -1
  10. package/dist/board/tasks.d.ts +14 -2
  11. package/dist/board/tasks.d.ts.map +1 -1
  12. package/dist/board/tasks.js +23 -8
  13. package/dist/board/tasks.js.map +1 -1
  14. package/dist/credentials.d.ts +5 -6
  15. package/dist/credentials.d.ts.map +1 -1
  16. package/dist/credentials.js +22 -15
  17. package/dist/credentials.js.map +1 -1
  18. package/dist/current-instance/changes.d.ts +87 -0
  19. package/dist/current-instance/changes.d.ts.map +1 -0
  20. package/dist/current-instance/changes.js +138 -0
  21. package/dist/current-instance/changes.js.map +1 -0
  22. package/dist/current-instance/current-instance.d.ts +89 -0
  23. package/dist/current-instance/current-instance.d.ts.map +1 -0
  24. package/dist/current-instance/current-instance.js +163 -0
  25. package/dist/current-instance/current-instance.js.map +1 -0
  26. package/dist/exe-dev.d.ts +6 -2
  27. package/dist/exe-dev.d.ts.map +1 -1
  28. package/dist/exe-dev.js +7 -8
  29. package/dist/exe-dev.js.map +1 -1
  30. package/dist/idle-triggers.d.ts +1 -1
  31. package/dist/idle-triggers.d.ts.map +1 -1
  32. package/dist/idle-triggers.js +1 -1
  33. package/dist/idle-triggers.js.map +1 -1
  34. package/dist/label-reconciler.d.ts +5 -2
  35. package/dist/label-reconciler.d.ts.map +1 -1
  36. package/dist/label-reconciler.js.map +1 -1
  37. package/dist/local.d.ts +4 -18
  38. package/dist/local.d.ts.map +1 -1
  39. package/dist/local.js +7 -45
  40. package/dist/local.js.map +1 -1
  41. package/dist/loop-matches.d.ts +28 -0
  42. package/dist/loop-matches.d.ts.map +1 -0
  43. package/dist/loop-matches.js +74 -0
  44. package/dist/loop-matches.js.map +1 -0
  45. package/dist/operator/attempt.d.ts +57 -10
  46. package/dist/operator/attempt.d.ts.map +1 -1
  47. package/dist/operator/attempt.js +49 -10
  48. package/dist/operator/attempt.js.map +1 -1
  49. package/dist/operator/board.d.ts +43 -16
  50. package/dist/operator/board.d.ts.map +1 -1
  51. package/dist/operator/board.js +43 -16
  52. package/dist/operator/board.js.map +1 -1
  53. package/dist/operator/configuration.d.ts +258 -0
  54. package/dist/operator/configuration.d.ts.map +1 -0
  55. package/dist/operator/configuration.js +410 -0
  56. package/dist/operator/configuration.js.map +1 -0
  57. package/dist/operator/desk.d.ts +181 -0
  58. package/dist/operator/desk.d.ts.map +1 -0
  59. package/dist/operator/desk.js +463 -0
  60. package/dist/operator/desk.js.map +1 -0
  61. package/dist/operator/github-changes.d.ts +88 -0
  62. package/dist/operator/github-changes.d.ts.map +1 -0
  63. package/dist/operator/github-changes.js +266 -0
  64. package/dist/operator/github-changes.js.map +1 -0
  65. package/dist/operator/http.d.ts +152 -57
  66. package/dist/operator/http.d.ts.map +1 -1
  67. package/dist/operator/http.js +140 -21
  68. package/dist/operator/http.js.map +1 -1
  69. package/dist/operator/need.d.ts +44 -11
  70. package/dist/operator/need.d.ts.map +1 -1
  71. package/dist/operator/need.js +46 -9
  72. package/dist/operator/need.js.map +1 -1
  73. package/dist/operator/operator.d.ts +109 -29
  74. package/dist/operator/operator.d.ts.map +1 -1
  75. package/dist/operator/operator.js +254 -52
  76. package/dist/operator/operator.js.map +1 -1
  77. package/dist/operator/overview.d.ts +7 -7
  78. package/dist/operator/overview.d.ts.map +1 -1
  79. package/dist/operator/overview.js +5 -5
  80. package/dist/operator/overview.js.map +1 -1
  81. package/dist/operator/projection.d.ts +54 -5
  82. package/dist/operator/projection.d.ts.map +1 -1
  83. package/dist/operator/projection.js +100 -9
  84. package/dist/operator/projection.js.map +1 -1
  85. package/dist/operator/run.d.ts +71 -6
  86. package/dist/operator/run.d.ts.map +1 -1
  87. package/dist/operator/run.js +69 -6
  88. package/dist/operator/run.js.map +1 -1
  89. package/dist/operator/task.d.ts +93 -0
  90. package/dist/operator/task.d.ts.map +1 -0
  91. package/dist/operator/task.js +204 -0
  92. package/dist/operator/task.js.map +1 -0
  93. package/dist/operator/transcript.d.ts +12 -12
  94. package/dist/operator/transcript.d.ts.map +1 -1
  95. package/dist/operator/transcript.js +11 -9
  96. package/dist/operator/transcript.js.map +1 -1
  97. package/dist/operator/usage.d.ts +111 -0
  98. package/dist/operator/usage.d.ts.map +1 -0
  99. package/dist/operator/usage.js +219 -0
  100. package/dist/operator/usage.js.map +1 -0
  101. package/dist/orchestrator.d.ts +8 -5
  102. package/dist/orchestrator.d.ts.map +1 -1
  103. package/dist/orchestrator.js +4 -2
  104. package/dist/orchestrator.js.map +1 -1
  105. package/dist/polling/cycle.d.ts +28 -10
  106. package/dist/polling/cycle.d.ts.map +1 -1
  107. package/dist/polling/cycle.js +20 -6
  108. package/dist/polling/cycle.js.map +1 -1
  109. package/dist/polling/evaluation-failures.d.ts +42 -0
  110. package/dist/polling/evaluation-failures.d.ts.map +1 -0
  111. package/dist/polling/evaluation-failures.js +103 -0
  112. package/dist/polling/evaluation-failures.js.map +1 -0
  113. package/dist/polling/hints.d.ts +2 -2
  114. package/dist/polling/hints.d.ts.map +1 -1
  115. package/dist/polling/hints.js +2 -2
  116. package/dist/polling/hints.js.map +1 -1
  117. package/dist/polling/loop-evaluation.d.ts +21 -11
  118. package/dist/polling/loop-evaluation.d.ts.map +1 -1
  119. package/dist/polling/loop-evaluation.js +70 -27
  120. package/dist/polling/loop-evaluation.js.map +1 -1
  121. package/dist/polling/open-issues.d.ts +23 -0
  122. package/dist/polling/open-issues.d.ts.map +1 -0
  123. package/dist/polling/open-issues.js +77 -0
  124. package/dist/polling/open-issues.js.map +1 -0
  125. package/dist/polling/polling.d.ts +20 -11
  126. package/dist/polling/polling.d.ts.map +1 -1
  127. package/dist/polling/polling.js +201 -51
  128. package/dist/polling/polling.js.map +1 -1
  129. package/dist/polling/repository-sync.d.ts +20 -14
  130. package/dist/polling/repository-sync.d.ts.map +1 -1
  131. package/dist/polling/repository-sync.js +34 -27
  132. package/dist/polling/repository-sync.js.map +1 -1
  133. package/dist/polling-triggers.d.ts +1 -1
  134. package/dist/polling-triggers.d.ts.map +1 -1
  135. package/dist/polling-triggers.js +1 -1
  136. package/dist/polling-triggers.js.map +1 -1
  137. package/dist/reloads.d.ts +14 -0
  138. package/dist/reloads.d.ts.map +1 -0
  139. package/dist/reloads.js +7 -0
  140. package/dist/reloads.js.map +1 -0
  141. package/dist/runtime.d.ts +24 -0
  142. package/dist/runtime.d.ts.map +1 -0
  143. package/dist/runtime.js +58 -0
  144. package/dist/runtime.js.map +1 -0
  145. package/dist/schedule-triggers.d.ts +14 -10
  146. package/dist/schedule-triggers.d.ts.map +1 -1
  147. package/dist/schedule-triggers.js +36 -31
  148. package/dist/schedule-triggers.js.map +1 -1
  149. package/dist/scheduler.d.ts +35 -4
  150. package/dist/scheduler.d.ts.map +1 -1
  151. package/dist/scheduler.js +327 -41
  152. package/dist/scheduler.js.map +1 -1
  153. package/dist/ssh.d.ts +39 -0
  154. package/dist/ssh.d.ts.map +1 -0
  155. package/dist/ssh.js +75 -0
  156. package/dist/ssh.js.map +1 -0
  157. package/dist/trigger-condition.d.ts +12 -0
  158. package/dist/trigger-condition.d.ts.map +1 -0
  159. package/dist/trigger-condition.js +88 -0
  160. package/dist/trigger-condition.js.map +1 -0
  161. package/dist/trigger-submission.d.ts +16 -13
  162. package/dist/trigger-submission.d.ts.map +1 -1
  163. package/dist/trigger-submission.js +19 -14
  164. package/dist/trigger-submission.js.map +1 -1
  165. package/dist/worker-engine.d.ts +10 -0
  166. package/dist/worker-engine.d.ts.map +1 -0
  167. package/dist/worker-engine.js +25 -0
  168. package/dist/worker-engine.js.map +1 -0
  169. package/dist/worker-status.d.ts +70 -0
  170. package/dist/worker-status.d.ts.map +1 -0
  171. package/dist/worker-status.js +55 -0
  172. package/dist/worker-status.js.map +1 -0
  173. package/package.json +31 -10
package/dist/scheduler.js CHANGED
@@ -1,52 +1,257 @@
1
1
  import { resolveParentEffort } from "@usine/core/agent";
2
2
  import { AgentFailure, InfraFailure } from "@usine/core/attempt/failure";
3
- import { WorkerName } from "@usine/core/worker";
4
- import { CheckoutRequest, Executor, ExecutorError, } from "@usine/executor";
3
+ import { salvageRefFor } from "@usine/core/attempt/salvage";
4
+ import { BotLogin, WorkerName } from "@usine/core/worker";
5
+ import { CheckoutRequest, Executor, ExecutorError, ExecutorOperationError } from "@usine/executor";
5
6
  import { StepExecutor } from "@usine/engine/step-executor";
6
- import { DateTime, Deferred, Effect, Layer, Option, Order, Queue, Ref, Schema, TxPriorityQueue, } from "effect";
7
+ import { GitHubApp } from "@usine/github/github-app";
8
+ import { Array as EffectArray, Context, DateTime, Deferred, Effect, Exit, Layer, Match, Option, Order, Ref, Schema, Semaphore, TxPriorityQueue, TxRef, } from "effect";
9
+ import { agentsWithNewBrains, workersChange, } from "./current-instance/changes.js";
10
+ import { CurrentInstance, reloadPreflightFailed, restartRequired, } from "./current-instance/current-instance.js";
11
+ import { recordPreflight, unchecked, WorkerStatus } from "./worker-status.js";
7
12
  export class UnsupportedWorkerError extends Schema.TaggedError("@usine/orchestrator/UnsupportedWorkerError")("UnsupportedWorkerError", {
8
13
  worker: WorkerName,
9
14
  kind: Schema.String,
10
15
  }) {
11
16
  }
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
- };
17
+ // Reservations for a specific Worker (Attempts already running there) go first; otherwise, the Run
18
+ // whose Event arrived first goes first.
19
+ const reservationOrder = Order.combineAll([
20
+ Order.mapInput(Order.Boolean, (reservation) => Option.isNone(reservation.worker)),
21
+ Order.mapInput(Order.Number, (reservation) => reservation.eventTime),
22
+ Order.mapInput(Order.Number, (reservation) => reservation.order),
23
+ ]);
24
+ const slotPoolOf = (workers, previous) => {
25
+ const declared = new Set(workers.map(({ name }) => name));
26
+ return new Map([
27
+ ...workers.map(({ name, maxConcurrentAttempts }) => [
28
+ name,
29
+ { capacity: maxConcurrentAttempts, leased: previous.get(name)?.leased ?? 0 },
30
+ ]),
31
+ ...[...previous]
32
+ .filter(([name, { leased }]) => !declared.has(name) && leased > 0)
33
+ .map(([name, { leased }]) => [name, { capacity: 0, leased }]),
34
+ ]);
35
+ };
36
+ const isFree = (pool, worker) => {
37
+ const slots = pool.get(worker);
38
+ return slots !== undefined && slots.leased < slots.capacity;
39
+ };
40
+ /**
41
+ * Returns the Worker with a free slot for `reservation`: its specified Worker, or else the first
42
+ * free one.
43
+ */
44
+ const workerFor = (pool, reservation) => Option.match(reservation.worker, {
45
+ onNone: () => Option.fromNullishOr([...pool.keys()].find((worker) => isFree(pool, worker))),
46
+ onSome: (worker) => (isFree(pool, worker) ? Option.some(worker) : Option.none()),
27
47
  });
48
+ const withLeased = (pool, worker, change) => {
49
+ const slots = pool.get(worker);
50
+ if (slots === undefined)
51
+ return pool;
52
+ return new Map(pool).set(worker, { ...slots, leased: slots.leased + change });
53
+ };
54
+ const releasedFrom = (pool, worker) => {
55
+ const slots = pool.get(worker);
56
+ if (slots === undefined)
57
+ return [{ _tag: "Dropped" }, pool];
58
+ if (slots.capacity === 0 && slots.leased <= 1) {
59
+ const next = new Map(pool);
60
+ next.delete(worker);
61
+ return [{ _tag: "Dropped" }, next];
62
+ }
63
+ const next = withLeased(pool, worker, -1);
64
+ return slots.leased > slots.capacity
65
+ ? [{ _tag: "Retired", running: slots.leased - 1, slots: slots.capacity }, next]
66
+ : [{ _tag: "Freed" }, next];
67
+ };
68
+ // Only errors that a retry can avoid become the `InfraFailure` that the engine retries.
69
+ const asAttemptFailure = (error) => Match.valueTags(error, {
70
+ WorkerCapabilityError: ({ message }) => new AgentFailure({ message }),
71
+ CredentialUnavailableError: ({ reason, message }) => reason === "refused"
72
+ ? new AgentFailure({ message })
73
+ : new InfraFailure({ message, cause: error }),
74
+ ExecutorOperationError: ({ operation, message }) => new InfraFailure({ message: `Executor ${operation} failed: ${message}`, cause: error }),
75
+ });
76
+ // The operation error has no Worker field, and reports must include the Worker.
77
+ const namingWorker = (worker) => (error) => error._tag === "ExecutorOperationError"
78
+ ? new ExecutorOperationError({
79
+ operation: error.operation,
80
+ message: `worker "${worker}": ${error.message}`,
81
+ cause: error.cause,
82
+ })
83
+ : error;
28
84
  const validateWorkers = (kind, workers) => {
29
85
  const unsupported = workers.find((worker) => worker.kind !== kind);
30
86
  return unsupported === undefined
31
87
  ? Effect.succeed(workers)
32
88
  : new UnsupportedWorkerError({ worker: unsupported.name, kind: unsupported.kind });
33
89
  };
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* () {
90
+ const brainLabel = ({ harness, model, effort }) => `${harness}/${model}/${effort}`;
91
+ /** The login that exe.dev Workers write to GitHub as, through exe.dev's integration (ADR 0011). */
92
+ const EXE_DEV_BOT_LOGIN = BotLogin.make("exe-dev-github-integration[bot]");
93
+ const decodeBotLogin = Schema.decodeUnknownOption(BotLogin);
94
+ /** The Worker set of an executor that runs any Worker of its kind by name. */
95
+ const anyWorker = { add: () => Effect.void, remove: () => Effect.void };
96
+ /**
97
+ * Schedules Attempts FIFO over the Workers and adapts the Executor to the engine's `StepExecutor`
98
+ * port. Reservations for a specific Worker go first (#177), and a removed Worker stays until its
99
+ * last Attempt ends.
100
+ */
101
+ export const stepExecutorLayer = (config, brains, options = {}) => Layer.effectContext(Effect.gen(function* () {
36
102
  const executor = yield* Executor;
103
+ const instances = yield* CurrentInstance;
104
+ const app = yield* GitHubApp;
37
105
  const workers = yield* validateWorkers(executor.kind, config.workers);
38
- yield* Effect.forEach(workers, ({ name }) => executor.preflight(name, brains), {
106
+ const pool = yield* TxRef.make(slotPoolOf(workers, new Map()));
107
+ const pending = yield* TxPriorityQueue.empty(reservationOrder);
108
+ const nextOrder = yield* Ref.make(0);
109
+ const preflights = yield* Ref.make(new Map());
110
+ const executorWorkers = options.workers ?? anyWorker;
111
+ // Every change to the executor's Workers takes this permit, so a removal never undoes an
112
+ // addition.
113
+ const membership = yield* Semaphore.make(1);
114
+ const adding = yield* Ref.make(new Set());
115
+ const recordPreflightExit = Effect.fn("WorkerScheduler.recordPreflight")(function* (worker, roster, exit) {
116
+ const failure = Exit.findErrorOption(exit);
117
+ // An interrupted or defective preflight gives no information about the Worker.
118
+ if (Exit.isFailure(exit) && Option.isNone(failure))
119
+ return;
120
+ const checkedAt = yield* DateTime.now;
121
+ yield* Ref.update(preflights, (current) => new Map(current).set(worker, recordPreflight(current.get(worker) ?? unchecked(worker), roster, checkedAt, failure)));
122
+ });
123
+ /**
124
+ * Runs `before`, then the Worker's preflight, and records both outcomes as the Worker's
125
+ * preflight.
126
+ */
127
+ const preflightWorker = (worker, roster, before = Effect.void) => before.pipe(Effect.andThen(executor.preflight(worker.name, roster, worker.maxConcurrentAttempts)), Effect.mapError(namingWorker(worker.name)), Effect.onExit((exit) => recordPreflightExit(worker.name, roster, exit)));
128
+ /**
129
+ * Removes `worker` from the executor unless the scheduler has it or a reload is adding it.
130
+ * Callers must hold `membership`.
131
+ */
132
+ const removeUnused = Effect.fn("WorkerScheduler.removeFromExecutor")(function* (worker) {
133
+ yield* Effect.annotateCurrentSpan({ worker });
134
+ const scheduled = (yield* TxRef.get(pool)).has(worker);
135
+ const added = (yield* Ref.get(adding)).has(worker);
136
+ if (scheduled || added) {
137
+ yield* Effect.logDebug("The Worker stays with the executor, because the scheduler has it or a reload is adding it", { worker, scheduled, added });
138
+ return;
139
+ }
140
+ yield* executorWorkers.remove(worker);
141
+ });
142
+ /**
143
+ * Ends a reload's addition of `added` and removes each Worker that the scheduler doesn't
144
+ * have.
145
+ */
146
+ const settleAdded = (added, removed) => membership.withPermit(Ref.update(adding, (current) => new Set([...current].filter((name) => !added.has(name)))).pipe(Effect.andThen(Effect.forEach(removed, removeUnused, { discard: true }))));
147
+ const unservedChange = (worker) => worker.kind === executor.kind
148
+ ? Option.none()
149
+ : Option.some({
150
+ block: "workers",
151
+ field: `workers.${worker.name}.kind`,
152
+ reason: `worker "${worker.name}" has kind ${worker.kind}, and the running workers have kind ${executor.kind}`,
153
+ });
154
+ const applyWorkers = Effect.fn("WorkerScheduler.applyWorkers")(function* (change, declared) {
155
+ const before = yield* TxRef.modify(pool, (current) => [
156
+ current,
157
+ slotPoolOf(declared, current),
158
+ ]);
159
+ const running = (worker) => before.get(worker)?.leased ?? 0;
160
+ yield* Effect.forEach(change.resized, ({ worker, from }) => Effect.logInfo("Worker slots resized by a reload; running Attempts continue", {
161
+ worker: worker.name,
162
+ slotsBefore: from,
163
+ slotsAfter: worker.maxConcurrentAttempts,
164
+ running: running(worker.name),
165
+ }));
166
+ yield* Effect.forEach(change.added, (worker) => Effect.logInfo("Worker added by a reload; it takes Attempts now", {
167
+ worker: worker.name,
168
+ slots: worker.maxConcurrentAttempts,
169
+ }));
170
+ yield* Effect.forEach(change.removed, ({ name }) => running(name) === 0
171
+ ? Effect.logInfo("Worker removed by a reload; it runs no Attempt, so it leaves the scheduler now", { worker: name })
172
+ : Effect.logInfo("Worker removed by a reload; it takes no new Attempt, and its running Attempts finish", { worker: name, running: running(name) }));
173
+ yield* settleAdded(new Set(change.added.map(({ name }) => name)), change.removed.map(({ name }) => name));
174
+ });
175
+ const prepareReload = Effect.fn("WorkerScheduler.prepareReload")(function* (running, loaded) {
176
+ const change = workersChange(running.config.workers, loaded.config.workers);
177
+ const restart = [
178
+ ...change.restart,
179
+ ...EffectArray.getSomes(change.added.map(unservedChange)),
180
+ ];
181
+ if (EffectArray.isReadonlyArrayNonEmpty(restart)) {
182
+ return yield* restartRequired(restart);
183
+ }
184
+ const agents = agentsWithNewBrains(running, loaded);
185
+ const agentNames = agents.map(({ name }) => name);
186
+ const newBrains = EffectArray.dedupe(agents.map(({ agent }) => agent.brain));
187
+ const roster = EffectArray.dedupe(loaded.agents.map(({ agent }) => agent.brain));
188
+ const wholeRoster = new Set([
189
+ ...change.added.map(({ name }) => name),
190
+ ...change.resized
191
+ .filter(({ worker, from }) => worker.maxConcurrentAttempts > from)
192
+ .map(({ worker }) => worker.name),
193
+ ]);
194
+ const checks = loaded.config.workers.flatMap((worker) => wholeRoster.has(worker.name)
195
+ ? [{ worker, brains: roster }]
196
+ : newBrains.length > 0
197
+ ? [{ worker, brains: newBrains }]
198
+ : []);
199
+ yield* Effect.annotateCurrentSpan({ agents: agentNames, workers: [...wholeRoster] });
200
+ if (checks.length === 0) {
201
+ yield* Effect.logDebug("The reload adds no Worker, slot, or brain, so it runs no Worker preflight");
202
+ return applyWorkers(change, loaded.config.workers);
203
+ }
204
+ const added = new Set(change.added.map(({ name }) => name));
205
+ yield* membership.withPermit(Ref.update(adding, (current) => new Set([...current, ...added])));
206
+ yield* Effect.logInfo("Preflighting the Workers, slots, and brains the reload adds", {
207
+ agents: agentNames,
208
+ brains: newBrains.map(brainLabel),
209
+ workers: [...wholeRoster],
210
+ });
211
+ // Add the Worker to the executor first, so its preflight can connect to its machine.
212
+ yield* Effect.forEach(checks, ({ worker, brains }) => added.has(worker.name)
213
+ ? preflightWorker(worker, brains, executorWorkers.add(worker))
214
+ : preflightWorker(worker, brains), { concurrency: "unbounded", discard: true }).pipe(Effect.mapError((cause) => reloadPreflightFailed(agentNames, [...wholeRoster], cause)), Effect.onExit((exit) => Exit.isFailure(exit) ? settleAdded(added, [...added]) : Effect.void));
215
+ return applyWorkers(change, loaded.config.workers);
216
+ });
217
+ yield* instances.registerWorkers(prepareReload);
218
+ // A reload can change the roster after the caller read `brains` and before the registration.
219
+ const { agents } = yield* instances.get;
220
+ const startupRoster = EffectArray.dedupe([
221
+ ...brains,
222
+ ...agents.map(({ agent }) => agent.brain),
223
+ ]);
224
+ yield* Effect.forEach(workers, (worker) => preflightWorker(worker, startupRoster), {
39
225
  concurrency: "unbounded",
40
226
  discard: true,
227
+ }).pipe(Effect.withSpan("WorkerScheduler.preflight"));
228
+ const releaseSlot = (worker) => TxRef.modify(pool, (current) => releasedFrom(current, worker)).pipe(Effect.flatMap((release) => Match.valueTags(release, {
229
+ Freed: () => Effect.logDebug("Worker slot released", { worker }),
230
+ Retired: ({ running, slots }) => Effect.logInfo("An Attempt ended on a Worker that runs more Attempts than it has slots; its slot retires", { worker, running, slots }),
231
+ Dropped: () => Effect.logInfo("The last Attempt on a removed Worker ended; the Worker leaves the scheduler", { worker }).pipe(Effect.andThen(membership.withPermit(removeUnused(worker)))),
232
+ })));
233
+ const makeLease = Effect.fn("WorkerScheduler.makeLease")(function* (worker) {
234
+ const released = yield* Ref.make(false);
235
+ return {
236
+ worker,
237
+ release: Ref.modify(released, (done) => [!done, true]).pipe(Effect.flatMap((first) => (first ? releaseSlot(worker) : Effect.void))),
238
+ };
41
239
  });
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);
240
+ // Retries until a free slot can take a waiting reservation, then takes both. A reservation
241
+ // whose Worker has no free slot doesn't block the ones behind it.
242
+ const nextAssignment = Effect.tx(Effect.gen(function* () {
243
+ const current = yield* TxRef.get(pool);
244
+ const next = EffectArray.findFirst(yield* TxPriorityQueue.toArray(pending), (reservation) => Option.map(workerFor(current, reservation), (worker) => ({ worker, reservation })));
245
+ if (Option.isNone(next))
246
+ return yield* Effect.txRetry;
247
+ const { worker, reservation } = next.value;
248
+ yield* TxPriorityQueue.removeIf(pending, (waiting) => waiting === reservation);
249
+ yield* TxRef.set(pool, withLeased(current, worker, 1));
250
+ return next.value;
251
+ }));
46
252
  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);
253
+ const { worker, reservation } = yield* nextAssignment;
254
+ const lease = yield* makeLease(worker);
50
255
  const assign = yield* Ref.modify(reservation.state, (state) => state._tag === "Pending"
51
256
  ? [true, { _tag: "Assigned", lease }]
52
257
  : [false, state]);
@@ -59,50 +264,131 @@ export const stepExecutorLayer = (config, brains) => Layer.effect(StepExecutor,
59
264
  }
60
265
  }));
61
266
  yield* Effect.forkScoped(dispatch);
62
- const reserve = Effect.fn("WorkerScheduler.reserve")(function* (submission) {
267
+ const occupy = Effect.fn("WorkerScheduler.occupy")(function* (worker) {
268
+ yield* Effect.annotateCurrentSpan({ worker });
269
+ // The Attempt runs on the Worker even without a free slot, so count it now. A slot over
270
+ // capacity retires when an Attempt there ends.
271
+ const slots = yield* TxRef.modify(pool, (current) => [current.get(worker), withLeased(current, worker, 1)]);
272
+ if (slots === undefined) {
273
+ yield* Effect.logWarning("An Attempt already runs on a Worker the scheduler does not have; it occupies no slot, and that Worker takes no new Attempt", { worker });
274
+ return { worker, release: Effect.void };
275
+ }
276
+ const fields = { worker, running: slots.leased + 1, slots: slots.capacity };
277
+ if (slots.leased < slots.capacity)
278
+ yield* Effect.logInfo("An Attempt that already runs on the Worker occupies a slot", fields);
279
+ else
280
+ yield* Effect.logWarning("An Attempt that already runs on the Worker occupies a slot beyond its max_concurrent_attempts; the Worker takes no new Attempt until enough of its Attempts end", fields);
281
+ return yield* makeLease(worker);
282
+ });
283
+ const reserve = Effect.fn("WorkerScheduler.reserve")(function* (submission, worker) {
284
+ const run = { loop: submission.loop, itemKey: submission.itemKey };
285
+ yield* Effect.annotateCurrentSpan(run);
286
+ if (Option.isSome(worker))
287
+ yield* Effect.annotateCurrentSpan({ worker: worker.value });
63
288
  const deferred = yield* Deferred.make();
64
289
  const state = yield* Ref.make({ _tag: "Pending" });
65
290
  const reservation = {
66
291
  deferred,
292
+ worker,
67
293
  eventTime: DateTime.toEpochMillis(submission.event.receivedAt),
68
294
  order: yield* Ref.getAndUpdate(nextOrder, (value) => value + 1),
69
295
  state,
70
296
  };
71
297
  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
- });
298
+ const fields = { ...run, queued: yield* TxPriorityQueue.size(pending) };
299
+ if (Option.isNone(worker))
300
+ yield* Effect.logInfo("Run waits for a worker slot", fields);
301
+ else if (((yield* TxRef.get(pool)).get(worker.value)?.capacity ?? 0) > 0)
302
+ yield* Effect.logInfo("Run waits for a slot on the Worker its reattached Attempt runs on", { ...fields, worker: worker.value });
303
+ else
304
+ yield* Effect.logWarning("Run waits for a slot on the Worker its reattached Attempt runs on, which usine.yaml does not declare; it waits until a reload declares that Worker again or the Run is canceled", { ...fields, worker: worker.value });
77
305
  return yield* Deferred.await(deferred).pipe(Effect.onInterrupt(() => Ref.modify(state, (current) => current._tag === "Assigned"
78
306
  ? [Option.some(current.lease), { _tag: "Canceled" }]
79
- : [Option.none(), { _tag: "Canceled" }]).pipe(Effect.flatMap(Option.match({ onNone: () => Effect.void, onSome: (lease) => lease.release })))));
307
+ : [Option.none(), { _tag: "Canceled" }]).pipe(
308
+ // Remove a canceled reservation from the queue, so one whose Worker never frees a
309
+ // slot doesn't stay there.
310
+ Effect.tap(() => TxPriorityQueue.removeIf(pending, (waiting) => waiting === reservation)), Effect.flatMap(Option.match({ onNone: () => Effect.void, onSome: (lease) => lease.release })))));
311
+ });
312
+ // If the login can't be read, harvesting asks GitHub; the Attempt never fails for this.
313
+ const botLoginFor = Effect.fn("WorkerScheduler.botLogin")(function* (attemptId) {
314
+ if (executor.kind === "exe.dev")
315
+ return Option.some(EXE_DEV_BOT_LOGIN);
316
+ const installation = yield* app.installation().pipe(Effect.map(Option.some), Effect.catch((error) => Effect.logWarning("Could not read the App's installation; harvesting will ask GitHub for the login of the Attempt's credential", { attemptId, errorTag: error._tag, message: error.message }).pipe(Effect.as(Option.none()))));
317
+ if (Option.isNone(installation))
318
+ return Option.none();
319
+ const { appSlug } = installation.value;
320
+ // GitHub's REST API names an App's bot `<slug>[bot]`; its GraphQL API drops the suffix.
321
+ const login = decodeBotLogin(`${appSlug}[bot]`);
322
+ if (Option.isNone(login))
323
+ yield* Effect.logWarning("The App's slug does not form a bot login; harvesting will ask GitHub for the login of the Attempt's credential", { attemptId, appSlug });
324
+ return login;
80
325
  });
81
326
  const execute = Effect.fn("WorkerScheduler.execute")(function* (execution, io) {
82
327
  yield* Effect.annotateCurrentSpan({
83
328
  attemptId: execution.attempt.id,
84
329
  runId: execution.run.id,
85
330
  worker: execution.attempt.worker,
331
+ loop: execution.run.loop,
332
+ permissions: execution.permissions,
333
+ reattach: execution.reattach,
86
334
  });
335
+ const { settings } = (yield* instances.get).config;
336
+ const botLogin = yield* botLoginFor(execution.attempt.id);
87
337
  const prepared = yield* executor
88
338
  .prepare(new CheckoutRequest({
89
339
  attemptId: execution.attempt.id,
90
340
  worker: execution.attempt.worker,
91
341
  repository: execution.repository,
342
+ loop: execution.run.loop,
343
+ permissions: execution.permissions,
92
344
  revision: execution.revision,
93
345
  payload: execution.event.payload,
94
346
  task: execution.task,
95
347
  agent: execution.agent,
96
348
  parentModel: execution.parentModel,
97
- maxChildren: config.settings.maxChildren,
98
- maxAttemptMinutes: config.settings.maxAttemptMinutes,
99
- maxAttemptTokens: config.settings.maxAttemptTokens,
100
- parentEffort: resolveParentEffort(execution.agent, config.settings.parentEffort),
349
+ maxChildren: settings.maxChildren,
350
+ maxAttemptMinutes: settings.maxAttemptMinutes,
351
+ maxAttemptTokens: settings.maxAttemptTokens,
352
+ parentEffort: resolveParentEffort(execution.agent, settings.parentEffort),
353
+ salvageRef: salvageRefFor(execution.run.id, execution.attempt.number),
354
+ resume: execution.resume,
355
+ reattach: execution.reattach,
356
+ botLogin,
101
357
  }))
102
- .pipe(Effect.mapError(asAttemptFailure));
358
+ .pipe(Effect.tapError((error) => error._tag === "CredentialUnavailableError"
359
+ ? Effect.logWarning(error.reason === "refused"
360
+ ? "The Attempt's repository access was refused; the Attempt fails without an automatic retry"
361
+ : "The Attempt's repository access could not be obtained now; the Attempt fails with an infrastructure failure, which is retried", {
362
+ attemptId: execution.attempt.id,
363
+ worker: execution.attempt.worker,
364
+ repository: error.repository,
365
+ reason: error.reason,
366
+ message: error.message,
367
+ })
368
+ : Effect.void), Effect.mapError(asAttemptFailure));
369
+ // The engine reconciles a checkout kept for a reattachment until preparation acquires it;
370
+ // from here the executor releases it.
371
+ yield* io.checkoutAcquired;
103
372
  return yield* prepared.launch(io);
104
373
  }, Effect.scoped);
105
374
  const interrupt = (attemptId) => executor.cancel(attemptId).pipe(Effect.mapError(asAttemptFailure));
106
- return StepExecutor.of({ execute, interrupt, reserve, intervene: executor.intervene });
375
+ const status = WorkerStatus.of({
376
+ slots: TxRef.get(pool).pipe(Effect.map((current) => [...current].map(([worker, { capacity, leased }]) => ({ worker, capacity, leased })))),
377
+ preflights: Ref.get(preflights).pipe(Effect.map((current) => [...current.values()])),
378
+ });
379
+ const stepExecutor = StepExecutor.of({
380
+ workers: TxRef.get(pool).pipe(Effect.map((current) => [...current.keys()])),
381
+ execute,
382
+ interrupt,
383
+ isLive: executor.isLive,
384
+ outcome: executor.outcome,
385
+ reserve,
386
+ occupy,
387
+ intervene: executor.intervene,
388
+ recover: (attempt, record) => executor
389
+ .recover(attempt, record)
390
+ .pipe(Effect.catchIf(Schema.is(ExecutorError), (error) => Effect.fail(asAttemptFailure(error)))),
391
+ });
392
+ return Context.make(StepExecutor, stepExecutor).pipe(Context.add(WorkerStatus, status));
107
393
  }));
108
394
  //# sourceMappingURL=scheduler.js.map
@@ -1 +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,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,GAAG,EACH,MAAM,EACN,eAAe,GAChB,MAAM,QAAQ,CAAC;AAEhB,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,WAAW,CAC5D,4CAA4C,CAC7C,CAAC,wBAAwB,EAAE;IAC1B,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;CAAG;AAcL,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CACpC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,WAAwB,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EACjF,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,WAAwB,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAC9E,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,KAA6C,EAAE,EAAE,CACzE,KAA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,CAAC,CACrF,CACF;QACD,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;KACrF,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,CAAC;QACnC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3E,OAAO;QACP,SAAS;QACT,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,OAAO;QACP,MAAM;QACN,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC3B,QAAQ;aACL,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;aACxB,IAAI,CACH,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CACjD,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CACrC,CACF;KACN,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1F,CAAC,CAAC,CACH,CAAC"}
package/dist/ssh.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { SshWorker, UsineConfig } from "@usine/config/factory";
2
+ import type { BrainSpec } from "@usine/core/agent/brain";
3
+ import type { InstanceDirectory } from "@usine/core/instance";
4
+ import { WorkerCapabilityError } from "@usine/executor";
5
+ import { type SshExecutorOptions, SshWorkers } from "@usine/executor/ssh";
6
+ import { Effect, Layer, Option } from "effect";
7
+ /** Returns the SSH Workers that `usine.yaml` declares, in declared order. */
8
+ export declare const sshWorkersOf: (config: UsineConfig) => ReadonlyArray<SshWorker>;
9
+ /**
10
+ * Returns how the executor connects to each declared SSH Worker, reading Gateway admin tokens at
11
+ * startup. If an `admin_token_env` variable is unset, fails with a `gateway` capability error.
12
+ */
13
+ export declare const sshWorkerAddressesOf: (config: UsineConfig) => Effect.Effect<{
14
+ name: string & import("effect/Brand").Brand<"WorkerName">;
15
+ destination: string & import("effect/Brand").Brand<"SshDestination">;
16
+ identityFile: Option.Option<string & import("effect/Brand").Brand<"SshIdentityFile">>;
17
+ port: Option.Option<number & import("effect/Brand").Brand<"SshPort">>;
18
+ root: string & import("effect/Brand").Brand<"WorkerRoot">;
19
+ gateway: Option.Option<{
20
+ domain: string & import("effect/Brand").Brand<"GatewayDomain">;
21
+ destination: string & import("effect/Brand").Brand<"SshDestination">;
22
+ adminPort: number & import("effect/Brand").Brand<"GatewayAdminPort">;
23
+ adminToken: import("effect/Redacted").Redacted<string>;
24
+ llmProviders: readonly "anthropic"[];
25
+ }>;
26
+ }[], WorkerCapabilityError, never>;
27
+ /**
28
+ * Provides the scheduler over the SSH executor, so reloads can resize, add, and remove SSH Workers.
29
+ * A reload that adds a Worker fails with a `gateway` capability error if its `admin_token_env`
30
+ * variable is unset.
31
+ */
32
+ export declare const sshStepExecutorLayer: (config: UsineConfig, brains: ReadonlyArray<BrainSpec>) => Layer.Layer<import("@usine/engine/step-executor").StepExecutor | import("./worker-status.ts").WorkerStatus, import("@usine/executor").CredentialUnavailableError | import("@usine/executor").ExecutorOperationError | import("./scheduler.ts").UnsupportedWorkerError | WorkerCapabilityError, import("./current-instance/current-instance.ts").CurrentInstance | import("@usine/executor").Executor | import("@usine/github/github-app").GitHubApp | SshWorkers>;
33
+ /**
34
+ * Provides the full engine and `WorkerStatus` for SSH Workers. Requires `CredentialProvider`,
35
+ * `GitHubApp`, `TriggerCondition`, `AttemptRuntime` (built before the engine), `ClaudeLoginLock`,
36
+ * and `CurrentInstance`.
37
+ */
38
+ export declare const layer: (instanceDirectory: InstanceDirectory, config: UsineConfig, brains: ReadonlyArray<BrainSpec>, options: SshExecutorOptions) => Layer.Layer<import("@usine/engine/board-moves").BoardMoves | import("@usine/engine/cursor").CursorStore | import("@usine/engine/cycle-budget").CycleBudgets | import("@usine/engine/item-projection").ItemProjectionReader | import("@usine/engine/item-projection").ItemProjectionWriter | import("@usine/engine/loop-control").LoopControl | import("@usine/engine/repository-label-projection").RepositoryLabelProjectionReader | import("@usine/engine/repository-label-projection").RepositoryLabelProjectionWriter | import("@usine/engine/engine").RunEngine | import("@usine/engine/run-reader").RunReader | import("@usine/engine/step-executor").StepExecutor | import("./worker-status.ts").WorkerStatus, import("@usine/engine/engine").AttemptCancellationError | import("@usine/executor").CredentialUnavailableError | import("@usine/engine/engine").EnginePersistenceError | import("@usine/executor").ExecutorOperationError | import("@usine/engine/engine").RunInterventionRejectedError | import("@usine/engine/engine").RunNotFoundError | import("@usine/engine/engine").RunOperationRejectedError | import("@usine/engine/engine").RunRetryBlockedError | import("./scheduler.ts").UnsupportedWorkerError | WorkerCapabilityError, import("@usine/durable/attempt-runtime").AttemptRuntime | import("@usine/agents/runtime").ClaudeLoginLock | import("@usine/executor").CredentialProvider | import("./current-instance/current-instance.ts").CurrentInstance | import("@usine/github/github-app").GitHubApp | import("@usine/engine/trigger-condition").TriggerCondition>;
39
+ //# sourceMappingURL=ssh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssh.d.ts","sourceRoot":"","sources":["../src/ssh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAA0B,MAAM,uBAAuB,CAAC;AAC5F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAEL,KAAK,kBAAkB,EAEvB,UAAU,EACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA0B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIvE,6EAA6E;AAC7E,eAAO,MAAM,YAAY,WAAY,WAAW,KAAG,aAAa,CAAC,SAAS,CACK,CAAC;AA0ChF;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;kCAU/B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,WAAY,WAAW,UAAU,aAAa,CAAC,SAAS,CAAC,scAsBvF,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,KAAK,sBACG,iBAAiB,UAC5B,WAAW,UACX,aAAa,CAAC,SAAS,CAAC,WACvB,kBAAkB,wgDAQ5B,CAAC"}
package/dist/ssh.js ADDED
@@ -0,0 +1,75 @@
1
+ import { NodeServices } from "@effect/platform-node";
2
+ import { layer as localEngineLayer } from "@usine/engine/local-sqlite";
3
+ import { WorkerCapabilityError } from "@usine/executor";
4
+ import { layer as sshExecutorLayer, SshWorkers, } from "@usine/executor/ssh";
5
+ import { Config, ConfigProvider, Effect, Layer, Option } from "effect";
6
+ import { FetchHttpClient } from "effect/unstable/http";
7
+ import { stepExecutorLayer } from "./scheduler.js";
8
+ /** Returns the SSH Workers that `usine.yaml` declares, in declared order. */
9
+ export const sshWorkersOf = (config) => config.workers.filter((worker) => worker.kind === "ssh");
10
+ /**
11
+ * Returns how the executor connects to `worker`, reading the Gateway admin token from
12
+ * `admin_token_env`. Fails with a `gateway` capability error if the variable is unset.
13
+ */
14
+ const sshWorkerAddressOf = (worker, missing) => Effect.gen(function* () {
15
+ const gateway = yield* Effect.transposeOption(Option.map(worker.gateway, (settings) => Effect.gen(function* () {
16
+ const adminToken = yield* Config.redacted(settings.adminTokenEnv);
17
+ return {
18
+ domain: settings.domain,
19
+ destination: settings.destination,
20
+ adminPort: settings.adminPort,
21
+ adminToken,
22
+ llmProviders: settings.llmProviders,
23
+ };
24
+ }).pipe(Effect.mapError((cause) => new WorkerCapabilityError({
25
+ worker: worker.name,
26
+ capability: "gateway",
27
+ message: missing(settings.adminTokenEnv),
28
+ cause,
29
+ })))));
30
+ return {
31
+ name: worker.name,
32
+ destination: worker.destination,
33
+ identityFile: worker.identityFile,
34
+ port: worker.port,
35
+ root: worker.root,
36
+ gateway,
37
+ };
38
+ });
39
+ /**
40
+ * Returns how the executor connects to each declared SSH Worker, reading Gateway admin tokens at
41
+ * startup. If an `admin_token_env` variable is unset, fails with a `gateway` capability error.
42
+ */
43
+ export const sshWorkerAddressesOf = Effect.fn("Orchestrator.sshWorkerAddressesOf")(function* (config) {
44
+ return yield* Effect.forEach(sshWorkersOf(config), (worker) => sshWorkerAddressOf(worker, (variable) => `The gateway admin token for SSH worker "${worker.name}" is missing. Set ${variable} in the orchestrator's environment.`));
45
+ });
46
+ /**
47
+ * Provides the scheduler over the SSH executor, so reloads can resize, add, and remove SSH Workers.
48
+ * A reload that adds a Worker fails with a `gateway` capability error if its `admin_token_env`
49
+ * variable is unset.
50
+ */
51
+ export const sshStepExecutorLayer = (config, brains) => Layer.unwrap(Effect.gen(function* () {
52
+ const machines = yield* SshWorkers;
53
+ const environment = yield* ConfigProvider.ConfigProvider;
54
+ const add = Effect.fn("Orchestrator.addSshWorker")(function* (worker) {
55
+ yield* Effect.annotateCurrentSpan({ worker: worker.name });
56
+ if (worker.kind !== "ssh")
57
+ return yield* Effect.die(new Error(`The SSH executor cannot run worker "${worker.name}" of kind ${worker.kind}`));
58
+ const address = yield* sshWorkerAddressOf(worker, (variable) => `The gateway admin token for SSH worker "${worker.name}" is missing: ${variable} is not set in the orchestrator's environment. usine up reads only the variables that were set when it started. Set ${variable} and restart usine up, or set admin_token_env to a variable that usine up already has.`).pipe(Effect.provideService(ConfigProvider.ConfigProvider, environment));
59
+ yield* machines.addWorker(address);
60
+ });
61
+ return stepExecutorLayer(config, brains, {
62
+ workers: { add, remove: machines.removeWorker },
63
+ });
64
+ }));
65
+ /**
66
+ * Provides the full engine and `WorkerStatus` for SSH Workers. Requires `CredentialProvider`,
67
+ * `GitHubApp`, `TriggerCondition`, `AttemptRuntime` (built before the engine), `ClaudeLoginLock`,
68
+ * and `CurrentInstance`.
69
+ */
70
+ export const layer = (instanceDirectory, config, brains, options) => {
71
+ const executor = sshExecutorLayer(options).pipe(Layer.provide(NodeServices.layer), Layer.provide(FetchHttpClient.layer));
72
+ const stepExecutor = sshStepExecutorLayer(config, brains).pipe(Layer.provide(executor));
73
+ return localEngineLayer(instanceDirectory).pipe(Layer.provideMerge(stepExecutor));
74
+ };
75
+ //# sourceMappingURL=ssh.js.map