@graftland/plugin-remote 0.3.1 → 0.3.3
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.
- package/dist/Auth.d.ts +2 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js.map +1 -1
- package/dist/{Bootstrap-Dr6sX7el.js → Bootstrap-H9gDsgsC.js} +2 -2
- package/dist/{Contract-DL2mHvaT.js → Contract-DsJtisvL.js} +2 -2
- package/dist/Contract.js +1 -1
- package/dist/{Errors-BMKmu5Y7.js → Errors-DYhsGZcZ.js} +3 -1
- package/dist/Errors.d.ts +7 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +3 -1
- package/dist/Errors.js.map +1 -1
- package/dist/{FailureGroup-BcH0XOBi.js → FailureGroup-BgT73AaR.js} +14 -4
- package/dist/{Framing-zaYdOJnT.js → Framing-G9eSaeLb.js} +1 -1
- package/dist/{Graft-CVyueNOf.js → Graft-B71CPA2Y.js} +20 -16
- package/dist/{Packages-JNL34JpS.js → Packages-AgoCGotL.js} +23 -26
- package/dist/{Peer-BT7eAGmh.js → Peer-DXeVrGBh.js} +5 -5
- package/dist/{ProcessObservation-DEGrEMfP.js → ProcessObservation-gLgGirYv.js} +1 -1
- package/dist/{ServeLifecycle-CJM0gG5B.js → ServeLifecycle-Bd1FPJ6e.js} +1 -1
- package/dist/Transport.d.ts +2 -2
- package/dist/Transport.d.ts.map +1 -1
- package/dist/Transport.js.map +1 -1
- package/dist/bin.js +48 -47
- package/dist/bin.js.map +1 -1
- package/dist/{childRuntime-An0HsIzl.js → childRuntime-Bm3iSg_N.js} +29 -26
- package/dist/{connectionEnded-DCpFCjMX.js → connectionEnded-BwcxQ7W8.js} +4 -4
- package/dist/{entry-B89sepMU.js → entry-psOpX3Bj.js} +72 -35
- package/dist/host/auth/bearer.d.ts +9 -1
- package/dist/host/auth/bearer.d.ts.map +1 -1
- package/dist/host/auth/bearer.js +1 -1
- package/dist/host/auth/jwt.d.ts +9 -1
- package/dist/host/auth/jwt.d.ts.map +1 -1
- package/dist/host/auth/jwt.js +1 -1
- package/dist/host/auth/mtls.d.ts +8 -1
- package/dist/host/auth/mtls.d.ts.map +1 -1
- package/dist/host/auth/mtls.js +2 -2
- package/dist/host/auth/none.d.ts +3 -1
- package/dist/host/auth/none.js +1 -1
- package/dist/host/command.d.ts +14 -1
- package/dist/host/command.d.ts.map +1 -1
- package/dist/host/command.js +4 -4
- package/dist/host/local.d.ts +2 -1
- package/dist/host/local.d.ts.map +1 -1
- package/dist/host/local.js +3 -3
- package/dist/host/unix.d.ts +6 -1
- package/dist/host/unix.d.ts.map +1 -1
- package/dist/host/unix.js +3 -3
- package/dist/host/websocket.d.ts +10 -1
- package/dist/host/websocket.d.ts.map +1 -1
- package/dist/host/websocket.js +3 -3
- package/dist/host/worker.d.ts +3 -1
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +4 -5
- package/dist/{importer-Bk6U_sn4.js → importer-Cvf88eAY.js} +5 -8
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/internal/Certificates.js +4 -4
- package/dist/internal/Certificates.js.map +1 -1
- package/dist/internal/FailureGroup.js +3 -2
- package/dist/internal/FailureGroup.js.map +1 -1
- package/dist/internal/assembly.d.ts +2 -1
- package/dist/internal/assembly.js +9 -2
- package/dist/internal/assembly.js.map +1 -1
- package/dist/internal/auth/mtls.js +1 -1
- package/dist/internal/auth/mtls.js.map +1 -1
- package/dist/internal/auth/tokenCredentials.d.ts +2 -1
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
- package/dist/internal/child.js +20 -17
- package/dist/internal/child.js.map +1 -1
- package/dist/internal/childRuntime.js +4 -4
- package/dist/internal/childRuntime.js.map +1 -1
- package/dist/internal/credentials.d.ts +1 -1
- package/dist/internal/directTransport.d.ts +1 -1
- package/dist/internal/entry.d.ts +415 -3
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +1 -1
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/execution.js +40 -5
- package/dist/internal/execution.js.map +1 -1
- package/dist/internal/host/runner.js +7 -6
- package/dist/internal/host/runner.js.map +1 -1
- package/dist/internal/host.js +5 -5
- package/dist/internal/host.js.map +1 -1
- package/dist/internal/port.js +5 -5
- package/dist/internal/port.js.map +1 -1
- package/dist/internal/release.js +1 -1
- package/dist/internal/release.js.map +1 -1
- package/dist/internal/runner/Connection.d.ts +1 -1
- package/dist/internal/runner/Connection.js +4 -4
- package/dist/internal/runner/Connection.js.map +1 -1
- package/dist/internal/runner/Execution.js +3 -3
- package/dist/internal/runner/Execution.js.map +1 -1
- package/dist/internal/runner/Framing.js +1 -1
- package/dist/internal/runner/Framing.js.map +1 -1
- package/dist/internal/runner/Local.js +1 -1
- package/dist/internal/runner/Local.js.map +1 -1
- package/dist/internal/runner/Lock.js +1 -1
- package/dist/internal/runner/Lock.js.map +1 -1
- package/dist/internal/runner/Packages.d.ts +1 -1
- package/dist/internal/runner/Packages.js +22 -25
- package/dist/internal/runner/Packages.js.map +1 -1
- package/dist/internal/runner/Processes.js +7 -9
- package/dist/internal/runner/Processes.js.map +1 -1
- package/dist/internal/runner/Store.js +3 -3
- package/dist/internal/runner/Store.js.map +1 -1
- package/dist/internal/runner/Supervisor.js +46 -47
- package/dist/internal/runner/Supervisor.js.map +1 -1
- package/dist/internal/runner/accept.js +3 -3
- package/dist/internal/runner/accept.js.map +1 -1
- package/dist/internal/runner/model.js +1 -1
- package/dist/internal/runner/model.js.map +1 -1
- package/dist/internal/serve.js +1 -1
- package/dist/internal/serve.js.map +1 -1
- package/dist/internal/supervisorPlugin.js +1 -1
- package/dist/internal/watchdogMain.js +5 -5
- package/dist/internal/watchdogMain.js.map +1 -1
- package/dist/internal/websocketServer.js +3 -1
- package/dist/internal/websocketServer.js.map +1 -1
- package/dist/internal/workerMain.js +3 -3
- package/dist/{port-DSVUY8Bq.js → port--3x2zJ4D.js} +8 -8
- package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
- package/dist/runner/auth/bearer.d.ts +6 -1
- package/dist/runner/auth/bearer.d.ts.map +1 -1
- package/dist/runner/auth/bearer.js +2 -2
- package/dist/runner/auth/jwt.d.ts +29 -2
- package/dist/runner/auth/jwt.d.ts.map +1 -1
- package/dist/runner/auth/jwt.js +4 -4
- package/dist/runner/auth/jwt.js.map +1 -1
- package/dist/runner/auth/mtls.d.ts +6 -1
- package/dist/runner/auth/mtls.d.ts.map +1 -1
- package/dist/runner/auth/mtls.js +3 -3
- package/dist/runner/auth/none.d.ts +7 -1
- package/dist/runner/auth/none.js +1 -1
- package/dist/runner/index.d.ts +310 -1
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +5 -5
- package/dist/runner/stdio.d.ts +6 -1
- package/dist/runner/stdio.d.ts.map +1 -1
- package/dist/runner/stdio.js +3 -3
- package/dist/runner/unix.d.ts +6 -1
- package/dist/runner/unix.d.ts.map +1 -1
- package/dist/runner/unix.js +3 -3
- package/dist/runner/websocket.d.ts +24 -1
- package/dist/runner/websocket.d.ts.map +1 -1
- package/dist/runner/websocket.js +4 -4
- package/dist/{socketChannel-C_ppdSzz.js → socketChannel-CJvL2DiB.js} +2 -2
- package/dist/{supervisorPlugin-CivhM7x5.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
- package/dist/{token-Cc_1CTbE.js → token-CYBNNlhS.js} +1 -1
- package/dist/{tokenCredentials-CI6mMRRd.js → tokenCredentials-CbCuk-Rt.js} +3 -3
- package/dist/{websocketServer-D2Hk7wsA.js → websocketServer-NQhODlEt.js} +5 -3
- package/dist/{workerChannel-cmLc13vm.js → workerChannel-C8hhBJzA.js} +1 -1
- package/package.json +4 -4
- package/src/Auth.ts +9 -2
- package/src/Errors.ts +8 -0
- package/src/Transport.ts +6 -2
- package/src/bin.ts +28 -30
- package/src/index.ts +5 -3
- package/src/internal/Certificates.ts +10 -13
- package/src/internal/FailureGroup.ts +128 -121
- package/src/internal/assembly.ts +19 -10
- package/src/internal/auth/mtls.ts +19 -20
- package/src/internal/child.ts +248 -239
- package/src/internal/childRuntime.ts +81 -80
- package/src/internal/entry.ts +10 -11
- package/src/internal/execution.ts +69 -12
- package/src/internal/host/runner.ts +153 -153
- package/src/internal/host.ts +116 -120
- package/src/internal/port.ts +100 -103
- package/src/internal/release.ts +3 -2
- package/src/internal/runner/Connection.ts +52 -60
- package/src/internal/runner/Execution.ts +163 -164
- package/src/internal/runner/Framing.ts +9 -10
- package/src/internal/runner/Local.ts +26 -27
- package/src/internal/runner/Lock.ts +23 -25
- package/src/internal/runner/Packages.ts +67 -70
- package/src/internal/runner/Processes.ts +89 -92
- package/src/internal/runner/Store.ts +110 -114
- package/src/internal/runner/Supervisor.ts +392 -405
- package/src/internal/runner/accept.ts +76 -84
- package/src/internal/runner/model.ts +20 -21
- package/src/internal/serve.ts +15 -13
- package/src/internal/watchdogMain.ts +16 -11
- package/src/internal/websocketServer.ts +18 -3
- package/src/runner/auth/jwt.ts +10 -6
- package/dist/cleanup-CXLa1Wd9.js +0 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { make as make$1 } from "../FailureGroup.js";
|
|
2
2
|
import { close } from "../release.js";
|
|
3
|
-
import { defaults } from "../Limits.js";
|
|
4
3
|
import { save } from "./Retention.js";
|
|
4
|
+
import { defaults } from "../Limits.js";
|
|
5
5
|
import { cleanupCause } from "../cleanup.js";
|
|
6
6
|
import { Execution, ExecutionError, LeaseExpired, RunnerClosing, SessionConflict, SessionStopped, StaleSession, Store, TerminationUnconfirmed, childOf, keyOf, negotiate, stoppedRecord, stoppingRecord } from "./model.js";
|
|
7
7
|
import { Array, Cause, Clock, Context, Data, Deferred, Duration, Effect, Equal, Exit, FiberHandle, FiberSet, HashMap, Layer, Option, RcMap, Ref, Result, Scope, Semaphore, SynchronizedRef } from "effect";
|
|
@@ -83,34 +83,32 @@ const emptyTermination = {
|
|
|
83
83
|
};
|
|
84
84
|
const exitCause = (exit) => Exit.isFailure(exit) ? exit.cause : Cause.empty;
|
|
85
85
|
/** A signal is a request; only the exited effect confirms that the execution has stopped. */
|
|
86
|
-
const terminate = (execution, grace, confirmation)
|
|
87
|
-
if (execution._tag === "Absent") return
|
|
88
|
-
if (execution._tag === "Exited") return
|
|
86
|
+
const terminate = Effect.fnUntraced(function* (execution, grace, confirmation) {
|
|
87
|
+
if (execution._tag === "Absent") return emptyTermination;
|
|
88
|
+
if (execution._tag === "Exited") return {
|
|
89
89
|
...emptyTermination,
|
|
90
90
|
exit: execution.exit
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
const child = execution.unit;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
cause
|
|
105
|
-
});
|
|
106
|
-
return {
|
|
107
|
-
kind: "Killed",
|
|
108
|
-
exit: forced.value.value,
|
|
109
|
-
cause
|
|
110
|
-
};
|
|
93
|
+
const graceful = yield* child.interrupt.pipe(Effect.andThen(child.exited), Effect.timeoutOption(grace), Effect.exit);
|
|
94
|
+
if (Exit.isSuccess(graceful) && Option.isSome(graceful.value)) return {
|
|
95
|
+
...emptyTermination,
|
|
96
|
+
exit: graceful.value.value
|
|
97
|
+
};
|
|
98
|
+
const killed = yield* Effect.exit(child.kill);
|
|
99
|
+
const forced = yield* child.exited.pipe(Effect.timeoutOption(confirmation), Effect.exit);
|
|
100
|
+
const cause = Cause.combine(Cause.combine(exitCause(graceful), exitCause(killed)), exitCause(forced));
|
|
101
|
+
if (Exit.isFailure(forced) || Option.isNone(forced.value)) return yield* TerminationUnconfirmed.make({
|
|
102
|
+
detail: "The child exit could not be confirmed",
|
|
103
|
+
cause
|
|
111
104
|
});
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
return {
|
|
106
|
+
kind: "Killed",
|
|
107
|
+
exit: forced.value.value,
|
|
108
|
+
cause
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
const initialize = Effect.fnUntraced(function* (options = {}) {
|
|
114
112
|
const store = yield* Store;
|
|
115
113
|
const execution = yield* Execution;
|
|
116
114
|
const random = yield* SecureRandom.SecureRandom;
|
|
@@ -146,19 +144,19 @@ const operations = (runtime) => {
|
|
|
146
144
|
return Option.isSome(found) && Equal.equals(keyOf(found.value.handle.key), keyOf(handle.key)) && found.value.handle.generation === handle.generation ? Effect.succeed(found.value) : Effect.fail(StaleSession.make({ detail: "Unknown session or generation" }));
|
|
147
145
|
}));
|
|
148
146
|
const latest = (key) => Ref.get(records).pipe(Effect.map((all) => Array.reduce(Array.fromIterable(HashMap.values(all)), 0, (value, record) => Equal.equals(keyOf(record.handle.key), keyOf(key)) ? Math.max(value, record.handle.generation) : value)));
|
|
149
|
-
const entryFor =
|
|
147
|
+
const entryFor = Effect.fnUntraced(function* (handle) {
|
|
150
148
|
yield* status(handle);
|
|
151
149
|
const all = yield* Ref.get(entries);
|
|
152
150
|
const found = HashMap.get(all, handle.token);
|
|
153
151
|
if (Option.isNone(found)) return yield* SessionStopped.make({ detail: "The session was retired during recovery" });
|
|
154
152
|
return found.value;
|
|
155
153
|
});
|
|
156
|
-
const commit = (entry, transition) => SynchronizedRef.updateEffect(entry.state,
|
|
154
|
+
const commit = (entry, transition) => SynchronizedRef.updateEffect(entry.state, Effect.fnUntraced(function* (state) {
|
|
157
155
|
const next = yield* Effect.fromResult(transition(state));
|
|
158
156
|
yield* persist(snapshot(next));
|
|
159
157
|
return next;
|
|
160
158
|
}));
|
|
161
|
-
const finishStop = (entry, state, saved)
|
|
159
|
+
const finishStop = Effect.fnUntraced(function* (entry, state, saved) {
|
|
162
160
|
yield* FiberHandle.clear(entry.loading);
|
|
163
161
|
const result = yield* terminate(state.execution, grace, confirmation);
|
|
164
162
|
const closed = yield* Effect.exit(close(entry.unitScope, Exit.void));
|
|
@@ -175,7 +173,7 @@ const operations = (runtime) => {
|
|
|
175
173
|
return termination;
|
|
176
174
|
});
|
|
177
175
|
/** Called with the session ref locked; the worker starts after its transition is published. */
|
|
178
|
-
const stopLocked = (entry, state, reason, exit)
|
|
176
|
+
const stopLocked = Effect.fnUntraced(function* (entry, state, reason, exit) {
|
|
179
177
|
if (state._tag === "Stopping" || state._tag === "Stopped") return [state.reply, state];
|
|
180
178
|
const reply = yield* Deferred.make();
|
|
181
179
|
const next = beginStop(state, reason, reply, exit);
|
|
@@ -192,7 +190,7 @@ const operations = (runtime) => {
|
|
|
192
190
|
return stopLocked(entry, state, { _tag: "Expired" }, Option.none()).pipe(Effect.map(([, next]) => next));
|
|
193
191
|
});
|
|
194
192
|
})), { startImmediately: false });
|
|
195
|
-
const register = (entry, unit) => SynchronizedRef.updateEffect(entry.state,
|
|
193
|
+
const register = (entry, unit) => SynchronizedRef.updateEffect(entry.state, Effect.fnUntraced(function* (state) {
|
|
196
194
|
const now = yield* Clock.monotonicTimeNanos;
|
|
197
195
|
const current = yield* Effect.fromResult(live(state, now));
|
|
198
196
|
const next = yield* Effect.fromResult(registerUnit(current, unit));
|
|
@@ -201,7 +199,7 @@ const operations = (runtime) => {
|
|
|
201
199
|
yield* FiberSet.run(workers, observe(unit.exited.pipe(Effect.flatMap((exit) => stop(entry, { _tag: "Exited" }, Option.some(exit))))));
|
|
202
200
|
return next;
|
|
203
201
|
})).pipe(Effect.uninterruptible);
|
|
204
|
-
const runLoad = (entry, state) => execution.spawn(state.record.handle, state.request, state.record.limits).pipe(Scope.provide(entry.unitScope), Effect.flatMap((unit) => register(entry, unit).pipe(Effect.andThen(unit.start), Effect.as(unit.code))), Effect.tap((code) => commit(entry, (current) => loaded(current, code))), Effect.onExit(
|
|
202
|
+
const runLoad = (entry, state) => execution.spawn(state.record.handle, state.request, state.record.limits).pipe(Scope.provide(entry.unitScope), Effect.flatMap((unit) => register(entry, unit).pipe(Effect.andThen(unit.start), Effect.as(unit.code))), Effect.tap((code) => commit(entry, (current) => loaded(current, code))), Effect.onExit(Effect.fnUntraced(function* (result) {
|
|
205
203
|
if (Exit.isSuccess(result)) {
|
|
206
204
|
yield* Deferred.done(state.reply, result);
|
|
207
205
|
return;
|
|
@@ -224,7 +222,7 @@ const operations = (runtime) => {
|
|
|
224
222
|
healthy
|
|
225
223
|
};
|
|
226
224
|
};
|
|
227
|
-
const recover =
|
|
225
|
+
const recover = Effect.fnUntraced(function* (runtime, actions) {
|
|
228
226
|
const { store, execution, confirmation, records } = runtime;
|
|
229
227
|
const { persist } = actions;
|
|
230
228
|
const stored = yield* store.list;
|
|
@@ -245,10 +243,10 @@ const recover = (runtime, actions) => Effect.gen(function* () {
|
|
|
245
243
|
yield* persist(stoppedRecord(record.phase === "Stopping" ? record.previous : record, { _tag: "Recovery" }, termination));
|
|
246
244
|
}
|
|
247
245
|
});
|
|
248
|
-
const ownShutdown =
|
|
246
|
+
const ownShutdown = Effect.fnUntraced(function* (runtime, actions) {
|
|
249
247
|
const { entries, health, closing } = runtime;
|
|
250
248
|
const { stop } = actions;
|
|
251
|
-
yield* Effect.addFinalizer(
|
|
249
|
+
yield* Effect.addFinalizer(Effect.fnUntraced(function* () {
|
|
252
250
|
yield* Ref.set(closing, true);
|
|
253
251
|
const all = yield* Ref.get(entries);
|
|
254
252
|
const exits = yield* Effect.forEach(HashMap.values(all), (entry) => stop(entry, { _tag: "Shutdown" }).pipe(Effect.flatMap(Deferred.await), Effect.exit));
|
|
@@ -257,18 +255,19 @@ const ownShutdown = (runtime, actions) => Effect.gen(function* () {
|
|
|
257
255
|
if (cause.reasons.length > 0) return yield* Effect.failCause(cleanupCause(cause));
|
|
258
256
|
}));
|
|
259
257
|
});
|
|
260
|
-
const protocol =
|
|
258
|
+
const protocol = Effect.fnUntraced(function* (runtime, actions) {
|
|
261
259
|
const { random, owner, locks, lease, limits, records, entries, health } = runtime;
|
|
262
260
|
const { persist, status, latest, entryFor, stop, scheduleLease, runLoad, healthy } = actions;
|
|
263
261
|
return Supervisor.of({
|
|
264
262
|
await: health.await,
|
|
265
263
|
status,
|
|
266
264
|
highWater: (key) => latest(key).pipe(Effect.map((value) => value === 0 ? null : value)),
|
|
267
|
-
open:
|
|
265
|
+
open: Effect.fnUntraced(function* (request) {
|
|
268
266
|
yield* healthy;
|
|
269
267
|
const leaseMillis = Duration.toMillis(request.lease ?? lease);
|
|
270
268
|
const negotiated = negotiate(limits, request.limits ?? defaults);
|
|
271
|
-
|
|
269
|
+
const lock = yield* RcMap.get(locks, keyOf(request.key));
|
|
270
|
+
return yield* Effect.gen(function* () {
|
|
272
271
|
yield* healthy;
|
|
273
272
|
const allRecords = yield* Ref.get(records);
|
|
274
273
|
const same = Array.filter(Array.fromIterable(HashMap.values(allRecords)), (row) => Equal.equals(keyOf(row.handle.key), keyOf(request.key)));
|
|
@@ -319,28 +318,28 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
|
|
|
319
318
|
yield* scheduleLease(entry, deadline);
|
|
320
319
|
return record;
|
|
321
320
|
}));
|
|
322
|
-
}));
|
|
323
|
-
})
|
|
324
|
-
renew:
|
|
321
|
+
}).pipe(lock.withPermit);
|
|
322
|
+
}, Effect.scoped),
|
|
323
|
+
renew: Effect.fnUntraced(function* (handle) {
|
|
325
324
|
yield* healthy;
|
|
326
325
|
const entry = yield* entryFor(handle);
|
|
327
|
-
return yield* SynchronizedRef.modifyEffect(entry.state,
|
|
326
|
+
return yield* Effect.uninterruptibleMask((restore) => SynchronizedRef.modifyEffect(entry.state, Effect.fnUntraced(function* (state) {
|
|
328
327
|
const now = yield* Clock.monotonicTimeNanos;
|
|
329
328
|
const current = yield* Effect.fromResult(live(state, now));
|
|
330
329
|
const running = executionOf(current);
|
|
331
|
-
if (running._tag === "Running") yield* running.unit.renew(current.record.leaseMillis);
|
|
330
|
+
if (running._tag === "Running") yield* restore(running.unit.renew(current.record.leaseMillis));
|
|
332
331
|
const deadline = now + nanos(current.record.leaseMillis);
|
|
333
332
|
yield* scheduleLease(entry, deadline);
|
|
334
333
|
return [current.record.leaseMillis, {
|
|
335
334
|
...current,
|
|
336
335
|
deadline
|
|
337
336
|
}];
|
|
338
|
-
}));
|
|
337
|
+
})));
|
|
339
338
|
}),
|
|
340
|
-
load:
|
|
339
|
+
load: Effect.fnUntraced(function* (handle, request) {
|
|
341
340
|
yield* healthy;
|
|
342
341
|
const entry = yield* entryFor(handle);
|
|
343
|
-
return yield* yield* SynchronizedRef.modifyEffect(entry.state,
|
|
342
|
+
return yield* yield* SynchronizedRef.modifyEffect(entry.state, Effect.fnUntraced(function* (state) {
|
|
344
343
|
const now = yield* Clock.monotonicTimeNanos;
|
|
345
344
|
const current = yield* Effect.fromResult(live(state, now));
|
|
346
345
|
if (current._tag !== "Open") {
|
|
@@ -354,7 +353,7 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
|
|
|
354
353
|
return [Deferred.await(done), next];
|
|
355
354
|
})).pipe(Effect.uninterruptible);
|
|
356
355
|
}),
|
|
357
|
-
dispose:
|
|
356
|
+
dispose: Effect.fnUntraced(function* (handle) {
|
|
358
357
|
const record = yield* status(handle);
|
|
359
358
|
if (record.phase === "Stopped") return record.termination;
|
|
360
359
|
const entry = yield* entryFor(handle);
|
|
@@ -362,7 +361,7 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
|
|
|
362
361
|
})
|
|
363
362
|
});
|
|
364
363
|
});
|
|
365
|
-
const make = (options = {})
|
|
364
|
+
const make = Effect.fnUntraced(function* (options = {}) {
|
|
366
365
|
const runtime = yield* initialize(options);
|
|
367
366
|
const actions = operations(runtime);
|
|
368
367
|
yield* recover(runtime, actions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Supervisor.js","names":["FailureGroup.make","Retention.save","Release.close"],"sources":["../../../src/internal/runner/Supervisor.ts"],"sourcesContent":["import * as FailureGroup from \"../FailureGroup\"\nimport {\n\tArray,\n\tCause,\n\tClock,\n\tContext,\n\tData,\n\tDeferred,\n\tDuration,\n\tEffect,\n\tEqual,\n\tExit,\n\tFiberHandle,\n\tFiberSet,\n\tHashMap,\n\tLayer,\n\tOption,\n\tRcMap,\n\tRef,\n\tResult,\n\tScope,\n\tSemaphore,\n\tSynchronizedRef,\n} from \"effect\"\nimport * as Release from \"../release\"\nimport { SecureRandom } from \"effect/crypto\"\nimport * as Retention from \"./Retention\"\nimport { cleanupCause } from \"../cleanup\"\nimport {\n\tExecution,\n\tStore,\n\tStaleSession,\n\tLeaseExpired,\n\tSessionStopped,\n\tSessionConflict,\n\tStateStorageError,\n\tExecutionError,\n\tPackageError,\n\tTerminationUnconfirmed,\n\tRunnerClosing,\n\tchildOf,\n\tdefaults,\n\tkeyOf,\n\tnegotiate,\n\tstoppingRecord,\n\tstoppedRecord,\n\ttype ActiveRecord,\n\ttype CodeIdentity,\n\ttype ExitStatus,\n\ttype Handle,\n\ttype Key,\n\ttype Limits,\n\ttype Load,\n\ttype SessionRecord,\n\ttype SessionKey,\n\ttype StopReason,\n\ttype Termination,\n\ttype Unit,\n\ttype OpenRecord,\n\ttype LoadedRecord,\n\ttype StoppingRecord,\n\ttype StoppedRecord,\n} from \"./model\"\n\nexport type SupervisorError =\n\t| StaleSession\n\t| LeaseExpired\n\t| SessionStopped\n\t| SessionConflict\n\t| StateStorageError\n\t| ExecutionError\n\t| PackageError\n\t| TerminationUnconfirmed\n\t| RunnerClosing\nexport interface Options {\n\treadonly lease?: Duration.Input\n\treadonly grace?: Duration.Input\n\treadonly confirmationTimeout?: Duration.Input\n\treadonly limits?: Limits\n}\nexport interface Open {\n\treadonly key: Key\n\treadonly requestId: string\n\treadonly expectedGeneration?: number | null\n\treadonly lease?: Duration.Input\n\treadonly limits?: Limits\n}\nexport class Supervisor extends Context.Service<\n\tSupervisor,\n\t{\n\t\treadonly await: Effect.Effect<never, SupervisorError>\n\t\treadonly status: (\n\t\t\thandle: Handle,\n\t\t) => Effect.Effect<SessionRecord, StaleSession>\n\t\treadonly highWater: (key: Key) => Effect.Effect<number | null>\n\t\treadonly open: (\n\t\t\trequest: Open,\n\t\t) => Effect.Effect<SessionRecord, SupervisorError>\n\t\treadonly renew: (handle: Handle) => Effect.Effect<number, SupervisorError>\n\t\treadonly load: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t) => Effect.Effect<CodeIdentity, SupervisorError>\n\t\treadonly dispose: (\n\t\t\thandle: Handle,\n\t\t) => Effect.Effect<Termination, SupervisorError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/Supervisor\") {}\n\ntype Launch = Data.TaggedEnum<{\n\tStarting: {}\n\tRegistered: { readonly unit: Unit }\n}>\nconst Launch = Data.taggedEnum<Launch>()\ntype ExecutionState = Data.TaggedEnum<{\n\tAbsent: {}\n\tRunning: { readonly unit: Unit }\n\tExited: { readonly exit: ExitStatus }\n}>\nconst ExecutionState = Data.taggedEnum<ExecutionState>()\ntype LoadReply = Deferred.Deferred<CodeIdentity, SupervisorError>\ntype StopReply = Deferred.Deferred<Termination, SupervisorError>\ntype Session = Data.TaggedEnum<{\n\tOpen: { readonly record: typeof OpenRecord.Type; readonly deadline: bigint }\n\tLoading: {\n\t\treadonly record: typeof OpenRecord.Type\n\t\treadonly request: Load\n\t\treadonly launch: Launch\n\t\treadonly reply: LoadReply\n\t\treadonly deadline: bigint\n\t}\n\tLoaded: {\n\t\treadonly record: typeof LoadedRecord.Type\n\t\treadonly unit: Unit\n\t\treadonly deadline: bigint\n\t}\n\tStopping: {\n\t\treadonly record: typeof StoppingRecord.Type\n\t\treadonly execution: ExecutionState\n\t\treadonly reply: StopReply\n\t}\n\tStopped: {\n\t\treadonly record: typeof StoppedRecord.Type\n\t\treadonly reply: StopReply\n\t}\n}>\nconst Session = Data.taggedEnum<Session>()\ntype Live = Extract<Session, { readonly _tag: \"Open\" | \"Loading\" | \"Loaded\" }>\ntype Loading = Extract<Session, { readonly _tag: \"Loading\" }>\ntype Stopping = Extract<Session, { readonly _tag: \"Stopping\" }>\ninterface Entry {\n\treadonly state: SynchronizedRef.SynchronizedRef<Session>\n\treadonly timer: FiberHandle.FiberHandle<void, never>\n\treadonly loading: FiberHandle.FiberHandle<void, never>\n\treadonly scope: Scope.Closeable\n\treadonly unitScope: Scope.Closeable\n}\nfunction snapshot(state: Live): ActiveRecord\nfunction snapshot(state: Session): SessionRecord\nfunction snapshot(state: Session): SessionRecord {\n\treturn state._tag === \"Loading\"\n\t\t? {\n\t\t\t\t...state.record,\n\t\t\t\tphase: \"Loading\",\n\t\t\t\tload: state.request,\n\t\t\t\tlaunch:\n\t\t\t\t\tstate.launch._tag === \"Starting\"\n\t\t\t\t\t\t? { _tag: \"Starting\" }\n\t\t\t\t\t\t: { _tag: \"Registered\", child: state.launch.unit.identity },\n\t\t\t}\n\t\t: state.record\n}\nconst live = (\n\tstate: Session,\n\tnow: bigint,\n): Result.Result<Live, LeaseExpired | SessionStopped> => {\n\tif (state._tag === \"Stopping\" || state._tag === \"Stopped\")\n\t\treturn Result.fail(\n\t\t\tstate.record.reason._tag === \"Expired\"\n\t\t\t\t? LeaseExpired.make({\n\t\t\t\t\t\tdetail: \"The session lease has expired\",\n\t\t\t\t\t})\n\t\t\t\t: SessionStopped.make({\n\t\t\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t\t\t}),\n\t\t)\n\treturn now >= state.deadline\n\t\t? Result.fail(\n\t\t\t\tLeaseExpired.make({\n\t\t\t\t\tdetail: \"The session lease has expired\",\n\t\t\t\t}),\n\t\t\t)\n\t\t: Result.succeed(state)\n}\nconst executionOf = (state: Live): ExecutionState => {\n\tswitch (state._tag) {\n\t\tcase \"Open\":\n\t\t\treturn ExecutionState.Absent()\n\t\tcase \"Loading\":\n\t\t\treturn state.launch._tag === \"Registered\"\n\t\t\t\t? ExecutionState.Running({ unit: state.launch.unit })\n\t\t\t\t: ExecutionState.Absent()\n\t\tcase \"Loaded\":\n\t\t\treturn ExecutionState.Running({ unit: state.unit })\n\t}\n}\n/** All state transitions are pure; the caller serializes persistence and publication. */\nconst beginLoad = (\n\tstate: Extract<Session, { _tag: \"Open\" }>,\n\trequest: Load,\n\treply: LoadReply,\n): Loading =>\n\tSession.Loading({\n\t\trecord: state.record,\n\t\tdeadline: state.deadline,\n\t\trequest,\n\t\treply,\n\t\tlaunch: Launch.Starting(),\n\t})\nconst registerUnit = (\n\tstate: Session,\n\tunit: Unit,\n): Result.Result<Session, SessionStopped | ExecutionError> => {\n\tif (state._tag !== \"Loading\")\n\t\treturn Result.fail(\n\t\t\tSessionStopped.make({\n\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t}),\n\t\t)\n\tif (state.launch._tag === \"Registered\")\n\t\treturn Result.fail(\n\t\t\tExecutionError.make({\n\t\t\t\tdetail: \"An execution adapter registered more than one child\",\n\t\t\t}),\n\t\t)\n\treturn Result.succeed(\n\t\tSession.Loading({ ...state, launch: Launch.Registered({ unit }) }),\n\t)\n}\nconst loaded = (\n\tstate: Session,\n\tcode: CodeIdentity,\n): Result.Result<Session, SessionStopped | ExecutionError> => {\n\tif (state._tag !== \"Loading\")\n\t\treturn Result.fail(\n\t\t\tSessionStopped.make({\n\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t}),\n\t\t)\n\tif (state.launch._tag !== \"Registered\")\n\t\treturn Result.fail(\n\t\t\tExecutionError.make({\n\t\t\t\tdetail: \"Execution adapter returned without registering its child\",\n\t\t\t}),\n\t\t)\n\treturn Result.succeed(\n\t\tSession.Loaded({\n\t\t\tdeadline: state.deadline,\n\t\t\tunit: state.launch.unit,\n\t\t\trecord: {\n\t\t\t\t...state.record,\n\t\t\t\tphase: \"Loaded\",\n\t\t\t\tload: state.request,\n\t\t\t\tcode,\n\t\t\t\tchild: state.launch.unit.identity,\n\t\t\t},\n\t\t}),\n\t)\n}\nconst beginStop = (\n\tstate: Live,\n\treason: StopReason,\n\treply: StopReply,\n\texit: Option.Option<ExitStatus>,\n): Stopping =>\n\tSession.Stopping({\n\t\trecord: stoppingRecord(snapshot(state), reason),\n\t\treply,\n\t\texecution: Option.match(exit, {\n\t\t\tonNone: () => executionOf(state),\n\t\t\tonSome: (exit) => ExecutionState.Exited({ exit }),\n\t\t}),\n\t})\nconst nanos = (millis: number) => BigInt(Math.ceil(millis * 1_000_000))\nconst emptyTermination: Termination = {\n\tkind: \"Exited\",\n\texit: { code: 0, signal: null },\n\tcause: Cause.empty,\n}\nconst exitCause = <A, E>(exit: Exit.Exit<A, E>) =>\n\tExit.isFailure(exit) ? exit.cause : Cause.empty\n\n/** A signal is a request; only the exited effect confirms that the execution has stopped. */\nconst terminate = (\n\texecution: ExecutionState,\n\tgrace: number,\n\tconfirmation: number,\n): Effect.Effect<Termination, TerminationUnconfirmed> => {\n\tif (execution._tag === \"Absent\") return Effect.succeed(emptyTermination)\n\tif (execution._tag === \"Exited\")\n\t\treturn Effect.succeed({ ...emptyTermination, exit: execution.exit })\n\tconst child = execution.unit\n\treturn Effect.gen(function* () {\n\t\tconst graceful = yield* child.interrupt.pipe(\n\t\t\tEffect.andThen(child.exited),\n\t\t\tEffect.timeoutOption(grace),\n\t\t\tEffect.exit,\n\t\t)\n\t\tif (Exit.isSuccess(graceful) && Option.isSome(graceful.value))\n\t\t\treturn { ...emptyTermination, exit: graceful.value.value }\n\t\tconst killed = yield* Effect.exit(child.kill)\n\t\tconst forced = yield* child.exited.pipe(\n\t\t\tEffect.timeoutOption(confirmation),\n\t\t\tEffect.exit,\n\t\t)\n\t\tconst cause = Cause.combine(\n\t\t\tCause.combine(exitCause(graceful), exitCause(killed)),\n\t\t\texitCause(forced),\n\t\t)\n\t\tif (Exit.isFailure(forced) || Option.isNone(forced.value))\n\t\t\treturn yield* TerminationUnconfirmed.make({\n\t\t\t\tdetail: \"The child exit could not be confirmed\",\n\t\t\t\tcause,\n\t\t\t})\n\t\treturn {\n\t\t\tkind: \"Killed\",\n\t\t\texit: forced.value.value,\n\t\t\tcause,\n\t\t} satisfies Termination\n\t})\n}\n\nconst initialize = (options: Options = {}) =>\n\tEffect.gen(function* () {\n\t\tconst store = yield* Store\n\t\tconst execution = yield* Execution\n\t\tconst random = yield* SecureRandom.SecureRandom\n\t\tconst parent = yield* Effect.scope\n\t\tconst owner = yield* Scope.fork(parent)\n\t\t// Cleanup must continue after a health failure so every registered process is reaped.\n\t\tconst workers = yield* FiberSet.make<void, never>().pipe(\n\t\t\tScope.provide(owner),\n\t\t)\n\t\tconst locks = yield* RcMap.make({\n\t\t\tlookup: (_key: SessionKey) => Semaphore.make(1),\n\t\t}).pipe(Scope.provide(owner))\n\t\tconst lease = Duration.toMillis(options.lease ?? \"15 seconds\")\n\t\tconst grace = Duration.toMillis(options.grace ?? \"5 seconds\")\n\t\tconst confirmation = Duration.toMillis(\n\t\t\toptions.confirmationTimeout ?? \"5 seconds\",\n\t\t)\n\t\tconst limits = options.limits ?? defaults\n\t\tconst records = yield* Ref.make(HashMap.empty<string, SessionRecord>())\n\t\tconst entries = yield* Ref.make(HashMap.empty<string, Entry>())\n\t\tconst health = yield* FailureGroup.make<SupervisorError>().pipe(\n\t\t\tScope.provide(owner),\n\t\t)\n\t\tconst closing = yield* Ref.make(false)\n\t\treturn {\n\t\t\tstore,\n\t\t\texecution,\n\t\t\trandom,\n\t\t\towner,\n\t\t\tworkers,\n\t\t\tlocks,\n\t\t\tlease,\n\t\t\tgrace,\n\t\t\tconfirmation,\n\t\t\tlimits,\n\t\t\trecords,\n\t\t\tentries,\n\t\t\thealth,\n\t\t\tclosing,\n\t\t}\n\t})\ntype Runtime = Effect.Success<ReturnType<typeof initialize>>\nconst operations = (runtime: Runtime) => {\n\tconst {\n\t\tstore,\n\t\texecution,\n\t\tworkers,\n\t\tgrace,\n\t\tconfirmation,\n\t\trecords,\n\t\tentries,\n\t\thealth,\n\t\tclosing,\n\t} = runtime\n\n\tconst poison = health.failCause\n\tconst observe = <A>(effect: Effect.Effect<A, SupervisorError>) =>\n\t\teffect.pipe(Effect.asVoid, Effect.catchCause(poison))\n\tconst healthy = health.check.pipe(\n\t\tEffect.andThen(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tif (yield* Ref.get(closing))\n\t\t\t\t\treturn yield* RunnerClosing.make({ detail: \"The runner is closing\" })\n\t\t\t}),\n\t\t),\n\t)\n\tconst persist = (record: SessionRecord) =>\n\t\tstore\n\t\t\t.save(record)\n\t\t\t.pipe(\n\t\t\t\tEffect.tapCause(poison),\n\t\t\t\tEffect.andThen(\n\t\t\t\t\tRef.update(records, (all) => Retention.save(all, record)),\n\t\t\t\t),\n\t\t\t)\n\tconst status = (handle: Handle) =>\n\t\tRef.get(records).pipe(\n\t\t\tEffect.flatMap((all) => {\n\t\t\t\tconst found = HashMap.get(all, handle.token)\n\t\t\t\treturn Option.isSome(found) &&\n\t\t\t\t\tEqual.equals(keyOf(found.value.handle.key), keyOf(handle.key)) &&\n\t\t\t\t\tfound.value.handle.generation === handle.generation\n\t\t\t\t\t? Effect.succeed(found.value)\n\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\tStaleSession.make({\n\t\t\t\t\t\t\t\tdetail: \"Unknown session or generation\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t}),\n\t\t)\n\tconst latest = (key: Key) =>\n\t\tRef.get(records).pipe(\n\t\t\tEffect.map((all) =>\n\t\t\t\tArray.reduce(\n\t\t\t\t\tArray.fromIterable(HashMap.values(all)),\n\t\t\t\t\t0,\n\t\t\t\t\t(value, record) =>\n\t\t\t\t\t\tEqual.equals(keyOf(record.handle.key), keyOf(key))\n\t\t\t\t\t\t\t? Math.max(value, record.handle.generation)\n\t\t\t\t\t\t\t: value,\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\tconst entryFor = (handle: Handle) =>\n\t\tEffect.gen(function* () {\n\t\t\tyield* status(handle)\n\t\t\tconst all = yield* Ref.get(entries)\n\t\t\tconst found = HashMap.get(all, handle.token)\n\t\t\tif (Option.isNone(found))\n\t\t\t\treturn yield* SessionStopped.make({\n\t\t\t\t\tdetail: \"The session was retired during recovery\",\n\t\t\t\t})\n\t\t\treturn found.value\n\t\t})\n\tconst commit = (\n\t\tentry: Entry,\n\t\ttransition: (\n\t\t\tstate: Session,\n\t\t) => Result.Result<Session, ExecutionError | SessionStopped>,\n\t) =>\n\t\tSynchronizedRef.updateEffect(entry.state, (state) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst next = yield* Effect.fromResult(transition(state))\n\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\treturn next\n\t\t\t}),\n\t\t)\n\tconst finishStop = (\n\t\tentry: Entry,\n\t\tstate: Stopping,\n\t\tsaved: Exit.Exit<void, StateStorageError>,\n\t) =>\n\t\tEffect.gen(function* () {\n\t\t\tyield* FiberHandle.clear(entry.loading)\n\t\t\tconst result = yield* terminate(state.execution, grace, confirmation)\n\t\t\tconst closed = yield* Effect.exit(\n\t\t\t\tRelease.close(entry.unitScope, Exit.void),\n\t\t\t)\n\t\t\tconst termination: Termination = {\n\t\t\t\t...result,\n\t\t\t\tcause: Cause.combine(result.cause, exitCause(closed)),\n\t\t\t}\n\t\t\tconst record = stoppedRecord(\n\t\t\t\tstate.record.previous,\n\t\t\t\tstate.record.reason,\n\t\t\t\ttermination,\n\t\t\t)\n\t\t\tyield* SynchronizedRef.updateEffect(entry.state, () =>\n\t\t\t\tpersist(record).pipe(\n\t\t\t\t\tEffect.as(Session.Stopped({ record, reply: state.reply })),\n\t\t\t\t),\n\t\t\t)\n\t\t\tif (Exit.isFailure(saved)) return yield* Effect.failCause(saved.cause)\n\t\t\treturn termination\n\t\t})\n\t/** Called with the session ref locked; the worker starts after its transition is published. */\n\tconst stopLocked = (\n\t\tentry: Entry,\n\t\tstate: Session,\n\t\treason: StopReason,\n\t\texit: Option.Option<ExitStatus>,\n\t): Effect.Effect<readonly [StopReply, Session]> =>\n\t\tEffect.gen(function* () {\n\t\t\tif (state._tag === \"Stopping\" || state._tag === \"Stopped\")\n\t\t\t\treturn [state.reply, state]\n\t\t\tconst reply = yield* Deferred.make<Termination, SupervisorError>()\n\t\t\tconst next = beginStop(state, reason, reply, exit)\n\t\t\t// Fence in memory even when the journal cannot acknowledge the transition.\n\t\t\tconst saved = yield* Effect.exit(persist(next.record))\n\t\t\tyield* FiberSet.run(\n\t\t\t\tworkers,\n\t\t\t\tfinishStop(entry, next, saved).pipe(\n\t\t\t\t\tEffect.onExit((result) => Deferred.done(reply, result)),\n\t\t\t\t\tobserve,\n\t\t\t\t),\n\t\t\t\t{ startImmediately: false },\n\t\t\t)\n\t\t\treturn [reply, next]\n\t\t})\n\tconst stop = (\n\t\tentry: Entry,\n\t\treason: StopReason,\n\t\texit: Option.Option<ExitStatus> = Option.none(),\n\t) =>\n\t\tSynchronizedRef.modifyEffect(entry.state, (state) =>\n\t\t\tstopLocked(entry, state, reason, exit),\n\t\t).pipe(Effect.uninterruptible)\n\tconst scheduleLease = (entry: Entry, deadline: bigint) =>\n\t\tFiberHandle.run(\n\t\t\tentry.timer,\n\t\t\tobserve(\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\tyield* Effect.sleep(\n\t\t\t\t\t\tDuration.nanos(deadline > now ? deadline - now : 0n),\n\t\t\t\t\t)\n\t\t\t\t\tyield* SynchronizedRef.updateEffect(entry.state, (state) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstate._tag === \"Stopping\" ||\n\t\t\t\t\t\t\tstate._tag === \"Stopped\" ||\n\t\t\t\t\t\t\tstate.deadline !== deadline\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn Effect.succeed(state)\n\t\t\t\t\t\treturn stopLocked(\n\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\t{ _tag: \"Expired\" },\n\t\t\t\t\t\t\tOption.none(),\n\t\t\t\t\t\t).pipe(Effect.map(([, next]) => next))\n\t\t\t\t\t})\n\t\t\t\t}),\n\t\t\t),\n\t\t\t{ startImmediately: false },\n\t\t)\n\tconst register = (entry: Entry, unit: Unit) =>\n\t\tSynchronizedRef.updateEffect(entry.state, (state) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\tconst next = yield* Effect.fromResult(registerUnit(current, unit))\n\t\t\t\tyield* unit.renew(\n\t\t\t\t\tNumber(current.deadline - (yield* Clock.monotonicTimeNanos)) /\n\t\t\t\t\t\t1_000_000,\n\t\t\t\t)\n\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\tyield* FiberSet.run(\n\t\t\t\t\tworkers,\n\t\t\t\t\tobserve(\n\t\t\t\t\t\tunit.exited.pipe(\n\t\t\t\t\t\t\tEffect.flatMap((exit) =>\n\t\t\t\t\t\t\t\tstop(entry, { _tag: \"Exited\" }, Option.some(exit)),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\treturn next\n\t\t\t}),\n\t\t).pipe(Effect.uninterruptible)\n\tconst runLoad = (entry: Entry, state: Loading) =>\n\t\texecution\n\t\t\t.spawn(state.record.handle, state.request, state.record.limits)\n\t\t\t.pipe(\n\t\t\t\tScope.provide(entry.unitScope),\n\t\t\t\tEffect.flatMap((unit) =>\n\t\t\t\t\tregister(entry, unit).pipe(\n\t\t\t\t\t\tEffect.andThen(unit.start),\n\t\t\t\t\t\tEffect.as(unit.code),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tEffect.tap((code) => commit(entry, (current) => loaded(current, code))),\n\t\t\t\tEffect.onExit((result) =>\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tif (Exit.isSuccess(result)) {\n\t\t\t\t\t\t\tyield* Deferred.done(state.reply, result)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst current = yield* SynchronizedRef.get(entry.state)\n\t\t\t\t\t\tif (current._tag === \"Loading\")\n\t\t\t\t\t\t\tyield* stop(entry, { _tag: \"LoadFailed\", cause: result.cause })\n\t\t\t\t\t\tconst healthCause = yield* health.cause\n\t\t\t\t\t\tyield* Deferred.failCause(\n\t\t\t\t\t\t\tstate.reply,\n\t\t\t\t\t\t\tCause.combine(result.cause, healthCause),\n\t\t\t\t\t\t)\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\t// Load's caller observes its complete exit through the reply, including cancellation.\n\t\t\t\tEffect.exit,\n\t\t\t\tEffect.asVoid,\n\t\t\t)\n\n\treturn {\n\t\tpersist,\n\t\tstatus,\n\t\tlatest,\n\t\tentryFor,\n\t\tstop,\n\t\tscheduleLease,\n\t\trunLoad,\n\t\thealthy,\n\t}\n}\ntype Operations = ReturnType<typeof operations>\nconst recover = (runtime: Runtime, actions: Operations) =>\n\tEffect.gen(function* () {\n\t\tconst { store, execution, confirmation, records } = runtime\n\t\tconst { persist } = actions\n\t\t// Recover before the service is published. Construction does not resume old leases.\n\t\tconst stored = yield* store.list\n\t\tyield* Ref.set(\n\t\t\trecords,\n\t\t\tHashMap.fromIterable(\n\t\t\t\tArray.map(stored, (record) => [record.handle.token, record] as const),\n\t\t\t),\n\t\t)\n\t\tfor (const record of stored) {\n\t\t\tif (record.phase === \"Stopped\") continue\n\t\t\tconst child = childOf(record)\n\t\t\tconst termination = Option.isNone(child)\n\t\t\t\t? emptyTermination\n\t\t\t\t: yield* execution.recover(child.value).pipe(\n\t\t\t\t\t\tEffect.timeout(confirmation),\n\t\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\t\tExecutionError: (error) =>\n\t\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\t\tTerminationUnconfirmed.make({\n\t\t\t\t\t\t\t\t\t\tdetail: \"Orphan recovery did not confirm exit\",\n\t\t\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tTimeoutError: (error) =>\n\t\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\t\tTerminationUnconfirmed.make({\n\t\t\t\t\t\t\t\t\t\tdetail: \"Orphan recovery did not confirm exit\",\n\t\t\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\tyield* persist(\n\t\t\t\tstoppedRecord(\n\t\t\t\t\trecord.phase === \"Stopping\" ? record.previous : record,\n\t\t\t\t\t{ _tag: \"Recovery\" },\n\t\t\t\t\ttermination,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t})\nconst ownShutdown = (runtime: Runtime, actions: Operations) =>\n\tEffect.gen(function* () {\n\t\tconst { entries, health, closing } = runtime\n\t\tconst { stop } = actions\n\t\tyield* Effect.addFinalizer(() =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* Ref.set(closing, true)\n\t\t\t\tconst all = yield* Ref.get(entries)\n\t\t\t\tconst exits = yield* Effect.forEach(HashMap.values(all), (entry) =>\n\t\t\t\t\tstop(entry, { _tag: \"Shutdown\" }).pipe(\n\t\t\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t\t\t\tEffect.exit,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tconst initial: Cause.Cause<unknown> = yield* health.cause\n\t\t\t\tconst cause = Array.reduce(exits, initial, (cause, exit) =>\n\t\t\t\t\tCause.combine(\n\t\t\t\t\t\tcause,\n\t\t\t\t\t\tExit.isFailure(exit) ? exit.cause : exit.value.cause,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tif (cause.reasons.length > 0)\n\t\t\t\t\treturn yield* Effect.failCause(cleanupCause(cause))\n\t\t\t}),\n\t\t)\n\t})\nconst protocol = (runtime: Runtime, actions: Operations) =>\n\tEffect.gen(function* () {\n\t\tconst { random, owner, locks, lease, limits, records, entries, health } =\n\t\t\truntime\n\t\tconst {\n\t\t\tpersist,\n\t\t\tstatus,\n\t\t\tlatest,\n\t\t\tentryFor,\n\t\t\tstop,\n\t\t\tscheduleLease,\n\t\t\trunLoad,\n\t\t\thealthy,\n\t\t} = actions\n\t\treturn Supervisor.of({\n\t\t\tawait: health.await,\n\t\t\tstatus,\n\t\t\thighWater: (key) =>\n\t\t\t\tlatest(key).pipe(Effect.map((value) => (value === 0 ? null : value))),\n\t\t\topen: (request) =>\n\t\t\t\tEffect.scoped(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tyield* healthy\n\t\t\t\t\t\tconst leaseMillis = Duration.toMillis(request.lease ?? lease)\n\t\t\t\t\t\tconst negotiated = negotiate(limits, request.limits ?? defaults)\n\t\t\t\t\t\tconst lock = yield* RcMap.get(locks, keyOf(request.key))\n\t\t\t\t\t\treturn yield* lock.withPermit(\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tyield* healthy\n\t\t\t\t\t\t\t\tconst allRecords = yield* Ref.get(records)\n\t\t\t\t\t\t\t\tconst same = Array.filter(\n\t\t\t\t\t\t\t\t\tArray.fromIterable(HashMap.values(allRecords)),\n\t\t\t\t\t\t\t\t\t(row) =>\n\t\t\t\t\t\t\t\t\t\tEqual.equals(keyOf(row.handle.key), keyOf(request.key)),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst prior = Array.findFirst(\n\t\t\t\t\t\t\t\t\tsame,\n\t\t\t\t\t\t\t\t\t(row) => row.requestId === request.requestId,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (Option.isSome(prior)) return prior.value\n\t\t\t\t\t\t\t\tconst generation = yield* latest(request.key)\n\t\t\t\t\t\t\t\tif (generation !== (request.expectedGeneration ?? 0))\n\t\t\t\t\t\t\t\t\treturn yield* StaleSession.make({\n\t\t\t\t\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\t\t\t\t\"Open expectedGeneration does not match the generation high-water mark\",\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\tfor (const record of same) {\n\t\t\t\t\t\t\t\t\tconst allEntries = yield* Ref.get(entries)\n\t\t\t\t\t\t\t\t\tconst entry = HashMap.get(allEntries, record.handle.token)\n\t\t\t\t\t\t\t\t\tif (Option.isSome(entry))\n\t\t\t\t\t\t\t\t\t\tyield* stop(entry.value, { _tag: \"Superseded\" }).pipe(\n\t\t\t\t\t\t\t\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t\t\t\t\t\t\t\t\tEffect.tap((result) =>\n\t\t\t\t\t\t\t\t\t\t\t\tresult.cause.reasons.length === 0\n\t\t\t\t\t\t\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t\t\t\t\t\t\t: Effect.logWarning(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Superseded remote execution cleanup failed\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.cause,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t).pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tEffect.annotateLogs({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"remote.identity\": record.handle.key.identity,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"remote.instance\": record.handle.key.instance,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"remote.generation\": record.handle.generation,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tyield* healthy\n\t\t\t\t\t\t\t\tconst token = yield* random.uuidV4()\n\t\t\t\t\t\t\t\tconst record: typeof OpenRecord.Type = {\n\t\t\t\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\t\t\t\tphase: \"Open\",\n\t\t\t\t\t\t\t\t\thandle: {\n\t\t\t\t\t\t\t\t\t\tkey: request.key,\n\t\t\t\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t\t\t\tgeneration: generation + 1,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\trequestId: request.requestId,\n\t\t\t\t\t\t\t\t\tleaseMillis,\n\t\t\t\t\t\t\t\t\tlimits: negotiated,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn yield* Effect.uninterruptible(\n\t\t\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\t\t\tyield* persist(record)\n\t\t\t\t\t\t\t\t\t\tconst deadline =\n\t\t\t\t\t\t\t\t\t\t\t(yield* Clock.monotonicTimeNanos) + nanos(leaseMillis)\n\t\t\t\t\t\t\t\t\t\tconst scope = yield* Scope.fork(owner)\n\t\t\t\t\t\t\t\t\t\tconst entry: Entry = {\n\t\t\t\t\t\t\t\t\t\t\tstate: yield* SynchronizedRef.make<Session>(\n\t\t\t\t\t\t\t\t\t\t\t\tSession.Open({ record, deadline }),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\t\tunitScope: yield* Scope.fork(scope),\n\t\t\t\t\t\t\t\t\t\t\ttimer: yield* FiberHandle.make<void, never>().pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tScope.provide(scope),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\tloading: yield* FiberHandle.make<void, never>().pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tScope.provide(scope),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t// The store's retention policy is also the in-memory eviction policy.\n\t\t\t\t\t\t\t\t\t\tconst retained = yield* Ref.get(records)\n\t\t\t\t\t\t\t\t\t\tconst old = yield* Ref.modify(\n\t\t\t\t\t\t\t\t\t\t\tentries,\n\t\t\t\t\t\t\t\t\t\t\t(all) =>\n\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\tArray.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tArray.fromIterable(HashMap.entries(all)),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t([key]) => !HashMap.has(retained, key),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\tHashMap.set(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tHashMap.filter(all, (_, key) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tHashMap.has(retained, key),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t] as const,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tfor (const [, retired] of old)\n\t\t\t\t\t\t\t\t\t\t\tyield* Release.close(retired.scope, Exit.void)\n\t\t\t\t\t\t\t\t\t\tyield* scheduleLease(entry, deadline)\n\t\t\t\t\t\t\t\t\t\treturn record\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\trenew: (handle) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tyield* healthy\n\t\t\t\t\tconst entry = yield* entryFor(handle)\n\t\t\t\t\treturn yield* SynchronizedRef.modifyEffect(entry.state, (state) =>\n\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\t\t\t\tconst running = executionOf(current)\n\t\t\t\t\t\t\tif (running._tag === \"Running\")\n\t\t\t\t\t\t\t\tyield* running.unit.renew(current.record.leaseMillis)\n\t\t\t\t\t\t\tconst deadline = now + nanos(current.record.leaseMillis)\n\t\t\t\t\t\t\tyield* scheduleLease(entry, deadline)\n\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\tcurrent.record.leaseMillis,\n\t\t\t\t\t\t\t\t{ ...current, deadline },\n\t\t\t\t\t\t\t] as const\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\tload: (handle, request) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tyield* healthy\n\t\t\t\t\tconst entry = yield* entryFor(handle)\n\t\t\t\t\tconst reply = yield* SynchronizedRef.modifyEffect(\n\t\t\t\t\t\tentry.state,\n\t\t\t\t\t\t(state) =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\t\t\t\t\tif (current._tag !== \"Open\") {\n\t\t\t\t\t\t\t\t\tconst before =\n\t\t\t\t\t\t\t\t\t\tcurrent._tag === \"Loading\"\n\t\t\t\t\t\t\t\t\t\t\t? current.request\n\t\t\t\t\t\t\t\t\t\t\t: current.record.load\n\t\t\t\t\t\t\t\t\tif (before.specifier !== request.specifier)\n\t\t\t\t\t\t\t\t\t\treturn yield* SessionConflict.make({\n\t\t\t\t\t\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\t\t\t\t\t\"Load was already requested with a different specifier\",\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t\t\tcurrent._tag === \"Loading\"\n\t\t\t\t\t\t\t\t\t\t\t? Deferred.await(current.reply)\n\t\t\t\t\t\t\t\t\t\t\t: Effect.succeed(current.record.code),\n\t\t\t\t\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\t\t\t\t] as const\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst done = yield* Deferred.make<\n\t\t\t\t\t\t\t\t\tCodeIdentity,\n\t\t\t\t\t\t\t\t\tSupervisorError\n\t\t\t\t\t\t\t\t>()\n\t\t\t\t\t\t\t\tconst next = beginLoad(current, request, done)\n\t\t\t\t\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\t\t\t\t\tif (next._tag === \"Loading\")\n\t\t\t\t\t\t\t\t\tyield* FiberHandle.run(entry.loading, runLoad(entry, next), {\n\t\t\t\t\t\t\t\t\t\tstartImmediately: false,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\treturn [Deferred.await(done), next] as const\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t).pipe(Effect.uninterruptible)\n\t\t\t\t\treturn yield* reply\n\t\t\t\t}),\n\t\t\tdispose: (handle) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst record = yield* status(handle)\n\t\t\t\t\tif (record.phase === \"Stopped\") return record.termination\n\t\t\t\t\tconst entry = yield* entryFor(handle)\n\t\t\t\t\treturn yield* stop(entry, { _tag: \"Disposed\" }).pipe(\n\t\t\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t})\n\t})\nexport const make = (options: Options = {}) =>\n\tEffect.gen(function* () {\n\t\tconst runtime = yield* initialize(options)\n\t\tconst actions = operations(runtime)\n\t\tyield* recover(runtime, actions)\n\t\tyield* ownShutdown(runtime, actions)\n\t\treturn yield* protocol(runtime, actions)\n\t})\nexport const layer = (options: Options = {}) =>\n\tLayer.effect(Supervisor, make(options))\n"],"mappings":";;;;;;;;;AAuFA,IAAa,aAAb,cAAgC,QAAQ,QAoBtC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC;AAM5D,MAAM,SAAS,KAAK,WAAmB;AAMvC,MAAM,iBAAiB,KAAK,WAA2B;AA2BvD,MAAM,UAAU,KAAK,WAAoB;AAazC,SAAS,SAAS,OAA+B;CAChD,OAAO,MAAM,SAAS,YACnB;EACA,GAAG,MAAM;EACT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Q,UACR,QAAQ,OAAO,KAAA,CACR,cAAc,QAAQ,WAChC,OAAO,OAAO,gBAAgB,KAAK,EAClC,QACC,wDACF,CAAC;KACF,OAAO,CACN,QAAQ,SAAS,YACd,SAAS,MAAM,QAAQ,KAAK,IAC5B,OAAO,QAAQ,QAAQ,OAAO,IAAI,GACrC,OACD;IACD;IACA,MAAM,OAAO,OAAO,SAAS,KAG3B;IACF,MAAM,OAAO,UAAU,SAAS,SAAS,IAAI;IAC7C,OAAO,QAAQ,SAAS,IAAI,CAAC;IAC7B,IAAI,KAAK,SAAS,WACjB,OAAO,YAAY,IAAI,MAAM,SAAS,QAAQ,OAAO,IAAI,GAAG,EAC3D,kBAAkB,MACnB,CAAC;IACF,OAAO,CAAC,SAAS,MAAM,IAAI,GAAG,IAAI;GACnC,CAAC,CACH,CAAC,CAAC,KAAK,OAAO,eAAe;EAE9B,CAAC;EACF,UAAU,WACT,OAAO,IAAI,aAAa;GACvB,MAAM,SAAS,OAAO,OAAO,MAAM;GACnC,IAAI,OAAO,UAAU,WAAW,OAAO,OAAO;GAC9C,MAAM,QAAQ,OAAO,SAAS,MAAM;GACpC,OAAO,OAAO,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,KAC/C,OAAO,QAAQ,SAAS,KAAK,CAC9B;EACD,CAAC;CACH,CAAC;AACF,CAAC;AACF,MAAa,QAAQ,UAAmB,CAAC,MACxC,OAAO,IAAI,aAAa;CACvB,MAAM,UAAU,OAAO,WAAW,OAAO;CACzC,MAAM,UAAU,WAAW,OAAO;CAClC,OAAO,QAAQ,SAAS,OAAO;CAC/B,OAAO,YAAY,SAAS,OAAO;CACnC,OAAO,OAAO,SAAS,SAAS,OAAO;AACxC,CAAC;AACF,MAAa,SAAS,UAAmB,CAAC,MACzC,MAAM,OAAO,YAAY,KAAK,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"Supervisor.js","names":["FailureGroup.make","Retention.save","Release.close"],"sources":["../../../src/internal/runner/Supervisor.ts"],"sourcesContent":["import * as FailureGroup from \"../FailureGroup\"\nimport {\n\tArray,\n\tCause,\n\tClock,\n\tContext,\n\tData,\n\tDeferred,\n\tDuration,\n\tEffect,\n\tEqual,\n\tExit,\n\tFiberHandle,\n\tFiberSet,\n\tHashMap,\n\tLayer,\n\tOption,\n\tRcMap,\n\tRef,\n\tResult,\n\tScope,\n\tSemaphore,\n\tSynchronizedRef,\n} from \"effect\"\nimport * as Release from \"../release\"\nimport { SecureRandom } from \"effect/crypto\"\nimport * as Retention from \"./Retention\"\nimport { cleanupCause } from \"../cleanup\"\nimport {\n\tExecution,\n\tStore,\n\tStaleSession,\n\tLeaseExpired,\n\tSessionStopped,\n\tSessionConflict,\n\tStateStorageError,\n\tExecutionError,\n\tPackageError,\n\tTerminationUnconfirmed,\n\tRunnerClosing,\n\tchildOf,\n\tdefaults,\n\tkeyOf,\n\tnegotiate,\n\tstoppingRecord,\n\tstoppedRecord,\n\ttype ActiveRecord,\n\ttype CodeIdentity,\n\ttype ExitStatus,\n\ttype Handle,\n\ttype Key,\n\ttype Limits,\n\ttype Load,\n\ttype SessionRecord,\n\ttype SessionKey,\n\ttype StopReason,\n\ttype Termination,\n\ttype Unit,\n\ttype OpenRecord,\n\ttype LoadedRecord,\n\ttype StoppingRecord,\n\ttype StoppedRecord,\n} from \"./model\"\n\nexport type SupervisorError =\n\t| StaleSession\n\t| LeaseExpired\n\t| SessionStopped\n\t| SessionConflict\n\t| StateStorageError\n\t| ExecutionError\n\t| PackageError\n\t| TerminationUnconfirmed\n\t| RunnerClosing\nexport interface Options {\n\treadonly lease?: Duration.Input\n\treadonly grace?: Duration.Input\n\treadonly confirmationTimeout?: Duration.Input\n\treadonly limits?: Limits\n}\nexport interface Open {\n\treadonly key: Key\n\treadonly requestId: string\n\treadonly expectedGeneration?: number | null\n\treadonly lease?: Duration.Input\n\treadonly limits?: Limits\n}\nexport class Supervisor extends Context.Service<\n\tSupervisor,\n\t{\n\t\treadonly await: Effect.Effect<never, SupervisorError>\n\t\treadonly status: (\n\t\t\thandle: Handle,\n\t\t) => Effect.Effect<SessionRecord, StaleSession>\n\t\treadonly highWater: (key: Key) => Effect.Effect<number | null>\n\t\treadonly open: (\n\t\t\trequest: Open,\n\t\t) => Effect.Effect<SessionRecord, SupervisorError>\n\t\treadonly renew: (handle: Handle) => Effect.Effect<number, SupervisorError>\n\t\treadonly load: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t) => Effect.Effect<CodeIdentity, SupervisorError>\n\t\treadonly dispose: (\n\t\t\thandle: Handle,\n\t\t) => Effect.Effect<Termination, SupervisorError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/Supervisor\") {}\n\ntype Launch = Data.TaggedEnum<{\n\tStarting: {}\n\tRegistered: { readonly unit: Unit }\n}>\nconst Launch = Data.taggedEnum<Launch>()\ntype ExecutionState = Data.TaggedEnum<{\n\tAbsent: {}\n\tRunning: { readonly unit: Unit }\n\tExited: { readonly exit: ExitStatus }\n}>\nconst ExecutionState = Data.taggedEnum<ExecutionState>()\ntype LoadReply = Deferred.Deferred<CodeIdentity, SupervisorError>\ntype StopReply = Deferred.Deferred<Termination, SupervisorError>\ntype Session = Data.TaggedEnum<{\n\tOpen: { readonly record: typeof OpenRecord.Type; readonly deadline: bigint }\n\tLoading: {\n\t\treadonly record: typeof OpenRecord.Type\n\t\treadonly request: Load\n\t\treadonly launch: Launch\n\t\treadonly reply: LoadReply\n\t\treadonly deadline: bigint\n\t}\n\tLoaded: {\n\t\treadonly record: typeof LoadedRecord.Type\n\t\treadonly unit: Unit\n\t\treadonly deadline: bigint\n\t}\n\tStopping: {\n\t\treadonly record: typeof StoppingRecord.Type\n\t\treadonly execution: ExecutionState\n\t\treadonly reply: StopReply\n\t}\n\tStopped: {\n\t\treadonly record: typeof StoppedRecord.Type\n\t\treadonly reply: StopReply\n\t}\n}>\nconst Session = Data.taggedEnum<Session>()\ntype Live = Extract<Session, { readonly _tag: \"Open\" | \"Loading\" | \"Loaded\" }>\ntype Loading = Extract<Session, { readonly _tag: \"Loading\" }>\ntype Stopping = Extract<Session, { readonly _tag: \"Stopping\" }>\ninterface Entry {\n\treadonly state: SynchronizedRef.SynchronizedRef<Session>\n\treadonly timer: FiberHandle.FiberHandle<void, never>\n\treadonly loading: FiberHandle.FiberHandle<void, never>\n\treadonly scope: Scope.Closeable\n\treadonly unitScope: Scope.Closeable\n}\nfunction snapshot(state: Live): ActiveRecord\nfunction snapshot(state: Session): SessionRecord\nfunction snapshot(state: Session): SessionRecord {\n\treturn state._tag === \"Loading\"\n\t\t? {\n\t\t\t\t...state.record,\n\t\t\t\tphase: \"Loading\",\n\t\t\t\tload: state.request,\n\t\t\t\tlaunch:\n\t\t\t\t\tstate.launch._tag === \"Starting\"\n\t\t\t\t\t\t? { _tag: \"Starting\" }\n\t\t\t\t\t\t: { _tag: \"Registered\", child: state.launch.unit.identity },\n\t\t\t}\n\t\t: state.record\n}\nconst live = (\n\tstate: Session,\n\tnow: bigint,\n): Result.Result<Live, LeaseExpired | SessionStopped> => {\n\tif (state._tag === \"Stopping\" || state._tag === \"Stopped\")\n\t\treturn Result.fail(\n\t\t\tstate.record.reason._tag === \"Expired\"\n\t\t\t\t? LeaseExpired.make({\n\t\t\t\t\t\tdetail: \"The session lease has expired\",\n\t\t\t\t\t})\n\t\t\t\t: SessionStopped.make({\n\t\t\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t\t\t}),\n\t\t)\n\treturn now >= state.deadline\n\t\t? Result.fail(\n\t\t\t\tLeaseExpired.make({\n\t\t\t\t\tdetail: \"The session lease has expired\",\n\t\t\t\t}),\n\t\t\t)\n\t\t: Result.succeed(state)\n}\nconst executionOf = (state: Live): ExecutionState => {\n\tswitch (state._tag) {\n\t\tcase \"Open\":\n\t\t\treturn ExecutionState.Absent()\n\t\tcase \"Loading\":\n\t\t\treturn state.launch._tag === \"Registered\"\n\t\t\t\t? ExecutionState.Running({ unit: state.launch.unit })\n\t\t\t\t: ExecutionState.Absent()\n\t\tcase \"Loaded\":\n\t\t\treturn ExecutionState.Running({ unit: state.unit })\n\t}\n}\n/** All state transitions are pure; the caller serializes persistence and publication. */\nconst beginLoad = (\n\tstate: Extract<Session, { _tag: \"Open\" }>,\n\trequest: Load,\n\treply: LoadReply,\n): Loading =>\n\tSession.Loading({\n\t\trecord: state.record,\n\t\tdeadline: state.deadline,\n\t\trequest,\n\t\treply,\n\t\tlaunch: Launch.Starting(),\n\t})\nconst registerUnit = (\n\tstate: Session,\n\tunit: Unit,\n): Result.Result<Session, SessionStopped | ExecutionError> => {\n\tif (state._tag !== \"Loading\")\n\t\treturn Result.fail(\n\t\t\tSessionStopped.make({\n\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t}),\n\t\t)\n\tif (state.launch._tag === \"Registered\")\n\t\treturn Result.fail(\n\t\t\tExecutionError.make({\n\t\t\t\tdetail: \"An execution adapter registered more than one child\",\n\t\t\t}),\n\t\t)\n\treturn Result.succeed(\n\t\tSession.Loading({ ...state, launch: Launch.Registered({ unit }) }),\n\t)\n}\nconst loaded = (\n\tstate: Session,\n\tcode: CodeIdentity,\n): Result.Result<Session, SessionStopped | ExecutionError> => {\n\tif (state._tag !== \"Loading\")\n\t\treturn Result.fail(\n\t\t\tSessionStopped.make({\n\t\t\t\tdetail: \"The session is stopping or stopped\",\n\t\t\t}),\n\t\t)\n\tif (state.launch._tag !== \"Registered\")\n\t\treturn Result.fail(\n\t\t\tExecutionError.make({\n\t\t\t\tdetail: \"Execution adapter returned without registering its child\",\n\t\t\t}),\n\t\t)\n\treturn Result.succeed(\n\t\tSession.Loaded({\n\t\t\tdeadline: state.deadline,\n\t\t\tunit: state.launch.unit,\n\t\t\trecord: {\n\t\t\t\t...state.record,\n\t\t\t\tphase: \"Loaded\",\n\t\t\t\tload: state.request,\n\t\t\t\tcode,\n\t\t\t\tchild: state.launch.unit.identity,\n\t\t\t},\n\t\t}),\n\t)\n}\nconst beginStop = (\n\tstate: Live,\n\treason: StopReason,\n\treply: StopReply,\n\texit: Option.Option<ExitStatus>,\n): Stopping =>\n\tSession.Stopping({\n\t\trecord: stoppingRecord(snapshot(state), reason),\n\t\treply,\n\t\texecution: Option.match(exit, {\n\t\t\tonNone: () => executionOf(state),\n\t\t\tonSome: (exit) => ExecutionState.Exited({ exit }),\n\t\t}),\n\t})\nconst nanos = (millis: number) => BigInt(Math.ceil(millis * 1_000_000))\nconst emptyTermination: Termination = {\n\tkind: \"Exited\",\n\texit: { code: 0, signal: null },\n\tcause: Cause.empty,\n}\nconst exitCause = <A, E>(exit: Exit.Exit<A, E>) =>\n\tExit.isFailure(exit) ? exit.cause : Cause.empty\n\n/** A signal is a request; only the exited effect confirms that the execution has stopped. */\nconst terminate = Effect.fnUntraced(function* (\n\texecution: ExecutionState,\n\tgrace: number,\n\tconfirmation: number,\n): Effect.fn.Return<Termination, TerminationUnconfirmed> {\n\tif (execution._tag === \"Absent\") return emptyTermination\n\tif (execution._tag === \"Exited\")\n\t\treturn { ...emptyTermination, exit: execution.exit }\n\tconst child = execution.unit\n\tconst graceful = yield* child.interrupt.pipe(\n\t\tEffect.andThen(child.exited),\n\t\tEffect.timeoutOption(grace),\n\t\tEffect.exit,\n\t)\n\tif (Exit.isSuccess(graceful) && Option.isSome(graceful.value))\n\t\treturn { ...emptyTermination, exit: graceful.value.value }\n\tconst killed = yield* Effect.exit(child.kill)\n\tconst forced = yield* child.exited.pipe(\n\t\tEffect.timeoutOption(confirmation),\n\t\tEffect.exit,\n\t)\n\tconst cause = Cause.combine(\n\t\tCause.combine(exitCause(graceful), exitCause(killed)),\n\t\texitCause(forced),\n\t)\n\tif (Exit.isFailure(forced) || Option.isNone(forced.value))\n\t\treturn yield* TerminationUnconfirmed.make({\n\t\t\tdetail: \"The child exit could not be confirmed\",\n\t\t\tcause,\n\t\t})\n\treturn {\n\t\tkind: \"Killed\",\n\t\texit: forced.value.value,\n\t\tcause,\n\t} satisfies Termination\n})\n\nconst initialize = Effect.fnUntraced(function* (options: Options = {}) {\n\tconst store = yield* Store\n\tconst execution = yield* Execution\n\tconst random = yield* SecureRandom.SecureRandom\n\tconst parent = yield* Effect.scope\n\tconst owner = yield* Scope.fork(parent)\n\t// Cleanup must continue after a health failure so every registered process is reaped.\n\tconst workers = yield* FiberSet.make<void, never>().pipe(Scope.provide(owner))\n\tconst locks = yield* RcMap.make({\n\t\tlookup: (_key: SessionKey) => Semaphore.make(1),\n\t}).pipe(Scope.provide(owner))\n\tconst lease = Duration.toMillis(options.lease ?? \"15 seconds\")\n\tconst grace = Duration.toMillis(options.grace ?? \"5 seconds\")\n\tconst confirmation = Duration.toMillis(\n\t\toptions.confirmationTimeout ?? \"5 seconds\",\n\t)\n\tconst limits = options.limits ?? defaults\n\tconst records = yield* Ref.make(HashMap.empty<string, SessionRecord>())\n\tconst entries = yield* Ref.make(HashMap.empty<string, Entry>())\n\tconst health = yield* FailureGroup.make<SupervisorError>().pipe(\n\t\tScope.provide(owner),\n\t)\n\tconst closing = yield* Ref.make(false)\n\treturn {\n\t\tstore,\n\t\texecution,\n\t\trandom,\n\t\towner,\n\t\tworkers,\n\t\tlocks,\n\t\tlease,\n\t\tgrace,\n\t\tconfirmation,\n\t\tlimits,\n\t\trecords,\n\t\tentries,\n\t\thealth,\n\t\tclosing,\n\t}\n})\ntype Runtime = Effect.Success<ReturnType<typeof initialize>>\nconst operations = (runtime: Runtime) => {\n\tconst {\n\t\tstore,\n\t\texecution,\n\t\tworkers,\n\t\tgrace,\n\t\tconfirmation,\n\t\trecords,\n\t\tentries,\n\t\thealth,\n\t\tclosing,\n\t} = runtime\n\n\tconst poison = health.failCause\n\tconst observe = <A>(effect: Effect.Effect<A, SupervisorError>) =>\n\t\teffect.pipe(Effect.asVoid, Effect.catchCause(poison))\n\tconst healthy = health.check.pipe(\n\t\tEffect.andThen(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tif (yield* Ref.get(closing))\n\t\t\t\t\treturn yield* RunnerClosing.make({ detail: \"The runner is closing\" })\n\t\t\t}),\n\t\t),\n\t)\n\tconst persist = (record: SessionRecord) =>\n\t\tstore\n\t\t\t.save(record)\n\t\t\t.pipe(\n\t\t\t\tEffect.tapCause(poison),\n\t\t\t\tEffect.andThen(\n\t\t\t\t\tRef.update(records, (all) => Retention.save(all, record)),\n\t\t\t\t),\n\t\t\t)\n\tconst status = (handle: Handle) =>\n\t\tRef.get(records).pipe(\n\t\t\tEffect.flatMap((all) => {\n\t\t\t\tconst found = HashMap.get(all, handle.token)\n\t\t\t\treturn Option.isSome(found) &&\n\t\t\t\t\tEqual.equals(keyOf(found.value.handle.key), keyOf(handle.key)) &&\n\t\t\t\t\tfound.value.handle.generation === handle.generation\n\t\t\t\t\t? Effect.succeed(found.value)\n\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\tStaleSession.make({\n\t\t\t\t\t\t\t\tdetail: \"Unknown session or generation\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t}),\n\t\t)\n\tconst latest = (key: Key) =>\n\t\tRef.get(records).pipe(\n\t\t\tEffect.map((all) =>\n\t\t\t\tArray.reduce(\n\t\t\t\t\tArray.fromIterable(HashMap.values(all)),\n\t\t\t\t\t0,\n\t\t\t\t\t(value, record) =>\n\t\t\t\t\t\tEqual.equals(keyOf(record.handle.key), keyOf(key))\n\t\t\t\t\t\t\t? Math.max(value, record.handle.generation)\n\t\t\t\t\t\t\t: value,\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\tconst entryFor = Effect.fnUntraced(function* (handle: Handle) {\n\t\tyield* status(handle)\n\t\tconst all = yield* Ref.get(entries)\n\t\tconst found = HashMap.get(all, handle.token)\n\t\tif (Option.isNone(found))\n\t\t\treturn yield* SessionStopped.make({\n\t\t\t\tdetail: \"The session was retired during recovery\",\n\t\t\t})\n\t\treturn found.value\n\t})\n\tconst commit = (\n\t\tentry: Entry,\n\t\ttransition: (\n\t\t\tstate: Session,\n\t\t) => Result.Result<Session, ExecutionError | SessionStopped>,\n\t) =>\n\t\tSynchronizedRef.updateEffect(\n\t\t\tentry.state,\n\t\t\tEffect.fnUntraced(function* (state: Session) {\n\t\t\t\tconst next = yield* Effect.fromResult(transition(state))\n\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\treturn next\n\t\t\t}),\n\t\t)\n\tconst finishStop = Effect.fnUntraced(function* (\n\t\tentry: Entry,\n\t\tstate: Stopping,\n\t\tsaved: Exit.Exit<void, StateStorageError>,\n\t) {\n\t\tyield* FiberHandle.clear(entry.loading)\n\t\tconst result = yield* terminate(state.execution, grace, confirmation)\n\t\tconst closed = yield* Effect.exit(Release.close(entry.unitScope, Exit.void))\n\t\tconst termination: Termination = {\n\t\t\t...result,\n\t\t\tcause: Cause.combine(result.cause, exitCause(closed)),\n\t\t}\n\t\tconst record = stoppedRecord(\n\t\t\tstate.record.previous,\n\t\t\tstate.record.reason,\n\t\t\ttermination,\n\t\t)\n\t\tyield* SynchronizedRef.updateEffect(entry.state, () =>\n\t\t\tpersist(record).pipe(\n\t\t\t\tEffect.as(Session.Stopped({ record, reply: state.reply })),\n\t\t\t),\n\t\t)\n\t\tif (Exit.isFailure(saved)) return yield* Effect.failCause(saved.cause)\n\t\treturn termination\n\t})\n\t/** Called with the session ref locked; the worker starts after its transition is published. */\n\tconst stopLocked = Effect.fnUntraced(function* (\n\t\tentry: Entry,\n\t\tstate: Session,\n\t\treason: StopReason,\n\t\texit: Option.Option<ExitStatus>,\n\t): Effect.fn.Return<readonly [StopReply, Session]> {\n\t\tif (state._tag === \"Stopping\" || state._tag === \"Stopped\")\n\t\t\treturn [state.reply, state] as const\n\t\tconst reply = yield* Deferred.make<Termination, SupervisorError>()\n\t\tconst next = beginStop(state, reason, reply, exit)\n\t\t// Fence in memory even when the journal cannot acknowledge the transition.\n\t\tconst saved = yield* Effect.exit(persist(next.record))\n\t\tyield* FiberSet.run(\n\t\t\tworkers,\n\t\t\tfinishStop(entry, next, saved).pipe(\n\t\t\t\tEffect.onExit((result) => Deferred.done(reply, result)),\n\t\t\t\tobserve,\n\t\t\t),\n\t\t\t{ startImmediately: false },\n\t\t)\n\t\treturn [reply, next] as const\n\t})\n\tconst stop = (\n\t\tentry: Entry,\n\t\treason: StopReason,\n\t\texit: Option.Option<ExitStatus> = Option.none(),\n\t) =>\n\t\tSynchronizedRef.modifyEffect(entry.state, (state) =>\n\t\t\tstopLocked(entry, state, reason, exit),\n\t\t).pipe(Effect.uninterruptible)\n\tconst scheduleLease = (entry: Entry, deadline: bigint) =>\n\t\tFiberHandle.run(\n\t\t\tentry.timer,\n\t\t\tobserve(\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\tyield* Effect.sleep(\n\t\t\t\t\t\tDuration.nanos(deadline > now ? deadline - now : 0n),\n\t\t\t\t\t)\n\t\t\t\t\tyield* SynchronizedRef.updateEffect(entry.state, (state) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tstate._tag === \"Stopping\" ||\n\t\t\t\t\t\t\tstate._tag === \"Stopped\" ||\n\t\t\t\t\t\t\tstate.deadline !== deadline\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn Effect.succeed(state)\n\t\t\t\t\t\treturn stopLocked(\n\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\t{ _tag: \"Expired\" },\n\t\t\t\t\t\t\tOption.none(),\n\t\t\t\t\t\t).pipe(Effect.map(([, next]) => next))\n\t\t\t\t\t})\n\t\t\t\t}),\n\t\t\t),\n\t\t\t{ startImmediately: false },\n\t\t)\n\tconst register = (entry: Entry, unit: Unit) =>\n\t\tSynchronizedRef.updateEffect(\n\t\t\tentry.state,\n\t\t\tEffect.fnUntraced(function* (state: Session) {\n\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\tconst next = yield* Effect.fromResult(registerUnit(current, unit))\n\t\t\t\tyield* unit.renew(\n\t\t\t\t\tNumber(current.deadline - (yield* Clock.monotonicTimeNanos)) /\n\t\t\t\t\t\t1_000_000,\n\t\t\t\t)\n\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\tyield* FiberSet.run(\n\t\t\t\t\tworkers,\n\t\t\t\t\tobserve(\n\t\t\t\t\t\tunit.exited.pipe(\n\t\t\t\t\t\t\tEffect.flatMap((exit) =>\n\t\t\t\t\t\t\t\tstop(entry, { _tag: \"Exited\" }, Option.some(exit)),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\treturn next\n\t\t\t}),\n\t\t).pipe(Effect.uninterruptible)\n\tconst runLoad = (entry: Entry, state: Loading) =>\n\t\texecution\n\t\t\t.spawn(state.record.handle, state.request, state.record.limits)\n\t\t\t.pipe(\n\t\t\t\tScope.provide(entry.unitScope),\n\t\t\t\tEffect.flatMap((unit) =>\n\t\t\t\t\tregister(entry, unit).pipe(\n\t\t\t\t\t\tEffect.andThen(unit.start),\n\t\t\t\t\t\tEffect.as(unit.code),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tEffect.tap((code) => commit(entry, (current) => loaded(current, code))),\n\t\t\t\tEffect.onExit(\n\t\t\t\t\tEffect.fnUntraced(function* (\n\t\t\t\t\t\tresult: Exit.Exit<CodeIdentity, SupervisorError>,\n\t\t\t\t\t) {\n\t\t\t\t\t\tif (Exit.isSuccess(result)) {\n\t\t\t\t\t\t\tyield* Deferred.done(state.reply, result)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst current = yield* SynchronizedRef.get(entry.state)\n\t\t\t\t\t\tif (current._tag === \"Loading\")\n\t\t\t\t\t\t\tyield* stop(entry, { _tag: \"LoadFailed\", cause: result.cause })\n\t\t\t\t\t\tconst healthCause = yield* health.cause\n\t\t\t\t\t\tyield* Deferred.failCause(\n\t\t\t\t\t\t\tstate.reply,\n\t\t\t\t\t\t\tCause.combine(result.cause, healthCause),\n\t\t\t\t\t\t)\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\t// Load's caller observes its complete exit through the reply, including cancellation.\n\t\t\t\tEffect.exit,\n\t\t\t\tEffect.asVoid,\n\t\t\t)\n\n\treturn {\n\t\tpersist,\n\t\tstatus,\n\t\tlatest,\n\t\tentryFor,\n\t\tstop,\n\t\tscheduleLease,\n\t\trunLoad,\n\t\thealthy,\n\t}\n}\ntype Operations = ReturnType<typeof operations>\nconst recover = Effect.fnUntraced(function* (\n\truntime: Runtime,\n\tactions: Operations,\n) {\n\tconst { store, execution, confirmation, records } = runtime\n\tconst { persist } = actions\n\t// Recover before the service is published. Construction does not resume old leases.\n\tconst stored = yield* store.list\n\tyield* Ref.set(\n\t\trecords,\n\t\tHashMap.fromIterable(\n\t\t\tArray.map(stored, (record) => [record.handle.token, record] as const),\n\t\t),\n\t)\n\tfor (const record of stored) {\n\t\tif (record.phase === \"Stopped\") continue\n\t\tconst child = childOf(record)\n\t\tconst termination = Option.isNone(child)\n\t\t\t? emptyTermination\n\t\t\t: yield* execution.recover(child.value).pipe(\n\t\t\t\t\tEffect.timeout(confirmation),\n\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\tExecutionError: (error) =>\n\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\tTerminationUnconfirmed.make({\n\t\t\t\t\t\t\t\t\tdetail: \"Orphan recovery did not confirm exit\",\n\t\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tTimeoutError: (error) =>\n\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\tTerminationUnconfirmed.make({\n\t\t\t\t\t\t\t\t\tdetail: \"Orphan recovery did not confirm exit\",\n\t\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\tyield* persist(\n\t\t\tstoppedRecord(\n\t\t\t\trecord.phase === \"Stopping\" ? record.previous : record,\n\t\t\t\t{ _tag: \"Recovery\" },\n\t\t\t\ttermination,\n\t\t\t),\n\t\t)\n\t}\n})\nconst ownShutdown = Effect.fnUntraced(function* (\n\truntime: Runtime,\n\tactions: Operations,\n) {\n\tconst { entries, health, closing } = runtime\n\tconst { stop } = actions\n\tyield* Effect.addFinalizer(\n\t\tEffect.fnUntraced(function* () {\n\t\t\tyield* Ref.set(closing, true)\n\t\t\tconst all = yield* Ref.get(entries)\n\t\t\tconst exits = yield* Effect.forEach(HashMap.values(all), (entry) =>\n\t\t\t\tstop(entry, { _tag: \"Shutdown\" }).pipe(\n\t\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t\t\tEffect.exit,\n\t\t\t\t),\n\t\t\t)\n\t\t\tconst initial: Cause.Cause<unknown> = yield* health.cause\n\t\t\tconst cause = Array.reduce(exits, initial, (cause, exit) =>\n\t\t\t\tCause.combine(\n\t\t\t\t\tcause,\n\t\t\t\t\tExit.isFailure(exit) ? exit.cause : exit.value.cause,\n\t\t\t\t),\n\t\t\t)\n\t\t\tif (cause.reasons.length > 0)\n\t\t\t\treturn yield* Effect.failCause(cleanupCause(cause))\n\t\t}),\n\t)\n})\nconst protocol = Effect.fnUntraced(function* (\n\truntime: Runtime,\n\tactions: Operations,\n) {\n\tconst { random, owner, locks, lease, limits, records, entries, health } =\n\t\truntime\n\tconst {\n\t\tpersist,\n\t\tstatus,\n\t\tlatest,\n\t\tentryFor,\n\t\tstop,\n\t\tscheduleLease,\n\t\trunLoad,\n\t\thealthy,\n\t} = actions\n\treturn Supervisor.of({\n\t\tawait: health.await,\n\t\tstatus,\n\t\thighWater: (key) =>\n\t\t\tlatest(key).pipe(Effect.map((value) => (value === 0 ? null : value))),\n\t\topen: Effect.fnUntraced(function* (request: Open) {\n\t\t\tyield* healthy\n\t\t\tconst leaseMillis = Duration.toMillis(request.lease ?? lease)\n\t\t\tconst negotiated = negotiate(limits, request.limits ?? defaults)\n\t\t\tconst lock = yield* RcMap.get(locks, keyOf(request.key))\n\t\t\treturn yield* Effect.gen(function* () {\n\t\t\t\tyield* healthy\n\t\t\t\tconst allRecords = yield* Ref.get(records)\n\t\t\t\tconst same = Array.filter(\n\t\t\t\t\tArray.fromIterable(HashMap.values(allRecords)),\n\t\t\t\t\t(row) => Equal.equals(keyOf(row.handle.key), keyOf(request.key)),\n\t\t\t\t)\n\t\t\t\tconst prior = Array.findFirst(\n\t\t\t\t\tsame,\n\t\t\t\t\t(row) => row.requestId === request.requestId,\n\t\t\t\t)\n\t\t\t\tif (Option.isSome(prior)) return prior.value\n\t\t\t\tconst generation = yield* latest(request.key)\n\t\t\t\tif (generation !== (request.expectedGeneration ?? 0))\n\t\t\t\t\treturn yield* StaleSession.make({\n\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\"Open expectedGeneration does not match the generation high-water mark\",\n\t\t\t\t\t})\n\t\t\t\tfor (const record of same) {\n\t\t\t\t\tconst allEntries = yield* Ref.get(entries)\n\t\t\t\t\tconst entry = HashMap.get(allEntries, record.handle.token)\n\t\t\t\t\tif (Option.isSome(entry))\n\t\t\t\t\t\tyield* stop(entry.value, { _tag: \"Superseded\" }).pipe(\n\t\t\t\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t\t\t\t\tEffect.tap((result) =>\n\t\t\t\t\t\t\t\tresult.cause.reasons.length === 0\n\t\t\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t\t\t: Effect.logWarning(\n\t\t\t\t\t\t\t\t\t\t\t\"Superseded remote execution cleanup failed\",\n\t\t\t\t\t\t\t\t\t\t\tresult.cause,\n\t\t\t\t\t\t\t\t\t\t).pipe(\n\t\t\t\t\t\t\t\t\t\t\tEffect.annotateLogs({\n\t\t\t\t\t\t\t\t\t\t\t\t\"remote.identity\": record.handle.key.identity,\n\t\t\t\t\t\t\t\t\t\t\t\t\"remote.instance\": record.handle.key.instance,\n\t\t\t\t\t\t\t\t\t\t\t\t\"remote.generation\": record.handle.generation,\n\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tyield* healthy\n\t\t\t\tconst token = yield* random.uuidV4()\n\t\t\t\tconst record: typeof OpenRecord.Type = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tphase: \"Open\",\n\t\t\t\t\thandle: {\n\t\t\t\t\t\tkey: request.key,\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\tgeneration: generation + 1,\n\t\t\t\t\t},\n\t\t\t\t\trequestId: request.requestId,\n\t\t\t\t\tleaseMillis,\n\t\t\t\t\tlimits: negotiated,\n\t\t\t\t}\n\t\t\t\treturn yield* Effect.uninterruptible(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tyield* persist(record)\n\t\t\t\t\t\tconst deadline =\n\t\t\t\t\t\t\t(yield* Clock.monotonicTimeNanos) + nanos(leaseMillis)\n\t\t\t\t\t\tconst scope = yield* Scope.fork(owner)\n\t\t\t\t\t\tconst entry: Entry = {\n\t\t\t\t\t\t\tstate: yield* SynchronizedRef.make<Session>(\n\t\t\t\t\t\t\t\tSession.Open({ record, deadline }),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\tunitScope: yield* Scope.fork(scope),\n\t\t\t\t\t\t\ttimer: yield* FiberHandle.make<void, never>().pipe(\n\t\t\t\t\t\t\t\tScope.provide(scope),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tloading: yield* FiberHandle.make<void, never>().pipe(\n\t\t\t\t\t\t\t\tScope.provide(scope),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// The store's retention policy is also the in-memory eviction policy.\n\t\t\t\t\t\tconst retained = yield* Ref.get(records)\n\t\t\t\t\t\tconst old = yield* Ref.modify(\n\t\t\t\t\t\t\tentries,\n\t\t\t\t\t\t\t(all) =>\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tArray.filter(\n\t\t\t\t\t\t\t\t\t\tArray.fromIterable(HashMap.entries(all)),\n\t\t\t\t\t\t\t\t\t\t([key]) => !HashMap.has(retained, key),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tHashMap.set(\n\t\t\t\t\t\t\t\t\t\tHashMap.filter(all, (_, key) => HashMap.has(retained, key)),\n\t\t\t\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t] as const,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tfor (const [, retired] of old)\n\t\t\t\t\t\t\tyield* Release.close(retired.scope, Exit.void)\n\t\t\t\t\t\tyield* scheduleLease(entry, deadline)\n\t\t\t\t\t\treturn record\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}).pipe(lock.withPermit)\n\t\t}, Effect.scoped),\n\t\trenew: Effect.fnUntraced(function* (handle: Handle) {\n\t\t\tyield* healthy\n\t\t\tconst entry = yield* entryFor(handle)\n\t\t\t// Arming the new timer interrupts the old one, so the new deadline must be stored too.\n\t\t\t// Telling the child may block on its control pipe, so that step stays interruptible:\n\t\t\t// if it is cut short, nothing is stored and the old timer keeps its deadline.\n\t\t\treturn yield* Effect.uninterruptibleMask((restore) =>\n\t\t\t\tSynchronizedRef.modifyEffect(\n\t\t\t\t\tentry.state,\n\t\t\t\t\tEffect.fnUntraced(function* (state: Session) {\n\t\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\t\t\tconst running = executionOf(current)\n\t\t\t\t\t\tif (running._tag === \"Running\")\n\t\t\t\t\t\t\tyield* restore(running.unit.renew(current.record.leaseMillis))\n\t\t\t\t\t\tconst deadline = now + nanos(current.record.leaseMillis)\n\t\t\t\t\t\tyield* scheduleLease(entry, deadline)\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tcurrent.record.leaseMillis,\n\t\t\t\t\t\t\t{ ...current, deadline },\n\t\t\t\t\t\t] as const\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\t\t}),\n\t\tload: Effect.fnUntraced(function* (handle: Handle, request: Load) {\n\t\t\tyield* healthy\n\t\t\tconst entry = yield* entryFor(handle)\n\t\t\tconst reply = yield* SynchronizedRef.modifyEffect(\n\t\t\t\tentry.state,\n\t\t\t\tEffect.fnUntraced(function* (state: Session) {\n\t\t\t\t\tconst now = yield* Clock.monotonicTimeNanos\n\t\t\t\t\tconst current = yield* Effect.fromResult(live(state, now))\n\t\t\t\t\tif (current._tag !== \"Open\") {\n\t\t\t\t\t\tconst before =\n\t\t\t\t\t\t\tcurrent._tag === \"Loading\" ? current.request : current.record.load\n\t\t\t\t\t\tif (before.specifier !== request.specifier)\n\t\t\t\t\t\t\treturn yield* SessionConflict.make({\n\t\t\t\t\t\t\t\tdetail: \"Load was already requested with a different specifier\",\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tcurrent._tag === \"Loading\"\n\t\t\t\t\t\t\t\t? Deferred.await(current.reply)\n\t\t\t\t\t\t\t\t: Effect.succeed(current.record.code),\n\t\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\t] as const\n\t\t\t\t\t}\n\t\t\t\t\tconst done = yield* Deferred.make<CodeIdentity, SupervisorError>()\n\t\t\t\t\tconst next = beginLoad(current, request, done)\n\t\t\t\t\tyield* persist(snapshot(next))\n\t\t\t\t\tif (next._tag === \"Loading\")\n\t\t\t\t\t\tyield* FiberHandle.run(entry.loading, runLoad(entry, next), {\n\t\t\t\t\t\t\tstartImmediately: false,\n\t\t\t\t\t\t})\n\t\t\t\t\treturn [Deferred.await(done), next] as const\n\t\t\t\t}),\n\t\t\t).pipe(Effect.uninterruptible)\n\t\t\treturn yield* reply\n\t\t}),\n\t\tdispose: Effect.fnUntraced(function* (handle: Handle) {\n\t\t\tconst record = yield* status(handle)\n\t\t\tif (record.phase === \"Stopped\") return record.termination\n\t\t\tconst entry = yield* entryFor(handle)\n\t\t\treturn yield* stop(entry, { _tag: \"Disposed\" }).pipe(\n\t\t\t\tEffect.flatMap(Deferred.await),\n\t\t\t)\n\t\t}),\n\t})\n})\nexport const make = Effect.fnUntraced(function* (options: Options = {}) {\n\tconst runtime = yield* initialize(options)\n\tconst actions = operations(runtime)\n\tyield* recover(runtime, actions)\n\tyield* ownShutdown(runtime, actions)\n\treturn yield* protocol(runtime, actions)\n})\nexport const layer = (options: Options = {}) =>\n\tLayer.effect(Supervisor, make(options))\n"],"mappings":";;;;;;;;;AAuFA,IAAa,aAAb,cAAgC,QAAQ,QAoBtC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC;AAM5D,MAAM,SAAS,KAAK,WAAmB;AAMvC,MAAM,iBAAiB,KAAK,WAA2B;AA2BvD,MAAM,UAAU,KAAK,WAAoB;AAazC,SAAS,SAAS,OAA+B;CAChD,OAAO,MAAM,SAAS,YACnB;EACA,GAAG,MAAM;EACT,OAAO;EACP,MAAM,MAAM;EACZ,QACC,MAAM,OAAO,SAAS,aACnB,EAAE,MAAM,WAAW,IACnB;GAAE,MAAM;GAAc,OAAO,MAAM,OAAO,KAAK;EAAS;CAC7D,IACC,MAAM;AACV;AACA,MAAM,QACL,OACA,QACwD;CACxD,IAAI,MAAM,SAAS,cAAc,MAAM,SAAS,WAC/C,OAAO,OAAO,KACb,MAAM,OAAO,OAAO,SAAS,YAC1B,aAAa,KAAK,EAClB,QAAQ,gCACT,CAAC,IACA,eAAe,KAAK,EACpB,QAAQ,qCACT,CAAC,CACJ;CACD,OAAO,OAAO,MAAM,WACjB,OAAO,KACP,aAAa,KAAK,EACjB,QAAQ,gCACT,CAAC,CACF,IACC,OAAO,QAAQ,KAAK;AACxB;AACA,MAAM,eAAe,UAAgC;CACpD,Q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CACF,CAAC,CAAC,KAAK,OAAO,eAAe;EAE9B,CAAC;EACD,SAAS,OAAO,WAAW,WAAW,QAAgB;GACrD,MAAM,SAAS,OAAO,OAAO,MAAM;GACnC,IAAI,OAAO,UAAU,WAAW,OAAO,OAAO;GAC9C,MAAM,QAAQ,OAAO,SAAS,MAAM;GACpC,OAAO,OAAO,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,KAC/C,OAAO,QAAQ,SAAS,KAAK,CAC9B;EACD,CAAC;CACF,CAAC;AACF,CAAC;AACD,MAAa,OAAO,OAAO,WAAW,WAAW,UAAmB,CAAC,GAAG;CACvE,MAAM,UAAU,OAAO,WAAW,OAAO;CACzC,MAAM,UAAU,WAAW,OAAO;CAClC,OAAO,QAAQ,SAAS,OAAO;CAC/B,OAAO,YAAY,SAAS,OAAO;CACnC,OAAO,OAAO,SAAS,SAAS,OAAO;AACxC,CAAC;AACD,MAAa,SAAS,UAAmB,CAAC,MACzC,MAAM,OAAO,YAAY,KAAK,OAAO,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { SessionAccessDenied, SessionConflict } from "./model.js";
|
|
|
7
7
|
import { Cause, Effect, Option, Ref, Scope, Semaphore } from "effect";
|
|
8
8
|
import { RpcServer } from "effect/rpc";
|
|
9
9
|
// src/internal/runner/accept.ts
|
|
10
|
-
const accept = (supervisor, execution, channel$1)
|
|
10
|
+
const accept = Effect.fnUntraced(function* (supervisor, execution, channel$1) {
|
|
11
11
|
const identity = yield* Peer;
|
|
12
12
|
const scope = yield* Effect.scope;
|
|
13
13
|
const mux = yield* make$1(channel$1);
|
|
@@ -34,7 +34,7 @@ const accept = (supervisor, execution, channel$1) => Effect.gen(function* () {
|
|
|
34
34
|
...leaseMillis === void 0 ? {} : { lease: leaseMillis },
|
|
35
35
|
limits
|
|
36
36
|
}),
|
|
37
|
-
Load: ({ handle, ...request })
|
|
37
|
+
Load: Effect.fnUntraced(function* ({ handle, ...request }) {
|
|
38
38
|
yield* authorize(handle);
|
|
39
39
|
const attachment = yield* Ref.get(attached);
|
|
40
40
|
if (Option.isSome(attachment) && attachment.value !== handle.token) return yield* SessionConflict.make({ detail: "A connection can attach only one execution" });
|
|
@@ -45,7 +45,7 @@ const accept = (supervisor, execution, channel$1) => Effect.gen(function* () {
|
|
|
45
45
|
yield* Effect.all([Effect.forever(Effect.flatMap(mux.take(1), (bytes) => child.send(1, bytes))), Effect.forever(Effect.flatMap(child.take(1), (bytes) => mux.send(1, bytes)))], { concurrency: "unbounded" }).pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : child.fail(TransportError.make({ cause }))), Effect.forkIn(scope));
|
|
46
46
|
}
|
|
47
47
|
return code;
|
|
48
|
-
}
|
|
48
|
+
}, loading.withPermit),
|
|
49
49
|
Renew: (handle) => authorize(handle).pipe(Effect.andThen(supervisor.renew(handle))),
|
|
50
50
|
Dispose: (handle) => authorize(handle).pipe(Effect.andThen(supervisor.dispose(handle))),
|
|
51
51
|
Status: (handle) => authorize(handle).pipe(Effect.andThen(supervisor.status(handle)))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept.js","names":["Multiplex.make","channel","Port.make","Wire.channel","Wire.Session"],"sources":["../../../src/internal/runner/accept.ts"],"sourcesContent":["import { Cause, Effect, Ref, Option, Scope, Semaphore } from \"effect\"\nimport { RpcServer } from \"effect/rpc\"\nimport { Peer } from \"../Peer\"\nimport { TransportError } from \"../../Errors\"\nimport type { Channel } from \"../../Transport\"\nimport type { Supervisor } from \"./Supervisor\"\nimport type { Channels } from \"./Execution\"\nimport * as Port from \"../port\"\nimport * as Multiplex from \"./Multiplex\"\nimport * as Wire from \"./Wire\"\nimport { SessionAccessDenied, SessionConflict, type Handle } from \"./model\"\n\nexport const accept = (\n\tsupervisor: typeof Supervisor.Service,\n\texecution: typeof Channels.Service,\n\tchannel: Channel,\n)
|
|
1
|
+
{"version":3,"file":"accept.js","names":["Multiplex.make","channel","Port.make","Wire.channel","Wire.Session"],"sources":["../../../src/internal/runner/accept.ts"],"sourcesContent":["import { Cause, Effect, Ref, Option, Scope, Semaphore } from \"effect\"\nimport { RpcServer } from \"effect/rpc\"\nimport { Peer } from \"../Peer\"\nimport { TransportError } from \"../../Errors\"\nimport type { Channel } from \"../../Transport\"\nimport type { Supervisor } from \"./Supervisor\"\nimport type { Channels } from \"./Execution\"\nimport * as Port from \"../port\"\nimport * as Multiplex from \"./Multiplex\"\nimport * as Wire from \"./Wire\"\nimport { SessionAccessDenied, SessionConflict, type Handle } from \"./model\"\n\nexport const accept = Effect.fnUntraced(function* (\n\tsupervisor: typeof Supervisor.Service,\n\texecution: typeof Channels.Service,\n\tchannel: Channel,\n) {\n\tconst identity = yield* Peer\n\tconst scope = yield* Effect.scope\n\tconst mux = yield* Multiplex.make(channel)\n\tconst peer = yield* Port.make(Wire.channel(mux, 0), {\n\t\tsession: \"session-v1\",\n\t\tserve: { session: Wire.Session },\n\t\tcall: {},\n\t})\n\tconst attached = yield* Ref.make(Option.none<string>())\n\tconst loading = yield* Semaphore.make(1)\n\tconst authorize = (handle: Handle) =>\n\t\thandle.key.identity === identity\n\t\t\t? Effect.void\n\t\t\t: Effect.fail(\n\t\t\t\t\tSessionAccessDenied.make({\n\t\t\t\t\t\tdetail: \"The session belongs to another authenticated identity\",\n\t\t\t\t\t}),\n\t\t\t\t)\n\tconst handlers = yield* Wire.Session.toHandlers({\n\t\tHighWater: ({ instance }) => supervisor.highWater({ identity, instance }),\n\t\tOpen: ({ instance, requestId, expectedGeneration, leaseMillis, limits }) =>\n\t\t\tsupervisor.open({\n\t\t\t\tkey: { identity, instance },\n\t\t\t\trequestId,\n\t\t\t\texpectedGeneration,\n\t\t\t\t...(leaseMillis === undefined ? {} : { lease: leaseMillis }),\n\t\t\t\tlimits,\n\t\t\t}),\n\t\tLoad: Effect.fnUntraced(function* ({ handle, ...request }) {\n\t\t\tyield* authorize(handle)\n\t\t\tconst attachment = yield* Ref.get(attached)\n\t\t\tif (Option.isSome(attachment) && attachment.value !== handle.token)\n\t\t\t\treturn yield* SessionConflict.make({\n\t\t\t\t\tdetail: \"A connection can attach only one execution\",\n\t\t\t\t})\n\t\t\tconst code = yield* supervisor.load(handle, request)\n\t\t\tif (Option.isNone(attachment)) {\n\t\t\t\tconst child = yield* execution\n\t\t\t\t\t.peer(handle.token)\n\t\t\t\t\t.pipe(Scope.provide(scope))\n\t\t\t\tyield* Ref.set(attached, Option.some(handle.token))\n\t\t\t\t// A child EOF must not destroy the session channel before Dispose can acknowledge exit.\n\t\t\t\tyield* Effect.all(\n\t\t\t\t\t[\n\t\t\t\t\t\tEffect.forever(\n\t\t\t\t\t\t\tEffect.flatMap(mux.take(1), (bytes) => child.send(1, bytes)),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.forever(\n\t\t\t\t\t\t\tEffect.flatMap(child.take(1), (bytes) => mux.send(1, bytes)),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t\t{ concurrency: \"unbounded\" },\n\t\t\t\t).pipe(\n\t\t\t\t\tEffect.catchCause((cause) =>\n\t\t\t\t\t\tCause.hasInterruptsOnly(cause)\n\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t: child.fail(TransportError.make({ cause })),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.forkIn(scope),\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn code\n\t\t}, loading.withPermit),\n\t\tRenew: (handle) =>\n\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.renew(handle))),\n\t\tDispose: (handle) =>\n\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.dispose(handle))),\n\t\tStatus: (handle) =>\n\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.status(handle))),\n\t})\n\treturn yield* RpcServer.make(Wire.Session, {\n\t\tdisableFatalDefects: true,\n\t}).pipe(\n\t\tEffect.provideContext(handlers),\n\t\tEffect.provideService(RpcServer.Protocol, peer.serverProtocol(\"session\")),\n\t\t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B,OAAO,IAAI,IAAI,UAAU,OAAO,KAAK,OAAO,KAAK,CAAC;IAElD,OAAO,OAAO,IACb,CACC,OAAO,QACN,OAAO,QAAQ,IAAI,KAAK,CAAC,IAAI,UAAU,MAAM,KAAK,GAAG,KAAK,CAAC,CAC5D,GACA,OAAO,QACN,OAAO,QAAQ,MAAM,KAAK,CAAC,IAAI,UAAU,IAAI,KAAK,GAAG,KAAK,CAAC,CAC5D,CACD,GACA,EAAE,aAAa,YAAY,CAC5B,CAAC,CAAC,KACD,OAAO,YAAY,UAClB,MAAM,kBAAkB,KAAK,IAC1B,OAAO,OACP,MAAM,KAAK,eAAe,KAAK,EAAE,MAAM,CAAC,CAAC,CAC7C,GACA,OAAO,OAAO,KAAK,CACpB;GACD;GACA,OAAO;EACR,GAAG,QAAQ,UAAU;EACrB,QAAQ,WACP,UAAU,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,WAAW,MAAM,MAAM,CAAC,CAAC;EAChE,UAAU,WACT,UAAU,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,WAAW,QAAQ,MAAM,CAAC,CAAC;EAClE,SAAS,WACR,UAAU,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,WAAW,OAAO,MAAM,CAAC,CAAC;CAClE,CAAC;CACD,OAAO,OAAO,UAAU,KAAKA,SAAc,EAC1C,qBAAqB,KACtB,CAAC,CAAC,CAAC,KACF,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,SAAS,CAAC,GACxE,OAAO,UAAU,IAAI,KAAK,CAC3B;AACD,CAAC"}
|
|
@@ -217,7 +217,7 @@ var Store = class extends Context.Service()("@graftland/plugin-remote/internal/r
|
|
|
217
217
|
var Execution = class extends Context.Service()("@graftland/plugin-remote/internal/runner/model/Execution") {};
|
|
218
218
|
var RemoteTerminationUnconfirmed = class extends Schema.TaggedError()("RemoteTerminationUnconfirmed", { handle: Handle }) {};
|
|
219
219
|
/** Losing contact never becomes a successful stop merely because a lease duration passed. */
|
|
220
|
-
const awaitTermination = (handle, confirmation, leaseMillis, marginMillis)
|
|
220
|
+
const awaitTermination = Effect.fnUntraced(function* (handle, confirmation, leaseMillis, marginMillis) {
|
|
221
221
|
const [elapsed, result] = yield* Effect.exit(Effect.timeoutOption(confirmation, leaseMillis + marginMillis)).pipe(Effect.timed);
|
|
222
222
|
if (result._tag === "Success") {
|
|
223
223
|
if (Option.isSome(result.value)) return result.value.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../../src/internal/runner/model.ts"],"sourcesContent":["import { Limits, PositiveInt } from \"../Limits\"\nexport { Limits, PositiveInt, PositiveFinite, defaults } from \"../Limits\"\nimport {\n\tArray,\n\tCause,\n\tContext,\n\tData,\n\tDuration,\n\tEffect,\n\tOption,\n\tSchema,\n} from \"effect\"\nimport type { Scope } from \"effect\"\n\nconst diagnosticCause = Schema.Cause(\n\tSchema.Defect({ includeStack: true }),\n\tSchema.Defect({ includeStack: true }),\n)\nexport class PackageError extends Schema.TaggedError<\n\tPackageError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionAccessDenied extends Schema.TaggedError<\n\tSessionAccessDenied,\n\t{ readonly brand: unique symbol }\n>()(\"SessionAccessDenied\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StaleSession extends Schema.TaggedError<\n\tStaleSession,\n\t{ readonly brand: unique symbol }\n>()(\"StaleSession\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class LeaseExpired extends Schema.TaggedError<\n\tLeaseExpired,\n\t{ readonly brand: unique symbol }\n>()(\"LeaseExpired\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionStopped extends Schema.TaggedError<\n\tSessionStopped,\n\t{ readonly brand: unique symbol }\n>()(\"SessionStopped\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionConflict extends Schema.TaggedError<\n\tSessionConflict,\n\t{ readonly brand: unique symbol }\n>()(\"SessionConflict\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateStorageError extends Schema.TaggedError<\n\tStateStorageError,\n\t{ readonly brand: unique symbol }\n>()(\"StateStorageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class ExecutionError extends Schema.TaggedError<\n\tExecutionError,\n\t{ readonly brand: unique symbol }\n>()(\"ExecutionError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class TerminationUnconfirmed extends Schema.TaggedError<\n\tTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"TerminationUnconfirmed\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class RunnerClosing extends Schema.TaggedError<\n\tRunnerClosing,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerClosing\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateDirectoryLocked extends Schema.TaggedError<\n\tStateDirectoryLocked,\n\t{ readonly brand: unique symbol }\n>()(\"StateDirectoryLocked\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport const Key = Schema.Struct({\n\tidentity: Schema.NonEmptyString,\n\tinstance: Schema.NonEmptyString,\n})\nexport type Key = typeof Key.Type\n/** Structural keys keep identity namespaces separate without delimiter conventions. */\nexport class SessionKey extends Data.Class<Key> {}\nexport const keyOf = (key: Key) => new SessionKey(key)\nexport const negotiate = (local: Limits, peer: Limits): Limits => ({\n\tcontrol: Math.min(local.control, peer.control),\n\tdata: Math.min(local.data, peer.data),\n\tlog: Math.min(local.log, peer.log),\n})\nexport const Handle = Schema.Struct({\n\tkey: Key,\n\ttoken: Schema.NonEmptyString,\n\tgeneration: PositiveInt,\n})\nexport type Handle = typeof Handle.Type\nexport const ProcessIdentity = Schema.Struct({\n\tpid: Schema.Int,\n\tstart: Schema.Struct({ born: Schema.String }),\n})\nexport type ProcessIdentity = typeof ProcessIdentity.Type\nexport const ExitStatus = Schema.Struct({\n\tstderr: Schema.optionalKey(Schema.String),\n\tcause: Schema.optionalKey(diagnosticCause),\n\tcode: Schema.NullOr(Schema.Int),\n\tsignal: Schema.NullOr(Schema.String),\n})\nexport type ExitStatus = typeof ExitStatus.Type\nexport const CodeIdentity = Schema.Struct({\n\tname: Schema.String,\n\tversion: Schema.String,\n\tdigest: Schema.optionalKey(Schema.String),\n})\nexport type CodeIdentity = typeof CodeIdentity.Type\nexport const Load = Schema.Struct({\n\tspecifier: Schema.String,\n\tdigest: Schema.optionalKey(Schema.Boolean),\n})\nexport type Load = typeof Load.Type\nexport const Termination = Schema.Struct({\n\tkind: Schema.Literals([\"Exited\", \"Killed\"]),\n\texit: ExitStatus,\n\tcause: diagnosticCause,\n})\nexport type Termination = typeof Termination.Type\nconst Fields = {\n\tversion: Schema.Literal(1),\n\thandle: Handle,\n\trequestId: Schema.String,\n\tleaseMillis: Schema.Finite,\n\tlimits: Limits,\n}\nexport const OpenRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Open\"),\n})\nexport const Launch = Schema.Union([\n\tSchema.TaggedStruct(\"Starting\", {}),\n\tSchema.TaggedStruct(\"Registered\", { child: ProcessIdentity }),\n])\nexport const LoadingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loading\"),\n\tload: Load,\n\tlaunch: Launch,\n})\nexport const LoadedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loaded\"),\n\tload: Load,\n\tchild: ProcessIdentity,\n\tcode: CodeIdentity,\n})\nexport const ActiveRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n])\nexport type ActiveRecord = typeof ActiveRecord.Type\nexport const StopReason = Schema.Union([\n\t...Array.map(\n\t\t[\n\t\t\t\"Disposed\",\n\t\t\t\"Expired\",\n\t\t\t\"Superseded\",\n\t\t\t\"Recovery\",\n\t\t\t\"Shutdown\",\n\t\t\t\"Exited\",\n\t\t] as const,\n\t\t(tag) => Schema.TaggedStruct(tag, {}),\n\t),\n\tSchema.TaggedStruct(\"LoadFailed\", { cause: diagnosticCause }),\n])\nexport type StopReason = typeof StopReason.Type\nexport const StoppingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopping\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n})\nexport const StoppedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopped\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n})\nexport const SessionRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n\tStoppingRecord,\n\tStoppedRecord,\n])\nexport type SessionRecord = typeof SessionRecord.Type\nexport const childOf = (\n\trecord: SessionRecord,\n): Option.Option<ProcessIdentity> => {\n\tswitch (record.phase) {\n\t\tcase \"Open\":\n\t\t\treturn Option.none()\n\t\tcase \"Loading\":\n\t\t\treturn record.launch._tag === \"Registered\"\n\t\t\t\t? Option.some(record.launch.child)\n\t\t\t\t: Option.none()\n\t\tcase \"Loaded\":\n\t\t\treturn Option.some(record.child)\n\t\tcase \"Stopping\":\n\t\tcase \"Stopped\":\n\t\t\treturn childOf(record.previous)\n\t}\n}\nexport const stoppingRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n): typeof StoppingRecord.Type => ({\n\tversion: previous.version,\n\thandle: previous.handle,\n\trequestId: previous.requestId,\n\tleaseMillis: previous.leaseMillis,\n\tlimits: previous.limits,\n\tphase: \"Stopping\",\n\tprevious,\n\treason,\n})\nexport const stoppedRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n): typeof StoppedRecord.Type => ({\n\t...stoppingRecord(previous, reason),\n\tphase: \"Stopped\",\n\ttermination,\n})\n\nexport class Store extends Context.Service<\n\tStore,\n\t{\n\t\treadonly list: Effect.Effect<\n\t\t\tReadonlyArray<SessionRecord>,\n\t\t\tStateStorageError\n\t\t>\n\t\treadonly save: (\n\t\t\trecord: SessionRecord,\n\t\t) => Effect.Effect<void, StateStorageError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Store\") {}\nexport type ExecutionFailure =\n\tExecutionError | PackageError | TerminationUnconfirmed\nexport interface Unit {\n\treadonly code: CodeIdentity\n\t/** The supervisor persists identity and renews the lease before releasing the child startup gate. */\n\treadonly start: Effect.Effect<void, ExecutionFailure>\n\treadonly identity: ProcessIdentity\n\treadonly exited: Effect.Effect<ExitStatus, ExecutionFailure>\n\treadonly interrupt: Effect.Effect<void, ExecutionFailure>\n\treadonly kill: Effect.Effect<void, ExecutionFailure>\n\treadonly renew: (millis: number) => Effect.Effect<void, ExecutionFailure>\n}\nexport class Execution extends Context.Service<\n\tExecution,\n\t{\n\t\treadonly spawn: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t\tlimits: Limits,\n\t\t) => Effect.Effect<Unit, ExecutionFailure, Scope.Scope>\n\t\treadonly recover: (\n\t\t\tchild: ProcessIdentity,\n\t\t) => Effect.Effect<Termination, ExecutionFailure>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Execution\") {}\nexport class RemoteTerminationUnconfirmed extends Schema.TaggedError<\n\tRemoteTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"RemoteTerminationUnconfirmed\", { handle: Handle }) {}\n/** Losing contact never becomes a successful stop merely because a lease duration passed. */\nexport const awaitTermination = <E, R>(\n\thandle: Handle,\n\tconfirmation: Effect.Effect<Termination, E, R>,\n\tleaseMillis: number,\n\tmarginMillis: number,\n) =>\n\tEffect.gen(function* () {\n\t\tconst [elapsed, result] = yield* Effect.exit(\n\t\t\tEffect.timeoutOption(confirmation, leaseMillis + marginMillis),\n\t\t).pipe(Effect.timed)\n\t\tif (result._tag === \"Success\") {\n\t\t\tif (Option.isSome(result.value)) return result.value.value\n\t\t\treturn yield* RemoteTerminationUnconfirmed.make({ handle })\n\t\t}\n\t\t// Confirmation and the disconnected wait share one deadline.\n\t\tyield* Effect.sleep(\n\t\t\tMath.max(0, leaseMillis + marginMillis - Duration.toMillis(elapsed)),\n\t\t)\n\t\treturn yield* Effect.failCause(\n\t\t\tCause.combine(\n\t\t\t\tresult.cause,\n\t\t\t\tCause.fail(RemoteTerminationUnconfirmed.make({ handle })),\n\t\t\t),\n\t\t)\n\t})\n"],"mappings":";;;AAcA,MAAM,kBAAkB,OAAO,MAC9B,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,GACpC,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,CACrC;AACA,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CACnB,QAAQ,OAAO;CACf,OAAO,OAAO,YAAY,eAAe;AAC1C,CAAC,CAAC,CAAC;CACF,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;AACA,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CAC1B,QAAQ,OAAO;CACf,OAAO,O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AE,OAAO,CAAC;CAC3D;CAEA,OAAO,OAAO,MACb,KAAK,IAAI,GAAG,cAAc,eAAe,SAAS,SAAS,OAAO,CAAC,CACpE;CACA,OAAO,OAAO,OAAO,UACpB,MAAM,QACL,OAAO,OACP,MAAM,KAAK,6BAA6B,KAAK,EAAE,OAAO,CAAC,CAAC,CACzD,CACD;AACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../../src/internal/runner/model.ts"],"sourcesContent":["import { Limits, PositiveInt } from \"../Limits\"\nexport { Limits, PositiveInt, PositiveFinite, defaults } from \"../Limits\"\nimport {\n\tArray,\n\tCause,\n\tContext,\n\tData,\n\tDuration,\n\tEffect,\n\tOption,\n\tSchema,\n} from \"effect\"\nimport type { Scope } from \"effect\"\n\nconst diagnosticCause = Schema.Cause(\n\tSchema.Defect({ includeStack: true }),\n\tSchema.Defect({ includeStack: true }),\n)\nexport class PackageError extends Schema.TaggedError<\n\tPackageError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionAccessDenied extends Schema.TaggedError<\n\tSessionAccessDenied,\n\t{ readonly brand: unique symbol }\n>()(\"SessionAccessDenied\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StaleSession extends Schema.TaggedError<\n\tStaleSession,\n\t{ readonly brand: unique symbol }\n>()(\"StaleSession\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class LeaseExpired extends Schema.TaggedError<\n\tLeaseExpired,\n\t{ readonly brand: unique symbol }\n>()(\"LeaseExpired\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionStopped extends Schema.TaggedError<\n\tSessionStopped,\n\t{ readonly brand: unique symbol }\n>()(\"SessionStopped\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionConflict extends Schema.TaggedError<\n\tSessionConflict,\n\t{ readonly brand: unique symbol }\n>()(\"SessionConflict\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateStorageError extends Schema.TaggedError<\n\tStateStorageError,\n\t{ readonly brand: unique symbol }\n>()(\"StateStorageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class ExecutionError extends Schema.TaggedError<\n\tExecutionError,\n\t{ readonly brand: unique symbol }\n>()(\"ExecutionError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class TerminationUnconfirmed extends Schema.TaggedError<\n\tTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"TerminationUnconfirmed\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class RunnerClosing extends Schema.TaggedError<\n\tRunnerClosing,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerClosing\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateDirectoryLocked extends Schema.TaggedError<\n\tStateDirectoryLocked,\n\t{ readonly brand: unique symbol }\n>()(\"StateDirectoryLocked\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport const Key = Schema.Struct({\n\tidentity: Schema.NonEmptyString,\n\tinstance: Schema.NonEmptyString,\n})\nexport type Key = typeof Key.Type\n/** Structural keys keep identity namespaces separate without delimiter conventions. */\nexport class SessionKey extends Data.Class<Key> {}\nexport const keyOf = (key: Key) => new SessionKey(key)\nexport const negotiate = (local: Limits, peer: Limits): Limits => ({\n\tcontrol: Math.min(local.control, peer.control),\n\tdata: Math.min(local.data, peer.data),\n\tlog: Math.min(local.log, peer.log),\n})\nexport const Handle = Schema.Struct({\n\tkey: Key,\n\ttoken: Schema.NonEmptyString,\n\tgeneration: PositiveInt,\n})\nexport type Handle = typeof Handle.Type\nexport const ProcessIdentity = Schema.Struct({\n\tpid: Schema.Int,\n\tstart: Schema.Struct({ born: Schema.String }),\n})\nexport type ProcessIdentity = typeof ProcessIdentity.Type\nexport const ExitStatus = Schema.Struct({\n\tstderr: Schema.optionalKey(Schema.String),\n\tcause: Schema.optionalKey(diagnosticCause),\n\tcode: Schema.NullOr(Schema.Int),\n\tsignal: Schema.NullOr(Schema.String),\n})\nexport type ExitStatus = typeof ExitStatus.Type\nexport const CodeIdentity = Schema.Struct({\n\tname: Schema.String,\n\tversion: Schema.String,\n\tdigest: Schema.optionalKey(Schema.String),\n})\nexport type CodeIdentity = typeof CodeIdentity.Type\nexport const Load = Schema.Struct({\n\tspecifier: Schema.String,\n\tdigest: Schema.optionalKey(Schema.Boolean),\n})\nexport type Load = typeof Load.Type\nexport const Termination = Schema.Struct({\n\tkind: Schema.Literals([\"Exited\", \"Killed\"]),\n\texit: ExitStatus,\n\tcause: diagnosticCause,\n})\nexport type Termination = typeof Termination.Type\nconst Fields = {\n\tversion: Schema.Literal(1),\n\thandle: Handle,\n\trequestId: Schema.String,\n\tleaseMillis: Schema.Finite,\n\tlimits: Limits,\n}\nexport const OpenRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Open\"),\n})\nexport const Launch = Schema.Union([\n\tSchema.TaggedStruct(\"Starting\", {}),\n\tSchema.TaggedStruct(\"Registered\", { child: ProcessIdentity }),\n])\nexport const LoadingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loading\"),\n\tload: Load,\n\tlaunch: Launch,\n})\nexport const LoadedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loaded\"),\n\tload: Load,\n\tchild: ProcessIdentity,\n\tcode: CodeIdentity,\n})\nexport const ActiveRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n])\nexport type ActiveRecord = typeof ActiveRecord.Type\nexport const StopReason = Schema.Union([\n\t...Array.map(\n\t\t[\n\t\t\t\"Disposed\",\n\t\t\t\"Expired\",\n\t\t\t\"Superseded\",\n\t\t\t\"Recovery\",\n\t\t\t\"Shutdown\",\n\t\t\t\"Exited\",\n\t\t] as const,\n\t\t(tag) => Schema.TaggedStruct(tag, {}),\n\t),\n\tSchema.TaggedStruct(\"LoadFailed\", { cause: diagnosticCause }),\n])\nexport type StopReason = typeof StopReason.Type\nexport const StoppingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopping\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n})\nexport const StoppedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopped\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n})\nexport const SessionRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n\tStoppingRecord,\n\tStoppedRecord,\n])\nexport type SessionRecord = typeof SessionRecord.Type\nexport const childOf = (\n\trecord: SessionRecord,\n): Option.Option<ProcessIdentity> => {\n\tswitch (record.phase) {\n\t\tcase \"Open\":\n\t\t\treturn Option.none()\n\t\tcase \"Loading\":\n\t\t\treturn record.launch._tag === \"Registered\"\n\t\t\t\t? Option.some(record.launch.child)\n\t\t\t\t: Option.none()\n\t\tcase \"Loaded\":\n\t\t\treturn Option.some(record.child)\n\t\tcase \"Stopping\":\n\t\tcase \"Stopped\":\n\t\t\treturn childOf(record.previous)\n\t}\n}\nexport const stoppingRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n): typeof StoppingRecord.Type => ({\n\tversion: previous.version,\n\thandle: previous.handle,\n\trequestId: previous.requestId,\n\tleaseMillis: previous.leaseMillis,\n\tlimits: previous.limits,\n\tphase: \"Stopping\",\n\tprevious,\n\treason,\n})\nexport const stoppedRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n): typeof StoppedRecord.Type => ({\n\t...stoppingRecord(previous, reason),\n\tphase: \"Stopped\",\n\ttermination,\n})\n\nexport class Store extends Context.Service<\n\tStore,\n\t{\n\t\treadonly list: Effect.Effect<\n\t\t\tReadonlyArray<SessionRecord>,\n\t\t\tStateStorageError\n\t\t>\n\t\treadonly save: (\n\t\t\trecord: SessionRecord,\n\t\t) => Effect.Effect<void, StateStorageError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Store\") {}\nexport type ExecutionFailure =\n\tExecutionError | PackageError | TerminationUnconfirmed\nexport interface Unit {\n\treadonly code: CodeIdentity\n\t/** The supervisor persists identity and renews the lease before releasing the child startup gate. */\n\treadonly start: Effect.Effect<void, ExecutionFailure>\n\treadonly identity: ProcessIdentity\n\treadonly exited: Effect.Effect<ExitStatus, ExecutionFailure>\n\treadonly interrupt: Effect.Effect<void, ExecutionFailure>\n\treadonly kill: Effect.Effect<void, ExecutionFailure>\n\treadonly renew: (millis: number) => Effect.Effect<void, ExecutionFailure>\n}\nexport class Execution extends Context.Service<\n\tExecution,\n\t{\n\t\treadonly spawn: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t\tlimits: Limits,\n\t\t) => Effect.Effect<Unit, ExecutionFailure, Scope.Scope>\n\t\treadonly recover: (\n\t\t\tchild: ProcessIdentity,\n\t\t) => Effect.Effect<Termination, ExecutionFailure>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Execution\") {}\nexport class RemoteTerminationUnconfirmed extends Schema.TaggedError<\n\tRemoteTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"RemoteTerminationUnconfirmed\", { handle: Handle }) {}\n/** Losing contact never becomes a successful stop merely because a lease duration passed. */\nexport const awaitTermination = Effect.fnUntraced(function* <E, R>(\n\thandle: Handle,\n\tconfirmation: Effect.Effect<Termination, E, R>,\n\tleaseMillis: number,\n\tmarginMillis: number,\n) {\n\tconst [elapsed, result] = yield* Effect.exit(\n\t\tEffect.timeoutOption(confirmation, leaseMillis + marginMillis),\n\t).pipe(Effect.timed)\n\tif (result._tag === \"Success\") {\n\t\tif (Option.isSome(result.value)) return result.value.value\n\t\treturn yield* RemoteTerminationUnconfirmed.make({ handle })\n\t}\n\t// Confirmation and the disconnected wait share one deadline.\n\tyield* Effect.sleep(\n\t\tMath.max(0, leaseMillis + marginMillis - Duration.toMillis(elapsed)),\n\t)\n\treturn yield* Effect.failCause(\n\t\tCause.combine(\n\t\t\tresult.cause,\n\t\t\tCause.fail(RemoteTerminationUnconfirmed.make({ handle })),\n\t\t),\n\t)\n})\n"],"mappings":";;;AAcA,MAAM,kBAAkB,OAAO,MAC9B,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,GACpC,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,CACrC;AACA,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CACnB,QAAQ,OAAO;CACf,OAAO,OAAO,YAAY,eAAe;AAC1C,CAAC,CAAC,CAAC;CACF,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;AACA,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CAC1B,QAAQ,OAAO;CACf,OAAO,OAAO,YAAY,eAAe;AAC1C,CAAC,CAAC,CAAC;CACF,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;AACA,IAAa,eAAb,cAAkC,OAAO,YAGvC,C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,UACpB,MAAM,QACL,OAAO,OACP,MAAM,KAAK,6BAA6B,KAAK,EAAE,OAAO,CAAC,CAAC,CACzD,CACD;AACD,CAAC"}
|
package/dist/internal/serve.js
CHANGED
|
@@ -23,7 +23,7 @@ const ready = Plugin.make({
|
|
|
23
23
|
})
|
|
24
24
|
});
|
|
25
25
|
/** Loader logs child cleanup errors; the supervisor's release signal also reaches the command exit. */
|
|
26
|
-
const close =
|
|
26
|
+
const close = Effect.fnUntraced(function* (entries, lifecycle) {
|
|
27
27
|
const disposed = yield* Effect.exit(entries.dispose);
|
|
28
28
|
const released = yield* Effect.exit(Deferred.await(lifecycle.released));
|
|
29
29
|
const cause = Array.reduce([disposed, released], Cause.empty, (cause, exit) => Exit.isFailure(exit) ? Cause.combine(cause, exit.cause) : cause);
|