effect 4.1.5 → 4.1.7

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 (441) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Config.d.ts +1 -1
  11. package/dist/Config.d.ts.map +1 -1
  12. package/dist/Config.js +5 -3
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts.map +1 -1
  15. package/dist/Context.js +79 -31
  16. package/dist/Context.js.map +1 -1
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +10 -9
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Effect.d.ts +139 -18
  21. package/dist/Effect.d.ts.map +1 -1
  22. package/dist/Effect.js +10 -2
  23. package/dist/Effect.js.map +1 -1
  24. package/dist/Equal.d.ts +4 -4
  25. package/dist/Equal.d.ts.map +1 -1
  26. package/dist/Equal.js +78 -66
  27. package/dist/Equal.js.map +1 -1
  28. package/dist/Formatter.js +4 -4
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Hash.d.ts.map +1 -1
  31. package/dist/Hash.js +34 -41
  32. package/dist/Hash.js.map +1 -1
  33. package/dist/LayerRef.d.ts +1 -1
  34. package/dist/LayerRef.d.ts.map +1 -1
  35. package/dist/LayerRef.js +3 -3
  36. package/dist/LayerRef.js.map +1 -1
  37. package/dist/Logger.d.ts +37 -13
  38. package/dist/Logger.d.ts.map +1 -1
  39. package/dist/Logger.js +39 -10
  40. package/dist/Logger.js.map +1 -1
  41. package/dist/Match.d.ts +23 -23
  42. package/dist/Match.d.ts.map +1 -1
  43. package/dist/Match.js.map +1 -1
  44. package/dist/Metric.d.ts.map +1 -1
  45. package/dist/Metric.js +3 -4
  46. package/dist/Metric.js.map +1 -1
  47. package/dist/Order.js +1 -1
  48. package/dist/Order.js.map +1 -1
  49. package/dist/Pool.d.ts.map +1 -1
  50. package/dist/Pool.js +49 -21
  51. package/dist/Pool.js.map +1 -1
  52. package/dist/Predicate.d.ts.map +1 -1
  53. package/dist/Predicate.js +2 -1
  54. package/dist/Predicate.js.map +1 -1
  55. package/dist/Scheduler.d.ts.map +1 -1
  56. package/dist/Scheduler.js +15 -9
  57. package/dist/Scheduler.js.map +1 -1
  58. package/dist/Schema.d.ts +41 -0
  59. package/dist/Schema.d.ts.map +1 -1
  60. package/dist/Schema.js +51 -390
  61. package/dist/Schema.js.map +1 -1
  62. package/dist/SchemaAST.d.ts +2 -2
  63. package/dist/SchemaAST.d.ts.map +1 -1
  64. package/dist/SchemaAST.js +199 -98
  65. package/dist/SchemaAST.js.map +1 -1
  66. package/dist/SchemaParser.d.ts.map +1 -1
  67. package/dist/SchemaParser.js +29 -50
  68. package/dist/SchemaParser.js.map +1 -1
  69. package/dist/ScopedCache.d.ts.map +1 -1
  70. package/dist/ScopedCache.js +6 -4
  71. package/dist/ScopedCache.js.map +1 -1
  72. package/dist/Stream.d.ts +128 -5
  73. package/dist/Stream.d.ts.map +1 -1
  74. package/dist/Stream.js +124 -29
  75. package/dist/Stream.js.map +1 -1
  76. package/dist/String.js +1 -1
  77. package/dist/String.js.map +1 -1
  78. package/dist/Tracer.d.ts +10 -0
  79. package/dist/Tracer.d.ts.map +1 -1
  80. package/dist/Tracer.js +3 -4
  81. package/dist/Tracer.js.map +1 -1
  82. package/dist/ai/McpClient.d.ts +68 -4
  83. package/dist/ai/McpClient.d.ts.map +1 -1
  84. package/dist/ai/McpClient.js +100 -17
  85. package/dist/ai/McpClient.js.map +1 -1
  86. package/dist/ai/McpClientError.d.ts +46 -4
  87. package/dist/ai/McpClientError.d.ts.map +1 -1
  88. package/dist/ai/McpClientError.js +38 -3
  89. package/dist/ai/McpClientError.js.map +1 -1
  90. package/dist/ai/McpServer.d.ts +158 -7
  91. package/dist/ai/McpServer.d.ts.map +1 -1
  92. package/dist/ai/McpServer.js +103 -49
  93. package/dist/ai/McpServer.js.map +1 -1
  94. package/dist/ai/Prompt.d.ts +3 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +17 -3
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Skill.d.ts +172 -0
  99. package/dist/ai/Skill.d.ts.map +1 -0
  100. package/dist/ai/Skill.js +209 -0
  101. package/dist/ai/Skill.js.map +1 -0
  102. package/dist/ai/index.d.ts +5 -0
  103. package/dist/ai/index.d.ts.map +1 -1
  104. package/dist/ai/index.js +5 -0
  105. package/dist/ai/index.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
  107. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
  109. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  110. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
  111. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  112. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
  113. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  114. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  116. package/dist/ai/internal/mcpProtocol.js +11 -0
  117. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  118. package/dist/ai/internal/mcpRuntime.js +29 -17
  119. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
  121. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
  123. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
  125. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  126. package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
  127. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  128. package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
  129. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  130. package/dist/cluster/ClusterCron.d.ts +5 -20
  131. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  132. package/dist/cluster/ClusterCron.js +16 -4
  133. package/dist/cluster/ClusterCron.js.map +1 -1
  134. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  135. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  136. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  137. package/dist/cluster/MessageStorage.d.ts +56 -0
  138. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  139. package/dist/cluster/MessageStorage.js +18 -2
  140. package/dist/cluster/MessageStorage.js.map +1 -1
  141. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  142. package/dist/cluster/SqlMessageStorage.js +48 -23
  143. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  144. package/dist/cluster/internal/entityActivation.js +2 -0
  145. package/dist/cluster/internal/entityActivation.js.map +1 -1
  146. package/dist/cluster/internal/entityManager.js +8 -5
  147. package/dist/cluster/internal/entityManager.js.map +1 -1
  148. package/dist/encoding/Base64.js +5 -1
  149. package/dist/encoding/Base64.js.map +1 -1
  150. package/dist/encoding/Base64Url.d.ts.map +1 -1
  151. package/dist/encoding/Base64Url.js +6 -1
  152. package/dist/encoding/Base64Url.js.map +1 -1
  153. package/dist/encoding/Hex.js +7 -5
  154. package/dist/encoding/Hex.js.map +1 -1
  155. package/dist/encoding/Xml.d.ts +38 -9
  156. package/dist/encoding/Xml.d.ts.map +1 -1
  157. package/dist/encoding/Xml.js +63 -31
  158. package/dist/encoding/Xml.js.map +1 -1
  159. package/dist/http/FetchHttpClient.d.ts +2 -1
  160. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  161. package/dist/http/FetchHttpClient.js +14 -10
  162. package/dist/http/FetchHttpClient.js.map +1 -1
  163. package/dist/http/Headers.d.ts +201 -3
  164. package/dist/http/Headers.d.ts.map +1 -1
  165. package/dist/http/Headers.js +205 -3
  166. package/dist/http/Headers.js.map +1 -1
  167. package/dist/http/HttpClient.d.ts.map +1 -1
  168. package/dist/http/HttpClient.js +11 -7
  169. package/dist/http/HttpClient.js.map +1 -1
  170. package/dist/http/HttpClientError.d.ts +1 -0
  171. package/dist/http/HttpClientError.d.ts.map +1 -1
  172. package/dist/http/HttpClientError.js +32 -9
  173. package/dist/http/HttpClientError.js.map +1 -1
  174. package/dist/http/HttpClientRequest.d.ts +46 -0
  175. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  176. package/dist/http/HttpClientRequest.js +15 -0
  177. package/dist/http/HttpClientRequest.js.map +1 -1
  178. package/dist/http/HttpClientResponse.d.ts +132 -0
  179. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  180. package/dist/http/HttpClientResponse.js +83 -0
  181. package/dist/http/HttpClientResponse.js.map +1 -1
  182. package/dist/http/HttpEffect.d.ts.map +1 -1
  183. package/dist/http/HttpEffect.js +31 -2
  184. package/dist/http/HttpEffect.js.map +1 -1
  185. package/dist/http/HttpMiddleware.js +1 -1
  186. package/dist/http/HttpMiddleware.js.map +1 -1
  187. package/dist/http/HttpServerError.d.ts +1 -1
  188. package/dist/http/HttpServerError.js +1 -1
  189. package/dist/http/HttpServerResponse.d.ts +118 -0
  190. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  191. package/dist/http/HttpServerResponse.js +43 -0
  192. package/dist/http/HttpServerResponse.js.map +1 -1
  193. package/dist/http/Multipart.d.ts.map +1 -1
  194. package/dist/http/Multipart.js +0 -5
  195. package/dist/http/Multipart.js.map +1 -1
  196. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  197. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  198. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  199. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  200. package/dist/http/internal/clientPath.d.ts +2 -0
  201. package/dist/http/internal/clientPath.d.ts.map +1 -0
  202. package/dist/http/internal/clientPath.js +24 -0
  203. package/dist/http/internal/clientPath.js.map +1 -0
  204. package/dist/http/internal/redactedPath.js +2 -0
  205. package/dist/http/internal/redactedPath.js.map +1 -1
  206. package/dist/http/internal/tracing.js +5 -3
  207. package/dist/http/internal/tracing.js.map +1 -1
  208. package/dist/http-api/HttpApi.d.ts +2 -2
  209. package/dist/http-api/HttpApi.d.ts.map +1 -1
  210. package/dist/http-api/HttpApi.js +30 -7
  211. package/dist/http-api/HttpApi.js.map +1 -1
  212. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  213. package/dist/http-api/HttpApiBuilder.js +5 -2
  214. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  215. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  216. package/dist/http-api/HttpApiClient.js +23 -6
  217. package/dist/http-api/HttpApiClient.js.map +1 -1
  218. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  219. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  220. package/dist/http-api/internal/redactedKeys.js +37 -0
  221. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  222. package/dist/internal/base64.js +34 -2
  223. package/dist/internal/base64.js.map +1 -1
  224. package/dist/internal/core.js +60 -43
  225. package/dist/internal/core.js.map +1 -1
  226. package/dist/internal/dateTime.js +35 -17
  227. package/dist/internal/dateTime.js.map +1 -1
  228. package/dist/internal/effect.js +60 -52
  229. package/dist/internal/effect.js.map +1 -1
  230. package/dist/internal/equal.js +44 -13
  231. package/dist/internal/equal.js.map +1 -1
  232. package/dist/internal/fiberCachedKeys.d.ts +2 -0
  233. package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
  234. package/dist/internal/fiberCachedKeys.js +48 -0
  235. package/dist/internal/fiberCachedKeys.js.map +1 -0
  236. package/dist/internal/hashMap.js +1 -1
  237. package/dist/internal/hashMap.js.map +1 -1
  238. package/dist/internal/matcher.js +17 -17
  239. package/dist/internal/matcher.js.map +1 -1
  240. package/dist/internal/predicate.d.ts +2 -0
  241. package/dist/internal/predicate.d.ts.map +1 -0
  242. package/dist/internal/predicate.js +10 -0
  243. package/dist/internal/predicate.js.map +1 -0
  244. package/dist/internal/references.js +8 -11
  245. package/dist/internal/references.js.map +1 -1
  246. package/dist/internal/schema/schemaCodegen.js +3 -2
  247. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  248. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  249. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  250. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  251. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  252. package/dist/internal/schema/toEquivalence.js +3 -4
  253. package/dist/internal/schema/toEquivalence.js.map +1 -1
  254. package/dist/internal/version.js +1 -1
  255. package/dist/jose/JoseError.d.ts +51 -1
  256. package/dist/jose/JoseError.d.ts.map +1 -1
  257. package/dist/jose/JoseError.js +25 -18
  258. package/dist/jose/JoseError.js.map +1 -1
  259. package/dist/jose/internal/compact.js +10 -5
  260. package/dist/jose/internal/compact.js.map +1 -1
  261. package/dist/observability/Otlp.d.ts +19 -0
  262. package/dist/observability/Otlp.d.ts.map +1 -1
  263. package/dist/observability/Otlp.js +10 -0
  264. package/dist/observability/Otlp.js.map +1 -1
  265. package/dist/observability/OtlpExporter.d.ts +49 -13
  266. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  267. package/dist/observability/OtlpExporter.js +135 -54
  268. package/dist/observability/OtlpExporter.js.map +1 -1
  269. package/dist/observability/OtlpLogger.d.ts +14 -0
  270. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  271. package/dist/observability/OtlpLogger.js +10 -2
  272. package/dist/observability/OtlpLogger.js.map +1 -1
  273. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  274. package/dist/observability/OtlpMetrics.js +2 -0
  275. package/dist/observability/OtlpMetrics.js.map +1 -1
  276. package/dist/observability/OtlpTracer.d.ts +14 -0
  277. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  278. package/dist/observability/OtlpTracer.js +10 -2
  279. package/dist/observability/OtlpTracer.js.map +1 -1
  280. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  281. package/dist/persistence/KeyValueStore.js +6 -4
  282. package/dist/persistence/KeyValueStore.js.map +1 -1
  283. package/dist/reactivity/Atom.d.ts.map +1 -1
  284. package/dist/reactivity/Atom.js +10 -9
  285. package/dist/reactivity/Atom.js.map +1 -1
  286. package/dist/rpc/RpcClient.d.ts.map +1 -1
  287. package/dist/rpc/RpcClient.js +32 -1
  288. package/dist/rpc/RpcClient.js.map +1 -1
  289. package/dist/rpc/RpcGroup.d.ts +1 -1
  290. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  291. package/dist/rpc/RpcGroup.js +4 -0
  292. package/dist/rpc/RpcGroup.js.map +1 -1
  293. package/dist/sql/Migrator.d.ts.map +1 -1
  294. package/dist/sql/Migrator.js +2 -5
  295. package/dist/sql/Migrator.js.map +1 -1
  296. package/dist/sql/SqlClient.d.ts.map +1 -1
  297. package/dist/sql/SqlClient.js +5 -1
  298. package/dist/sql/SqlClient.js.map +1 -1
  299. package/dist/sql/Statement.d.ts +23 -0
  300. package/dist/sql/Statement.d.ts.map +1 -1
  301. package/dist/sql/Statement.js +30 -5
  302. package/dist/sql/Statement.js.map +1 -1
  303. package/dist/workers/Worker.d.ts +21 -0
  304. package/dist/workers/Worker.d.ts.map +1 -1
  305. package/dist/workers/Worker.js +23 -0
  306. package/dist/workers/Worker.js.map +1 -1
  307. package/dist/workflow/Activity.d.ts +18 -0
  308. package/dist/workflow/Activity.d.ts.map +1 -1
  309. package/dist/workflow/Activity.js +13 -4
  310. package/dist/workflow/Activity.js.map +1 -1
  311. package/dist/workflow/Workflow.d.ts +10 -9
  312. package/dist/workflow/Workflow.d.ts.map +1 -1
  313. package/dist/workflow/Workflow.js +33 -22
  314. package/dist/workflow/Workflow.js.map +1 -1
  315. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  316. package/dist/workflow/WorkflowEngine.js +26 -12
  317. package/dist/workflow/WorkflowEngine.js.map +1 -1
  318. package/dist/workflow/internal/retry.d.ts +2 -0
  319. package/dist/workflow/internal/retry.d.ts.map +1 -0
  320. package/dist/workflow/internal/retry.js +11 -0
  321. package/dist/workflow/internal/retry.js.map +1 -0
  322. package/dist/workflow/internal/scope.d.ts +2 -0
  323. package/dist/workflow/internal/scope.d.ts.map +1 -0
  324. package/dist/workflow/internal/scope.js +26 -0
  325. package/dist/workflow/internal/scope.js.map +1 -0
  326. package/package.json +3 -3
  327. package/src/Channel.ts +105 -8
  328. package/src/Codegen.ts +7 -2
  329. package/src/Config.ts +6 -3
  330. package/src/Context.ts +108 -50
  331. package/src/Cron.ts +11 -10
  332. package/src/Effect.ts +224 -48
  333. package/src/Equal.ts +93 -80
  334. package/src/Formatter.ts +4 -4
  335. package/src/Hash.ts +49 -48
  336. package/src/LayerRef.ts +6 -4
  337. package/src/Logger.ts +68 -25
  338. package/src/Match.ts +78 -50
  339. package/src/Metric.ts +4 -4
  340. package/src/Order.ts +1 -1
  341. package/src/Pool.ts +62 -33
  342. package/src/Predicate.ts +2 -5
  343. package/src/Scheduler.ts +27 -10
  344. package/src/Schema.ts +79 -296
  345. package/src/SchemaAST.ts +231 -157
  346. package/src/SchemaParser.ts +40 -57
  347. package/src/ScopedCache.ts +6 -4
  348. package/src/Stream.ts +167 -33
  349. package/src/String.ts +1 -1
  350. package/src/Tracer.ts +11 -2
  351. package/src/ai/McpClient.ts +157 -15
  352. package/src/ai/McpClientError.ts +55 -4
  353. package/src/ai/McpServer.ts +318 -91
  354. package/src/ai/Prompt.ts +20 -3
  355. package/src/ai/Skill.ts +236 -0
  356. package/src/ai/index.ts +6 -0
  357. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
  358. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
  359. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
  360. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
  361. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
  362. package/src/ai/internal/mcpProtocol.ts +15 -0
  363. package/src/ai/internal/mcpRuntime.ts +36 -13
  364. package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
  365. package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
  366. package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
  367. package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
  368. package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
  369. package/src/cluster/ClusterCron.ts +31 -20
  370. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  371. package/src/cluster/MessageStorage.ts +51 -2
  372. package/src/cluster/SqlMessageStorage.ts +88 -36
  373. package/src/cluster/internal/entityActivation.ts +6 -0
  374. package/src/cluster/internal/entityManager.ts +8 -4
  375. package/src/encoding/Base64.ts +5 -1
  376. package/src/encoding/Base64Url.ts +6 -1
  377. package/src/encoding/Hex.ts +5 -5
  378. package/src/encoding/Xml.ts +96 -26
  379. package/src/http/FetchHttpClient.ts +8 -5
  380. package/src/http/Headers.ts +309 -3
  381. package/src/http/HttpClient.ts +19 -7
  382. package/src/http/HttpClientError.ts +42 -9
  383. package/src/http/HttpClientRequest.ts +51 -0
  384. package/src/http/HttpClientResponse.ts +156 -0
  385. package/src/http/HttpEffect.ts +23 -3
  386. package/src/http/HttpMiddleware.ts +1 -1
  387. package/src/http/HttpServerError.ts +1 -1
  388. package/src/http/HttpServerResponse.ts +126 -0
  389. package/src/http/Multipart.ts +0 -5
  390. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  391. package/src/http/internal/clientPath.ts +39 -0
  392. package/src/http/internal/redactedPath.ts +4 -0
  393. package/src/http/internal/tracing.ts +6 -3
  394. package/src/http-api/HttpApi.ts +29 -8
  395. package/src/http-api/HttpApiBuilder.ts +7 -2
  396. package/src/http-api/HttpApiClient.ts +30 -7
  397. package/src/http-api/internal/redactedKeys.ts +40 -0
  398. package/src/internal/base64.ts +57 -2
  399. package/src/internal/core.ts +80 -44
  400. package/src/internal/dateTime.ts +43 -24
  401. package/src/internal/effect.ts +115 -157
  402. package/src/internal/equal.ts +73 -17
  403. package/src/internal/fiberCachedKeys.ts +81 -0
  404. package/src/internal/hashMap.ts +1 -1
  405. package/src/internal/matcher.ts +34 -113
  406. package/src/internal/predicate.ts +10 -0
  407. package/src/internal/references.ts +21 -14
  408. package/src/internal/schema/schemaCodegen.ts +5 -4
  409. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  410. package/src/internal/schema/toEquivalence.ts +3 -5
  411. package/src/internal/version.ts +1 -1
  412. package/src/jose/JoseError.ts +34 -0
  413. package/src/jose/internal/compact.ts +14 -5
  414. package/src/observability/Otlp.ts +29 -0
  415. package/src/observability/OtlpExporter.ts +206 -75
  416. package/src/observability/OtlpLogger.ts +24 -2
  417. package/src/observability/OtlpMetrics.ts +2 -0
  418. package/src/observability/OtlpTracer.ts +24 -3
  419. package/src/persistence/KeyValueStore.ts +17 -14
  420. package/src/reactivity/Atom.ts +12 -18
  421. package/src/rpc/RpcClient.ts +26 -1
  422. package/src/rpc/RpcGroup.ts +4 -1
  423. package/src/sql/Migrator.ts +2 -11
  424. package/src/sql/SqlClient.ts +14 -8
  425. package/src/sql/Statement.ts +48 -12
  426. package/src/workers/Worker.ts +25 -0
  427. package/src/workflow/Activity.ts +28 -4
  428. package/src/workflow/Workflow.ts +68 -44
  429. package/src/workflow/WorkflowEngine.ts +38 -15
  430. package/src/workflow/internal/retry.ts +12 -0
  431. package/src/workflow/internal/scope.ts +36 -0
  432. package/dist/internal/hash.d.ts +0 -2
  433. package/dist/internal/hash.d.ts.map +0 -1
  434. package/dist/internal/hash.js +0 -11
  435. package/dist/internal/hash.js.map +0 -1
  436. package/dist/internal/metric.d.ts +0 -2
  437. package/dist/internal/metric.d.ts.map +0 -1
  438. package/dist/internal/metric.js +0 -3
  439. package/dist/internal/metric.js.map +0 -1
  440. package/src/internal/hash.ts +0 -11
  441. package/src/internal/metric.ts +0 -2
@@ -538,14 +538,6 @@ export const GetPromptResult = Schema.Struct({
538
538
  messages: Schema.Array(PromptMessage)
539
539
  })
540
540
 
541
- /**
542
- * @internal
543
- */
544
- export const ListToolsResult = Schema.Struct({
545
- ...Previous.PaginatedResult.fields,
546
- tools: Schema.Array(Tool)
547
- })
548
-
549
541
  /**
550
542
  * @internal
551
543
  */
@@ -590,7 +582,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
590
582
  * @internal
591
583
  */
592
584
  export class ListTools extends Rpc.make("tools/list", {
593
- success: ListToolsResult,
585
+ success: Previous.ListToolsResult,
594
586
  error: Previous.McpError,
595
587
  payload: Schema.UndefinedOr(Previous.PaginatedRequest)
596
588
  }) {}
@@ -627,14 +627,12 @@ export class GetPrompt extends Rpc.make("prompts/get", {
627
627
  /**
628
628
  * @internal
629
629
  */
630
- export const ListToolsResult = Schema.StructWithRest(
631
- Schema.Struct({
632
- ...PaginatedResult,
633
- ...CacheableResult,
634
- tools: Schema.Array(Tool)
635
- }),
636
- [UnknownObject]
637
- )
630
+ export const ListToolsResult = Schema.Struct({
631
+ ...PaginatedResult,
632
+ ...CacheableResult,
633
+ // Already JSON-encoded by the protocol adapter; a rest signature would re-walk them.
634
+ tools: Schema.Any
635
+ })
638
636
  /**
639
637
  * @internal
640
638
  */
@@ -15,12 +15,13 @@
15
15
  * @stability unstable
16
16
  * @since 4.0.0
17
17
  */
18
+ import * as Cause from "../Cause.ts"
18
19
  import * as Context from "../Context.ts"
19
20
  import * as Cron from "../Cron.ts"
20
21
  import * as DateTime from "../DateTime.ts"
21
22
  import * as Duration from "../Duration.ts"
22
23
  import * as Effect from "../Effect.ts"
23
- import * as Exit from "../Exit.ts"
24
+ import * as Fiber from "../Fiber.ts"
24
25
  import * as Layer from "../Layer.ts"
25
26
  import * as PrimaryKey from "../PrimaryKey.ts"
26
27
  import * as Rpc from "../rpc/Rpc.ts"
@@ -79,6 +80,10 @@ export class CronSchedule extends Context.Service<CronSchedule, {
79
80
  * scheduling step and optional controls for shard group, next-run calculation,
80
81
  * and skipping stale scheduled runs.
81
82
  *
83
+ * A run that fails or dies is logged and not retried, and the next run is
84
+ * scheduled as usual. To retry typed failures, apply `Effect.retry` inside
85
+ * `execute` with your own stopping policy.
86
+ *
82
87
  * @stability unstable
83
88
  * @category constructors
84
89
  * @since 4.0.0
@@ -103,9 +108,7 @@ export const make = <E, R>(options: {
103
108
  * current time.
104
109
  *
105
110
  * When enabled, all runs are processed one at a time by a single entity, so
106
- * missed runs are caught up in order without overlapping. A run that fails
107
- * is retried in place and blocks later runs until it succeeds or is older
108
- * than `skipIfOlderThan`.
111
+ * missed runs are caught up in order without overlapping.
109
112
  */
110
113
  readonly calculateNextRunFromPrevious?: boolean | undefined
111
114
 
@@ -168,16 +171,23 @@ export const make = <E, R>(options: {
168
171
  { shardGroup: options.shardGroup }
169
172
  )
170
173
 
171
- const execute = Effect.fnUntraced(function*(dateTime: DateTime.Utc) {
172
- const now = yield* DateTime.now
173
- if (DateTime.isLessThan(dateTime, DateTime.subtractDuration(now, cronSchedule.skipIfOlderThan))) {
174
- return
175
- }
176
- return yield* Effect.provideContext(
177
- options.execute,
178
- Context.add(scheduleContext, CurrentScheduledTime, dateTime)
179
- )
180
- }, Effect.orDie)
174
+ const execute = Effect.fnUntraced(
175
+ function*(dateTime: DateTime.Utc) {
176
+ const now = yield* DateTime.now
177
+ if (DateTime.isLessThan(dateTime, DateTime.subtractDuration(now, cronSchedule.skipIfOlderThan))) {
178
+ return
179
+ }
180
+ // the run gets its own fiber and scope, so its child fibers stop and its
181
+ // finalizers see its exit before the next run is scheduled
182
+ const fiber = yield* Effect.forkChild(
183
+ Effect.provideContext(options.execute, Context.add(scheduleContext, CurrentScheduledTime, dateTime)),
184
+ { uninterruptible: "inherit" }
185
+ )
186
+ return yield* Fiber.join(fiber).pipe(Effect.onInterrupt(() => Fiber.interrupt(fiber)))
187
+ },
188
+ Effect.scoped,
189
+ Effect.orDie
190
+ )
181
191
 
182
192
  const EntityLayer = CronEntity.toLayer(Effect.gen(function*() {
183
193
  const address = yield* Entity.CurrentAddress
@@ -193,12 +203,13 @@ export const make = <E, R>(options: {
193
203
  }
194
204
  processedRun = true
195
205
  return Effect.onExitPrimitive(
196
- execute(dateTime),
197
- (exit) =>
198
- Effect.andThen(
199
- Exit.isFailure(exit) ? Effect.logWarning(exit.cause) : Effect.void,
200
- fromPrevious ? schedule(nextRun(dateTime)) : Effect.flatMap(DateTime.now, (now) => schedule(nextRun(now)))
201
- ),
206
+ execute(dateTime).pipe(
207
+ Effect.tapCause(Effect.logWarning),
208
+ // interrupted runs are left for the entity manager to replay
209
+ Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), () => Effect.void)
210
+ ),
211
+ () =>
212
+ fromPrevious ? schedule(nextRun(dateTime)) : Effect.flatMap(DateTime.now, (now) => schedule(nextRun(now))),
202
213
  true
203
214
  ).pipe(
204
215
  Effect.annotateLogs({
@@ -16,6 +16,7 @@ import * as Effect from "../Effect.ts"
16
16
  import * as Exit from "../Exit.ts"
17
17
  import * as Fiber from "../Fiber.ts"
18
18
  import * as Headers from "../http/Headers.ts"
19
+ import * as Latch from "../Latch.ts"
19
20
  import * as Layer from "../Layer.ts"
20
21
  import * as Option from "../Option.ts"
21
22
  import * as PrimaryKey from "../PrimaryKey.ts"
@@ -30,6 +31,8 @@ import * as Semaphore from "../Semaphore.ts"
30
31
  import * as Activity from "../workflow/Activity.ts"
31
32
  import * as DurableClock from "../workflow/DurableClock.ts"
32
33
  import * as DurableDeferred from "../workflow/DurableDeferred.ts"
34
+ import { RetryingExecution } from "../workflow/internal/retry.ts"
35
+ import { markScopeAbandoned, reuseOrForkScope } from "../workflow/internal/scope.ts"
33
36
  import * as Workflow from "../workflow/Workflow.ts"
34
37
  import * as WorkflowEngine from "../workflow/WorkflowEngine.ts"
35
38
  import * as ClusterSchema from "./ClusterSchema.ts"
@@ -40,7 +43,7 @@ import * as EntityId from "./EntityId.ts"
40
43
  import * as EntityType from "./EntityType.ts"
41
44
  import * as Envelope from "./Envelope.ts"
42
45
  import * as ClusterAbandon from "./internal/clusterAbandon.ts"
43
- import { CurrentActivationScope } from "./internal/entityActivation.ts"
46
+ import { CurrentActivationScope, CurrentRetirementLatch } from "./internal/entityActivation.ts"
44
47
  import * as Message from "./Message.ts"
45
48
  import { MessageStorage } from "./MessageStorage.ts"
46
49
  import type { WithExitEncoded } from "./Reply.ts"
@@ -94,6 +97,7 @@ export const make = Effect.gen(function*() {
94
97
  Schema.declare<Workflow.Result<any, any>>
95
98
  >
96
99
  | typeof ResumeRpc
100
+ | typeof ParentRpc
97
101
  >
98
102
  >()
99
103
  const partialEntities = new Map<
@@ -106,7 +110,6 @@ export const make = Effect.gen(function*() {
106
110
  Schema.Struct<{ name: typeof Schema.String; attempt: typeof Schema.Int }>,
107
111
  Schema.declare<Workflow.Result<any, any>>
108
112
  >
109
- | typeof ResumeRpc
110
113
  >
111
114
  >()
112
115
  const ensureEntity = (workflow: Workflow.Any) => {
@@ -142,9 +145,8 @@ export const make = Effect.gen(function*() {
142
145
  Effect.suspend(() => {
143
146
  const scope = state.scope
144
147
  if (abandoned) {
145
- for (const instance of state.instances) instance.abandoned = true
148
+ markScopeAbandoned(scope)
146
149
  }
147
- state.instances.clear()
148
150
  state.scope = Scope.makeUnsafe()
149
151
  return Scope.close(scope, Exit.void)
150
152
  })
@@ -166,21 +168,21 @@ export const make = Effect.gen(function*() {
166
168
  }),
167
169
  idleTimeToLive: "5 minutes"
168
170
  })
169
- const entityAddressFor = (options: {
170
- readonly workflow: Workflow.Any
171
- readonly entityType: string
172
- readonly executionId: string
173
- }) => {
174
- const shardGroup = Context.get(options.workflow.annotations, ClusterSchema.ShardGroup)(
175
- options.executionId as EntityId.EntityId
176
- )
177
- const entityId = EntityId.make(options.executionId)
171
+ const shardGroupFor = (workflow: Workflow.Any, executionId: string) =>
172
+ Context.get(workflow.annotations, ClusterSchema.ShardGroup)(executionId as EntityId.EntityId)
173
+ const entityAddress = (entityType: string, executionId: string, shardGroup: string) => {
174
+ const entityId = EntityId.make(executionId)
178
175
  return EntityAddress.make({
179
- entityType: EntityType.make(options.entityType),
176
+ entityType: EntityType.make(entityType),
180
177
  entityId,
181
178
  shardId: sharding.getShardId(entityId, shardGroup)
182
179
  })
183
180
  }
181
+ const entityAddressFor = (options: {
182
+ readonly workflow: Workflow.Any
183
+ readonly entityType: string
184
+ readonly executionId: string
185
+ }) => entityAddress(options.entityType, options.executionId, shardGroupFor(options.workflow, options.executionId))
184
186
 
185
187
  const sendDiscard = Effect.fnUntraced(function*(options: {
186
188
  readonly rpc: Rpc.AnyWithProps
@@ -249,6 +251,9 @@ export const make = Effect.gen(function*() {
249
251
  return yield* replyForRequestId(requestId.value)
250
252
  })
251
253
 
254
+ const runReply = (workflow: Workflow.Any, executionId: string) =>
255
+ requestReply({ workflow, entityType: `Workflow/${workflow._tag}`, executionId, tag: "run", id: "" })
256
+
252
257
  const resetActivityAttempt = Effect.fnUntraced(
253
258
  function*(options: {
254
259
  readonly workflow: Workflow.Any
@@ -281,27 +286,11 @@ export const make = Effect.gen(function*() {
281
286
  readonly workflow: Workflow.Any
282
287
  readonly executionId: string
283
288
  }) {
284
- const shardGroup = Context.get(options.workflow.annotations, ClusterSchema.ShardGroup)(
285
- options.executionId as EntityId.EntityId
286
- )
287
- const entityId = EntityId.make(options.executionId)
288
- const shardId = sharding.getShardId(entityId, shardGroup)
289
- const clockAddress = EntityAddress.make({
290
- entityType: ClockEntity.type,
291
- entityId,
292
- shardId
293
- })
294
- yield* storage.clearAddress(clockAddress)
289
+ yield* storage.clearAddress(entityAddressFor({ ...options, entityType: ClockEntity.type }))
295
290
  })
296
291
 
297
292
  const resume = Effect.fnUntraced(function*(workflow: Workflow.Any, executionId: string, mode: WakeMode) {
298
- const maybeReply = yield* requestReply({
299
- workflow,
300
- entityType: `Workflow/${workflow._tag}`,
301
- executionId,
302
- tag: "run",
303
- id: ""
304
- })
293
+ const maybeReply = yield* runReply(workflow, executionId)
305
294
 
306
295
  const maybeSuspended = Option.filter(maybeReply, isSuspendedReply)
307
296
 
@@ -328,25 +317,30 @@ export const make = Effect.gen(function*() {
328
317
  pending.results.has(InterruptSignal.name)
329
318
  })
330
319
 
331
- const sendResumeParent = Effect.fnUntraced(function*(options: {
332
- readonly workflowName: string
333
- readonly executionId: string
334
- }, childExecutionId: string) {
335
- const requestId = yield* requestIdFor({
336
- workflow: workflows.get(options.workflowName)!,
337
- entityType: `Workflow/${options.workflowName}`,
338
- executionId: options.executionId,
320
+ const sendResumeParent = Effect.fnUntraced(function*(parent: ParentRef, childExecutionId: string) {
321
+ // Parents saved before `shardGroup` existed, or in the default group, omit it.
322
+ const workflow = workflows.get(parent.workflowName)
323
+ const address = entityAddress(
324
+ `Workflow/${parent.workflowName}`,
325
+ parent.executionId,
326
+ parent.shardGroup ?? (workflow ? shardGroupFor(workflow, parent.executionId) : "default")
327
+ )
328
+ const requestId = yield* storage.requestIdForPrimaryKey({
329
+ address,
339
330
  tag: "resume",
340
331
  id: childExecutionId
341
332
  })
342
333
  if (Option.isNone(requestId)) {
343
- const client = (yield* RcMap.get(clientsPartial, options.workflowName))(options.executionId)
344
- return yield* client.resume({ childExecutionId }, { discard: true })
334
+ return yield* sendDiscard({
335
+ rpc: ResumeRpc,
336
+ address,
337
+ payload: { childExecutionId }
338
+ })
345
339
  }
346
340
  const reply = yield* replyForRequestId(requestId.value)
347
341
  if (Option.isNone(reply)) return
348
342
  yield* sharding.reset(requestId.value, { expectedReplyId: Snowflake.Snowflake(reply.value.id) })
349
- }, Effect.scoped)
343
+ })
350
344
 
351
345
  // Subscribe to the run's next reply before reading storage, so a reply
352
346
  // cannot fall between the read and the subscription. Returns `true` when the
@@ -421,11 +415,7 @@ export const make = Effect.gen(function*() {
421
415
  }
422
416
  const reply = yield* replyForRequestId(requestId.value)
423
417
 
424
- const nonSuspendedReply = Option.filter(
425
- reply,
426
- (reply) => !isSuspendedReply(reply)
427
- )
428
- if (Option.isSome(nonSuspendedReply)) {
418
+ if (isRunSettled(reply)) {
429
419
  return Option.none()
430
420
  }
431
421
 
@@ -471,12 +461,15 @@ export const make = Effect.gen(function*() {
471
461
  (decoded.exit._tag === "Success" ? decoded.exit.value : decoded.exit) as Exit.Exit<unknown, unknown>
472
462
  )
473
463
  }
464
+ const retired = Option.getOrUndefined(yield* Effect.serviceOption(CurrentRetirementLatch))
474
465
  pending = {
475
466
  workflowName: workflow._tag,
476
467
  executionId,
477
468
  results,
478
- instances: new Set(),
479
- scope: Scope.makeUnsafe()
469
+ scope: Scope.makeUnsafe(),
470
+ retired,
471
+ idle: Latch.makeUnsafe(true),
472
+ executing: 0
480
473
  }
481
474
  yield* Scope.addFinalizer(activation, closeRuns(pending, true))
482
475
  pendingByActivation.set(activation, pending)
@@ -488,6 +481,9 @@ export const make = Effect.gen(function*() {
488
481
  readonly instance: WorkflowEngine.WorkflowInstance["Service"]
489
482
  // Activity awaits must wake the run after suspension without preempting it.
490
483
  readonly activityAwaits: Map<string, number>
484
+ // Set once the exiting run starts listing its parents, so a later
485
+ // `parent` registration waits for the reply and wakes its own parent.
486
+ completing: boolean
491
487
  } | undefined
492
488
  // Concurrent automatic wakes share one wait for the current run to
493
489
  // publish its reply. Explicit wakes cannot be dropped, because an
@@ -509,17 +505,30 @@ export const make = Effect.gen(function*() {
509
505
  )
510
506
  )
511
507
  )
508
+ // An asynchronous reply releases the RPC concurrency permit while
509
+ // the effect waits; the pending request still occupies mailbox capacity.
510
+ // The activation owns the fiber so it survives handler rebuilds,
511
+ // but activation shutdown still interrupts it for durable redelivery.
512
+ const forkReply = <A>(effect: Effect.Effect<A>) => {
513
+ const reply = Deferred.makeUnsafe<A>()
514
+ return effect.pipe(
515
+ Deferred.into(reply),
516
+ Effect.forkIn(activation, { startImmediately: true }),
517
+ Effect.as(reply)
518
+ )
519
+ }
512
520
  return {
513
521
  run: (request: Entity.Request<any>) => {
514
- // Each run gets a fresh scope under the activation's parent, so
515
- // replays rebuild compensations while suspended runs keep theirs.
522
+ // A superseded instance retained by a finalizer no longer needs its wait sets.
523
+ currentRun?.instance.awaitedDeferreds.clear()
524
+ currentRun?.instance.completedDeferreds.clear()
516
525
  const instance = WorkflowEngine.WorkflowInstance.initial(workflow, executionId, {
517
- scope: Scope.forkUnsafe(pending.scope)
526
+ scope: reuseOrForkScope(currentRun?.instance.scope, pending.scope)
518
527
  })
519
- pending.instances.add(instance)
520
- currentRun = { request, instance, activityAwaits: new Map() }
528
+ const current = { request, instance, activityAwaits: new Map<string, number>(), completing: false }
529
+ currentRun = current
521
530
  const parent = (request.payload as any)[payloadParentKey] as
522
- | { workflowName: string; executionId: string; detached?: boolean }
531
+ | (ParentRef & { readonly detached?: boolean })
523
532
  | undefined
524
533
  return execute(workflow.payloadSchema.make(request.payload) as object, executionId).pipe(
525
534
  Effect.onExit((exit) => {
@@ -531,10 +540,19 @@ export const make = Effect.gen(function*() {
531
540
  if (instance.abandoned) {
532
541
  instance.suspended = false
533
542
  }
534
- // Abandoned runs never wake the parent; another owner replays them.
535
- const resumeParent = parent && !parent.detached && !instance.abandoned
536
- ? ensureSuccess(sendResumeParent(parent, executionId))
537
- : Effect.void
543
+ // Abandoned runs never wake parents; another owner replays them.
544
+ const resumeParent = instance.abandoned ? Effect.void : ensureSuccess(Effect.gen(function*() {
545
+ current.completing = true
546
+ const parents = (yield* storage.requestsForAddress({ address, tag: "parent" }))
547
+ .map((registration) => registration.payload as ParentRef)
548
+ // Registrations are unique by parent; only an older caller's payload parent can repeat one.
549
+ if (parent && !parent.detached && !parents.some((ref) => sameParent(ref, parent))) {
550
+ parents.push(parent)
551
+ }
552
+ for (const ref of parents) {
553
+ yield* sendResumeParent(ref, executionId)
554
+ }
555
+ }))
538
556
  if (
539
557
  !instance.suspended &&
540
558
  !instance.abandoned &&
@@ -613,9 +631,12 @@ export const make = Effect.gen(function*() {
613
631
  Context.add(CurrentActivationScope, activation),
614
632
  Context.add(Activity.CurrentAttempt, payload.attempt)
615
633
  )
634
+ pending.executing++
635
+ pending.idle.closeUnsafe()
616
636
  return entry.activity.executeEncoded.pipe(
617
637
  Effect.provideContext(context),
618
638
  Workflow.intoResult,
639
+ Effect.provideService(RetryingExecution, Context.get(entry.context, RetryingExecution)),
619
640
  Effect.tap((result) =>
620
641
  Effect.sync(() => {
621
642
  entry.result = result
@@ -629,6 +650,9 @@ export const make = Effect.gen(function*() {
629
650
  )
630
651
  return suspend ? Effect.succeed(new Workflow.Suspended({})) : Effect.failCause(cause)
631
652
  }),
653
+ Effect.ensuring(Effect.sync(() => {
654
+ if (--pending.executing === 0) pending.idle.openUnsafe()
655
+ })),
632
656
  Effect.provideService(WorkflowEngine.WorkflowInstance, instance),
633
657
  Effect.provideService(Activity.CurrentAttempt, payload.attempt),
634
658
  Rpc.wrap({ fork: true, uninterruptible: true })
@@ -659,24 +683,32 @@ export const make = Effect.gen(function*() {
659
683
  Effect.andThen(resumeCurrentRun(mode))
660
684
  )
661
685
  )
662
- // An asynchronous reply releases the RPC concurrency permit while
663
- // the wake waits; the pending request still occupies mailbox capacity.
664
- // The activation owns the wake so it survives handler rebuilds,
665
- // but activation shutdown still interrupts it for durable redelivery.
666
- const reply = Deferred.makeUnsafe<Exit.Exit<unknown, unknown>>()
667
- return wake.pipe(
668
- Effect.as(payload.exit),
669
- Deferred.into(reply),
670
- Effect.forkIn(activation, { startImmediately: true }),
671
- Effect.as(reply)
672
- )
686
+ return forkReply(Effect.as(wake, payload.exit as Exit.Exit<unknown, unknown>))
673
687
  },
674
688
 
675
- resume: () => resumeCurrentRun("automatic").pipe(Rpc.wrap({ fork: true, uninterruptible: true }))
689
+ resume: () => resumeCurrentRun("automatic").pipe(Rpc.wrap({ fork: true, uninterruptible: true })),
690
+
691
+ parent: (request: Entity.Request<any>) => {
692
+ const ref = request.payload as ParentRef
693
+ // The exiting run may have listed parents before this
694
+ // registration; wait for its reply, then wake.
695
+ if (currentRun?.completing) {
696
+ return forkReply(
697
+ ensureSuccess(
698
+ Effect.andThen(waitForRunReply(workflow, currentRun.request), sendResumeParent(ref, executionId))
699
+ )
700
+ )
701
+ }
702
+ return Effect.gen(function*() {
703
+ if (isRunSettled(yield* retryPersistence(runReply(workflow, executionId)))) {
704
+ yield* ensureSuccess(sendResumeParent(ref, executionId))
705
+ }
706
+ }).pipe(Rpc.wrap({ fork: true }))
707
+ }
676
708
  }
677
709
  }),
678
- // Alongside the run, let deferred handlers briefly acquire a permit to
679
- // fork their wake and return an asynchronous reply.
710
+ // Alongside the run, let deferred and `parent` handlers briefly acquire a
711
+ // permit to fork their wake and return an asynchronous reply.
680
712
  { concurrency: 2, maxIdleTime: entityMaxIdleTime }
681
713
  ) as Effect.Effect<void, never, Scope.Scope>
682
714
  if (existing === undefined || existing === workflow) return registration
@@ -692,20 +724,35 @@ export const make = Effect.gen(function*() {
692
724
  execute: (workflow, { detached, discard, executionId, parent, payload }) => {
693
725
  ensureEntity(workflow)
694
726
  return RcMap.get(clients, workflow._tag).pipe(
695
- Effect.flatMap((make) =>
696
- make(executionId).run(
697
- parent ?
727
+ Effect.flatMap((make) => {
728
+ const client = make(executionId)
729
+ // The shard group lets a runner without the parent's workflow address its wake.
730
+ const shardGroup = parent && !detached ? shardGroupFor(parent.workflow, parent.executionId) : "default"
731
+ const ref: ParentRef | undefined = parent && {
732
+ workflowName: parent.workflow._tag,
733
+ executionId: parent.executionId,
734
+ ...(shardGroup === "default" ? undefined : { shardGroup })
735
+ }
736
+ const run = client.run(
737
+ ref ?
698
738
  {
699
739
  ...payload,
700
740
  // A detached child keeps its parent for observability only.
701
- [payloadParentKey]: detached
702
- ? { workflowName: parent.workflow._tag, executionId: parent.executionId, detached: true }
703
- : { workflowName: parent.workflow._tag, executionId: parent.executionId }
741
+ [payloadParentKey]: detached ? { ...ref, detached: true } : ref
704
742
  } :
705
743
  payload,
706
744
  { discard }
707
745
  )
708
- ),
746
+ if (!ref || detached || sameParent(ref, { workflowName: workflow._tag, executionId })) {
747
+ return run
748
+ }
749
+ // Discarded, so an open transaction or an older runner cannot block it.
750
+ const register = Effect.flatMap(
751
+ runReply(workflow, executionId),
752
+ (reply) => isRunSettled(reply) ? Effect.void : client.parent(ref, { discard: true })
753
+ )
754
+ return Effect.andThen(register, run)
755
+ }),
709
756
  // A failed save inside a workflow would be stored as its result. Top-level
710
757
  // calls still fail, so their callers are not blocked during an outage.
711
758
  parent ? retryPersistence : Effect.orDie,
@@ -716,13 +763,7 @@ export const make = Effect.gen(function*() {
716
763
  poll: Effect.fnUntraced(function*(workflow, executionId) {
717
764
  const entity = ensureEntity(workflow)
718
765
  const exitSchema = Schema.toCodecJson(Rpc.exitSchema(entity.protocol.requests.get("run")!))
719
- const reply = yield* requestReply({
720
- workflow,
721
- entityType: `Workflow/${workflow._tag}`,
722
- executionId,
723
- tag: "run",
724
- id: ""
725
- })
766
+ const reply = yield* runReply(workflow, executionId)
726
767
  if (Option.isNone(reply)) return Option.none()
727
768
  const exit = yield* (Schema.decodeUnknownEffect(exitSchema)(reply.value.exit) as Effect.Effect<
728
769
  Exit.Exit<any, any>,
@@ -791,14 +832,25 @@ export const make = Effect.gen(function*() {
791
832
  if (activities.get(activityId) === entry) activities.delete(activityId)
792
833
  })
793
834
  )
835
+ const activation = yield* Effect.serviceOption(CurrentActivationScope)
836
+ const pending = Option.isSome(activation) ? pendingByActivation.get(activation.value) : undefined
837
+ const handoff = pending?.retired &&
838
+ pending.workflowName === instance.workflow._tag &&
839
+ pending.executionId === instance.executionId
840
+ ? Effect.andThen(pending.retired.await, Effect.as(pending.idle.await, Option.none()))
841
+ : Effect.never
794
842
  while (true) {
795
- const result = yield* retryPersistence(
843
+ const maybeResult = yield* retryPersistence(
796
844
  client.activity({
797
845
  name: activity.name,
798
846
  attempt,
799
847
  withTransaction: Context.get(activity.annotations, ClusterSchema.WithTransaction)
800
848
  })
801
- )
849
+ ).pipe(Effect.asSome, Effect.raceFirst(handoff))
850
+ // The retired entity will not run this activity. Leave the run for
851
+ // the next owner, which replays it and reads the saved results.
852
+ if (Option.isNone(maybeResult)) return yield* ClusterAbandon.interrupt
853
+ const result = maybeResult.value
802
854
  // If the activity has suspended and did not execute, we need to resume
803
855
  // it by resetting the attempt and re-executing.
804
856
  if (
@@ -995,15 +1047,22 @@ interface ActivationState {
995
1047
  readonly workflowName: string
996
1048
  readonly executionId: string
997
1049
  readonly results: Map<string, Exit.Exit<unknown, unknown>>
998
- // Every run forks its scope from here, so runs that suspended keep their
999
- // resources and durable finalizers until the execution finishes.
1050
+ // Parent of every run's scope, so runs that suspended keep their resources
1051
+ // and durable finalizers until the execution finishes.
1000
1052
  scope: Scope.Closeable
1001
- readonly instances: Set<WorkflowEngine.WorkflowInstance["Service"]>
1053
+ // Opens when this activation retires; paired with `idle` so in-flight
1054
+ // activities finish before any waiting run hands off to the next owner.
1055
+ readonly retired: Latch.Latch | undefined
1056
+ readonly idle: Latch.Latch
1057
+ executing: number
1002
1058
  }
1003
1059
 
1004
1060
  const isSuspendedReply = (reply: WithExitEncoded<Workflow.ResultEncoded<any, any>>) =>
1005
1061
  reply.exit._tag === "Success" && reply.exit.value._tag === "Suspended"
1006
1062
 
1063
+ const isRunSettled = (reply: Option.Option<WithExitEncoded<Workflow.ResultEncoded<any, any>>>) =>
1064
+ Option.isSome(reply) && !isSuspendedReply(reply.value)
1065
+
1007
1066
  const isFailedReply = (reply: WithExitEncoded<Workflow.ResultEncoded<any, any>>) =>
1008
1067
  reply.exit._tag === "Success" && reply.exit.value._tag === "Suspended" && reply.exit.value.failed === true
1009
1068
 
@@ -1024,6 +1083,24 @@ const ResumeRpc = Rpc.make("resume", {
1024
1083
  .annotate(ClusterSchema.Persisted, true)
1025
1084
  .annotate(ClusterSchema.Uninterruptible, "server")
1026
1085
 
1086
+ const ParentRefSchema = Schema.Struct({
1087
+ workflowName: Schema.String,
1088
+ executionId: Schema.String,
1089
+ shardGroup: Schema.optional(Schema.String)
1090
+ })
1091
+ type ParentRef = typeof ParentRefSchema.Type
1092
+
1093
+ // The shard group only routes the wake, so it is not part of a parent's identity.
1094
+ const sameParent = (a: ParentRef, b: ParentRef) => a.workflowName === b.workflowName && a.executionId === b.executionId
1095
+
1096
+ const ParentRpc = Rpc.make("parent", {
1097
+ payload: ParentRefSchema.fields,
1098
+ // Length-prefixed so an execution id containing a separator cannot collide.
1099
+ primaryKey: (parent) => `${parent.workflowName.length}:${parent.workflowName}:${parent.executionId}`
1100
+ })
1101
+ .annotate(ClusterSchema.Persisted, true)
1102
+ .annotate(ClusterSchema.Uninterruptible, "server")
1103
+
1027
1104
  const payloadParentKey = "~effect/cluster/ClusterWorkflowEngine/payloadParentKey"
1028
1105
 
1029
1106
  // Workflow state is durable, so an idle entity (completed or suspended) can
@@ -1038,8 +1115,7 @@ const makeWorkflowEntity = (workflow: Workflow.Any) =>
1038
1115
  payload: {
1039
1116
  ...workflow.payloadSchema.fields,
1040
1117
  [payloadParentKey]: Schema.optional(Schema.Struct({
1041
- workflowName: Schema.String,
1042
- executionId: Schema.String,
1118
+ ...ParentRefSchema.fields,
1043
1119
  detached: Schema.optional(Schema.Boolean)
1044
1120
  }))
1045
1121
  },
@@ -1054,13 +1130,13 @@ const makeWorkflowEntity = (workflow: Workflow.Any) =>
1054
1130
 
1055
1131
  DeferredRpc,
1056
1132
  ResumeRpc,
1133
+ ParentRpc,
1057
1134
  ActivityRpc
1058
1135
  ]).annotateMerge(workflow.annotations)
1059
1136
 
1060
1137
  const makePartialWorkflowEntity = (workflowName: string) =>
1061
1138
  Entity.make(`Workflow/${workflowName}`, [
1062
1139
  DeferredRpc,
1063
- ResumeRpc,
1064
1140
  ActivityRpc
1065
1141
  ])
1066
1142