@graftland/plugin-remote 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/Auth.d.ts +2 -2
  2. package/dist/Auth.d.ts.map +1 -1
  3. package/dist/Auth.js.map +1 -1
  4. package/dist/{Bootstrap-MCwivGN1.js → Bootstrap-H9gDsgsC.js} +2 -2
  5. package/dist/{Contract-CcpSIJm4.js → Contract-DsJtisvL.js} +8 -46
  6. package/dist/Contract.d.ts +50 -53
  7. package/dist/Contract.d.ts.map +1 -1
  8. package/dist/Contract.js +1 -1
  9. package/dist/Contract.js.map +1 -1
  10. package/dist/{Errors-oPsTLY7l.js → Errors-DYhsGZcZ.js} +14 -1
  11. package/dist/Errors.d.ts +19 -0
  12. package/dist/Errors.d.ts.map +1 -1
  13. package/dist/Errors.js +14 -1
  14. package/dist/Errors.js.map +1 -1
  15. package/dist/{FailureGroup-BcH0XOBi.js → FailureGroup-BgT73AaR.js} +14 -4
  16. package/dist/{Framing-zaYdOJnT.js → Framing-G9eSaeLb.js} +1 -1
  17. package/dist/{Graft-BsYq3F-J.js → Graft-B71CPA2Y.js} +46 -35
  18. package/dist/{Packages-B1TPk8pa.js → Packages-AgoCGotL.js} +23 -26
  19. package/dist/{Peer-IJgFK6mD.js → Peer-DXeVrGBh.js} +5 -5
  20. package/dist/{ProcessObservation-DEGrEMfP.js → ProcessObservation-gLgGirYv.js} +1 -1
  21. package/dist/{ServeLifecycle-CJM0gG5B.js → ServeLifecycle-Bd1FPJ6e.js} +1 -1
  22. package/dist/Testing.d.ts +4 -4
  23. package/dist/Testing.d.ts.map +1 -1
  24. package/dist/Testing.js +10 -4
  25. package/dist/Testing.js.map +1 -1
  26. package/dist/Transport.d.ts +2 -2
  27. package/dist/Transport.d.ts.map +1 -1
  28. package/dist/Transport.js.map +1 -1
  29. package/dist/bin.js +48 -47
  30. package/dist/bin.js.map +1 -1
  31. package/dist/{childRuntime-DSqtFN9o.js → childRuntime-Bm3iSg_N.js} +30 -26
  32. package/dist/connectionEnded-BwcxQ7W8.js +54 -0
  33. package/dist/{entry-SYsx9VNb.js → entry-psOpX3Bj.js} +76 -48
  34. package/dist/host/auth/bearer.d.ts +1 -2
  35. package/dist/host/auth/bearer.d.ts.map +1 -1
  36. package/dist/host/auth/bearer.js +1 -1
  37. package/dist/host/auth/bearer.js.map +1 -1
  38. package/dist/host/auth/jwt.d.ts +1 -2
  39. package/dist/host/auth/jwt.d.ts.map +1 -1
  40. package/dist/host/auth/jwt.js +1 -1
  41. package/dist/host/auth/jwt.js.map +1 -1
  42. package/dist/host/auth/mtls.js +2 -2
  43. package/dist/host/auth/none.js +1 -1
  44. package/dist/host/command.d.ts +1 -1
  45. package/dist/host/command.d.ts.map +1 -1
  46. package/dist/host/command.js +4 -4
  47. package/dist/host/command.js.map +1 -1
  48. package/dist/host/local.d.ts +1 -2
  49. package/dist/host/local.d.ts.map +1 -1
  50. package/dist/host/local.js +3 -3
  51. package/dist/host/local.js.map +1 -1
  52. package/dist/host/unix.d.ts +1 -1
  53. package/dist/host/unix.d.ts.map +1 -1
  54. package/dist/host/unix.js +3 -3
  55. package/dist/host/unix.js.map +1 -1
  56. package/dist/host/websocket.d.ts +1 -1
  57. package/dist/host/websocket.d.ts.map +1 -1
  58. package/dist/host/websocket.js +3 -3
  59. package/dist/host/websocket.js.map +1 -1
  60. package/dist/host/worker.d.ts +1 -2
  61. package/dist/host/worker.d.ts.map +1 -1
  62. package/dist/host/worker.js +4 -5
  63. package/dist/host/worker.js.map +1 -1
  64. package/dist/{importer-D7zSgqxq.js → importer-Cvf88eAY.js} +5 -8
  65. package/dist/index.d.ts +2 -3
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +10 -10
  68. package/dist/index.js.map +1 -1
  69. package/dist/internal/Certificates.js +4 -4
  70. package/dist/internal/Certificates.js.map +1 -1
  71. package/dist/internal/FailureGroup.js +3 -2
  72. package/dist/internal/FailureGroup.js.map +1 -1
  73. package/dist/internal/assembly.js +9 -2
  74. package/dist/internal/assembly.js.map +1 -1
  75. package/dist/internal/auth/mtls.js +1 -1
  76. package/dist/internal/auth/mtls.js.map +1 -1
  77. package/dist/internal/auth/tokenCredentials.d.ts +0 -1
  78. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  79. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  80. package/dist/internal/child.js +20 -17
  81. package/dist/internal/child.js.map +1 -1
  82. package/dist/internal/childRuntime.js +6 -4
  83. package/dist/internal/childRuntime.js.map +1 -1
  84. package/dist/internal/contract.js +26 -0
  85. package/dist/internal/contract.js.map +1 -0
  86. package/dist/internal/credentials.d.ts +6 -6
  87. package/dist/internal/credentials.d.ts.map +1 -1
  88. package/dist/internal/credentials.js.map +1 -1
  89. package/dist/internal/directTransport.d.ts +1 -1
  90. package/dist/internal/entry.d.ts +1 -2
  91. package/dist/internal/entry.d.ts.map +1 -1
  92. package/dist/internal/entry.js +4 -14
  93. package/dist/internal/entry.js.map +1 -1
  94. package/dist/internal/execution.js +44 -7
  95. package/dist/internal/execution.js.map +1 -1
  96. package/dist/internal/host/runner.js +7 -6
  97. package/dist/internal/host/runner.js.map +1 -1
  98. package/dist/internal/host.js +5 -5
  99. package/dist/internal/host.js.map +1 -1
  100. package/dist/internal/port.d.ts +2 -10
  101. package/dist/internal/port.js +5 -5
  102. package/dist/internal/port.js.map +1 -1
  103. package/dist/internal/release.js +1 -1
  104. package/dist/internal/release.js.map +1 -1
  105. package/dist/internal/runner/Connection.d.ts +1 -1
  106. package/dist/internal/runner/Connection.js +4 -4
  107. package/dist/internal/runner/Connection.js.map +1 -1
  108. package/dist/internal/runner/Execution.js +3 -3
  109. package/dist/internal/runner/Execution.js.map +1 -1
  110. package/dist/internal/runner/Framing.d.ts +1 -11
  111. package/dist/internal/runner/Framing.js +1 -1
  112. package/dist/internal/runner/Framing.js.map +1 -1
  113. package/dist/internal/runner/Local.js +1 -1
  114. package/dist/internal/runner/Local.js.map +1 -1
  115. package/dist/internal/runner/Lock.js +1 -1
  116. package/dist/internal/runner/Lock.js.map +1 -1
  117. package/dist/internal/runner/Packages.d.ts +1 -1
  118. package/dist/internal/runner/Packages.js +22 -25
  119. package/dist/internal/runner/Packages.js.map +1 -1
  120. package/dist/internal/runner/Processes.js +7 -9
  121. package/dist/internal/runner/Processes.js.map +1 -1
  122. package/dist/internal/runner/Store.js +3 -3
  123. package/dist/internal/runner/Store.js.map +1 -1
  124. package/dist/internal/runner/Supervisor.js +46 -47
  125. package/dist/internal/runner/Supervisor.js.map +1 -1
  126. package/dist/internal/runner/accept.js +3 -3
  127. package/dist/internal/runner/accept.js.map +1 -1
  128. package/dist/internal/runner/model.js +1 -1
  129. package/dist/internal/runner/model.js.map +1 -1
  130. package/dist/internal/serve.js +1 -1
  131. package/dist/internal/serve.js.map +1 -1
  132. package/dist/internal/services.d.ts +2 -12
  133. package/dist/internal/services.d.ts.map +1 -1
  134. package/dist/internal/services.js.map +1 -1
  135. package/dist/internal/supervisorPlugin.js +1 -1
  136. package/dist/internal/watchdogMain.js +5 -5
  137. package/dist/internal/watchdogMain.js.map +1 -1
  138. package/dist/internal/websocketServer.js +3 -1
  139. package/dist/internal/websocketServer.js.map +1 -1
  140. package/dist/internal/workerMain.js +3 -3
  141. package/dist/{port-Blbh8tms.js → port--3x2zJ4D.js} +8 -8
  142. package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
  143. package/dist/runner/auth/bearer.js +2 -2
  144. package/dist/runner/auth/jwt.js +4 -4
  145. package/dist/runner/auth/jwt.js.map +1 -1
  146. package/dist/runner/auth/mtls.js +3 -3
  147. package/dist/runner/auth/none.js +1 -1
  148. package/dist/runner/index.js +5 -5
  149. package/dist/runner/stdio.js +3 -3
  150. package/dist/runner/unix.js +3 -3
  151. package/dist/runner/websocket.js +4 -4
  152. package/dist/{socketChannel-KmtzF-9G.js → socketChannel-CJvL2DiB.js} +2 -2
  153. package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
  154. package/dist/{token-v5ne2I0-.js → token-CYBNNlhS.js} +1 -1
  155. package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CbCuk-Rt.js} +3 -3
  156. package/dist/{websocketServer-MXcCJx0v.js → websocketServer-NQhODlEt.js} +5 -3
  157. package/dist/{workerChannel-P82YdNjh.js → workerChannel-C8hhBJzA.js} +1 -1
  158. package/package.json +3 -3
  159. package/src/Auth.ts +9 -2
  160. package/src/Contract.ts +67 -51
  161. package/src/Errors.ts +23 -0
  162. package/src/Testing.ts +16 -2
  163. package/src/Transport.ts +6 -2
  164. package/src/bin.ts +28 -30
  165. package/src/host/auth/bearer.ts +1 -6
  166. package/src/host/auth/jwt.ts +1 -6
  167. package/src/host/command.ts +2 -0
  168. package/src/host/local.ts +5 -9
  169. package/src/host/unix.ts +2 -0
  170. package/src/host/websocket.ts +2 -0
  171. package/src/host/worker.ts +4 -6
  172. package/src/index.ts +8 -4
  173. package/src/internal/Certificates.ts +10 -13
  174. package/src/internal/FailureGroup.ts +128 -121
  175. package/src/internal/assembly.ts +19 -10
  176. package/src/internal/auth/mtls.ts +19 -20
  177. package/src/internal/auth/tokenCredentials.ts +1 -7
  178. package/src/internal/child.ts +249 -240
  179. package/src/internal/childRuntime.ts +84 -81
  180. package/src/internal/contract.ts +47 -0
  181. package/src/internal/credentials.ts +12 -9
  182. package/src/internal/entry.ts +11 -25
  183. package/src/internal/execution.ts +73 -14
  184. package/src/internal/host/runner.ts +153 -153
  185. package/src/internal/host.ts +123 -130
  186. package/src/internal/port.ts +100 -103
  187. package/src/internal/release.ts +3 -2
  188. package/src/internal/runner/Connection.ts +52 -60
  189. package/src/internal/runner/Execution.ts +163 -164
  190. package/src/internal/runner/Framing.ts +9 -10
  191. package/src/internal/runner/Local.ts +26 -27
  192. package/src/internal/runner/Lock.ts +23 -25
  193. package/src/internal/runner/Packages.ts +67 -70
  194. package/src/internal/runner/Processes.ts +89 -92
  195. package/src/internal/runner/Store.ts +110 -114
  196. package/src/internal/runner/Supervisor.ts +392 -405
  197. package/src/internal/runner/accept.ts +76 -84
  198. package/src/internal/runner/model.ts +20 -21
  199. package/src/internal/serve.ts +15 -13
  200. package/src/internal/services.ts +1 -19
  201. package/src/internal/watchdogMain.ts +16 -11
  202. package/src/internal/websocketServer.ts +18 -3
  203. package/src/runner/auth/jwt.ts +10 -6
  204. package/dist/cleanup-BPWr-5U9.js +0 -13
  205. package/dist/connectionEnded-DUgcobEd.js +0 -9
  206. package/dist/internal/childErrors.d.ts +0 -33
  207. package/dist/internal/childErrors.d.ts.map +0 -1
  208. package/dist/internal/port.d.ts.map +0 -1
  209. package/dist/internal/runner/Framing.d.ts.map +0 -1
@@ -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,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;CAC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C,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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,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) => Effect.gen(function* () {
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 }) => Effect.gen(function* () {
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
- }).pipe(loading.withPermit),
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) =>\n\tEffect.gen(function* () {\n\t\tconst identity = yield* Peer\n\t\tconst scope = yield* Effect.scope\n\t\tconst mux = yield* Multiplex.make(channel)\n\t\tconst peer = yield* Port.make(Wire.channel(mux, 0), {\n\t\t\tsession: \"session-v1\",\n\t\t\tserve: { session: Wire.Session },\n\t\t\tcall: {},\n\t\t})\n\t\tconst attached = yield* Ref.make(Option.none<string>())\n\t\tconst loading = yield* Semaphore.make(1)\n\t\tconst authorize = (handle: Handle) =>\n\t\t\thandle.key.identity === identity\n\t\t\t\t? Effect.void\n\t\t\t\t: Effect.fail(\n\t\t\t\t\t\tSessionAccessDenied.make({\n\t\t\t\t\t\t\tdetail: \"The session belongs to another authenticated identity\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\tconst handlers = yield* Wire.Session.toHandlers({\n\t\t\tHighWater: ({ instance }) => supervisor.highWater({ identity, instance }),\n\t\t\tOpen: ({\n\t\t\t\tinstance,\n\t\t\t\trequestId,\n\t\t\t\texpectedGeneration,\n\t\t\t\tleaseMillis,\n\t\t\t\tlimits,\n\t\t\t}) =>\n\t\t\t\tsupervisor.open({\n\t\t\t\t\tkey: { identity, instance },\n\t\t\t\t\trequestId,\n\t\t\t\t\texpectedGeneration,\n\t\t\t\t\t...(leaseMillis === undefined ? {} : { lease: leaseMillis }),\n\t\t\t\t\tlimits,\n\t\t\t\t}),\n\t\t\tLoad: ({ handle, ...request }) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tyield* authorize(handle)\n\t\t\t\t\tconst attachment = yield* Ref.get(attached)\n\t\t\t\t\tif (Option.isSome(attachment) && attachment.value !== handle.token)\n\t\t\t\t\t\treturn yield* SessionConflict.make({\n\t\t\t\t\t\t\tdetail: \"A connection can attach only one execution\",\n\t\t\t\t\t\t})\n\t\t\t\t\tconst code = yield* supervisor.load(handle, request)\n\t\t\t\t\tif (Option.isNone(attachment)) {\n\t\t\t\t\t\tconst child = yield* execution\n\t\t\t\t\t\t\t.peer(handle.token)\n\t\t\t\t\t\t\t.pipe(Scope.provide(scope))\n\t\t\t\t\t\tyield* Ref.set(attached, Option.some(handle.token))\n\t\t\t\t\t\t// A child EOF must not destroy the session channel before Dispose can acknowledge exit.\n\t\t\t\t\t\tyield* Effect.all(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tEffect.forever(\n\t\t\t\t\t\t\t\t\tEffect.flatMap(mux.take(1), (bytes) => child.send(1, bytes)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tEffect.forever(\n\t\t\t\t\t\t\t\t\tEffect.flatMap(child.take(1), (bytes) => mux.send(1, bytes)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t{ concurrency: \"unbounded\" },\n\t\t\t\t\t\t).pipe(\n\t\t\t\t\t\t\tEffect.catchCause((cause) =>\n\t\t\t\t\t\t\t\tCause.hasInterruptsOnly(cause)\n\t\t\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t\t\t: child.fail(TransportError.make({ cause })),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tEffect.forkIn(scope),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn code\n\t\t\t\t}).pipe(loading.withPermit),\n\t\t\tRenew: (handle) =>\n\t\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.renew(handle))),\n\t\t\tDispose: (handle) =>\n\t\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.dispose(handle))),\n\t\t\tStatus: (handle) =>\n\t\t\t\tauthorize(handle).pipe(Effect.andThen(supervisor.status(handle))),\n\t\t})\n\t\treturn yield* RpcServer.make(Wire.Session, {\n\t\t\tdisableFatalDefects: true,\n\t\t}).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, peer.serverProtocol(\"session\")),\n\t\t\tEffect.raceFirst(mux.await),\n\t\t)\n\t})\n"],"mappings":";;;;;;;;;AAYA,MAAa,UACZ,YACA,WACA,cAEA,OAAO,IAAI,aAAa;CACvB,MAAM,WAAW,OAAO;CACxB,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,MAAM,OAAOA,OAAeC,SAAO;CACzC,MAAM,OAAO,OAAOC,KAAUC,QAAa,KAAK,CAAC,GAAG;EACnD,SAAS;EACT,OAAO,EAAE,SAASC,QAAa;EAC/B,MAAM,CAAC;CACR,CAAC;CACD,MAAM,WAAW,OAAO,IAAI,KAAK,OAAO,KAAa,CAAC;CACtD,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC;CACvC,MAAM,aAAa,WAClB,OAAO,IAAI,aAAa,WACrB,OAAO,OACP,OAAO,KACP,oBAAoB,KAAK,EACxB,QAAQ,wDACT,CAAC,CACF;CACH,MAAM,WAAW,OAAA,QAAoB,WAAW;EAC/C,YAAY,EAAE,eAAe,WAAW,UAAU;GAAE;GAAU;EAAS,CAAC;EACxE,OAAO,EACN,UACA,WACA,oBACA,aACA,aAEA,WAAW,KAAK;GACf,KAAK;IAAE;IAAU;GAAS;GAC1B;GACA;GACA,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,O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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"}
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\tEffect.raceFirst(mux.await),\n\t)\n})\n"],"mappings":";;;;;;;;;AAYA,MAAa,SAAS,OAAO,WAAW,WACvC,YACA,WACA,WACC;CACD,MAAM,WAAW,OAAO;CACxB,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,MAAM,OAAOA,OAAeC,SAAO;CACzC,MAAM,OAAO,OAAOC,KAAUC,QAAa,KAAK,CAAC,GAAG;EACnD,SAAS;EACT,OAAO,EAAE,SAASC,QAAa;EAC/B,MAAM,CAAC;CACR,CAAC;CACD,MAAM,WAAW,OAAO,IAAI,KAAK,OAAO,KAAa,CAAC;CACtD,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC;CACvC,MAAM,aAAa,WAClB,OAAO,IAAI,aAAa,WACrB,OAAO,OACP,OAAO,KACP,oBAAoB,KAAK,EACxB,QAAQ,wDACT,CAAC,CACF;CACH,MAAM,WAAW,OAAA,QAAoB,WAAW;EAC/C,YAAY,EAAE,eAAe,WAAW,UAAU;GAAE;GAAU;EAAS,CAAC;EACxE,OAAO,EAAE,UAAU,WAAW,oBAAoB,aAAa,aAC9D,WAAW,KAAK;GACf,KAAK;IAAE;IAAU;GAAS;GAC1B;GACA;GACA,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,YAAY;GAC1D;EACD,CAAC;EACF,MAAM,OAAO,WAAW,WAAW,EAAE,QAAQ,GAAG,WAAW;GAC1D,OAAO,UAAU,MAAM;GACvB,MAAM,aAAa,OAAO,IAAI,IAAI,QAAQ;GAC1C,IAAI,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E,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) => Effect.gen(function* () {
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,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SAAS,UAAU,OAAO,OAAO,KACvC,OAAO,cAAc,cAAc,cAAc,YAAY,CAC9D,CAAC,CAAC,KAAK,OAAO,KAAK;CACnB,IAAI,OAAO,SAAS,WAAW;EAC9B,IAAI,OAAO,OAAO,OAAO,KAAK,GAAG,OAAO,OAAO,MAAM;EACrD,OAAO,OAAO,6BAA6B,KAAK,EAAE,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;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IAAI,OAAO,OAAO,OAAO,KAAK,GAAG,OAAO,OAAO,MAAM;EACrD,OAAO,OAAO,6BAA6B,KAAK,EAAE,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"}
@@ -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 = (entries, lifecycle) => Effect.gen(function* () {
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);
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","names":["make","Importer.make"],"sources":["../../src/internal/serve.ts"],"sourcesContent":["import { findSubtree, isSubtreeActive } from \"./forkTree\"\nimport { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport {\n\tConfigDirectory,\n\tInclude,\n\tLoader,\n\tModuleResolver,\n} from \"@graftland/loader\"\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tExit,\n\tLogger,\n\tOption,\n\tPath,\n\tStream,\n} from \"effect\"\nimport * as Importer from \"./importer\"\n\nimport { ServeLifecycle, StartupError, make } from \"./ServeLifecycle\"\nimport { cleanupCause } from \"./cleanup\"\nexport { StartupError } from \"./ServeLifecycle\"\n\nconst check = (\n\ttrees: ReadonlyArray<Fork.ForkTree>,\n): Effect.Effect<void, StartupError> =>\n\tEffect.forEach(\n\t\ttrees,\n\t\t(tree) => {\n\t\t\tif (tree.state._tag === \"Failed\")\n\t\t\t\treturn Effect.fail(\n\t\t\t\t\tStartupError.make({\n\t\t\t\t\t\tdetail: `Runner entry ${tree.name} failed`,\n\t\t\t\t\t\tcause: tree.state.cause,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\treturn check(tree.children)\n\t\t},\n\t\t{ discard: true },\n\t)\nconst ready = Plugin.make({\n\tname: \"remote-ready\",\n\tinject: [Loader.Loader],\n\tapply: Effect.fnUntraced(function* () {\n\t\tconst loader = yield* Loader.Loader\n\t\t// A failed authenticator can leave its listener child Pending while the outer plugin is Applying.\n\t\tyield* loader.ready.pipe(\n\t\t\tEffect.raceFirst(\n\t\t\t\tGraft.forks.pipe(\n\t\t\t\t\tStream.map((trees) => findSubtree(trees, loader.root.id)),\n\t\t\t\t\tStream.filter(Option.isSome),\n\t\t\t\t\tStream.runForEach((tree) => check([tree.value])),\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\t// Pending can still be reacting to a provider published during startup.\n\t\t// Observe the loader's subtree, excluding this startup observer itself.\n\t\tyield* Graft.forks.pipe(\n\t\t\tStream.map((trees) => findSubtree(trees, loader.root.id)),\n\t\t\tStream.filter(Option.isSome),\n\t\t\tStream.map((tree) => tree.value),\n\t\t\tStream.tap((tree) => check([tree])),\n\t\t\tStream.filter(isSubtreeActive),\n\t\t\tStream.runHead,\n\t\t)\n\t}),\n})\n\n/** Loader logs child cleanup errors; the supervisor's release signal also reaches the command exit. */\nconst close = (entries: Fork.Fork, lifecycle: typeof ServeLifecycle.Service) =>\n\tEffect.gen(function* () {\n\t\tconst disposed = yield* Effect.exit(entries.dispose)\n\t\tconst released = yield* Effect.exit(Deferred.await(lifecycle.released))\n\t\tconst cause = Array.reduce(\n\t\t\t[disposed, released],\n\t\t\tCause.empty,\n\t\t\t(cause: Cause.Cause<unknown>, exit: Exit.Exit<void, unknown>) =>\n\t\t\t\tExit.isFailure(exit) ? Cause.combine(cause, exit.cause) : cause,\n\t\t)\n\t\tif (cause.reasons.length > 0)\n\t\t\treturn yield* Effect.failCause(cleanupCause(cause))\n\t})\n\nconst load = Effect.fnUntraced(function* (config: string, directory: string) {\n\tconst lifecycle = yield* make\n\tyield* Graft.provide(ServeLifecycle, lifecycle)\n\tconst importer = yield* Importer.make(directory)\n\tconst resolver = yield* ModuleResolver.make({ base: directory, importer })\n\tyield* Graft.provide(ModuleResolver.ModuleResolver, resolver)\n\tconst entries = yield* Graft.plugin(Include.Include, {\n\t\tpath: config,\n\t\twatch: false,\n\t})\n\tyield* entries.await\n\tconst startup = yield* Graft.plugin(ready)\n\tyield* startup.await\n\treturn yield* Deferred.await(lifecycle.ended).pipe(\n\t\tEffect.ensuring(close(entries, lifecycle)),\n\t)\n})\nexport const run = Effect.fnUntraced(function* (config: string) {\n\tconst path = yield* Path.Path\n\tconst file = path.resolve(config)\n\tconst directory = path.dirname(file)\n\treturn yield* load(file, directory).pipe(\n\t\tEffect.mapError((error) =>\n\t\t\tStartupError.make({\n\t\t\t\tdetail: \"Starting the runner failed\",\n\t\t\t\tcause: Cause.fail(error),\n\t\t\t}),\n\t\t),\n\t\tEffect.provideService(ConfigDirectory, Option.some(directory)),\n\t\tEffect.provideService(Logger.LogToStderr, true),\n\t)\n})\n"],"mappings":";;;;;;;;AAyBA,MAAM,SACL,UAEA,OAAO,QACN,QACC,SAAS;CACT,IAAI,KAAK,MAAM,SAAS,UACvB,OAAO,OAAO,KACb,aAAa,KAAK;EACjB,QAAQ,gBAAgB,KAAK,KAAK;EAClC,OAAO,KAAK,MAAM;CACnB,CAAC,CACF;CACD,OAAO,MAAM,KAAK,QAAQ;AAC3B,GACA,EAAE,SAAS,KAAK,CACjB;AACD,MAAM,QAAQ,OAAO,KAAK;CACzB,MAAM;CACN,QAAQ,CAAC,OAAO,MAAM;CACtB,OAAO,OAAO,WAAW,aAAa;EACrC,MAAM,SAAS,OAAO,OAAO;EAE7B,OAAO,OAAO,MAAM,KACnB,OAAO,UACN,MAAM,MAAM,KACX,OAAO,KAAK,UAAU,YAAY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CAC1B;CACf,OAAO,OAAO,SAAS,MAAM,UAAU,KAAK,CAAC,CAAC,KAC7C,OAAO,SAAS,MAAM,SAAS,SAAS,CAAC,CAC1C;AACD,CAAC;AACD,MAAa,MAAM,OAAO,WAAW,WAAW,QAAgB;CAC/D,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,KAAK,QAAQ,MAAM;CAChC,MAAM,YAAY,KAAK,QAAQ,IAAI;CACnC,OAAO,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,KACnC,OAAO,UAAU,UAChB,aAAa,KAAK;EACjB,QAAQ;EACR,OAAO,MAAM,KAAK,KAAK;CACxB,CAAC,CACF,GACA,OAAO,eAAe,iBAAiB,OAAO,KAAK,SAAS,CAAC,GAC7D,OAAO,eAAe,OAAO,aAAa,IAAI,CAC/C;AACD,CAAC"}
1
+ {"version":3,"file":"serve.js","names":["make","Importer.make"],"sources":["../../src/internal/serve.ts"],"sourcesContent":["import { findSubtree, isSubtreeActive } from \"./forkTree\"\nimport { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport {\n\tConfigDirectory,\n\tInclude,\n\tLoader,\n\tModuleResolver,\n} from \"@graftland/loader\"\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tExit,\n\tLogger,\n\tOption,\n\tPath,\n\tStream,\n} from \"effect\"\nimport * as Importer from \"./importer\"\n\nimport { ServeLifecycle, StartupError, make } from \"./ServeLifecycle\"\nimport { cleanupCause } from \"./cleanup\"\nexport { StartupError } from \"./ServeLifecycle\"\n\nconst check = (\n\ttrees: ReadonlyArray<Fork.ForkTree>,\n): Effect.Effect<void, StartupError> =>\n\tEffect.forEach(\n\t\ttrees,\n\t\t(tree) => {\n\t\t\tif (tree.state._tag === \"Failed\")\n\t\t\t\treturn Effect.fail(\n\t\t\t\t\tStartupError.make({\n\t\t\t\t\t\tdetail: `Runner entry ${tree.name} failed`,\n\t\t\t\t\t\tcause: tree.state.cause,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\treturn check(tree.children)\n\t\t},\n\t\t{ discard: true },\n\t)\nconst ready = Plugin.make({\n\tname: \"remote-ready\",\n\tinject: [Loader.Loader],\n\tapply: Effect.fnUntraced(function* () {\n\t\tconst loader = yield* Loader.Loader\n\t\t// A failed authenticator can leave its listener child Pending while the outer plugin is Applying.\n\t\tyield* loader.ready.pipe(\n\t\t\tEffect.raceFirst(\n\t\t\t\tGraft.forks.pipe(\n\t\t\t\t\tStream.map((trees) => findSubtree(trees, loader.root.id)),\n\t\t\t\t\tStream.filter(Option.isSome),\n\t\t\t\t\tStream.runForEach((tree) => check([tree.value])),\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\t// Pending can still be reacting to a provider published during startup.\n\t\t// Observe the loader's subtree, excluding this startup observer itself.\n\t\tyield* Graft.forks.pipe(\n\t\t\tStream.map((trees) => findSubtree(trees, loader.root.id)),\n\t\t\tStream.filter(Option.isSome),\n\t\t\tStream.map((tree) => tree.value),\n\t\t\tStream.tap((tree) => check([tree])),\n\t\t\tStream.filter(isSubtreeActive),\n\t\t\tStream.runHead,\n\t\t)\n\t}),\n})\n\n/** Loader logs child cleanup errors; the supervisor's release signal also reaches the command exit. */\nconst close = Effect.fnUntraced(function* (\n\tentries: Fork.Fork,\n\tlifecycle: typeof ServeLifecycle.Service,\n) {\n\tconst disposed = yield* Effect.exit(entries.dispose)\n\tconst released = yield* Effect.exit(Deferred.await(lifecycle.released))\n\tconst cause = Array.reduce(\n\t\t[disposed, released],\n\t\tCause.empty,\n\t\t(cause: Cause.Cause<unknown>, exit: Exit.Exit<void, unknown>) =>\n\t\t\tExit.isFailure(exit) ? Cause.combine(cause, exit.cause) : cause,\n\t)\n\tif (cause.reasons.length > 0)\n\t\treturn yield* Effect.failCause(cleanupCause(cause))\n})\n\nconst load = Effect.fnUntraced(function* (config: string, directory: string) {\n\tconst lifecycle = yield* make\n\tyield* Graft.provide(ServeLifecycle, lifecycle)\n\tconst importer = yield* Importer.make(directory)\n\tconst resolver = yield* ModuleResolver.make({ base: directory, importer })\n\tyield* Graft.provide(ModuleResolver.ModuleResolver, resolver)\n\tconst entries = yield* Graft.plugin(Include.Include, {\n\t\tpath: config,\n\t\twatch: false,\n\t})\n\tyield* entries.await\n\tconst startup = yield* Graft.plugin(ready)\n\tyield* startup.await\n\treturn yield* Deferred.await(lifecycle.ended).pipe(\n\t\tEffect.ensuring(close(entries, lifecycle)),\n\t)\n})\nexport const run = Effect.fnUntraced(function* (config: string) {\n\tconst path = yield* Path.Path\n\tconst file = path.resolve(config)\n\tconst directory = path.dirname(file)\n\treturn yield* load(file, directory).pipe(\n\t\tEffect.mapError((error) =>\n\t\t\tStartupError.make({\n\t\t\t\tdetail: \"Starting the runner failed\",\n\t\t\t\tcause: Cause.fail(error),\n\t\t\t}),\n\t\t),\n\t\tEffect.provideService(ConfigDirectory, Option.some(directory)),\n\t\tEffect.provideService(Logger.LogToStderr, true),\n\t)\n})\n"],"mappings":";;;;;;;;AAyBA,MAAM,SACL,UAEA,OAAO,QACN,QACC,SAAS;CACT,IAAI,KAAK,MAAM,SAAS,UACvB,OAAO,OAAO,KACb,aAAa,KAAK;EACjB,QAAQ,gBAAgB,KAAK,KAAK;EAClC,OAAO,KAAK,MAAM;CACnB,CAAC,CACF;CACD,OAAO,MAAM,KAAK,QAAQ;AAC3B,GACA,EAAE,SAAS,KAAK,CACjB;AACD,MAAM,QAAQ,OAAO,KAAK;CACzB,MAAM;CACN,QAAQ,CAAC,OAAO,MAAM;CACtB,OAAO,OAAO,WAAW,aAAa;EACrC,MAAM,SAAS,OAAO,OAAO;EAE7B,OAAO,OAAO,MAAM,KACnB,OAAO,UACN,MAAM,MAAM,KACX,OAAO,KAAK,UAAU,YAAY,OAAO,OAAO,KAAK,EAAE,CAAC,GACxD,OAAO,OAAO,OAAO,MAAM,GAC3B,OAAO,YAAY,SAAS,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAChD,CACD,CACD;EAGA,OAAO,MAAM,MAAM,K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/D,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,KAAK,QAAQ,MAAM;CAChC,MAAM,YAAY,KAAK,QAAQ,IAAI;CACnC,OAAO,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,KACnC,OAAO,UAAU,UAChB,aAAa,KAAK;EACjB,QAAQ;EACR,OAAO,MAAM,KAAK,KAAK;CACxB,CAAC,CACF,GACA,OAAO,eAAe,iBAAiB,OAAO,KAAK,SAAS,CAAC,GAC7D,OAAO,eAAe,OAAO,aAAa,IAAI,CAC/C;AACD,CAAC"}
@@ -1,18 +1,8 @@
1
- import { Port } from "./port.js";
2
- import { Graft } from "@graftland/graft";
3
- import { Context, Effect, Scope } from "effect";
1
+ import { Service } from "../Contract.js";
2
+ import { Context } from "effect";
4
3
  import { Rpc, RpcClient, RpcClientError, RpcGroup } from "effect/rpc";
5
- type Peer = Port;
6
- /** RPC types stay inside the descriptor; Graft supplies its dynamic activation context. */
7
- export interface Service<R = never, ClientR = never> {
8
- readonly key: Context.Key<unknown, unknown>;
9
- readonly group: Pick<RpcGroup.RpcGroup<Rpc.Any>, "requests">;
10
- readonly serve: (port: Pick<Peer, "serverProtocol">) => Effect.Effect<never, never, R>;
11
- readonly publish: (port: Pick<Peer, "clientProtocol">) => Effect.Effect<void, Graft.ServiceConflict, Graft.Graft | Scope.Scope | ClientR>;
12
- }
13
4
  export declare const service: <I, S, R extends Rpc.Any, H extends RpcGroup.HandlersFrom<R>>(key: Context.Key<I, S>, group: RpcGroup.RpcGroup<R>, mapping: {
14
5
  readonly toHandlers: (value: S) => H;
15
6
  readonly fromClient: (client: RpcClient.RpcClient<R, RpcClientError.RpcClientError>) => S;
16
7
  }) => Service<RpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>, Rpc.MiddlewareClient<R>>;
17
- export {};
18
8
  //# sourceMappingURL=services.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","names":["Port.Port"],"sources":["../../src/internal/services.ts"],"mappings":";;;;KAOK,OAAOA;;iBAGK,QAAQ,WAAW;WAC1B,KAAK,QAAQ;WACb,OAAO,KAAK,SAAS,SAAS,IAAI;WAClC,QACR,MAAM,KAAK,4BACP,OAAO,qBAAqB;WACxB,UACR,MAAM,KAAK,4BACP,OAAO,aAEX,MAAM,iBACN,MAAM,QAAQ,MAAM,QAAQ;;qBAGjB,UACZ,GACA,GACA,UAAU,IAAI,KACd,UAAU,SAAS,aAAa,IAAE,KAE7B,QAAQ,IAAI,GAAG,IAAE,OACf,SAAS,SAAS,IAAE;WAEjB,aAAa,OAAO,MAAM;WAC1B,aACR,QAAQ,UAAU,UAAU,GAAG,eAAe,oBAC1C;MAEJ,QACF,SAAS,iBAAiB,GAAG,KAAK,IAAI,WAAW,KAAK,IAAI,eAAe,IACzE,IAAI,iBAAiB"}
1
+ {"version":3,"file":"services.d.ts","names":[],"sources":["../../src/internal/services.ts"],"mappings":";;;qBAMa,UACZ,GACA,GACA,UAAU,IAAI,KACd,UAAU,SAAS,aAAa,IAAE,KAE7B,QAAQ,IAAI,GAAG,IAAE,OACf,SAAS,SAAS,IAAE;WAEjB,aAAa,OAAO,MAAM;WAC1B,aACR,QAAQ,UAAU,UAAU,GAAG,eAAe,oBAC1C;MAEJ,QACF,SAAS,iBAAiB,GAAG,KAAK,IAAI,WAAW,KAAK,IAAI,eAAe,IACzE,IAAI,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport { Graft } from \"@graftland/graft\"\nimport { RpcClient, RpcServer } from \"effect/rpc\"\nimport type { Scope } from \"effect\"\nimport type { Rpc, RpcClientError, RpcGroup } from \"effect/rpc\"\nimport type * as Port from \"./port\"\n\ntype Peer = Port.Port\n\n/** RPC types stay inside the descriptor; Graft supplies its dynamic activation context. */\nexport interface Service<R = never, ClientR = never> {\n\treadonly key: Context.Key<unknown, unknown>\n\treadonly group: Pick<RpcGroup.RpcGroup<Rpc.Any>, \"requests\">\n\treadonly serve: (\n\t\tport: Pick<Peer, \"serverProtocol\">,\n\t) => Effect.Effect<never, never, R>\n\treadonly publish: (\n\t\tport: Pick<Peer, \"clientProtocol\">,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tGraft.ServiceConflict,\n\t\tGraft.Graft | Scope.Scope | ClientR\n\t>\n}\nexport const service = <\n\tI,\n\tS,\n\tR extends Rpc.Any,\n\tH extends RpcGroup.HandlersFrom<R>,\n>(\n\tkey: Context.Key<I, S>,\n\tgroup: RpcGroup.RpcGroup<R>,\n\tmapping: {\n\t\treadonly toHandlers: (value: S) => H\n\t\treadonly fromClient: (\n\t\t\tclient: RpcClient.RpcClient<R, RpcClientError.RpcClientError>,\n\t\t) => S\n\t},\n): Service<\n\tRpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>,\n\tRpc.MiddlewareClient<R>\n> => ({\n\tkey,\n\tgroup,\n\tserve: Effect.fnUntraced(function* (port) {\n\t\t// Graft admits the activation from this descriptor's key before serving it.\n\t\tconst context = yield* Effect.context<never>()\n\t\tconst value = yield* Effect.fromOption(\n\t\t\tContext.getOption(context, key),\n\t\t).pipe(Effect.orDie)\n\t\tconst handlers = yield* group.toHandlers(mapping.toHandlers(value))\n\t\treturn yield* RpcServer.make(group, { disableFatalDefects: true }).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, port.serverProtocol(key.key)),\n\t\t)\n\t}),\n\tpublish: Effect.fnUntraced(function* (port) {\n\t\tconst client = yield* RpcClient.make(group).pipe(\n\t\t\tEffect.provideService(RpcClient.Protocol, port.clientProtocol(key.key)),\n\t\t)\n\t\tyield* Graft.provide(key, mapping.fromClient(client))\n\t}),\n})\nexport const endpoints = (services: ReadonlyArray<Service>) =>\n\tRecord.fromEntries(\n\t\tArray.map(\n\t\t\tservices,\n\t\t\t(service) =>\n\t\t\t\t[service.key.key, service.group] satisfies readonly [\n\t\t\t\t\tstring,\n\t\t\t\t\tService[\"group\"],\n\t\t\t\t],\n\t\t),\n\t)\n"],"mappings":";;;;AAwBA,MAAa,WAMZ,KACA,OACA,aASK;CACL;CACA;CACA,OAAO,OAAO,WAAW,WAAW,MAAM;EAEzC,MAAM,UAAU,OAAO,OAAO,QAAe;EAC7C,MAAM,QAAQ,OAAO,OAAO,WAC3B,QAAQ,UAAU,SAAS,GAAG,CAC/B,CAAC,CAAC,KAAK,OAAO,KAAK;EACnB,MAAM,WAAW,OAAO,MAAM,WAAW,QAAQ,WAAW,KAAK,CAAC;EAClE,OAAO,OAAO,UAAU,KAAK,OAAO,EAAE,qBAAqB,KAAK,CAAC,CAAC,CAAC,KAClE,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;CACD,CAAC;CACD,SAAS,OAAO,WAAW,WAAW,MAAM;EAC3C,MAAM,SAAS,OAAO,UAAU,KAAK,KAAK,CAAC,CAAC,KAC3C,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;EACA,OAAO,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM,CAAC;CACrD,CAAC;AACF;AACA,MAAa,aAAa,aACzB,OAAO,YACN,MAAM,IACL,WACC,YACA,CAAC,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAIjC,CACD"}
1
+ {"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport { Graft } from \"@graftland/graft\"\nimport { RpcClient, RpcServer } from \"effect/rpc\"\nimport type { Rpc, RpcClientError, RpcGroup } from \"effect/rpc\"\nimport type { Service } from \"../Contract\"\n\nexport const service = <\n\tI,\n\tS,\n\tR extends Rpc.Any,\n\tH extends RpcGroup.HandlersFrom<R>,\n>(\n\tkey: Context.Key<I, S>,\n\tgroup: RpcGroup.RpcGroup<R>,\n\tmapping: {\n\t\treadonly toHandlers: (value: S) => H\n\t\treadonly fromClient: (\n\t\t\tclient: RpcClient.RpcClient<R, RpcClientError.RpcClientError>,\n\t\t) => S\n\t},\n): Service<\n\tRpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>,\n\tRpc.MiddlewareClient<R>\n> => ({\n\tkey,\n\tgroup,\n\tserve: Effect.fnUntraced(function* (port) {\n\t\t// Graft admits the activation from this descriptor's key before serving it.\n\t\tconst context = yield* Effect.context<never>()\n\t\tconst value = yield* Effect.fromOption(\n\t\t\tContext.getOption(context, key),\n\t\t).pipe(Effect.orDie)\n\t\tconst handlers = yield* group.toHandlers(mapping.toHandlers(value))\n\t\treturn yield* RpcServer.make(group, { disableFatalDefects: true }).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, port.serverProtocol(key.key)),\n\t\t)\n\t}),\n\tpublish: Effect.fnUntraced(function* (port) {\n\t\tconst client = yield* RpcClient.make(group).pipe(\n\t\t\tEffect.provideService(RpcClient.Protocol, port.clientProtocol(key.key)),\n\t\t)\n\t\tyield* Graft.provide(key, mapping.fromClient(client))\n\t}),\n})\nexport const endpoints = (services: ReadonlyArray<Service>) =>\n\tRecord.fromEntries(\n\t\tArray.map(\n\t\t\tservices,\n\t\t\t(service) =>\n\t\t\t\t[service.key.key, service.group] satisfies readonly [\n\t\t\t\t\tstring,\n\t\t\t\t\tService[\"group\"],\n\t\t\t\t],\n\t\t),\n\t)\n"],"mappings":";;;;AAMA,MAAa,WAMZ,KACA,OACA,aASK;CACL;CACA;CACA,OAAO,OAAO,WAAW,WAAW,MAAM;EAEzC,MAAM,UAAU,OAAO,OAAO,QAAe;EAC7C,MAAM,QAAQ,OAAO,OAAO,WAC3B,QAAQ,UAAU,SAAS,GAAG,CAC/B,CAAC,CAAC,KAAK,OAAO,KAAK;EACnB,MAAM,WAAW,OAAO,MAAM,WAAW,QAAQ,WAAW,KAAK,CAAC;EAClE,OAAO,OAAO,UAAU,KAAK,OAAO,EAAE,qBAAqB,KAAK,CAAC,CAAC,CAAC,KAClE,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;CACD,CAAC;CACD,SAAS,OAAO,WAAW,WAAW,MAAM;EAC3C,MAAM,SAAS,OAAO,UAAU,KAAK,KAAK,CAAC,CAAC,KAC3C,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;EACA,OAAO,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM,CAAC;CACrD,CAAC;AACF;AACA,MAAa,aAAa,aACzB,OAAO,YACN,MAAM,IACL,WACC,YACA,CAAC,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAIjC,CACD"}
@@ -1 +1 @@
1
- export { t as Config, n as default } from "../supervisorPlugin-Inb1S5IV.js";
1
+ export { t as Config, n as default } from "../supervisorPlugin-t6Z6PrhD.js";
@@ -1,5 +1,5 @@
1
1
  import { n as Notice, t as CommandJson } from "../WatchdogProtocol-BZmVxrBP.js";
2
- import { Effect, FiberHandle, Ref, Schema, Stream } from "effect";
2
+ import { Clock, Effect, FiberHandle, Ref, Schema, Stream } from "effect";
3
3
  import { NodeRuntime, NodeStream } from "@effect/platform-node";
4
4
  import process from "node:process";
5
5
  import { parentPort } from "node:worker_threads";
@@ -8,11 +8,11 @@ import { Socket } from "node:net";
8
8
  /** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */
9
9
  const die = Effect.sync(() => process.kill(process.pid, "SIGKILL")).pipe(Effect.andThen(Effect.never));
10
10
  const notify = (notice) => Schema.encodeEffect(Notice)(notice).pipe(Effect.flatMap((message) => Effect.sync(() => parentPort?.postMessage(message))));
11
- const now = Effect.sync(() => performance.now());
12
- const expire = (deadline) => Effect.gen(function* () {
11
+ const now = Clock.monotonicTimeNanos.pipe(Effect.map((nanos) => Number(nanos) / 1e6));
12
+ const expire = Effect.fnUntraced(function* (deadline) {
13
13
  const remaining = deadline - (yield* now);
14
14
  if (remaining <= 0) return yield* die;
15
- yield* Effect.sleep(Math.min(remaining, 2147483647));
15
+ yield* Effect.sleep(remaining);
16
16
  return yield* expire(deadline);
17
17
  });
18
18
  const main = Effect.scoped(Effect.gen(function* () {
@@ -30,7 +30,7 @@ const main = Effect.scoped(Effect.gen(function* () {
30
30
  socket.destroy();
31
31
  }));
32
32
  yield* notify("ready");
33
- yield* NodeStream.fromReadable({ evaluate: () => input }).pipe(Stream.decodeText(), Stream.splitLines, Stream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)), Stream.runForEach((command) => Effect.gen(function* () {
33
+ yield* NodeStream.fromReadable({ evaluate: () => input }).pipe(Stream.decodeText(), Stream.splitLines, Stream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)), Stream.runForEach(Effect.fnUntraced(function* (command) {
34
34
  if (command.kind === "start") return yield* notify("start");
35
35
  if (command.kind === "stop") {
36
36
  yield* Ref.update(lease, (state) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"watchdogMain.js","names":[],"sources":["../../src/internal/watchdogMain.ts"],"sourcesContent":["/** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */\nimport { NodeRuntime, NodeStream } from \"@effect/platform-node\"\nimport { Effect, FiberHandle, Ref, Schema, Stream } from \"effect\"\nimport { Socket } from \"node:net\"\nimport { parentPort } from \"node:worker_threads\"\nimport process from \"node:process\"\nimport { CommandJson, Notice } from \"./runner/WatchdogProtocol\"\n\n// The runner machine is trusted. A suspended machine cannot enforce a deadline until it resumes.\n// Killing this live process has no PID lookup; external supervisor kills retain a small PID reuse window.\nconst die = Effect.sync(() => process.kill(process.pid, \"SIGKILL\")).pipe(\n\tEffect.andThen(Effect.never),\n)\nconst notify = (notice: typeof Notice.Type) =>\n\tSchema.encodeEffect(Notice)(notice).pipe(\n\t\tEffect.flatMap((message) =>\n\t\t\tEffect.sync(() => parentPort?.postMessage(message)),\n\t\t),\n\t)\nconst now = Effect.sync(() => performance.now())\nconst expire = (deadline: number): Effect.Effect<never> =>\n\tEffect.gen(function* () {\n\t\tconst remaining = deadline - (yield* now)\n\t\tif (remaining <= 0) return yield* die\n\t\tyield* Effect.sleep(Math.min(remaining, 2147483647))\n\t\treturn yield* expire(deadline)\n\t})\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst lease = yield* Ref.make({\n\t\t\tdeadline: (yield* now) + 30000,\n\t\t\tstopped: false,\n\t\t})\n\t\tconst timer = yield* FiberHandle.make<never, never>()\n\t\tyield* FiberHandle.run(timer, expire((yield* Ref.get(lease)).deadline))\n\t\tconst input = yield* Effect.acquireRelease(\n\t\t\tEffect.sync(() => new Socket({ fd: 4, readable: true, writable: false })),\n\t\t\t(socket) =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tsocket.destroy()\n\t\t\t\t}),\n\t\t)\n\t\tyield* notify(\"ready\")\n\t\tyield* NodeStream.fromReadable({ evaluate: () => input }).pipe(\n\t\t\tStream.decodeText(),\n\t\t\tStream.splitLines,\n\t\t\tStream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)),\n\t\t\tStream.runForEach((command) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tif (command.kind === \"start\") return yield* notify(\"start\")\n\t\t\t\t\tif (command.kind === \"stop\") {\n\t\t\t\t\t\tyield* Ref.update(lease, (state) => ({ ...state, stopped: true }))\n\t\t\t\t\t\treturn yield* notify(\"stop\")\n\t\t\t\t\t}\n\t\t\t\t\tconst current = yield* Ref.get(lease)\n\t\t\t\t\tconst time = yield* now\n\t\t\t\t\tif (current.stopped || time >= current.deadline) return yield* die\n\t\t\t\t\tconst deadline = time + command.millis\n\t\t\t\t\tyield* Ref.set(lease, { deadline, stopped: false })\n\t\t\t\t\tyield* FiberHandle.run(timer, expire(deadline))\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn yield* die\n\t}),\n).pipe(\n\tEffect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I,CAAC,GACjE,OAAO,YAAY,YAClB,OAAO,IAAI,aAAa;EACvB,IAAI,QAAQ,SAAS,SAAS,OAAO,OAAO,OAAO,OAAO;EAC1D,IAAI,QAAQ,SAAS,QAAQ;GAC5B,OAAO,IAAI,OAAO,QAAQ,WAAW;IAAE,GAAG;IAAO,SAAS;GAAK,EAAE;GACjE,OAAO,OAAO,OAAO,MAAM;EAC5B;EACA,MAAM,UAAU,OAAO,IAAI,IAAI,KAAK;EACpC,MAAM,OAAO,OAAO;EACpB,IAAI,QAAQ,WAAW,QAAQ,QAAQ,UAAU,OAAO,OAAO;EAC/D,MAAM,WAAW,OAAO,QAAQ;EAChC,OAAO,IAAI,IAAI,OAAO;GAAE;GAAU,SAAS;EAAM,CAAC;EAClD,OAAO,YAAY,IAAI,OAAO,OAAO,QAAQ,CAAC;CAC/C,CAAC,CACF,CACD;CACA,OAAO,OAAO;AACf,CAAC,CACF,CAAC,CAAC,KACD,OAAO,YAAY,UAClB,OAAO,SAAS,mBAAmB,KAAK,CAAC,CAAC,KAAK,OAAO,QAAQ,GAAG,CAAC,CACnE,CACD;AAEA,YAAY,QAAQ,IAAI"}
1
+ {"version":3,"file":"watchdogMain.js","names":[],"sources":["../../src/internal/watchdogMain.ts"],"sourcesContent":["/** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */\nimport { NodeRuntime, NodeStream } from \"@effect/platform-node\"\nimport { Clock, Effect, FiberHandle, Ref, Schema, Stream } from \"effect\"\nimport { Socket } from \"node:net\"\nimport { parentPort } from \"node:worker_threads\"\nimport process from \"node:process\"\nimport { CommandJson, Notice } from \"./runner/WatchdogProtocol\"\n\n// The runner machine is trusted. A suspended machine cannot enforce a deadline until it resumes.\n// Killing this live process has no PID lookup; external supervisor kills retain a small PID reuse window.\nconst die = Effect.sync(() => process.kill(process.pid, \"SIGKILL\")).pipe(\n\tEffect.andThen(Effect.never),\n)\nconst notify = (notice: typeof Notice.Type) =>\n\tSchema.encodeEffect(Notice)(notice).pipe(\n\t\tEffect.flatMap((message) =>\n\t\t\tEffect.sync(() => parentPort?.postMessage(message)),\n\t\t),\n\t)\n// Milliseconds on the monotonic clock, which the lease sleep also uses.\nconst now = Clock.monotonicTimeNanos.pipe(\n\tEffect.map((nanos) => Number(nanos) / 1_000_000),\n)\nconst expire = Effect.fnUntraced(function* (\n\tdeadline: number,\n): Effect.fn.Return<never> {\n\tconst remaining = deadline - (yield* now)\n\tif (remaining <= 0) return yield* die\n\t// The clock splits sleeps longer than the platform timer limit.\n\tyield* Effect.sleep(remaining)\n\treturn yield* expire(deadline)\n})\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst lease = yield* Ref.make({\n\t\t\tdeadline: (yield* now) + 30000,\n\t\t\tstopped: false,\n\t\t})\n\t\tconst timer = yield* FiberHandle.make<never, never>()\n\t\tyield* FiberHandle.run(timer, expire((yield* Ref.get(lease)).deadline))\n\t\tconst input = yield* Effect.acquireRelease(\n\t\t\tEffect.sync(() => new Socket({ fd: 4, readable: true, writable: false })),\n\t\t\t(socket) =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tsocket.destroy()\n\t\t\t\t}),\n\t\t)\n\t\tyield* notify(\"ready\")\n\t\tyield* NodeStream.fromReadable({ evaluate: () => input }).pipe(\n\t\t\tStream.decodeText(),\n\t\t\tStream.splitLines,\n\t\t\tStream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)),\n\t\t\tStream.runForEach(\n\t\t\t\tEffect.fnUntraced(function* (command: typeof CommandJson.Type) {\n\t\t\t\t\tif (command.kind === \"start\") return yield* notify(\"start\")\n\t\t\t\t\tif (command.kind === \"stop\") {\n\t\t\t\t\t\tyield* Ref.update(lease, (state) => ({ ...state, stopped: true }))\n\t\t\t\t\t\treturn yield* notify(\"stop\")\n\t\t\t\t\t}\n\t\t\t\t\tconst current = yield* Ref.get(lease)\n\t\t\t\t\tconst time = yield* now\n\t\t\t\t\tif (current.stopped || time >= current.deadline) return yield* die\n\t\t\t\t\tconst deadline = time + command.millis\n\t\t\t\t\tyield* Ref.set(lease, { deadline, stopped: false })\n\t\t\t\t\tyield* FiberHandle.run(timer, expire(deadline))\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn yield* die\n\t}),\n).pipe(\n\tEffect.catchCause((cause) =>\n\t\tEffect.logError(\"Watchdog failed\", cause).pipe(Effect.andThen(die)),\n\t),\n)\n\nNodeRuntime.runMain(main)\n"],"mappings":";;;;;;;;AAUA,MAAM,MAAM,OAAO,WAAW,QAAQ,KAAK,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,KACnE,OAAO,QAAQ,OAAO,KAAK,CAC5B;AACA,MAAM,UAAU,WACf,OAAO,aAAa,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KACnC,OAAO,SAAS,YACf,OAAO,WAAW,YAAY,YAAY,OAAO,CAAC,CACnD,CACD;AAED,MAAM,MAAM,MAAM,mBAAmB,KACpC,OAAO,KAAK,UAAU,OAAO,KAAK,IAAI,GAAS,CAChD;AACA,MAAM,SAAS,OAAO,WAAW,WAChC,UAC0B;CAC1B,MAAM,YAAY,YAAY,OAAO;CACrC,IAAI,aAAa,GAAG,OAAO,OAAO;CAElC,OAAO,OAAO,MAAM,SAAS;CAC7B,OAAO,OAAO,OAAO,QAAQ;AAC9B,CAAC;AACD,MAAM,OAAO,OAAO,OACnB,OAAO,IAAI,aAAa;CACvB,MAAM,QAAQ,OAAO,IAAI,KAAK;EAC7B,WAAW,OAAO,OAAO;EACzB,SAAS;CACV,CAAC;CACD,MAAM,QAAQ,OAAO,YAAY,KAAmB;CACpD,OAAO,YAAY,IAAI,OAAO,QAAQ,OAAO,IAAI,IAAI,KAAK,EAAA,CAAG,QAAQ,CAAC;CACtE,MAAM,QAAQ,OAAO,OAAO,eAC3B,OAAO,WAAW,IAAI,OAAO;EAAE,IAAI;EAAG,UAAU;EAAM,UAAU;CAAM,CAAC,CAAC,IACvE,WACA,OAAO,WAAW;EACjB,OAAO,QAAQ;CAChB,CAAC,CACH;CACA,OAAO,OAAO,OAAO;CACrB,OAAO,WAAW,aAAa,EAAE,gBAAgB,MAAM,CAAC,CAAC,CAAC,KACzD,OAAO,WAAW,GAClB,OAAO,YACP,OAAO,WAAW,SAAS,OAAO,aAAa,WAAW,CAAC,CAAC,IAAI,CAAC,GACjE,OAAO,WACN,OAAO,WAAW,WAAW,SAAkC;EAC9D,IAAI,QAAQ,SAAS,SAAS,OAAO,OAAO,OAAO,OAAO;EAC1D,IAAI,QAAQ,SAAS,QAAQ;GAC5B,OAAO,IAAI,OAAO,QAAQ,WAAW;IAAE,GAAG;IAAO,SAAS;GAAK,EAAE;GACjE,OAAO,OAAO,OAAO,MAAM;EAC5B;EACA,MAAM,UAAU,OAAO,IAAI,IAAI,KAAK;EACpC,MAAM,OAAO,OAAO;EACpB,IAAI,QAAQ,WAAW,QAAQ,QAAQ,UAAU,OAAO,OAAO;EAC/D,MAAM,WAAW,OAAO,QAAQ;EAChC,OAAO,IAAI,IAAI,OAAO;GAAE;GAAU,SAAS;EAAM,CAAC;EAClD,OAAO,YAAY,IAAI,OAAO,OAAO,QAAQ,CAAC;CAC/C,CAAC,CACF,CACD;CACA,OAAO,OAAO;AACf,CAAC,CACF,CAAC,CAAC,KACD,OAAO,YAAY,UAClB,OAAO,SAAS,mBAAmB,KAAK,CAAC,CAAC,KAAK,OAAO,QAAQ,GAAG,CAAC,CACnE,CACD;AAEA,YAAY,QAAQ,IAAI"}
@@ -6,7 +6,9 @@ import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node";
6
6
  import { HttpServerRequest, HttpServerResponse } from "effect/http";
7
7
  import { TLSSocket } from "node:tls";
8
8
  // src/internal/websocketServer.ts
9
- const rejection = (error) => Effect.logWarning("Remote host authentication failed", { reason: error.reason }, ...error.cause === void 0 ? [] : [error.cause]).pipe(Effect.as(HttpServerResponse.empty({
9
+ const rejection = (error) => error._tag === "AuthenticatorUnavailable" ? unavailable(error) : unauthorized(error);
10
+ const unavailable = (error) => Effect.logError("Remote host authenticator is unavailable", error.cause).pipe(Effect.as(HttpServerResponse.empty({ status: 503 })));
11
+ const unauthorized = (error) => Effect.logWarning("Remote host authentication failed", { reason: error.reason }, ...error.cause === void 0 ? [] : [error.cause]).pipe(Effect.as(HttpServerResponse.empty({
10
12
  status: 401,
11
13
  headers: error.challenge === void 0 ? {} : { "www-authenticate": error.challenge }
12
14
  })));
@@ -1 +1 @@
1
- {"version":3,"file":"websocketServer.js","names":["Channel.fromSocket"],"sources":["../../src/internal/websocketServer.ts"],"sourcesContent":["import { NodeHttpServer, NodeHttpServerRequest } from \"@effect/platform-node\"\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tOption,\n\tRedacted,\n\tScope,\n\tString,\n} from \"effect\"\nimport { HttpServerRequest, HttpServerResponse } from \"effect/http\"\nimport type { Socket } from \"effect/socket\"\nimport { TLSSocket } from \"node:tls\"\nimport { AuthenticationFailed, TransportError } from \"../Errors\"\nimport type { Accept, Handshake, Serving } from \"../Transport\"\nimport * as Channel from \"./socketChannel\"\nimport { path, protocol, payloadLimit } from \"./websocket\"\n\nconst rejection = (error: AuthenticationFailed) =>\n\tEffect.logWarning(\n\t\t\"Remote host authentication failed\",\n\t\t{\n\t\t\treason: error.reason,\n\t\t},\n\t\t...(error.cause === undefined ? [] : [error.cause]),\n\t).pipe(\n\t\tEffect.as(\n\t\t\tHttpServerResponse.empty({\n\t\t\t\tstatus: 401,\n\t\t\t\theaders:\n\t\t\t\t\terror.challenge === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { \"www-authenticate\": error.challenge },\n\t\t\t}),\n\t\t),\n\t)\n\nconst handshake: Effect.Effect<\n\tHandshake,\n\tnever,\n\tHttpServerRequest.HttpServerRequest\n> = Effect.gen(function* () {\n\tconst request = yield* HttpServerRequest.HttpServerRequest\n\tconst { socket } = NodeHttpServerRequest.toIncomingMessage(request)\n\t// Only a TLS-verified peer is certificate evidence; forwarded headers are not.\n\tconst peer =\n\t\tsocket instanceof TLSSocket && socket.authorized\n\t\t\t? Option.some(socket.getPeerCertificate())\n\t\t\t: Option.none()\n\treturn {\n\t\tauthorization: Option.map(\n\t\t\tOption.fromUndefinedOr(request.headers[\"authorization\"]),\n\t\t\tRedacted.make,\n\t\t),\n\t\tcertificate: Option.map(peer, (certificate) => ({\n\t\t\tder: certificate.raw,\n\t\t\tsubjectAltName: Option.fromUndefinedOr(certificate.subjectaltname),\n\t\t})),\n\t}\n})\n\nconst open = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\t// The lazily created ws server belongs here, so serving scopes close before ws.close waits.\n\tconst resources = yield* Effect.acquireRelease(Scope.make(), Scope.close)\n\tconst ready = yield* Deferred.make<void>()\n\tconst server = yield* NodeHttpServer.make(createServer, {\n\t\t...options,\n\t\tdisablePreemptiveShutdown: true,\n\t\twebsocket: {\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\thandleProtocols: (protocols) =>\n\t\t\t\tprotocols.has(protocol) ? protocol : false,\n\t\t},\n\t}).pipe(Scope.provide(resources))\n\treturn {\n\t\taddress: server.address,\n\t\tready: Deferred.await(ready),\n\t\trun: <A, E, R>(\n\t\t\taccept: Effect.Effect<\n\t\t\t\t(socket: Socket.Socket) => Effect.Effect<A, E, R>,\n\t\t\t\tAuthenticationFailed,\n\t\t\t\tHttpServerRequest.HttpServerRequest\n\t\t\t>,\n\t\t) =>\n\t\t\tserver\n\t\t\t\t.serve(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest\n\t\t\t\t\t\tif (request.url !== path)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 404 })\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tString.toLowerCase(request.headers[\"upgrade\"] ?? \"\") !==\n\t\t\t\t\t\t\t\t\"websocket\" ||\n\t\t\t\t\t\t\t!Array.some(\n\t\t\t\t\t\t\t\tString.split(\n\t\t\t\t\t\t\t\t\trequest.headers[\"sec-websocket-protocol\"] ?? \"\",\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\t(value) => String.trim(value) === protocol,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 400 })\n\t\t\t\t\t\tconst session = yield* Effect.result(accept)\n\t\t\t\t\t\tif (session._tag === \"Failure\")\n\t\t\t\t\t\t\treturn yield* rejection(session.failure)\n\t\t\t\t\t\t// Authentication finishes before upgrade; session work is owned by the request scope.\n\t\t\t\t\t\tyield* request.upgrade.pipe(\n\t\t\t\t\t\t\tEffect.flatMap(session.success),\n\t\t\t\t\t\t\tEffect.interruptible,\n\t\t\t\t\t\t\tEffect.scoped,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn HttpServerResponse.empty()\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.andThen(Deferred.succeed(ready, undefined)),\n\t\t\t\t\tEffect.andThen(Effect.never),\n\t\t\t\t),\n\t}\n})\n\nexport const bind = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\tconst server = yield* open(createServer, options)\n\treturn {\n\t\taddress: server.address,\n\t\tready: server.ready,\n\t\tserve: (accept: Accept) =>\n\t\t\tserver\n\t\t\t\t.run(\n\t\t\t\t\thandshake.pipe(\n\t\t\t\t\t\tEffect.flatMap(accept),\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(session) => (socket: Socket.Socket) =>\n\t\t\t\t\t\t\t\tChannel.fromSocket(socket).pipe(Effect.flatMap(session)),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t} satisfies Serving & { readonly address: typeof server.address }\n})\n"],"mappings":";;;;;;;;AAmBA,MAAM,aAAa,UAClB,OAAO,WACN,qCACA,EACC,QAAQ,MAAM,OACf,GACA,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,MAAM,KAAK,CAClD,CAAC,CAAC,KACD,OAAO,GACN,mBAAmB,MAAM;CACxB,QAAQ;CACR,SACC,MAAM,cAAc,KAAA,IACjB,CAAC,IACD,EAAE,oBAAoB,MAAM,UAAU;AAC3C,CAAC,CACF,CACD;AAED,MAAM,YAIF,OAAO,IAAI,aAAa;CAC3B,MAAM,UAAU,OAAO,kBAAkB;CACzC,MAAM,EAAE,WAAW,sBAAsB,kBAAkB,OAAO;CAElE,MAAM,OACL,kBAAkB,aAAa,OAAO,aACnC,OAAO,KAAK,OAAO,mBAAmB,CAAC,IACvC,OAAO,KAAK;CAChB,OAAO;EACN,eAAe,OAAO,IACrB,OAAO,gBAAgB,QAAQ,QAAQ,gBAAgB,GACvD,SAAS,IACV;EACA,aAAa,OAAO,IAAI,OAAO,iBAAiB;GAC/C,KAAK,YAAY;GACjB,gBAAgB,OAAO,gBAAgB,YAAY,cAAc;EAClE,EAAE;CACH;AACD,CAAC;AAED,MAAM,OAAO,OAAO,WAAW,WAC9B,cACA,SACC;CAED,MAAM,YAAY,OAAO,OAAO,eAAe,MAAM,KAAK,GAAG,MAAM,KAAK;CACxE,MAAM,QAAQ,OAAO,SAAS,KAAW;CACzC,MAAM,SAAS,OAAO,eAAe,KAAK,cAAc;EACvD,GAAG;EACH,2BAA2B;EAC3B,WAAW;GACV,mBAAmB;GACnB,YAAY;GACZ,kBAAkB,cACjB,UAAU,IAAA,iBAAY,IAAI,WAAW;EACvC;CACD,CAAC,CAAC,CAAC,KAAK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"file":"websocketServer.js","names":["Channel.fromSocket"],"sources":["../../src/internal/websocketServer.ts"],"sourcesContent":["import { NodeHttpServer, NodeHttpServerRequest } from \"@effect/platform-node\"\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tOption,\n\tRedacted,\n\tScope,\n\tString,\n} from \"effect\"\nimport { HttpServerRequest, HttpServerResponse } from \"effect/http\"\nimport type { Socket } from \"effect/socket\"\nimport { TLSSocket } from \"node:tls\"\nimport {\n\ttype AuthenticationFailed,\n\ttype AuthenticatorUnavailable,\n\tTransportError,\n} from \"../Errors\"\nimport type { Accept, Handshake, Serving } from \"../Transport\"\nimport * as Channel from \"./socketChannel\"\nimport { path, protocol, payloadLimit } from \"./websocket\"\n\nconst rejection = (error: AuthenticationFailed | AuthenticatorUnavailable) =>\n\terror._tag === \"AuthenticatorUnavailable\"\n\t\t? unavailable(error)\n\t\t: unauthorized(error)\n\n// The credential was not judged, so the client is told to retry rather than to replace it.\nconst unavailable = (error: AuthenticatorUnavailable) =>\n\tEffect.logError(\"Remote host authenticator is unavailable\", error.cause).pipe(\n\t\tEffect.as(HttpServerResponse.empty({ status: 503 })),\n\t)\n\nconst unauthorized = (error: AuthenticationFailed) =>\n\tEffect.logWarning(\n\t\t\"Remote host authentication failed\",\n\t\t{\n\t\t\treason: error.reason,\n\t\t},\n\t\t...(error.cause === undefined ? [] : [error.cause]),\n\t).pipe(\n\t\tEffect.as(\n\t\t\tHttpServerResponse.empty({\n\t\t\t\tstatus: 401,\n\t\t\t\theaders:\n\t\t\t\t\terror.challenge === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { \"www-authenticate\": error.challenge },\n\t\t\t}),\n\t\t),\n\t)\n\nconst handshake: Effect.Effect<\n\tHandshake,\n\tnever,\n\tHttpServerRequest.HttpServerRequest\n> = Effect.gen(function* () {\n\tconst request = yield* HttpServerRequest.HttpServerRequest\n\tconst { socket } = NodeHttpServerRequest.toIncomingMessage(request)\n\t// Only a TLS-verified peer is certificate evidence; forwarded headers are not.\n\tconst peer =\n\t\tsocket instanceof TLSSocket && socket.authorized\n\t\t\t? Option.some(socket.getPeerCertificate())\n\t\t\t: Option.none()\n\treturn {\n\t\tauthorization: Option.map(\n\t\t\tOption.fromUndefinedOr(request.headers[\"authorization\"]),\n\t\t\tRedacted.make,\n\t\t),\n\t\tcertificate: Option.map(peer, (certificate) => ({\n\t\t\tder: certificate.raw,\n\t\t\tsubjectAltName: Option.fromUndefinedOr(certificate.subjectaltname),\n\t\t})),\n\t}\n})\n\nconst open = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\t// The lazily created ws server belongs here, so serving scopes close before ws.close waits.\n\tconst resources = yield* Effect.acquireRelease(Scope.make(), Scope.close)\n\tconst ready = yield* Deferred.make<void>()\n\tconst server = yield* NodeHttpServer.make(createServer, {\n\t\t...options,\n\t\tdisablePreemptiveShutdown: true,\n\t\twebsocket: {\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\thandleProtocols: (protocols) =>\n\t\t\t\tprotocols.has(protocol) ? protocol : false,\n\t\t},\n\t}).pipe(Scope.provide(resources))\n\treturn {\n\t\taddress: server.address,\n\t\tready: Deferred.await(ready),\n\t\trun: <A, E, R>(\n\t\t\taccept: Effect.Effect<\n\t\t\t\t(socket: Socket.Socket) => Effect.Effect<A, E, R>,\n\t\t\t\tAuthenticationFailed | AuthenticatorUnavailable,\n\t\t\t\tHttpServerRequest.HttpServerRequest\n\t\t\t>,\n\t\t) =>\n\t\t\tserver\n\t\t\t\t.serve(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest\n\t\t\t\t\t\tif (request.url !== path)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 404 })\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tString.toLowerCase(request.headers[\"upgrade\"] ?? \"\") !==\n\t\t\t\t\t\t\t\t\"websocket\" ||\n\t\t\t\t\t\t\t!Array.some(\n\t\t\t\t\t\t\t\tString.split(\n\t\t\t\t\t\t\t\t\trequest.headers[\"sec-websocket-protocol\"] ?? \"\",\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\t(value) => String.trim(value) === protocol,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 400 })\n\t\t\t\t\t\tconst session = yield* Effect.result(accept)\n\t\t\t\t\t\tif (session._tag === \"Failure\")\n\t\t\t\t\t\t\treturn yield* rejection(session.failure)\n\t\t\t\t\t\t// Authentication finishes before upgrade; session work is owned by the request scope.\n\t\t\t\t\t\tyield* request.upgrade.pipe(\n\t\t\t\t\t\t\tEffect.flatMap(session.success),\n\t\t\t\t\t\t\tEffect.interruptible,\n\t\t\t\t\t\t\tEffect.scoped,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn HttpServerResponse.empty()\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.andThen(Deferred.succeed(ready, undefined)),\n\t\t\t\t\tEffect.andThen(Effect.never),\n\t\t\t\t),\n\t}\n})\n\nexport const bind = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\tconst server = yield* open(createServer, options)\n\treturn {\n\t\taddress: server.address,\n\t\tready: server.ready,\n\t\tserve: (accept: Accept) =>\n\t\t\tserver\n\t\t\t\t.run(\n\t\t\t\t\thandshake.pipe(\n\t\t\t\t\t\tEffect.flatMap(accept),\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(session) => (socket: Socket.Socket) =>\n\t\t\t\t\t\t\t\tChannel.fromSocket(socket).pipe(Effect.flatMap(session)),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t} satisfies Serving & { readonly address: typeof server.address }\n})\n"],"mappings":";;;;;;;;AAuBA,MAAM,aAAa,UAClB,MAAM,SAAS,6BACZ,YAAY,KAAK,IACjB,aAAa,KAAK;AAGtB,MAAM,eAAe,UACpB,OAAO,SAAS,4CAA4C,MAAM,KAAK,CAAC,CAAC,KACxE,OAAO,GAAG,mBAAmB,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC,CACpD;AAED,MAAM,gBAAgB,UACrB,OAAO,WACN,qCACA,EACC,QAAQ,MAAM,OACf,GACA,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,MAAM,KAAK,CAClD,CAAC,CAAC,KACD,OAAO,GACN,mBAAmB,MAAM;CACxB,QAAQ;CACR,SACC,MAAM,cAAc,KAAA,IACjB,CAAC,IACD,EAAE,oBAAoB,MAAM,UAAU;AAC3C,CAAC,CACF,CACD;AAED,MAAM,YAIF,OAAO,IAAI,aAAa;CAC3B,MAAM,UAAU,OAAO,kBAAkB;CACzC,MAAM,EAAE,WAAW,sBAAsB,kBAAkB,OAAO;CAElE,MAAM,OACL,kBAAkB,aAAa,OAAO,aACnC,OAAO,KAAK,OAAO,mBAAmB,CAAC,IACvC,OAAO,KAAK;CAChB,OAAO;EACN,eAAe,OAAO,IACrB,OAAO,gBAAgB,QAAQ,QAAQ,gBAAgB,GACvD,SAAS,IACV;EACA,aAAa,OAAO,IAAI,OAAO,iBAAiB;GAC/C,KAAK,YAAY;GACjB,gBAAgB,OAAO,gBAAgB,YAAY,cAAc;EAClE,EAAE;CACH;AACD,CAAC;AAED,MAAM,OAAO,OAAO,WAAW,WAC9B,cACA,SACC;CAED,MAAM,YAAY,OAAO,OAAO,eA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A,UAAU,KACT,OAAO,QAAQ,MAAM,GACrB,OAAO,KACL,aAAa,WACbA,WAAmB,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,OAAO,CAAC,CACzD,CACD,CACD,CAAC,CACA,KACA,OAAO,UAAU,UAChB,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;CACH;AACD,CAAC"}
@@ -1,6 +1,6 @@
1
- import { r as layer } from "../Graft-BsYq3F-J.js";
2
- import { n as run, r as platform, t as load } from "../childRuntime-DSqtFN9o.js";
3
- import { n as Bootstrap, t as make } from "../workerChannel-P82YdNjh.js";
1
+ import { r as layer } from "../Graft-B71CPA2Y.js";
2
+ import { n as run, r as platform, t as load } from "../childRuntime-Bm3iSg_N.js";
3
+ import { n as Bootstrap, t as make } from "../workerChannel-C8hhBJzA.js";
4
4
  import { Effect, Layer, Schema } from "effect";
5
5
  import { NodeRuntime } from "@effect/platform-node";
6
6
  import { parentPort, workerData } from "node:worker_threads";