@smthrs/engine-store 1.0.0-rc.5 → 1.0.0-rc.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 (262) hide show
  1. package/README.md +15 -15
  2. package/dist/cjs/ArtifactGc.d.ts +1 -1
  3. package/dist/cjs/ArtifactGc.d.ts.map +1 -1
  4. package/dist/cjs/ArtifactGc.js +1 -1
  5. package/dist/cjs/ArtifactGc.js.map +1 -1
  6. package/dist/cjs/DeferredClockFold.d.ts +4 -4
  7. package/dist/cjs/DeferredClockFold.d.ts.map +1 -1
  8. package/dist/cjs/DeferredClockFold.js +1 -1
  9. package/dist/cjs/DeferredClockFold.js.map +1 -1
  10. package/dist/cjs/DisasterRecovery.d.ts +1 -1
  11. package/dist/cjs/DisasterRecovery.d.ts.map +1 -1
  12. package/dist/cjs/DisasterRecovery.js +1 -1
  13. package/dist/cjs/DisasterRecovery.js.map +1 -1
  14. package/dist/cjs/DurableEngineState.d.ts +1 -1
  15. package/dist/cjs/DurableEngineState.d.ts.map +1 -1
  16. package/dist/cjs/DurableEngineState.js +1 -1
  17. package/dist/cjs/DurableEngineState.js.map +1 -1
  18. package/dist/cjs/ExecutionSnapshot.d.ts +2 -2
  19. package/dist/cjs/ExecutionSnapshot.d.ts.map +1 -1
  20. package/dist/cjs/ExecutionSnapshot.js +1 -1
  21. package/dist/cjs/ExecutionSnapshot.js.map +1 -1
  22. package/dist/cjs/Migrations.d.ts +2 -2
  23. package/dist/cjs/Migrations.d.ts.map +1 -1
  24. package/dist/cjs/OwnerIdentity.js +1 -1
  25. package/dist/cjs/OwnerIdentity.js.map +2 -2
  26. package/dist/cjs/PlanInputStore.d.ts +1 -1
  27. package/dist/cjs/PlanInputStore.d.ts.map +1 -1
  28. package/dist/cjs/PlanInputStore.js +1 -1
  29. package/dist/cjs/PlanInputStore.js.map +1 -1
  30. package/dist/cjs/PlanMergeStore.d.ts +1 -1
  31. package/dist/cjs/PlanMergeStore.d.ts.map +1 -1
  32. package/dist/cjs/PlanMergeStore.js +1 -1
  33. package/dist/cjs/PlanMergeStore.js.map +1 -1
  34. package/dist/cjs/Retention.d.ts +2 -2
  35. package/dist/cjs/Retention.d.ts.map +1 -1
  36. package/dist/cjs/Retention.js +1 -1
  37. package/dist/cjs/Retention.js.map +1 -1
  38. package/dist/cjs/RunChangeFeed.d.ts +1 -1
  39. package/dist/cjs/RunChangeFeed.d.ts.map +1 -1
  40. package/dist/cjs/RunChangeFeed.js +1 -1
  41. package/dist/cjs/RunChangeFeed.js.map +1 -1
  42. package/dist/cjs/SelectionStore.d.ts +1 -1
  43. package/dist/cjs/SelectionStore.d.ts.map +1 -1
  44. package/dist/cjs/SelectionStore.js +1 -1
  45. package/dist/cjs/SelectionStore.js.map +1 -1
  46. package/dist/cjs/StepBoundary.d.ts +8 -6
  47. package/dist/cjs/StepBoundary.d.ts.map +1 -1
  48. package/dist/cjs/StepBoundary.js +13 -10
  49. package/dist/cjs/StepBoundary.js.map +2 -2
  50. package/dist/cjs/StepCacheFold.d.ts +2 -2
  51. package/dist/cjs/StepCacheFold.d.ts.map +1 -1
  52. package/dist/cjs/StepCacheFold.js +1 -1
  53. package/dist/cjs/StepCacheFold.js.map +1 -1
  54. package/dist/cjs/internal/EngineStateSchema.d.ts +1 -1
  55. package/dist/cjs/internal/EngineStateSchema.d.ts.map +1 -1
  56. package/dist/cjs/internal/EngineStateSchema.js.map +1 -1
  57. package/dist/cjs/internal/ExecutionSnapshotRead.d.ts +3 -3
  58. package/dist/cjs/internal/ExecutionSnapshotRead.d.ts.map +1 -1
  59. package/dist/cjs/internal/ExecutionSnapshotRead.js.map +1 -1
  60. package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts +1 -1
  61. package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts.map +1 -1
  62. package/dist/cjs/internal/ExecutionSnapshotRelations.js.map +1 -1
  63. package/dist/cjs/internal/RetentionOps.d.ts +2 -2
  64. package/dist/cjs/internal/RetentionOps.d.ts.map +1 -1
  65. package/dist/cjs/internal/RetentionOps.js +1 -1
  66. package/dist/cjs/internal/RetentionOps.js.map +1 -1
  67. package/dist/cjs/internal/RunCatalogOps.d.ts +1 -1
  68. package/dist/cjs/internal/RunCatalogOps.d.ts.map +1 -1
  69. package/dist/cjs/internal/RunCatalogOps.js +1 -1
  70. package/dist/cjs/internal/RunCatalogOps.js.map +1 -1
  71. package/dist/cjs/internal/RunListing.d.ts +1 -1
  72. package/dist/cjs/internal/RunListing.d.ts.map +1 -1
  73. package/dist/cjs/internal/RunListing.js +1 -1
  74. package/dist/cjs/internal/RunListing.js.map +1 -1
  75. package/dist/cjs/migrations/0001_initial.d.ts +1 -1
  76. package/dist/cjs/migrations/0001_initial.d.ts.map +1 -1
  77. package/dist/cjs/migrations/0001_initial.js +1 -1
  78. package/dist/cjs/migrations/0001_initial.js.map +1 -1
  79. package/dist/cjs/migrations/0002_selection_store.d.ts +1 -1
  80. package/dist/cjs/migrations/0002_selection_store.d.ts.map +1 -1
  81. package/dist/cjs/migrations/0002_selection_store.js +1 -1
  82. package/dist/cjs/migrations/0002_selection_store.js.map +1 -1
  83. package/dist/cjs/migrations/0003_plan_inputs.d.ts +1 -1
  84. package/dist/cjs/migrations/0003_plan_inputs.d.ts.map +1 -1
  85. package/dist/cjs/migrations/0003_plan_inputs.js +1 -1
  86. package/dist/cjs/migrations/0003_plan_inputs.js.map +1 -1
  87. package/dist/cjs/migrations/0004_plan_environment.d.ts +1 -1
  88. package/dist/cjs/migrations/0004_plan_environment.d.ts.map +1 -1
  89. package/dist/cjs/migrations/0004_plan_environment.js +1 -1
  90. package/dist/cjs/migrations/0004_plan_environment.js.map +1 -1
  91. package/dist/cjs/migrations/0005_plan_merges.d.ts +1 -1
  92. package/dist/cjs/migrations/0005_plan_merges.d.ts.map +1 -1
  93. package/dist/cjs/migrations/0005_plan_merges.js +1 -1
  94. package/dist/cjs/migrations/0005_plan_merges.js.map +1 -1
  95. package/dist/cjs/migrations/0006_execution_listing.d.ts +1 -1
  96. package/dist/cjs/migrations/0006_execution_listing.d.ts.map +1 -1
  97. package/dist/cjs/migrations/0006_execution_listing.js +1 -1
  98. package/dist/cjs/migrations/0006_execution_listing.js.map +1 -1
  99. package/dist/cjs/migrations/0007_run_parent_sequence.d.ts +1 -1
  100. package/dist/cjs/migrations/0007_run_parent_sequence.d.ts.map +1 -1
  101. package/dist/cjs/migrations/0007_run_parent_sequence.js +1 -1
  102. package/dist/cjs/migrations/0007_run_parent_sequence.js.map +1 -1
  103. package/dist/cjs/migrations/0008_deferred_consumption.d.ts +1 -1
  104. package/dist/cjs/migrations/0008_deferred_consumption.d.ts.map +1 -1
  105. package/dist/cjs/migrations/0008_deferred_consumption.js +1 -1
  106. package/dist/cjs/migrations/0008_deferred_consumption.js.map +1 -1
  107. package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts +1 -1
  108. package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts.map +1 -1
  109. package/dist/cjs/migrations/0009_deferred_clock_facts.js +1 -1
  110. package/dist/cjs/migrations/0009_deferred_clock_facts.js.map +1 -1
  111. package/dist/cjs/migrations/0010_pending_cancellation.d.ts +1 -1
  112. package/dist/cjs/migrations/0010_pending_cancellation.d.ts.map +1 -1
  113. package/dist/cjs/migrations/0010_pending_cancellation.js +1 -1
  114. package/dist/cjs/migrations/0010_pending_cancellation.js.map +1 -1
  115. package/dist/cjs/test/TestStores.d.ts +4 -4
  116. package/dist/cjs/test/TestStores.d.ts.map +1 -1
  117. package/dist/esm/ArtifactGc.d.ts +1 -1
  118. package/dist/esm/ArtifactGc.d.ts.map +1 -1
  119. package/dist/esm/ArtifactGc.js +1 -1
  120. package/dist/esm/ArtifactGc.js.map +1 -1
  121. package/dist/esm/DeferredClockFold.d.ts +4 -4
  122. package/dist/esm/DeferredClockFold.d.ts.map +1 -1
  123. package/dist/esm/DeferredClockFold.js +1 -1
  124. package/dist/esm/DeferredClockFold.js.map +1 -1
  125. package/dist/esm/DisasterRecovery.d.ts +1 -1
  126. package/dist/esm/DisasterRecovery.d.ts.map +1 -1
  127. package/dist/esm/DisasterRecovery.js +1 -1
  128. package/dist/esm/DisasterRecovery.js.map +1 -1
  129. package/dist/esm/DurableEngineState.d.ts +1 -1
  130. package/dist/esm/DurableEngineState.d.ts.map +1 -1
  131. package/dist/esm/DurableEngineState.js +1 -1
  132. package/dist/esm/DurableEngineState.js.map +1 -1
  133. package/dist/esm/ExecutionSnapshot.d.ts +2 -2
  134. package/dist/esm/ExecutionSnapshot.d.ts.map +1 -1
  135. package/dist/esm/ExecutionSnapshot.js +1 -1
  136. package/dist/esm/ExecutionSnapshot.js.map +1 -1
  137. package/dist/esm/Migrations.d.ts +2 -2
  138. package/dist/esm/Migrations.d.ts.map +1 -1
  139. package/dist/esm/OwnerIdentity.js +1 -1
  140. package/dist/esm/OwnerIdentity.js.map +1 -1
  141. package/dist/esm/PlanInputStore.d.ts +1 -1
  142. package/dist/esm/PlanInputStore.d.ts.map +1 -1
  143. package/dist/esm/PlanInputStore.js +1 -1
  144. package/dist/esm/PlanInputStore.js.map +1 -1
  145. package/dist/esm/PlanMergeStore.d.ts +1 -1
  146. package/dist/esm/PlanMergeStore.d.ts.map +1 -1
  147. package/dist/esm/PlanMergeStore.js +1 -1
  148. package/dist/esm/PlanMergeStore.js.map +1 -1
  149. package/dist/esm/Retention.d.ts +2 -2
  150. package/dist/esm/Retention.d.ts.map +1 -1
  151. package/dist/esm/Retention.js +1 -1
  152. package/dist/esm/Retention.js.map +1 -1
  153. package/dist/esm/RunChangeFeed.d.ts +1 -1
  154. package/dist/esm/RunChangeFeed.d.ts.map +1 -1
  155. package/dist/esm/RunChangeFeed.js +1 -1
  156. package/dist/esm/RunChangeFeed.js.map +1 -1
  157. package/dist/esm/SelectionStore.d.ts +1 -1
  158. package/dist/esm/SelectionStore.d.ts.map +1 -1
  159. package/dist/esm/SelectionStore.js +1 -1
  160. package/dist/esm/SelectionStore.js.map +1 -1
  161. package/dist/esm/StepBoundary.d.ts +8 -6
  162. package/dist/esm/StepBoundary.d.ts.map +1 -1
  163. package/dist/esm/StepBoundary.js +20 -11
  164. package/dist/esm/StepBoundary.js.map +1 -1
  165. package/dist/esm/StepCacheFold.d.ts +2 -2
  166. package/dist/esm/StepCacheFold.d.ts.map +1 -1
  167. package/dist/esm/StepCacheFold.js +1 -1
  168. package/dist/esm/StepCacheFold.js.map +1 -1
  169. package/dist/esm/internal/EngineStateSchema.d.ts +1 -1
  170. package/dist/esm/internal/EngineStateSchema.d.ts.map +1 -1
  171. package/dist/esm/internal/EngineStateSchema.js.map +1 -1
  172. package/dist/esm/internal/ExecutionSnapshotRead.d.ts +3 -3
  173. package/dist/esm/internal/ExecutionSnapshotRead.d.ts.map +1 -1
  174. package/dist/esm/internal/ExecutionSnapshotRead.js.map +1 -1
  175. package/dist/esm/internal/ExecutionSnapshotRelations.d.ts +1 -1
  176. package/dist/esm/internal/ExecutionSnapshotRelations.d.ts.map +1 -1
  177. package/dist/esm/internal/ExecutionSnapshotRelations.js.map +1 -1
  178. package/dist/esm/internal/RetentionOps.d.ts +2 -2
  179. package/dist/esm/internal/RetentionOps.d.ts.map +1 -1
  180. package/dist/esm/internal/RetentionOps.js +1 -1
  181. package/dist/esm/internal/RetentionOps.js.map +1 -1
  182. package/dist/esm/internal/RunCatalogOps.d.ts +1 -1
  183. package/dist/esm/internal/RunCatalogOps.d.ts.map +1 -1
  184. package/dist/esm/internal/RunCatalogOps.js +1 -1
  185. package/dist/esm/internal/RunCatalogOps.js.map +1 -1
  186. package/dist/esm/internal/RunListing.d.ts +1 -1
  187. package/dist/esm/internal/RunListing.d.ts.map +1 -1
  188. package/dist/esm/internal/RunListing.js +1 -1
  189. package/dist/esm/internal/RunListing.js.map +1 -1
  190. package/dist/esm/migrations/0001_initial.d.ts +1 -1
  191. package/dist/esm/migrations/0001_initial.d.ts.map +1 -1
  192. package/dist/esm/migrations/0001_initial.js +1 -1
  193. package/dist/esm/migrations/0001_initial.js.map +1 -1
  194. package/dist/esm/migrations/0002_selection_store.d.ts +1 -1
  195. package/dist/esm/migrations/0002_selection_store.d.ts.map +1 -1
  196. package/dist/esm/migrations/0002_selection_store.js +1 -1
  197. package/dist/esm/migrations/0002_selection_store.js.map +1 -1
  198. package/dist/esm/migrations/0003_plan_inputs.d.ts +1 -1
  199. package/dist/esm/migrations/0003_plan_inputs.d.ts.map +1 -1
  200. package/dist/esm/migrations/0003_plan_inputs.js +1 -1
  201. package/dist/esm/migrations/0003_plan_inputs.js.map +1 -1
  202. package/dist/esm/migrations/0004_plan_environment.d.ts +1 -1
  203. package/dist/esm/migrations/0004_plan_environment.d.ts.map +1 -1
  204. package/dist/esm/migrations/0004_plan_environment.js +1 -1
  205. package/dist/esm/migrations/0004_plan_environment.js.map +1 -1
  206. package/dist/esm/migrations/0005_plan_merges.d.ts +1 -1
  207. package/dist/esm/migrations/0005_plan_merges.d.ts.map +1 -1
  208. package/dist/esm/migrations/0005_plan_merges.js +1 -1
  209. package/dist/esm/migrations/0005_plan_merges.js.map +1 -1
  210. package/dist/esm/migrations/0006_execution_listing.d.ts +1 -1
  211. package/dist/esm/migrations/0006_execution_listing.d.ts.map +1 -1
  212. package/dist/esm/migrations/0006_execution_listing.js +1 -1
  213. package/dist/esm/migrations/0006_execution_listing.js.map +1 -1
  214. package/dist/esm/migrations/0007_run_parent_sequence.d.ts +1 -1
  215. package/dist/esm/migrations/0007_run_parent_sequence.d.ts.map +1 -1
  216. package/dist/esm/migrations/0007_run_parent_sequence.js +1 -1
  217. package/dist/esm/migrations/0007_run_parent_sequence.js.map +1 -1
  218. package/dist/esm/migrations/0008_deferred_consumption.d.ts +1 -1
  219. package/dist/esm/migrations/0008_deferred_consumption.d.ts.map +1 -1
  220. package/dist/esm/migrations/0008_deferred_consumption.js +1 -1
  221. package/dist/esm/migrations/0008_deferred_consumption.js.map +1 -1
  222. package/dist/esm/migrations/0009_deferred_clock_facts.d.ts +1 -1
  223. package/dist/esm/migrations/0009_deferred_clock_facts.d.ts.map +1 -1
  224. package/dist/esm/migrations/0009_deferred_clock_facts.js +1 -1
  225. package/dist/esm/migrations/0009_deferred_clock_facts.js.map +1 -1
  226. package/dist/esm/migrations/0010_pending_cancellation.d.ts +1 -1
  227. package/dist/esm/migrations/0010_pending_cancellation.d.ts.map +1 -1
  228. package/dist/esm/migrations/0010_pending_cancellation.js +1 -1
  229. package/dist/esm/migrations/0010_pending_cancellation.js.map +1 -1
  230. package/dist/esm/test/TestStores.d.ts +4 -4
  231. package/dist/esm/test/TestStores.d.ts.map +1 -1
  232. package/docs/api.md +19 -16
  233. package/package.json +22 -22
  234. package/src/ArtifactGc.ts +1 -1
  235. package/src/DeferredClockFold.ts +1 -1
  236. package/src/DisasterRecovery.ts +1 -1
  237. package/src/DurableEngineState.ts +1 -1
  238. package/src/ExecutionSnapshot.ts +1 -1
  239. package/src/OwnerIdentity.ts +1 -1
  240. package/src/PlanInputStore.ts +1 -1
  241. package/src/PlanMergeStore.ts +1 -1
  242. package/src/Retention.ts +2 -2
  243. package/src/RunChangeFeed.ts +1 -1
  244. package/src/SelectionStore.ts +1 -1
  245. package/src/StepBoundary.ts +32 -17
  246. package/src/StepCacheFold.ts +1 -1
  247. package/src/internal/EngineStateSchema.ts +1 -1
  248. package/src/internal/ExecutionSnapshotRead.ts +1 -1
  249. package/src/internal/ExecutionSnapshotRelations.ts +1 -1
  250. package/src/internal/RetentionOps.ts +2 -2
  251. package/src/internal/RunCatalogOps.ts +1 -1
  252. package/src/internal/RunListing.ts +1 -1
  253. package/src/migrations/0001_initial.ts +1 -1
  254. package/src/migrations/0002_selection_store.ts +1 -1
  255. package/src/migrations/0003_plan_inputs.ts +1 -1
  256. package/src/migrations/0004_plan_environment.ts +1 -1
  257. package/src/migrations/0005_plan_merges.ts +1 -1
  258. package/src/migrations/0006_execution_listing.ts +1 -1
  259. package/src/migrations/0007_run_parent_sequence.ts +1 -1
  260. package/src/migrations/0008_deferred_consumption.ts +1 -1
  261. package/src/migrations/0009_deferred_clock_facts.ts +1 -1
  262. package/src/migrations/0010_pending_cancellation.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"0010_pending_cancellation.d.ts","sourceRoot":"","sources":["../../../src/migrations/0010_pending_cancellation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,SAAS,CAIhF,CAAA"}
1
+ {"version":3,"file":"0010_pending_cancellation.d.ts","sourceRoot":"","sources":["../../../src/migrations/0010_pending_cancellation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,SAAS,CAIhF,CAAA"}
@@ -32,7 +32,7 @@ __export(pending_cancellation_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(pending_cancellation_exports);
34
34
  var Effect = __toESM(require("effect/Effect"), 1);
35
- var SqlClient = __toESM(require("effect/unstable/sql/SqlClient"), 1);
35
+ var SqlClient = __toESM(require("effect/sql/SqlClient"), 1);
36
36
  const pendingCancellation = Effect.gen(function* () {
37
37
  const sql = yield* SqlClient.SqlClient;
38
38
  yield* sql`CREATE INDEX flows_runs_pending_cancel_idx ON flows_runs (created_at_ms, run_id)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/migrations/0010_pending_cancellation.ts"],
4
- "sourcesContent": ["/**\n * Indexed cancellation cleanup for admissions whose handler is unavailable.\n *\n * @since 1.0.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\"\n\n/**\n * Bounds cleanup reads to requested pending rows.\n *\n * @category migrations\n * @since 1.0.0\n */\nexport const pendingCancellation: Effect.Effect<void, unknown, SqlClient.SqlClient> = Effect.gen(function*() {\n const sql = yield* SqlClient.SqlClient\n yield* sql`CREATE INDEX flows_runs_pending_cancel_idx ON flows_runs (created_at_ms, run_id)\n WHERE status = 'pending' AND cancel_requested_at_ms IS NOT NULL`\n})\n"],
4
+ "sourcesContent": ["/**\n * Indexed cancellation cleanup for admissions whose handler is unavailable.\n *\n * @since 1.0.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as SqlClient from \"effect/sql/SqlClient\"\n\n/**\n * Bounds cleanup reads to requested pending rows.\n *\n * @category migrations\n * @since 1.0.0\n */\nexport const pendingCancellation: Effect.Effect<void, unknown, SqlClient.SqlClient> = Effect.gen(function*() {\n const sql = yield* SqlClient.SqlClient\n yield* sql`CREATE INDEX flows_runs_pending_cancel_idx ON flows_runs (created_at_ms, run_id)\n WHERE status = 'pending' AND cancel_requested_at_ms IS NOT NULL`\n})\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,aAAwB;AACxB,gBAA2B;AAQpB,MAAM,sBAAyE,OAAO,IAAI,aAAY;AAC3G,QAAM,MAAM,OAAO,UAAU;AAC7B,SAAO;AAAA;AAET,CAAC;",
6
6
  "names": []
7
7
  }
@@ -39,7 +39,7 @@ export interface TestStoresOptions {
39
39
  * @category layers
40
40
  * @since 0.1.0
41
41
  */
42
- export declare const database: Layer.Layer<import("effect/unstable/sql/SqlClient").SqlClient | DurableWriter.DurableWriter, import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError, never>;
42
+ export declare const database: Layer.Layer<import("effect/sql/SqlClient").SqlClient | DurableWriter.DurableWriter, import("effect/sql/SqlError").SqlError | import("effect/sql/Migrator").MigrationError, never>;
43
43
  /**
44
44
  * Provides the production SQLite journal, run, attempt, and cache services
45
45
  * over one in-memory database. Migrations run before any durable service is
@@ -54,7 +54,7 @@ export declare const database: Layer.Layer<import("effect/unstable/sql/SqlClient
54
54
  * @category layers
55
55
  * @since 0.1.0
56
56
  */
57
- export declare const layer: (options?: TestStoresOptions) => Layer.Layer<DurableWriter.DurableWriter | CacheStore.CacheStore | import("@smthrs/journal/Journal").Journal | RunStore.RunStore | AttemptStore.AttemptStore | OwnerIdentity.OwnerIdentity | PlanInputStore.PlanInputStore | PlanMergeStore.PlanMergeStore | PlanStore.PlanStore, import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError | import("@smthrs/journal/Journal").JournalError, import("effect/Crypto").Crypto>;
57
+ export declare const layer: (options?: TestStoresOptions) => Layer.Layer<DurableWriter.DurableWriter | CacheStore.CacheStore | import("@smthrs/journal/Journal").Journal | RunStore.RunStore | AttemptStore.AttemptStore | OwnerIdentity.OwnerIdentity | PlanInputStore.PlanInputStore | PlanMergeStore.PlanMergeStore | PlanStore.PlanStore, import("effect/sql/SqlError").SqlError | import("effect/sql/Migrator").MigrationError | import("@smthrs/journal/Journal").JournalError, import("effect/Crypto").Crypto>;
58
58
  /**
59
59
  * The same schema over a named SQLite database or PostgreSQL URL, with the connection exposed.
60
60
  *
@@ -68,7 +68,7 @@ export declare const layer: (options?: TestStoresOptions) => Layer.Layer<Durable
68
68
  * @category layers
69
69
  * @since 0.1.0
70
70
  */
71
- export declare const databaseAt: (filename: string) => Layer.Layer<import("effect/unstable/sql/SqlClient").SqlClient | DurableWriter.DurableWriter, import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError, never>;
71
+ export declare const databaseAt: (filename: string) => Layer.Layer<import("effect/sql/SqlClient").SqlClient | DurableWriter.DurableWriter, import("effect/sql/SqlError").SqlError | import("effect/sql/Migrator").MigrationError, never>;
72
72
  /**
73
73
  * Every durable engine service over one named database, connection included.
74
74
  *
@@ -85,5 +85,5 @@ export declare const databaseAt: (filename: string) => Layer.Layer<import("effec
85
85
  * @category layers
86
86
  * @since 0.1.0
87
87
  */
88
- export declare const layerAt: (filename: string, options?: TestStoresOptions) => Layer.Layer<import("effect/unstable/sql/SqlClient").SqlClient | DurableWriter.DurableWriter | CacheStore.CacheStore | import("@smthrs/journal/Journal").Journal | RunStore.RunStore | DurableEngineState.DurableEngineState | AttemptStore.AttemptStore | OwnerIdentity.OwnerIdentity | PlanInputStore.PlanInputStore | PlanMergeStore.PlanMergeStore | PlanStore.PlanStore, import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError | import("@smthrs/journal/Journal").JournalError, import("effect/Crypto").Crypto>;
88
+ export declare const layerAt: (filename: string, options?: TestStoresOptions) => Layer.Layer<import("effect/sql/SqlClient").SqlClient | DurableWriter.DurableWriter | CacheStore.CacheStore | import("@smthrs/journal/Journal").Journal | RunStore.RunStore | DurableEngineState.DurableEngineState | AttemptStore.AttemptStore | OwnerIdentity.OwnerIdentity | PlanInputStore.PlanInputStore | PlanMergeStore.PlanMergeStore | PlanStore.PlanStore, import("effect/sql/SqlError").SqlError | import("effect/sql/Migrator").MigrationError | import("@smthrs/journal/Journal").JournalError, import("effect/Crypto").Crypto>;
89
89
  //# sourceMappingURL=TestStores.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TestStores.d.ts","sourceRoot":"","sources":["../../../src/test/TestStores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAA;AAI/D,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAA;AAC9D,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAA;AAE3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK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tD,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,aAAa,GAAG,aAAa,CAAA;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,mLAA2D,CAAA;AAEhF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAAI,UAAU,iBAAiB,6bAckB,CAAA;AAEnE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,sLAkB1C,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,MAAM,EAAE,UAAU,iBAAiB,ghBAce,CAAA"}
@@ -43,7 +43,7 @@ import * as Effect from "effect/Effect";
43
43
  import type * as FileSystem from "effect/FileSystem";
44
44
  import * as Layer from "effect/Layer";
45
45
  import * as Schema from "effect/Schema";
46
- import * as SqlClient from "effect/unstable/sql/SqlClient";
46
+ import * as SqlClient from "effect/sql/SqlClient";
47
47
  /**
48
48
  * Stable error codes returned by artifact garbage collection.
49
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ArtifactGc.d.ts","sourceRoot":"","sources":["../../src/ArtifactGc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,aAAa,MAAM,iCAAiC,CAAA;AAEhE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MA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A;AAEzC;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAS,WAAW,GAAG,aAAa,CAAC,YAAiB,KACrD,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAG1E,CAAA"}
@@ -44,7 +44,7 @@ import * as Effect from "effect/Effect";
44
44
  import * as Layer from "effect/Layer";
45
45
  import * as Option from "effect/Option";
46
46
  import * as Schema from "effect/Schema";
47
- import * as SqlClient from "effect/unstable/sql/SqlClient";
47
+ import * as SqlClient from "effect/sql/SqlClient";
48
48
  import * as ArtifactRoots from "./internal/ArtifactRoots.js";
49
49
  /**
50
50
  * Stable error codes returned by artifact garbage collection.
@@ -1 +1 @@
1
- {"version":3,"file":"ArtifactGc.js","sourceRoot":"","sources":["../../src/ArtifactGc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,aAAa,MAAM,iCAAiC,CAAA;AAChE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAC1D,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,iBAAiB,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAA;AAUtG;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,WAAW,EAAmB,CACxE,sCAAsC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S,EAAE,OAAO,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CACnH,CAAA","sourcesContent":["/**\n * Mark/sweep garbage collection for the content-addressed artifact store.\n *\n * The artifact tier is the one store in the composition with true *garbage*:\n * every output over the inline bound is spilled to `.flows/objects` by digest\n * (`StepBoundary`), nothing ever deletes a published blob, and a blob whose\n * every referencing row is gone is unreachable forever. The step cache is\n * deliberately NOT collected here — its rows are the *roots* of this graph,\n * they never become unreachable, and removing one is the policy decision\n * `CacheStore.evict` already serves.\n *\n * The design combines the two prior arts on the shelf:\n *\n * - **Reachability from durable roots** — git's `git gc` marks from refs;\n * Skyframe deletes what a keyed graph walk cannot reach. Here the roots are\n * every attempt row of every existing (never-deleted) run and every step\n * cache entry; each carries boundary evidence, and\n * `StepBoundary.referencedDigests` names the blobs that evidence needs.\n * Attempt checkpoints are roots too: they are opaque executable state, so\n * the mark keeps digest-shaped strings found in their JSON.\n * - **A grace period over mtime** — git refuses to prune unreachable objects\n * younger than `gc.pruneExpire` (two weeks), jj keeps operations newer than\n * its keep bound, and Bazel's disk-cache collector\n * (`reference/bazel/.../remote/disk/DiskCacheGarbageCollector.java`) fences\n * on mtime. The cutoff is the collection start time minus the grace period,\n * sampled before resolving policy pins or scanning roots and held fixed\n * through inventory and deletion. Only mtimes strictly before it are\n * eligible: a blob published — or freshened by a dedupe `put` — at or after\n * collection start survives, including same-millisecond writes at zero\n * grace, no lock required.\n *\n * Collection NEVER runs automatically. `gc()` is an explicit verb because\n * deletion is irreversible, and a human approving a plan must approve the\n * deletions too. The opt-in {@link ArtifactGcPolicy} layer\n * configures *how* an invocation collects (grace bound, pinned digests); it\n * does not schedule anything.\n *\n * @since 0.1.0\n */\n\nimport * as ArtifactSweep from \"@smthrs/artifacts/ArtifactSweep\"\nimport * as Clock from \"effect/Clock\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\"\nimport * as ArtifactRoots from \"./internal/ArtifactRoots.ts\"\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ArtifactGcErrorCode = Schema.Literals([\"invalid_options\", \"mark_failed\", \"sweep_failed\"])\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ArtifactGcErrorCode = typeof ArtifactGcErrorCode.Type\n\n/**\n * A collection that could not complete. `mark_failed` means the live set\n * could not be computed — nothing was deleted. `sweep_failed` means the live\n * set held but a deletion refused; everything already swept was garbage, so a\n * re-run converges from wherever the failure stopped it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class ArtifactGcError extends Schema.TaggedError<ArtifactGcError>()(\n \"@smthrs/engine-store/ArtifactGcError\",\n {\n code: ArtifactGcErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown)\n }\n) {}\n\n/**\n * The opt-in collection policy. Explicit {@link GcOptions} on a `gc()` call\n * override the installed policy; the policy overrides the defaults.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Policy {\n /** Grace bound applied when a `gc()` call does not name one. */\n readonly graceMs?: number | undefined\n /**\n * Digests held live regardless of reachability — the seam for references\n * this composition's tables cannot see (an external index, an export a\n * human wants kept). Resolved fresh on every collection.\n */\n readonly pins?: Effect.Effect<ReadonlyArray<string>> | undefined\n}\n\n/**\n * Service tag for the opt-in collection policy.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGcPolicy extends Context.Service<ArtifactGcPolicy, Policy>()(\n \"@smthrs/engine-store/ArtifactGcPolicy\"\n) {}\n\n/**\n * Installs a collection policy.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerPolicy = (policy: Policy): Layer.Layer<ArtifactGcPolicy> => Layer.succeed(ArtifactGcPolicy)(policy)\n\n/**\n * Options for one explicit collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcOptions {\n /**\n * How recently a blob must have been written or freshened to survive\n * unreferenced. Defaults to the installed {@link ArtifactGcPolicy}'s bound,\n * then to {@link defaultGraceMs}.\n */\n readonly graceMs?: number | undefined\n /** Digests held live for this collection, unioned with the policy's pins. */\n readonly pins?: ReadonlyArray<string> | undefined\n /** Compute and report without deleting anything. */\n readonly dryRun?: boolean | undefined\n}\n\n/**\n * What one collection did.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcReport {\n /** Blobs the inventory enumerated. */\n readonly scannedBlobs: number\n /** Distinct digests the mark phase proved live, pins included. */\n readonly liveDigests: number\n /** Digests deleted — or, under `dryRun`, the ones a real run would delete. */\n readonly sweptDigests: ReadonlyArray<string>\n /** Bytes the swept blobs held. */\n readonly reclaimedBytes: number\n /** Unreferenced blobs retained by the grace bound or a freshen race. */\n readonly keptByGrace: number\n readonly dryRun: boolean\n}\n\n/**\n * Explicit artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /**\n * Marks the live set from the durable roots, then sweeps every blob that\n * is both outside it and older than the grace bound. Explicit only —\n * nothing in the engine composition ever calls this.\n */\n readonly gc: (options?: GcOptions) => Effect.Effect<GcReport, ArtifactGcError>\n}\n\n/**\n * Service tag for artifact garbage collection.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGc extends Context.Service<ArtifactGc, Service>()(\"@smthrs/engine-store/ArtifactGc\") {}\n\n/**\n * Two weeks, git's `gc.pruneExpire` default. The bound is deliberately far\n * beyond any live attempt's duration: a blob spilled by a running step is\n * unreferenced until its attempt row finishes, and the grace period is the\n * only thing protecting it in that window.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultGraceMs = 14 * 24 * 60 * 60 * 1000\n\n/**\n * Construction options.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface MakeOptions {\n /** Rows per mark-phase page. Defaults to 500. */\n readonly pageSize?: number | undefined\n}\n\nconst markFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"mark_failed\", message, cause })\n\nconst sweepFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"sweep_failed\", message, cause })\n\nconst invalidOptions = (message: string): ArtifactGcError => new ArtifactGcError({ code: \"invalid_options\", message })\n\n/**\n * Extracts the digests one root row keeps live, FAIL-SAFE: a row whose\n * metadata carries a `boundary` this build cannot decode aborts the\n * collection rather than contributing nothing. Silently reading such a row as\n * \"references no artifacts\" is exactly how a live blob gets collected; a\n * metadata shape with no `boundary` key at all is the ordinary\n * foreign-evidence case `referencedDigests` already defines as empty.\n */\nconst rootDigests = (table: string, metaJson: string): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.rootDigests(table, metaJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\nconst checkpointDigests = (checkpointJson: string | null): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.checkpointDigests(checkpointJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\n/**\n * Builds the collector over the composition's own durable tables and the\n * host-local sweep surface.\n *\n * The mark phase reads `flows_step_cache` and `flows_attempts` directly, the\n * same way `DurableEngineState` range-scans `flows_runs`: this package\n * composes every one of those migrations, so the schema is its own. Every run\n * present in `flows_runs` is a live root — there is no deleted state, and the\n * attempt table's foreign key guarantees each attempt's run exists — so the\n * scan is simply *all* attempt rows plus *all* cache entries, paged by\n * primary key so no page holds more than `pageSize` rows in memory.\n *\n * Ordering is the safety argument. The live set is computed BEFORE the\n * inventory, so a root recorded during the sweep can only be missed, never\n * half-seen — and the blob such a root references is protected anyway: a\n * fresh publication carries a fresh mtime, a re-publication of existing bytes\n * freshens the blob's mtime (`ArtifactStore.put`), and the sweep's deletion\n * is fenced on that mtime (`ArtifactSweep.remove`'s `ifUnmodifiedSinceMs`).\n * A crash mid-sweep deletes some garbage and no live blobs; re-running\n * converges.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (\n options: MakeOptions = {}\n): Effect.Effect<Service, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Effect.gen(function*() {\n const sql = yield* Effect.service(SqlClient.SqlClient)\n const sweeper = yield* ArtifactSweep.ArtifactSweep\n const policy = yield* Effect.serviceOption(ArtifactGcPolicy)\n const pageSize = options.pageSize ?? 500\n\n const markCacheEntries = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = \"\"\n for (;;) {\n const rows = yield* sql<{ readonly key_digest: string; readonly meta_json: string }>`\n SELECT key_digest, meta_json FROM flows_step_cache\n WHERE key_digest > ${after}\n ORDER BY key_digest\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the step cache could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_step_cache\", row.meta_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n after = rows[rows.length - 1]!.key_digest\n }\n })\n\n const markAttempts = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = { runId: \"\", stepKeyDigest: \"\", attempt: -1 }\n for (;;) {\n const rows = yield* sql<{\n readonly run_id: string\n readonly step_key_digest: string\n readonly attempt: number\n readonly checkpoint_json: string | null\n readonly meta_json: string\n }>`\n SELECT run_id, step_key_digest, attempt, checkpoint_json, meta_json FROM flows_attempts\n WHERE (run_id, step_key_digest, attempt) > (${after.runId}, ${after.stepKeyDigest}, ${after.attempt})\n ORDER BY run_id, step_key_digest, attempt\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the attempt table could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_attempts\", row.meta_json)) {\n live.add(digest)\n }\n for (const digest of yield* checkpointDigests(row.checkpoint_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n const last = rows[rows.length - 1]!\n after = { runId: last.run_id, stepKeyDigest: last.step_key_digest, attempt: last.attempt }\n }\n })\n\n const gc: Service[\"gc\"] = Effect.fn(\"ArtifactGc.gc\")((gcOptions) =>\n Effect.gen(function*() {\n if (!Number.isSafeInteger(pageSize) || pageSize < 1) {\n return yield* Effect.fail(invalidOptions(\"artifact GC pageSize must be a positive safe integer\"))\n }\n const grace = gcOptions?.graceMs ??\n (Option.isSome(policy) ? policy.value.graceMs : undefined) ??\n defaultGraceMs\n if (!Number.isSafeInteger(grace) || grace < 0) {\n return yield* Effect.fail(invalidOptions(\"artifact GC graceMs must be a non-negative safe integer\"))\n }\n const startedAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n const bound = startedAtMs - grace\n const live = new Set<string>(gcOptions?.pins ?? [])\n if (Option.isSome(policy) && policy.value.pins !== undefined) {\n for (const digest of yield* policy.value.pins) live.add(digest)\n }\n yield* markCacheEntries(live)\n yield* markAttempts(live)\n const blobs = yield* sweeper.inventory.pipe(\n Effect.mapError((cause) => sweepFailed(`the blob inventory refused: ${cause.message}`, cause))\n )\n const swept: Array<string> = []\n let reclaimedBytes = 0\n let keptByGrace = 0\n for (const blob of blobs) {\n if (live.has(blob.digest)) continue\n if (blob.modifiedAtMs >= bound) {\n keptByGrace++\n continue\n }\n if (gcOptions?.dryRun === true) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n continue\n }\n // The fence re-reads the blob's age inside the deletion: an\n // unreferenced-at-mark blob a concurrent `put` freshened since the\n // inventory fails the fence and is retained, exactly as a fresher\n // cache row survives a laggard's fenced evict (issue #119).\n // remove's fence is inclusive; mtimes have millisecond resolution,\n // so exclude cutoff equality there just as in the inventory check.\n const removed = yield* sweeper.remove(blob.digest, { ifUnmodifiedSinceMs: bound - 1 }).pipe(\n Effect.mapError((cause) => sweepFailed(`sweeping ${blob.digest} refused: ${cause.message}`, cause))\n )\n if (removed) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n } else {\n keptByGrace++\n }\n }\n return {\n scannedBlobs: blobs.length,\n liveDigests: live.size,\n sweptDigests: swept,\n reclaimedBytes,\n keptByGrace,\n dryRun: gcOptions?.dryRun === true\n }\n })\n )\n\n return { gc }\n })\n\n/**\n * Provides the artifact garbage collector. Install {@link layerPolicy} into\n * this layer's inputs to configure collection; nothing schedules `gc()` —\n * invoking it stays an explicit caller decision.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = (\n options: MakeOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Layer.effect(ArtifactGc)(make(options))\n\n/**\n * Provides the artifact garbage collector over a filesystem objects directory:\n * {@link layer} with `ArtifactSweep.layerFileSystem` beneath it. Pass the same\n * `directory` and `coordination` the paired `ArtifactStore.layerFileSystem`\n * publishes with.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerFileSystem = (\n options: MakeOptions & ArtifactSweep.SweepOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | FileSystem.FileSystem> =>\n layer(options).pipe(\n Layer.provide(ArtifactSweep.layerFileSystem({ directory: options.directory, coordination: options.coordination }))\n )\n"]}
1
+ {"version":3,"file":"ArtifactGc.js","sourceRoot":"","sources":["../../src/ArtifactGc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,aAAa,MAAM,iCAAiC,CAAA;AAChE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,aAAa,MAAM,6BAA6B,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C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAoD,EAAE,EACuB,EAAE,CAC/E,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CACjB,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CACnH,CAAA","sourcesContent":["/**\n * Mark/sweep garbage collection for the content-addressed artifact store.\n *\n * The artifact tier is the one store in the composition with true *garbage*:\n * every output over the inline bound is spilled to `.flows/objects` by digest\n * (`StepBoundary`), nothing ever deletes a published blob, and a blob whose\n * every referencing row is gone is unreachable forever. The step cache is\n * deliberately NOT collected here — its rows are the *roots* of this graph,\n * they never become unreachable, and removing one is the policy decision\n * `CacheStore.evict` already serves.\n *\n * The design combines the two prior arts on the shelf:\n *\n * - **Reachability from durable roots** — git's `git gc` marks from refs;\n * Skyframe deletes what a keyed graph walk cannot reach. Here the roots are\n * every attempt row of every existing (never-deleted) run and every step\n * cache entry; each carries boundary evidence, and\n * `StepBoundary.referencedDigests` names the blobs that evidence needs.\n * Attempt checkpoints are roots too: they are opaque executable state, so\n * the mark keeps digest-shaped strings found in their JSON.\n * - **A grace period over mtime** — git refuses to prune unreachable objects\n * younger than `gc.pruneExpire` (two weeks), jj keeps operations newer than\n * its keep bound, and Bazel's disk-cache collector\n * (`reference/bazel/.../remote/disk/DiskCacheGarbageCollector.java`) fences\n * on mtime. The cutoff is the collection start time minus the grace period,\n * sampled before resolving policy pins or scanning roots and held fixed\n * through inventory and deletion. Only mtimes strictly before it are\n * eligible: a blob published — or freshened by a dedupe `put` — at or after\n * collection start survives, including same-millisecond writes at zero\n * grace, no lock required.\n *\n * Collection NEVER runs automatically. `gc()` is an explicit verb because\n * deletion is irreversible, and a human approving a plan must approve the\n * deletions too. The opt-in {@link ArtifactGcPolicy} layer\n * configures *how* an invocation collects (grace bound, pinned digests); it\n * does not schedule anything.\n *\n * @since 0.1.0\n */\n\nimport * as ArtifactSweep from \"@smthrs/artifacts/ArtifactSweep\"\nimport * as Clock from \"effect/Clock\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/sql/SqlClient\"\nimport * as ArtifactRoots from \"./internal/ArtifactRoots.ts\"\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ArtifactGcErrorCode = Schema.Literals([\"invalid_options\", \"mark_failed\", \"sweep_failed\"])\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ArtifactGcErrorCode = typeof ArtifactGcErrorCode.Type\n\n/**\n * A collection that could not complete. `mark_failed` means the live set\n * could not be computed — nothing was deleted. `sweep_failed` means the live\n * set held but a deletion refused; everything already swept was garbage, so a\n * re-run converges from wherever the failure stopped it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class ArtifactGcError extends Schema.TaggedError<ArtifactGcError>()(\n \"@smthrs/engine-store/ArtifactGcError\",\n {\n code: ArtifactGcErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown)\n }\n) {}\n\n/**\n * The opt-in collection policy. Explicit {@link GcOptions} on a `gc()` call\n * override the installed policy; the policy overrides the defaults.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Policy {\n /** Grace bound applied when a `gc()` call does not name one. */\n readonly graceMs?: number | undefined\n /**\n * Digests held live regardless of reachability — the seam for references\n * this composition's tables cannot see (an external index, an export a\n * human wants kept). Resolved fresh on every collection.\n */\n readonly pins?: Effect.Effect<ReadonlyArray<string>> | undefined\n}\n\n/**\n * Service tag for the opt-in collection policy.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGcPolicy extends Context.Service<ArtifactGcPolicy, Policy>()(\n \"@smthrs/engine-store/ArtifactGcPolicy\"\n) {}\n\n/**\n * Installs a collection policy.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerPolicy = (policy: Policy): Layer.Layer<ArtifactGcPolicy> => Layer.succeed(ArtifactGcPolicy)(policy)\n\n/**\n * Options for one explicit collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcOptions {\n /**\n * How recently a blob must have been written or freshened to survive\n * unreferenced. Defaults to the installed {@link ArtifactGcPolicy}'s bound,\n * then to {@link defaultGraceMs}.\n */\n readonly graceMs?: number | undefined\n /** Digests held live for this collection, unioned with the policy's pins. */\n readonly pins?: ReadonlyArray<string> | undefined\n /** Compute and report without deleting anything. */\n readonly dryRun?: boolean | undefined\n}\n\n/**\n * What one collection did.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcReport {\n /** Blobs the inventory enumerated. */\n readonly scannedBlobs: number\n /** Distinct digests the mark phase proved live, pins included. */\n readonly liveDigests: number\n /** Digests deleted — or, under `dryRun`, the ones a real run would delete. */\n readonly sweptDigests: ReadonlyArray<string>\n /** Bytes the swept blobs held. */\n readonly reclaimedBytes: number\n /** Unreferenced blobs retained by the grace bound or a freshen race. */\n readonly keptByGrace: number\n readonly dryRun: boolean\n}\n\n/**\n * Explicit artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /**\n * Marks the live set from the durable roots, then sweeps every blob that\n * is both outside it and older than the grace bound. Explicit only —\n * nothing in the engine composition ever calls this.\n */\n readonly gc: (options?: GcOptions) => Effect.Effect<GcReport, ArtifactGcError>\n}\n\n/**\n * Service tag for artifact garbage collection.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGc extends Context.Service<ArtifactGc, Service>()(\"@smthrs/engine-store/ArtifactGc\") {}\n\n/**\n * Two weeks, git's `gc.pruneExpire` default. The bound is deliberately far\n * beyond any live attempt's duration: a blob spilled by a running step is\n * unreferenced until its attempt row finishes, and the grace period is the\n * only thing protecting it in that window.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultGraceMs = 14 * 24 * 60 * 60 * 1000\n\n/**\n * Construction options.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface MakeOptions {\n /** Rows per mark-phase page. Defaults to 500. */\n readonly pageSize?: number | undefined\n}\n\nconst markFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"mark_failed\", message, cause })\n\nconst sweepFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"sweep_failed\", message, cause })\n\nconst invalidOptions = (message: string): ArtifactGcError => new ArtifactGcError({ code: \"invalid_options\", message })\n\n/**\n * Extracts the digests one root row keeps live, FAIL-SAFE: a row whose\n * metadata carries a `boundary` this build cannot decode aborts the\n * collection rather than contributing nothing. Silently reading such a row as\n * \"references no artifacts\" is exactly how a live blob gets collected; a\n * metadata shape with no `boundary` key at all is the ordinary\n * foreign-evidence case `referencedDigests` already defines as empty.\n */\nconst rootDigests = (table: string, metaJson: string): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.rootDigests(table, metaJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\nconst checkpointDigests = (checkpointJson: string | null): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.checkpointDigests(checkpointJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\n/**\n * Builds the collector over the composition's own durable tables and the\n * host-local sweep surface.\n *\n * The mark phase reads `flows_step_cache` and `flows_attempts` directly, the\n * same way `DurableEngineState` range-scans `flows_runs`: this package\n * composes every one of those migrations, so the schema is its own. Every run\n * present in `flows_runs` is a live root — there is no deleted state, and the\n * attempt table's foreign key guarantees each attempt's run exists — so the\n * scan is simply *all* attempt rows plus *all* cache entries, paged by\n * primary key so no page holds more than `pageSize` rows in memory.\n *\n * Ordering is the safety argument. The live set is computed BEFORE the\n * inventory, so a root recorded during the sweep can only be missed, never\n * half-seen — and the blob such a root references is protected anyway: a\n * fresh publication carries a fresh mtime, a re-publication of existing bytes\n * freshens the blob's mtime (`ArtifactStore.put`), and the sweep's deletion\n * is fenced on that mtime (`ArtifactSweep.remove`'s `ifUnmodifiedSinceMs`).\n * A crash mid-sweep deletes some garbage and no live blobs; re-running\n * converges.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (\n options: MakeOptions = {}\n): Effect.Effect<Service, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Effect.gen(function*() {\n const sql = yield* Effect.service(SqlClient.SqlClient)\n const sweeper = yield* ArtifactSweep.ArtifactSweep\n const policy = yield* Effect.serviceOption(ArtifactGcPolicy)\n const pageSize = options.pageSize ?? 500\n\n const markCacheEntries = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = \"\"\n for (;;) {\n const rows = yield* sql<{ readonly key_digest: string; readonly meta_json: string }>`\n SELECT key_digest, meta_json FROM flows_step_cache\n WHERE key_digest > ${after}\n ORDER BY key_digest\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the step cache could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_step_cache\", row.meta_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n after = rows[rows.length - 1]!.key_digest\n }\n })\n\n const markAttempts = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = { runId: \"\", stepKeyDigest: \"\", attempt: -1 }\n for (;;) {\n const rows = yield* sql<{\n readonly run_id: string\n readonly step_key_digest: string\n readonly attempt: number\n readonly checkpoint_json: string | null\n readonly meta_json: string\n }>`\n SELECT run_id, step_key_digest, attempt, checkpoint_json, meta_json FROM flows_attempts\n WHERE (run_id, step_key_digest, attempt) > (${after.runId}, ${after.stepKeyDigest}, ${after.attempt})\n ORDER BY run_id, step_key_digest, attempt\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the attempt table could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_attempts\", row.meta_json)) {\n live.add(digest)\n }\n for (const digest of yield* checkpointDigests(row.checkpoint_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n const last = rows[rows.length - 1]!\n after = { runId: last.run_id, stepKeyDigest: last.step_key_digest, attempt: last.attempt }\n }\n })\n\n const gc: Service[\"gc\"] = Effect.fn(\"ArtifactGc.gc\")((gcOptions) =>\n Effect.gen(function*() {\n if (!Number.isSafeInteger(pageSize) || pageSize < 1) {\n return yield* Effect.fail(invalidOptions(\"artifact GC pageSize must be a positive safe integer\"))\n }\n const grace = gcOptions?.graceMs ??\n (Option.isSome(policy) ? policy.value.graceMs : undefined) ??\n defaultGraceMs\n if (!Number.isSafeInteger(grace) || grace < 0) {\n return yield* Effect.fail(invalidOptions(\"artifact GC graceMs must be a non-negative safe integer\"))\n }\n const startedAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n const bound = startedAtMs - grace\n const live = new Set<string>(gcOptions?.pins ?? [])\n if (Option.isSome(policy) && policy.value.pins !== undefined) {\n for (const digest of yield* policy.value.pins) live.add(digest)\n }\n yield* markCacheEntries(live)\n yield* markAttempts(live)\n const blobs = yield* sweeper.inventory.pipe(\n Effect.mapError((cause) => sweepFailed(`the blob inventory refused: ${cause.message}`, cause))\n )\n const swept: Array<string> = []\n let reclaimedBytes = 0\n let keptByGrace = 0\n for (const blob of blobs) {\n if (live.has(blob.digest)) continue\n if (blob.modifiedAtMs >= bound) {\n keptByGrace++\n continue\n }\n if (gcOptions?.dryRun === true) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n continue\n }\n // The fence re-reads the blob's age inside the deletion: an\n // unreferenced-at-mark blob a concurrent `put` freshened since the\n // inventory fails the fence and is retained, exactly as a fresher\n // cache row survives a laggard's fenced evict (issue #119).\n // remove's fence is inclusive; mtimes have millisecond resolution,\n // so exclude cutoff equality there just as in the inventory check.\n const removed = yield* sweeper.remove(blob.digest, { ifUnmodifiedSinceMs: bound - 1 }).pipe(\n Effect.mapError((cause) => sweepFailed(`sweeping ${blob.digest} refused: ${cause.message}`, cause))\n )\n if (removed) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n } else {\n keptByGrace++\n }\n }\n return {\n scannedBlobs: blobs.length,\n liveDigests: live.size,\n sweptDigests: swept,\n reclaimedBytes,\n keptByGrace,\n dryRun: gcOptions?.dryRun === true\n }\n })\n )\n\n return { gc }\n })\n\n/**\n * Provides the artifact garbage collector. Install {@link layerPolicy} into\n * this layer's inputs to configure collection; nothing schedules `gc()` —\n * invoking it stays an explicit caller decision.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = (\n options: MakeOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Layer.effect(ArtifactGc)(make(options))\n\n/**\n * Provides the artifact garbage collector over a filesystem objects directory:\n * {@link layer} with `ArtifactSweep.layerFileSystem` beneath it. Pass the same\n * `directory` and `coordination` the paired `ArtifactStore.layerFileSystem`\n * publishes with.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerFileSystem = (\n options: MakeOptions & ArtifactSweep.SweepOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | FileSystem.FileSystem> =>\n layer(options).pipe(\n Layer.provide(ArtifactSweep.layerFileSystem({ directory: options.directory, coordination: options.coordination }))\n )\n"]}
@@ -36,7 +36,7 @@ import { Journal, JournalEvent, Projection } from "@smthrs/journal";
36
36
  import * as Effect from "effect/Effect";
37
37
  import * as Option from "effect/Option";
38
38
  import * as Schema from "effect/Schema";
39
- import * as SqlClient from "effect/unstable/sql/SqlClient";
39
+ import * as SqlClient from "effect/sql/SqlClient";
40
40
  /**
41
41
  * The journal event types the fold reads.
42
42
  *
@@ -276,7 +276,7 @@ export declare const capture: (runId: string, upTo: number) => Effect.Effect<{
276
276
  readonly exitDigest?: string;
277
277
  readonly metadataDigest?: string | null;
278
278
  }[];
279
- }, import("effect/unstable/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
279
+ }, import("effect/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
280
280
  /**
281
281
  * A checkpoint state that keeps the fold: `base` (an object, or nothing) with
282
282
  * the run's fold up to `upTo` under {@link checkpointKey}. A composition that
@@ -306,7 +306,7 @@ export declare const checkpointState: (runId: string, upTo: number, base?: Reado
306
306
  readonly metadataDigest?: string | null;
307
307
  }[];
308
308
  };
309
- }, import("effect/unstable/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
309
+ }, import("effect/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
310
310
  /**
311
311
  * What a {@link rebuild} read and wrote.
312
312
  *
@@ -349,6 +349,6 @@ export declare const rebuild: () => Effect.Effect<{
349
349
  clocks: number;
350
350
  deferreds: number;
351
351
  unexplained: number;
352
- }, import("effect/unstable/sql/SqlError").SqlError | import("@smthrs/database/DurableWriter").DatabaseError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | DurableWriter | Journal.Journal>;
352
+ }, import("effect/sql/SqlError").SqlError | import("@smthrs/database/DurableWriter").DatabaseError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | DurableWriter | Journal.Journal>;
353
353
  export {};
354
354
  //# sourceMappingURL=DeferredClockFold.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeferredClockFold.d.ts","sourceRoot":"","sources":["../../src/DeferredClockFold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,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;;GAOG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;yHAElB,CAAA;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;yHAM1B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAUD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,OAAO;;;;;kMAkGlB,CAAA"}
@@ -36,7 +36,7 @@ import { Journal, JournalEvent, Projection } from "@smthrs/journal";
36
36
  import * as Effect from "effect/Effect";
37
37
  import * as Option from "effect/Option";
38
38
  import * as Schema from "effect/Schema";
39
- import * as SqlClient from "effect/unstable/sql/SqlClient";
39
+ import * as SqlClient from "effect/sql/SqlClient";
40
40
  import { EventTypes } from "./EventTypes.js";
41
41
  /**
42
42
  * The journal event types the fold reads.
@@ -1 +1 @@
1
- {"version":3,"file":"DeferredClockFold.js","sourceRoot":"","sources":["../../src/DeferredClockFold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAC1D,OAAO,EAAE,UAAU,E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M,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,KAAK,CAAC,CAAC,GAAG,CAAA;;yCAEyB,QAAQ,CAAC,aAAa;+BAChC,QAAQ,CAAC,YAAY;4BACxB,QAAQ,CAAC,QAAQ;+BACd,QAAQ,CAAC,WAAW;gCACnB,QAAQ,CAAC,YAAY;OAC9C,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAC,CAAA;IACH,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,SAAS,CAAC,MAAM;QAC3B,WAAW,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM;KAC1B,CAAA;AACrB,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The deferred/clock fold: `flows_clock_deadlines` and the mutable half of\n * `flows_deferred_completions` rebuilt from the journal.\n *\n * Every change to either table is journalled on the run's own stream in the\n * transaction that makes it:\n *\n * - `flows.engine.clock-scheduled` when a clock row is inserted;\n * - `flows.engine.clock-completed` when a clock fires or its run settles\n * first (`completeClock`, `completeRunClocks`);\n * - `flows.engine.deferred-completed` when the first completion wins, naming\n * the row and the {@link JournalEvent.contentDigest} of its encoded `exit`\n * and `metadata`;\n * - `flows.engine.deferred-consumed` when a run first observes a result.\n *\n * The journal is redacted and replayed to sync subscribers, so it never\n * carries a completion's value (issue #72). A clock row holds no value at\n * all, so the fold rebuilds it whole. A completion row's value stays in the\n * row: the fold rebuilds its `completed_at_ms` and `consumed_at_ms`, and a\n * rebuild checks the stored text against the recorded digests. A completion\n * the journal names but no row holds, or holds with other bytes, is a typed\n * {@link FoldIncomplete}, never a silent gap.\n *\n * Compaction deletes a run's entries below its floor, so the fold's state at\n * the floor has to survive in the floor's checkpoint: {@link checkpointState}\n * adds it under {@link checkpointKey}, and a rebuild of a compacted run whose\n * floor checkpoint lacks it fails {@link FoldIncomplete} with reason\n * `checkpoint_missing`. A rewind archives the suffix and removes the rows it\n * explains (`@smthrs/time-travel`), so the remaining journal still explains\n * the remaining rows.\n *\n * @since 1.0.0\n */\n\nimport { DurableWriter } from \"@smthrs/database/DurableWriter\"\nimport { Journal, JournalEvent, Projection } from \"@smthrs/journal\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\"\nimport { EventTypes } from \"./EventTypes.ts\"\n\n/**\n * The journal event types the fold reads.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const eventTypes: ReadonlyArray<string> = [\n EventTypes.clockScheduled,\n EventTypes.clockCompleted,\n EventTypes.deferredCompleted,\n EventTypes.deferredConsumed\n]\n\n/**\n * The key a checkpoint's state keeps the fold under.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const checkpointKey = \"flows.engine.deferred-clock\"\n\nconst NonNegativeSafeInt = Schema.Int.check(\n Schema.isGreaterThanOrEqualTo(0),\n Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)\n)\nconst Digest = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/))\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Clock = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n clockName: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n dueAtMs: NonNegativeSafeInt,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Clock = typeof Clock.Type\n\n/**\n * A deferred completion as the journal records it. A completion journalled\n * before the fold existed carried its (redacted) value instead of digests and\n * no completion time: `exitDigest` and `metadataDigest` are then absent and\n * `completedAtMs` is `null`, and a rebuild keeps the row's own stamp.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Deferred = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt),\n exitDigest: Schema.optionalKey(Digest),\n metadataDigest: Schema.optionalKey(Schema.NullOr(Digest)),\n consumedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A deferred completion as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Deferred = typeof Deferred.Type\n\n/**\n * The folded clocks and completions, keyed by their row address.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface State {\n readonly clocks: ReadonlyMap<string, Clock>\n readonly deferreds: ReadonlyMap<string, Deferred>\n}\n\n/**\n * The empty fold.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const initial: State = { clocks: new Map(), deferreds: new Map() }\n\n/**\n * The key of a clock row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const clockKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly clockName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.clockName])\n\n/**\n * The key of a completion row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const deferredKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly deferredName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.deferredName])\n\nconst record = (value: unknown): Readonly<Record<string, unknown>> | undefined =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? value as Readonly<Record<string, unknown>>\n : undefined\n\nconst text = (value: unknown): value is string => typeof value === \"string\" && value.length > 0\nconst time = (value: unknown): value is number => typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0\nconst digest = (value: unknown): value is string => typeof value === \"string\" && /^[0-9a-f]{64}$/.test(value)\n\n/**\n * Folds one committed journal entry. First writes win: a clock keeps its first\n * schedule and first completion, and a completion its first recording and\n * first consumption, exactly as the rows do. An entry of another type, or one\n * whose payload names no row, leaves the state unchanged.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const reduce = (state: State, entry: JournalEvent.Entry): State => {\n const payload = record(entry.payload)\n if (payload === undefined || !text(payload.flowName) || !text(payload.executionId)) return state\n const flowName = payload.flowName\n const executionId = payload.executionId\n switch (entry.eventType) {\n case EventTypes.clockScheduled: {\n if (!text(payload.clockName) || !text(payload.deferredName) || !time(payload.dueAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n if (state.clocks.has(key)) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, {\n flowName,\n executionId,\n clockName: payload.clockName,\n deferredName: payload.deferredName,\n dueAtMs: payload.dueAtMs,\n completedAtMs: null\n })\n return { ...state, clocks }\n }\n case EventTypes.clockCompleted: {\n if (!text(payload.clockName) || !time(payload.completedAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n const clock = state.clocks.get(key)\n if (clock === undefined || clock.completedAtMs !== null) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, { ...clock, completedAtMs: payload.completedAtMs })\n return { ...state, clocks }\n }\n case EventTypes.deferredCompleted: {\n if (!text(payload.deferredName)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n if (state.deferreds.has(key)) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, {\n flowName,\n executionId,\n deferredName: payload.deferredName,\n completedAtMs: time(payload.completedAtMs) ? payload.completedAtMs : null,\n ...(digest(payload.exitDigest) ? { exitDigest: payload.exitDigest } : {}),\n ...(digest(payload.exitDigest) && (payload.metadataDigest === null || digest(payload.metadataDigest))\n ? { metadataDigest: payload.metadataDigest }\n : {}),\n consumedAtMs: null\n })\n return { ...state, deferreds }\n }\n case EventTypes.deferredConsumed: {\n if (!text(payload.deferredName) || !time(payload.consumedAtMs)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n const deferred = state.deferreds.get(key)\n if (deferred === undefined || deferred.consumedAtMs !== null) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, { ...deferred, consumedAtMs: payload.consumedAtMs })\n return { ...state, deferreds }\n }\n default:\n return state\n }\n}\n\n/**\n * The fold as a journal projection, for `Journal.project` over one run.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const projection: Projection.Projection<State> = Projection.make({\n name: \"flows.engine.deferred-clock\",\n initial,\n reduce: (state, entry) => Effect.succeed(reduce(state, entry))\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Encoded = Schema.Struct({\n clocks: Schema.Array(Clock),\n deferreds: Schema.Array(Deferred)\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Encoded = typeof Encoded.Type\n\n/**\n * Encodes the fold for a checkpoint.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const encode = (state: State): Encoded => ({\n clocks: [...state.clocks.values()],\n deferreds: [...state.deferreds.values()]\n})\n\n/**\n * Decodes the fold a checkpoint kept, or `None` when the checkpoint state\n * holds none under {@link checkpointKey}.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const fromCheckpoint = (checkpointState: unknown): Option.Option<State> => {\n const kept = record(checkpointState)?.[checkpointKey]\n if (kept === undefined) return Option.none()\n const decoded = Schema.decodeUnknownOption(Encoded)(kept)\n return Option.map(decoded, (encoded) => ({\n clocks: new Map(encoded.clocks.map((clock) => [clockKey(clock), clock])),\n deferreds: new Map(encoded.deferreds.map((deferred) => [deferredKey(deferred), deferred]))\n }))\n}\n\n/**\n * Why a rebuild could not reconstruct the tables.\n *\n * - `row_missing`: the journal names a completion no row holds.\n * - `digest_mismatch`: the row holds other bytes than the journal recorded.\n * - `run_missing`: a clock's run has no `flows_runs` row to hang it on.\n * - `checkpoint_missing`: a compacted run's floor checkpoint keeps no fold.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const FoldIncompleteReason = Schema.Literals([\n \"row_missing\",\n \"digest_mismatch\",\n \"run_missing\",\n \"checkpoint_missing\"\n])\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const Unjoined = Schema.Struct({\n reason: FoldIncompleteReason,\n executionId: Schema.String,\n flowName: Schema.optionalKey(Schema.String),\n name: Schema.optionalKey(Schema.String)\n})\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport type Unjoined = typeof Unjoined.Type\n\n/**\n * The journal references state the store no longer holds. The rebuild wrote\n * nothing.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class FoldIncomplete extends Schema.TaggedError<FoldIncomplete>()(\n \"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\",\n {\n code: Schema.Literal(\"fold_incomplete\"),\n message: Schema.String,\n unjoined: Schema.Array(Unjoined)\n }\n) {}\n\nconst pageSize = 512\n\n/** Folds one run's entries after `after` into `start`, in sequence order. */\nconst foldEntries = (\n journal: Journal.Service,\n runId: string,\n start: State,\n after: JournalEvent.Seq | undefined,\n upTo?: number | undefined\n) =>\n Effect.gen(function*() {\n let state = start\n let cursor = after\n while (true) {\n const page = yield* journal.entries({\n runId: runId as JournalEvent.RunId,\n eventTypes,\n limit: pageSize,\n ...(cursor === undefined ? {} : { after: cursor })\n })\n for (const entry of page.entries) {\n if (upTo !== undefined && entry.seq > upTo) return state\n state = reduce(state, entry)\n cursor = entry.seq\n }\n if (!page.hasMore) return state\n }\n })\n\n/** The run's compaction floor checkpoint, if compaction ever ran. */\nconst floorOf = (sql: SqlClient.SqlClient, runId: string) =>\n sql<{ readonly seq: number | string; readonly state_json: string }>`\n SELECT seq, state_json FROM flows_journal_checkpoints\n WHERE run_id = ${runId} AND compacted_at_ms IS NOT NULL\n ORDER BY seq DESC LIMIT 1\n `.pipe(Effect.map((rows) => rows[0]))\n\n/**\n * Folds one run: its floor checkpoint's fold, if it was compacted, then every\n * entry above the floor, up to and including `upTo` when given.\n */\nconst foldRun = (runId: string, upTo?: number | undefined) =>\n Effect.gen(function*() {\n const journal = yield* Journal.Journal\n const sql = yield* SqlClient.SqlClient\n const floor = yield* floorOf(sql, runId)\n if (floor === undefined) return yield* foldEntries(journal, runId, initial, undefined, upTo)\n const kept = fromCheckpoint(JSON.parse(floor.state_json) as unknown)\n if (Option.isNone(kept)) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `run ${runId} was compacted below a checkpoint that keeps no deferred/clock fold`,\n unjoined: [{ reason: \"checkpoint_missing\", executionId: runId }]\n })\n )\n }\n return yield* foldEntries(journal, runId, kept.value, Number(floor.seq) as JournalEvent.Seq, upTo)\n })\n\n/**\n * The fold of one run's entries up to and including `upTo`, for the state of\n * a checkpoint at `upTo`. It starts from the run's floor checkpoint when the\n * run was compacted before.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const capture = Effect.fn(\"DeferredClockFold.capture\")(function*(runId: string, upTo: number) {\n return encode(yield* foldRun(runId, upTo))\n})\n\n/**\n * A checkpoint state that keeps the fold: `base` (an object, or nothing) with\n * the run's fold up to `upTo` under {@link checkpointKey}. A composition that\n * compacts runs writes its checkpoints through this, so compaction cannot\n * lose the deferred/clock history.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const checkpointState = Effect.fn(\"DeferredClockFold.checkpointState\")(function*(\n runId: string,\n upTo: number,\n base?: Readonly<Record<string, unknown>> | undefined\n) {\n return { ...base, [checkpointKey]: yield* capture(runId, upTo) }\n})\n\n/**\n * What a {@link rebuild} read and wrote.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Rebuilt {\n /** Runs with deferred or clock entries, or with a compaction floor. */\n readonly runs: number\n /** Clock rows written. */\n readonly clocks: number\n /** Completion rows whose completion and consumption were rewritten. */\n readonly deferreds: number\n /** Completion rows no journal entry explains, left as they are. */\n readonly unexplained: number\n}\n\ninterface StoredDeferred {\n readonly flow_name: string\n readonly execution_id: string\n readonly deferred_name: string\n readonly exit_json: string\n readonly metadata_json: string | null\n}\n\n/**\n * Rebuilds `flows_clock_deadlines` and the completion and consumption stamps\n * of `flows_deferred_completions` from the journal.\n *\n * Every run with deferred or clock entries, and every compacted run, is\n * folded in sequence order, from its floor checkpoint when it was compacted;\n * a compacted run whose floor keeps no fold fails, even one that never had a\n * clock, because the journal can no longer say. Every reference is joined\n * before anything is written: a completion with no row or with other bytes,\n * a clock whose run is gone, or a compacted run whose floor keeps no fold\n * fails {@link FoldIncomplete} listing each one, and nothing is written.\n * Otherwise, in one writer transaction, the clock table is replaced by the\n * fold's clocks and each folded completion row gets the fold's\n * `completed_at_ms` and `consumed_at_ms`. A completion row the journal does\n * not explain is left alone and counted.\n *\n * Run it on a quiescent store, as a restore does.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const rebuild = Effect.fn(\"DeferredClockFold.rebuild\")(function*() {\n const sql = yield* SqlClient.SqlClient\n const writer = yield* DurableWriter\n // A compacted run may have no fold entry left above its floor, so every run\n // with a compaction floor is folded too.\n const runs = yield* sql<{ readonly run_id: string }>`\n SELECT run_id FROM flows_journal_events WHERE ${sql.in(\"event_type\", eventTypes)}\n UNION\n SELECT run_id FROM flows_journal_checkpoints WHERE compacted_at_ms IS NOT NULL\n ORDER BY run_id\n `\n const unjoined: Array<Unjoined> = []\n const clocks: Array<Clock> = []\n const deferreds: Array<Deferred> = []\n for (const { run_id } of runs) {\n const state = yield* foldRun(run_id).pipe(\n Effect.catchTag(\"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\", (error) => {\n unjoined.push(...error.unjoined)\n return Effect.succeed(initial)\n })\n )\n clocks.push(...state.clocks.values())\n deferreds.push(...state.deferreds.values())\n }\n const liveRuns = new Set(\n (yield* sql<{ readonly run_id: string }>`SELECT run_id FROM flows_runs`).map((row) => row.run_id)\n )\n for (const clock of clocks) {\n if (!liveRuns.has(clock.executionId)) {\n unjoined.push({\n reason: \"run_missing\",\n executionId: clock.executionId,\n flowName: clock.flowName,\n name: clock.clockName\n })\n }\n }\n const stored = new Map(\n (yield* sql<StoredDeferred>`\n SELECT flow_name, execution_id, deferred_name, exit_json, metadata_json\n FROM flows_deferred_completions\n `).map((row) => [\n deferredKey({ flowName: row.flow_name, executionId: row.execution_id, deferredName: row.deferred_name }),\n row\n ])\n )\n for (const deferred of deferreds) {\n const row = stored.get(deferredKey(deferred))\n const reference = { executionId: deferred.executionId, flowName: deferred.flowName, name: deferred.deferredName }\n if (row === undefined) {\n unjoined.push({ reason: \"row_missing\", ...reference })\n } else if (\n (deferred.exitDigest !== undefined && JournalEvent.contentDigest(row.exit_json) !== deferred.exitDigest) ||\n (deferred.metadataDigest !== undefined &&\n (row.metadata_json === null ? null : JournalEvent.contentDigest(row.metadata_json)) !==\n deferred.metadataDigest)\n ) {\n unjoined.push({ reason: \"digest_mismatch\", ...reference })\n }\n }\n if (unjoined.length > 0) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `the journal references ${unjoined.length} deferred/clock rows the store cannot join`,\n unjoined\n })\n )\n }\n yield* writer.write(Effect.gen(function*() {\n yield* sql`DELETE FROM flows_clock_deadlines`\n for (const clock of clocks) {\n yield* sql`\n INSERT INTO flows_clock_deadlines (\n flow_name, execution_id, clock_name, deferred_name, due_at_ms, completed_at_ms\n ) VALUES (\n ${clock.flowName}, ${clock.executionId}, ${clock.clockName}, ${clock.deferredName},\n ${clock.dueAtMs}, ${clock.completedAtMs}\n )\n `\n }\n for (const deferred of deferreds) {\n yield* sql`\n UPDATE flows_deferred_completions\n SET completed_at_ms = COALESCE(${deferred.completedAtMs}, completed_at_ms),\n consumed_at_ms = ${deferred.consumedAtMs}\n WHERE flow_name = ${deferred.flowName}\n AND execution_id = ${deferred.executionId}\n AND deferred_name = ${deferred.deferredName}\n `\n }\n }))\n return {\n runs: runs.length,\n clocks: clocks.length,\n deferreds: deferreds.length,\n unexplained: stored.size - deferreds.length\n } satisfies Rebuilt\n})\n"]}
1
+ {"version":3,"file":"DeferredClockFold.js","sourceRoot":"","sources":["../../src/DeferredClockFold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EA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AAK,CAAC,CAAC,GAAG,CAAA;;;;YAIJ,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,YAAY;YAC/E,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,aAAa;;OAE1C,CAAA;QACH,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,KAAK,CAAC,CAAC,GAAG,CAAA;;yCAEyB,QAAQ,CAAC,aAAa;+BAChC,QAAQ,CAAC,YAAY;4BACxB,QAAQ,CAAC,QAAQ;+BACd,QAAQ,CAAC,WAAW;gCACnB,QAAQ,CAAC,YAAY;OAC9C,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAC,CAAA;IACH,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,SAAS,CAAC,MAAM;QAC3B,WAAW,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM;KAC1B,CAAA;AACrB,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The deferred/clock fold: `flows_clock_deadlines` and the mutable half of\n * `flows_deferred_completions` rebuilt from the journal.\n *\n * Every change to either table is journalled on the run's own stream in the\n * transaction that makes it:\n *\n * - `flows.engine.clock-scheduled` when a clock row is inserted;\n * - `flows.engine.clock-completed` when a clock fires or its run settles\n * first (`completeClock`, `completeRunClocks`);\n * - `flows.engine.deferred-completed` when the first completion wins, naming\n * the row and the {@link JournalEvent.contentDigest} of its encoded `exit`\n * and `metadata`;\n * - `flows.engine.deferred-consumed` when a run first observes a result.\n *\n * The journal is redacted and replayed to sync subscribers, so it never\n * carries a completion's value (issue #72). A clock row holds no value at\n * all, so the fold rebuilds it whole. A completion row's value stays in the\n * row: the fold rebuilds its `completed_at_ms` and `consumed_at_ms`, and a\n * rebuild checks the stored text against the recorded digests. A completion\n * the journal names but no row holds, or holds with other bytes, is a typed\n * {@link FoldIncomplete}, never a silent gap.\n *\n * Compaction deletes a run's entries below its floor, so the fold's state at\n * the floor has to survive in the floor's checkpoint: {@link checkpointState}\n * adds it under {@link checkpointKey}, and a rebuild of a compacted run whose\n * floor checkpoint lacks it fails {@link FoldIncomplete} with reason\n * `checkpoint_missing`. A rewind archives the suffix and removes the rows it\n * explains (`@smthrs/time-travel`), so the remaining journal still explains\n * the remaining rows.\n *\n * @since 1.0.0\n */\n\nimport { DurableWriter } from \"@smthrs/database/DurableWriter\"\nimport { Journal, JournalEvent, Projection } from \"@smthrs/journal\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/sql/SqlClient\"\nimport { EventTypes } from \"./EventTypes.ts\"\n\n/**\n * The journal event types the fold reads.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const eventTypes: ReadonlyArray<string> = [\n EventTypes.clockScheduled,\n EventTypes.clockCompleted,\n EventTypes.deferredCompleted,\n EventTypes.deferredConsumed\n]\n\n/**\n * The key a checkpoint's state keeps the fold under.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const checkpointKey = \"flows.engine.deferred-clock\"\n\nconst NonNegativeSafeInt = Schema.Int.check(\n Schema.isGreaterThanOrEqualTo(0),\n Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)\n)\nconst Digest = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/))\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Clock = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n clockName: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n dueAtMs: NonNegativeSafeInt,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Clock = typeof Clock.Type\n\n/**\n * A deferred completion as the journal records it. A completion journalled\n * before the fold existed carried its (redacted) value instead of digests and\n * no completion time: `exitDigest` and `metadataDigest` are then absent and\n * `completedAtMs` is `null`, and a rebuild keeps the row's own stamp.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Deferred = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt),\n exitDigest: Schema.optionalKey(Digest),\n metadataDigest: Schema.optionalKey(Schema.NullOr(Digest)),\n consumedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A deferred completion as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Deferred = typeof Deferred.Type\n\n/**\n * The folded clocks and completions, keyed by their row address.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface State {\n readonly clocks: ReadonlyMap<string, Clock>\n readonly deferreds: ReadonlyMap<string, Deferred>\n}\n\n/**\n * The empty fold.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const initial: State = { clocks: new Map(), deferreds: new Map() }\n\n/**\n * The key of a clock row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const clockKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly clockName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.clockName])\n\n/**\n * The key of a completion row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const deferredKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly deferredName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.deferredName])\n\nconst record = (value: unknown): Readonly<Record<string, unknown>> | undefined =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? value as Readonly<Record<string, unknown>>\n : undefined\n\nconst text = (value: unknown): value is string => typeof value === \"string\" && value.length > 0\nconst time = (value: unknown): value is number => typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0\nconst digest = (value: unknown): value is string => typeof value === \"string\" && /^[0-9a-f]{64}$/.test(value)\n\n/**\n * Folds one committed journal entry. First writes win: a clock keeps its first\n * schedule and first completion, and a completion its first recording and\n * first consumption, exactly as the rows do. An entry of another type, or one\n * whose payload names no row, leaves the state unchanged.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const reduce = (state: State, entry: JournalEvent.Entry): State => {\n const payload = record(entry.payload)\n if (payload === undefined || !text(payload.flowName) || !text(payload.executionId)) return state\n const flowName = payload.flowName\n const executionId = payload.executionId\n switch (entry.eventType) {\n case EventTypes.clockScheduled: {\n if (!text(payload.clockName) || !text(payload.deferredName) || !time(payload.dueAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n if (state.clocks.has(key)) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, {\n flowName,\n executionId,\n clockName: payload.clockName,\n deferredName: payload.deferredName,\n dueAtMs: payload.dueAtMs,\n completedAtMs: null\n })\n return { ...state, clocks }\n }\n case EventTypes.clockCompleted: {\n if (!text(payload.clockName) || !time(payload.completedAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n const clock = state.clocks.get(key)\n if (clock === undefined || clock.completedAtMs !== null) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, { ...clock, completedAtMs: payload.completedAtMs })\n return { ...state, clocks }\n }\n case EventTypes.deferredCompleted: {\n if (!text(payload.deferredName)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n if (state.deferreds.has(key)) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, {\n flowName,\n executionId,\n deferredName: payload.deferredName,\n completedAtMs: time(payload.completedAtMs) ? payload.completedAtMs : null,\n ...(digest(payload.exitDigest) ? { exitDigest: payload.exitDigest } : {}),\n ...(digest(payload.exitDigest) && (payload.metadataDigest === null || digest(payload.metadataDigest))\n ? { metadataDigest: payload.metadataDigest }\n : {}),\n consumedAtMs: null\n })\n return { ...state, deferreds }\n }\n case EventTypes.deferredConsumed: {\n if (!text(payload.deferredName) || !time(payload.consumedAtMs)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n const deferred = state.deferreds.get(key)\n if (deferred === undefined || deferred.consumedAtMs !== null) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, { ...deferred, consumedAtMs: payload.consumedAtMs })\n return { ...state, deferreds }\n }\n default:\n return state\n }\n}\n\n/**\n * The fold as a journal projection, for `Journal.project` over one run.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const projection: Projection.Projection<State> = Projection.make({\n name: \"flows.engine.deferred-clock\",\n initial,\n reduce: (state, entry) => Effect.succeed(reduce(state, entry))\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Encoded = Schema.Struct({\n clocks: Schema.Array(Clock),\n deferreds: Schema.Array(Deferred)\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Encoded = typeof Encoded.Type\n\n/**\n * Encodes the fold for a checkpoint.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const encode = (state: State): Encoded => ({\n clocks: [...state.clocks.values()],\n deferreds: [...state.deferreds.values()]\n})\n\n/**\n * Decodes the fold a checkpoint kept, or `None` when the checkpoint state\n * holds none under {@link checkpointKey}.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const fromCheckpoint = (checkpointState: unknown): Option.Option<State> => {\n const kept = record(checkpointState)?.[checkpointKey]\n if (kept === undefined) return Option.none()\n const decoded = Schema.decodeUnknownOption(Encoded)(kept)\n return Option.map(decoded, (encoded) => ({\n clocks: new Map(encoded.clocks.map((clock) => [clockKey(clock), clock])),\n deferreds: new Map(encoded.deferreds.map((deferred) => [deferredKey(deferred), deferred]))\n }))\n}\n\n/**\n * Why a rebuild could not reconstruct the tables.\n *\n * - `row_missing`: the journal names a completion no row holds.\n * - `digest_mismatch`: the row holds other bytes than the journal recorded.\n * - `run_missing`: a clock's run has no `flows_runs` row to hang it on.\n * - `checkpoint_missing`: a compacted run's floor checkpoint keeps no fold.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const FoldIncompleteReason = Schema.Literals([\n \"row_missing\",\n \"digest_mismatch\",\n \"run_missing\",\n \"checkpoint_missing\"\n])\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const Unjoined = Schema.Struct({\n reason: FoldIncompleteReason,\n executionId: Schema.String,\n flowName: Schema.optionalKey(Schema.String),\n name: Schema.optionalKey(Schema.String)\n})\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport type Unjoined = typeof Unjoined.Type\n\n/**\n * The journal references state the store no longer holds. The rebuild wrote\n * nothing.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class FoldIncomplete extends Schema.TaggedError<FoldIncomplete>()(\n \"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\",\n {\n code: Schema.Literal(\"fold_incomplete\"),\n message: Schema.String,\n unjoined: Schema.Array(Unjoined)\n }\n) {}\n\nconst pageSize = 512\n\n/** Folds one run's entries after `after` into `start`, in sequence order. */\nconst foldEntries = (\n journal: Journal.Service,\n runId: string,\n start: State,\n after: JournalEvent.Seq | undefined,\n upTo?: number | undefined\n) =>\n Effect.gen(function*() {\n let state = start\n let cursor = after\n while (true) {\n const page = yield* journal.entries({\n runId: runId as JournalEvent.RunId,\n eventTypes,\n limit: pageSize,\n ...(cursor === undefined ? {} : { after: cursor })\n })\n for (const entry of page.entries) {\n if (upTo !== undefined && entry.seq > upTo) return state\n state = reduce(state, entry)\n cursor = entry.seq\n }\n if (!page.hasMore) return state\n }\n })\n\n/** The run's compaction floor checkpoint, if compaction ever ran. */\nconst floorOf = (sql: SqlClient.SqlClient, runId: string) =>\n sql<{ readonly seq: number | string; readonly state_json: string }>`\n SELECT seq, state_json FROM flows_journal_checkpoints\n WHERE run_id = ${runId} AND compacted_at_ms IS NOT NULL\n ORDER BY seq DESC LIMIT 1\n `.pipe(Effect.map((rows) => rows[0]))\n\n/**\n * Folds one run: its floor checkpoint's fold, if it was compacted, then every\n * entry above the floor, up to and including `upTo` when given.\n */\nconst foldRun = (runId: string, upTo?: number | undefined) =>\n Effect.gen(function*() {\n const journal = yield* Journal.Journal\n const sql = yield* SqlClient.SqlClient\n const floor = yield* floorOf(sql, runId)\n if (floor === undefined) return yield* foldEntries(journal, runId, initial, undefined, upTo)\n const kept = fromCheckpoint(JSON.parse(floor.state_json) as unknown)\n if (Option.isNone(kept)) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `run ${runId} was compacted below a checkpoint that keeps no deferred/clock fold`,\n unjoined: [{ reason: \"checkpoint_missing\", executionId: runId }]\n })\n )\n }\n return yield* foldEntries(journal, runId, kept.value, Number(floor.seq) as JournalEvent.Seq, upTo)\n })\n\n/**\n * The fold of one run's entries up to and including `upTo`, for the state of\n * a checkpoint at `upTo`. It starts from the run's floor checkpoint when the\n * run was compacted before.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const capture = Effect.fn(\"DeferredClockFold.capture\")(function*(runId: string, upTo: number) {\n return encode(yield* foldRun(runId, upTo))\n})\n\n/**\n * A checkpoint state that keeps the fold: `base` (an object, or nothing) with\n * the run's fold up to `upTo` under {@link checkpointKey}. A composition that\n * compacts runs writes its checkpoints through this, so compaction cannot\n * lose the deferred/clock history.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const checkpointState = Effect.fn(\"DeferredClockFold.checkpointState\")(function*(\n runId: string,\n upTo: number,\n base?: Readonly<Record<string, unknown>> | undefined\n) {\n return { ...base, [checkpointKey]: yield* capture(runId, upTo) }\n})\n\n/**\n * What a {@link rebuild} read and wrote.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Rebuilt {\n /** Runs with deferred or clock entries, or with a compaction floor. */\n readonly runs: number\n /** Clock rows written. */\n readonly clocks: number\n /** Completion rows whose completion and consumption were rewritten. */\n readonly deferreds: number\n /** Completion rows no journal entry explains, left as they are. */\n readonly unexplained: number\n}\n\ninterface StoredDeferred {\n readonly flow_name: string\n readonly execution_id: string\n readonly deferred_name: string\n readonly exit_json: string\n readonly metadata_json: string | null\n}\n\n/**\n * Rebuilds `flows_clock_deadlines` and the completion and consumption stamps\n * of `flows_deferred_completions` from the journal.\n *\n * Every run with deferred or clock entries, and every compacted run, is\n * folded in sequence order, from its floor checkpoint when it was compacted;\n * a compacted run whose floor keeps no fold fails, even one that never had a\n * clock, because the journal can no longer say. Every reference is joined\n * before anything is written: a completion with no row or with other bytes,\n * a clock whose run is gone, or a compacted run whose floor keeps no fold\n * fails {@link FoldIncomplete} listing each one, and nothing is written.\n * Otherwise, in one writer transaction, the clock table is replaced by the\n * fold's clocks and each folded completion row gets the fold's\n * `completed_at_ms` and `consumed_at_ms`. A completion row the journal does\n * not explain is left alone and counted.\n *\n * Run it on a quiescent store, as a restore does.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const rebuild = Effect.fn(\"DeferredClockFold.rebuild\")(function*() {\n const sql = yield* SqlClient.SqlClient\n const writer = yield* DurableWriter\n // A compacted run may have no fold entry left above its floor, so every run\n // with a compaction floor is folded too.\n const runs = yield* sql<{ readonly run_id: string }>`\n SELECT run_id FROM flows_journal_events WHERE ${sql.in(\"event_type\", eventTypes)}\n UNION\n SELECT run_id FROM flows_journal_checkpoints WHERE compacted_at_ms IS NOT NULL\n ORDER BY run_id\n `\n const unjoined: Array<Unjoined> = []\n const clocks: Array<Clock> = []\n const deferreds: Array<Deferred> = []\n for (const { run_id } of runs) {\n const state = yield* foldRun(run_id).pipe(\n Effect.catchTag(\"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\", (error) => {\n unjoined.push(...error.unjoined)\n return Effect.succeed(initial)\n })\n )\n clocks.push(...state.clocks.values())\n deferreds.push(...state.deferreds.values())\n }\n const liveRuns = new Set(\n (yield* sql<{ readonly run_id: string }>`SELECT run_id FROM flows_runs`).map((row) => row.run_id)\n )\n for (const clock of clocks) {\n if (!liveRuns.has(clock.executionId)) {\n unjoined.push({\n reason: \"run_missing\",\n executionId: clock.executionId,\n flowName: clock.flowName,\n name: clock.clockName\n })\n }\n }\n const stored = new Map(\n (yield* sql<StoredDeferred>`\n SELECT flow_name, execution_id, deferred_name, exit_json, metadata_json\n FROM flows_deferred_completions\n `).map((row) => [\n deferredKey({ flowName: row.flow_name, executionId: row.execution_id, deferredName: row.deferred_name }),\n row\n ])\n )\n for (const deferred of deferreds) {\n const row = stored.get(deferredKey(deferred))\n const reference = { executionId: deferred.executionId, flowName: deferred.flowName, name: deferred.deferredName }\n if (row === undefined) {\n unjoined.push({ reason: \"row_missing\", ...reference })\n } else if (\n (deferred.exitDigest !== undefined && JournalEvent.contentDigest(row.exit_json) !== deferred.exitDigest) ||\n (deferred.metadataDigest !== undefined &&\n (row.metadata_json === null ? null : JournalEvent.contentDigest(row.metadata_json)) !==\n deferred.metadataDigest)\n ) {\n unjoined.push({ reason: \"digest_mismatch\", ...reference })\n }\n }\n if (unjoined.length > 0) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `the journal references ${unjoined.length} deferred/clock rows the store cannot join`,\n unjoined\n })\n )\n }\n yield* writer.write(Effect.gen(function*() {\n yield* sql`DELETE FROM flows_clock_deadlines`\n for (const clock of clocks) {\n yield* sql`\n INSERT INTO flows_clock_deadlines (\n flow_name, execution_id, clock_name, deferred_name, due_at_ms, completed_at_ms\n ) VALUES (\n ${clock.flowName}, ${clock.executionId}, ${clock.clockName}, ${clock.deferredName},\n ${clock.dueAtMs}, ${clock.completedAtMs}\n )\n `\n }\n for (const deferred of deferreds) {\n yield* sql`\n UPDATE flows_deferred_completions\n SET completed_at_ms = COALESCE(${deferred.completedAtMs}, completed_at_ms),\n consumed_at_ms = ${deferred.consumedAtMs}\n WHERE flow_name = ${deferred.flowName}\n AND execution_id = ${deferred.executionId}\n AND deferred_name = ${deferred.deferredName}\n `\n }\n }))\n return {\n runs: runs.length,\n clocks: clocks.length,\n deferreds: deferreds.length,\n unexplained: stored.size - deferreds.length\n } satisfies Rebuilt\n})\n"]}
@@ -42,7 +42,7 @@ import * as Effect from "effect/Effect";
42
42
  import * as FileSystem from "effect/FileSystem";
43
43
  import type * as Layer from "effect/Layer";
44
44
  import * as Schema from "effect/Schema";
45
- import * as SqlClient from "effect/unstable/sql/SqlClient";
45
+ import * as SqlClient from "effect/sql/SqlClient";
46
46
  /**
47
47
  * The database file name inside a backup directory and a restored store
48
48
  * directory.
@@ -1 +1 @@
1
- {"version":3,"file":"DisasterRecovery.d.ts","sourceRoot":"","sources":["../../src/DisasterRecovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAE9D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAG1D;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kBAAkB,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kBAAkB,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YAAY,CAAA;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,kBAAkB,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAoB,CAAA;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;;;EAG3B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;EAGxB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,O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AAO,MAAM,eAAe,GAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAClD,SAAS,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,KACpC,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,CAAC,EAAE,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAOtG,CAAA"}
@@ -43,7 +43,7 @@ import * as Clock from "effect/Clock";
43
43
  import * as Effect from "effect/Effect";
44
44
  import * as FileSystem from "effect/FileSystem";
45
45
  import * as Schema from "effect/Schema";
46
- import * as SqlClient from "effect/unstable/sql/SqlClient";
46
+ import * as SqlClient from "effect/sql/SqlClient";
47
47
  import * as ArtifactRoots from "./internal/ArtifactRoots.js";
48
48
  /**
49
49
  * The database file name inside a backup directory and a restored store