@proofoftech/flowsafe 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +68 -6
  3. package/deployment-identity-protocol.d.mts +70 -1
  4. package/deployment-identity-protocol.mjs +423 -5
  5. package/dist/agent-host/index.d.ts +1 -1
  6. package/dist/agent-host/index.d.ts.map +1 -1
  7. package/dist/agent-host/index.js.map +1 -1
  8. package/dist/agent-host/router.d.ts.map +1 -1
  9. package/dist/agent-host/router.js +17 -4
  10. package/dist/agent-host/router.js.map +1 -1
  11. package/dist/agent-host/thread-host.d.ts +14 -1
  12. package/dist/agent-host/thread-host.d.ts.map +1 -1
  13. package/dist/agent-host/thread-host.js +865 -308
  14. package/dist/agent-host/thread-host.js.map +1 -1
  15. package/dist/agent-host/thread-topology.d.ts +43 -1
  16. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  17. package/dist/agent-host/thread-topology.js +301 -28
  18. package/dist/agent-host/thread-topology.js.map +1 -1
  19. package/dist/agent-runner/durable-agent-runner.d.ts +107 -8
  20. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  21. package/dist/agent-runner/durable-agent-runner.js +427 -55
  22. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  23. package/dist/agent-runner/index.d.ts +1 -1
  24. package/dist/agent-runner/index.d.ts.map +1 -1
  25. package/dist/agent-runner/index.js.map +1 -1
  26. package/dist/approval-api/actor-context.d.ts +4 -0
  27. package/dist/approval-api/actor-context.d.ts.map +1 -1
  28. package/dist/approval-api/actor-context.js +53 -5
  29. package/dist/approval-api/actor-context.js.map +1 -1
  30. package/dist/approval-api/d1-store.d.ts.map +1 -1
  31. package/dist/approval-api/d1-store.js +6 -3
  32. package/dist/approval-api/d1-store.js.map +1 -1
  33. package/dist/approval-api/principal-identity.d.ts +32 -0
  34. package/dist/approval-api/principal-identity.d.ts.map +1 -0
  35. package/dist/approval-api/principal-identity.js +69 -0
  36. package/dist/approval-api/principal-identity.js.map +1 -0
  37. package/dist/approval-api/principal.d.ts +10 -13
  38. package/dist/approval-api/principal.d.ts.map +1 -1
  39. package/dist/approval-api/principal.js +10 -46
  40. package/dist/approval-api/principal.js.map +1 -1
  41. package/dist/approval-api/retention.d.ts +1 -2
  42. package/dist/approval-api/retention.d.ts.map +1 -1
  43. package/dist/approval-api/retention.js.map +1 -1
  44. package/dist/approval-api/router.d.ts.map +1 -1
  45. package/dist/approval-api/router.js +9 -1
  46. package/dist/approval-api/router.js.map +1 -1
  47. package/dist/approval-api/service.d.ts +29 -14
  48. package/dist/approval-api/service.d.ts.map +1 -1
  49. package/dist/approval-api/service.js +83 -25
  50. package/dist/approval-api/service.js.map +1 -1
  51. package/dist/approval-api/types.d.ts +12 -0
  52. package/dist/approval-api/types.d.ts.map +1 -1
  53. package/dist/approval-api/types.js +12 -0
  54. package/dist/approval-api/types.js.map +1 -1
  55. package/dist/audit-export/index.d.ts +2 -2
  56. package/dist/audit-export/index.js +2 -2
  57. package/dist/background-tasks/d1-storage.d.ts +4 -3
  58. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  59. package/dist/background-tasks/d1-storage.js +7 -13
  60. package/dist/background-tasks/d1-storage.js.map +1 -1
  61. package/dist/background-tasks/host.d.ts +127 -14
  62. package/dist/background-tasks/host.d.ts.map +1 -1
  63. package/dist/background-tasks/host.js +579 -50
  64. package/dist/background-tasks/host.js.map +1 -1
  65. package/dist/background-tasks/index.d.ts +2 -2
  66. package/dist/background-tasks/index.d.ts.map +1 -1
  67. package/dist/background-tasks/index.js +11 -6
  68. package/dist/background-tasks/index.js.map +1 -1
  69. package/dist/background-tasks/routes.d.ts +19 -2
  70. package/dist/background-tasks/routes.d.ts.map +1 -1
  71. package/dist/background-tasks/routes.js +4 -4
  72. package/dist/background-tasks/routes.js.map +1 -1
  73. package/dist/deployment-identity-protocol.d.ts +2 -2
  74. package/dist/deployment-identity-protocol.d.ts.map +1 -1
  75. package/dist/deployment-identity-protocol.js +1 -1
  76. package/dist/deployment-identity-protocol.js.map +1 -1
  77. package/dist/do-runner/cause-chain.d.ts +53 -0
  78. package/dist/do-runner/cause-chain.d.ts.map +1 -0
  79. package/dist/do-runner/cause-chain.js +96 -0
  80. package/dist/do-runner/cause-chain.js.map +1 -0
  81. package/dist/do-runner/constants.d.ts +3 -0
  82. package/dist/do-runner/constants.d.ts.map +1 -0
  83. package/dist/do-runner/constants.js +3 -0
  84. package/dist/do-runner/constants.js.map +1 -0
  85. package/dist/do-runner/d1-storage.d.ts +47 -69
  86. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  87. package/dist/do-runner/d1-storage.js +972 -196
  88. package/dist/do-runner/d1-storage.js.map +1 -1
  89. package/dist/do-runner/deployment-identity.d.ts +29 -5
  90. package/dist/do-runner/deployment-identity.d.ts.map +1 -1
  91. package/dist/do-runner/deployment-identity.js +23 -6
  92. package/dist/do-runner/deployment-identity.js.map +1 -1
  93. package/dist/do-runner/do-error-response.d.ts +4 -23
  94. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  95. package/dist/do-runner/do-error-response.js +19 -24
  96. package/dist/do-runner/do-error-response.js.map +1 -1
  97. package/dist/do-runner/do-status-error.d.ts +37 -0
  98. package/dist/do-runner/do-status-error.d.ts.map +1 -0
  99. package/dist/do-runner/do-status-error.js +42 -0
  100. package/dist/do-runner/do-status-error.js.map +1 -0
  101. package/dist/do-runner/durable-object.d.ts +2 -1
  102. package/dist/do-runner/durable-object.d.ts.map +1 -1
  103. package/dist/do-runner/durable-object.js +617 -144
  104. package/dist/do-runner/durable-object.js.map +1 -1
  105. package/dist/do-runner/execution-admission.d.ts +114 -0
  106. package/dist/do-runner/execution-admission.d.ts.map +1 -0
  107. package/dist/do-runner/execution-admission.js +206 -0
  108. package/dist/do-runner/execution-admission.js.map +1 -0
  109. package/dist/do-runner/execution-context.d.ts.map +1 -1
  110. package/dist/do-runner/execution-context.js +1 -0
  111. package/dist/do-runner/execution-context.js.map +1 -1
  112. package/dist/do-runner/execution-fence.d.ts +379 -0
  113. package/dist/do-runner/execution-fence.d.ts.map +1 -0
  114. package/dist/do-runner/execution-fence.js +1098 -0
  115. package/dist/do-runner/execution-fence.js.map +1 -0
  116. package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
  117. package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
  118. package/dist/do-runner/fenced-workflow-capability.js +3 -0
  119. package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
  120. package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
  121. package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
  122. package/dist/do-runner/fenced-workflows-d1.js +894 -0
  123. package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
  124. package/dist/do-runner/index.d.ts +20 -8
  125. package/dist/do-runner/index.d.ts.map +1 -1
  126. package/dist/do-runner/index.js +21 -4
  127. package/dist/do-runner/index.js.map +1 -1
  128. package/dist/do-runner/init.d.ts +82 -1
  129. package/dist/do-runner/init.d.ts.map +1 -1
  130. package/dist/do-runner/init.js +58 -3
  131. package/dist/do-runner/init.js.map +1 -1
  132. package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
  133. package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
  134. package/dist/do-runner/initial-admission-refusal.js +41 -0
  135. package/dist/do-runner/initial-admission-refusal.js.map +1 -0
  136. package/dist/do-runner/inventory.d.ts +295 -0
  137. package/dist/do-runner/inventory.d.ts.map +1 -0
  138. package/dist/do-runner/inventory.js +800 -0
  139. package/dist/do-runner/inventory.js.map +1 -0
  140. package/dist/do-runner/notification-predicate.d.ts +8 -0
  141. package/dist/do-runner/notification-predicate.d.ts.map +1 -0
  142. package/dist/do-runner/notification-predicate.js +136 -0
  143. package/dist/do-runner/notification-predicate.js.map +1 -0
  144. package/dist/do-runner/run-lifecycle.d.ts +20 -1
  145. package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
  146. package/dist/do-runner/run-lifecycle.js +67 -13
  147. package/dist/do-runner/run-lifecycle.js.map +1 -1
  148. package/dist/do-runner/run-provenance.d.ts +38 -0
  149. package/dist/do-runner/run-provenance.d.ts.map +1 -0
  150. package/dist/do-runner/run-provenance.js +152 -0
  151. package/dist/do-runner/run-provenance.js.map +1 -0
  152. package/dist/do-runner/run-storage-tables.d.ts +2 -0
  153. package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
  154. package/dist/do-runner/run-storage-tables.js +4 -0
  155. package/dist/do-runner/run-storage-tables.js.map +1 -0
  156. package/dist/do-runner/run-terminal-state.d.ts +29 -0
  157. package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
  158. package/dist/do-runner/run-terminal-state.js +105 -0
  159. package/dist/do-runner/run-terminal-state.js.map +1 -0
  160. package/dist/do-runner/runtime.d.ts +191 -46
  161. package/dist/do-runner/runtime.d.ts.map +1 -1
  162. package/dist/do-runner/runtime.js +994 -378
  163. package/dist/do-runner/runtime.js.map +1 -1
  164. package/dist/do-runner/start-idempotency.d.ts +285 -0
  165. package/dist/do-runner/start-idempotency.d.ts.map +1 -0
  166. package/dist/do-runner/start-idempotency.js +994 -0
  167. package/dist/do-runner/start-idempotency.js.map +1 -0
  168. package/dist/do-runner/start-reservation-contract.d.ts +103 -0
  169. package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
  170. package/dist/do-runner/start-reservation-contract.js +338 -0
  171. package/dist/do-runner/start-reservation-contract.js.map +1 -0
  172. package/dist/do-runner/suspension-deadline.d.ts +4 -11
  173. package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
  174. package/dist/do-runner/suspension-deadline.js +8 -12
  175. package/dist/do-runner/suspension-deadline.js.map +1 -1
  176. package/dist/do-runner/table-prefix.d.ts.map +1 -1
  177. package/dist/do-runner/table-prefix.js +2 -1
  178. package/dist/do-runner/table-prefix.js.map +1 -1
  179. package/dist/do-runner/testing.d.ts +3 -0
  180. package/dist/do-runner/testing.d.ts.map +1 -0
  181. package/dist/do-runner/testing.js +3 -0
  182. package/dist/do-runner/testing.js.map +1 -0
  183. package/dist/do-runner/thread-do.d.ts +2 -1
  184. package/dist/do-runner/thread-do.d.ts.map +1 -1
  185. package/dist/do-runner/thread-do.js +14 -10
  186. package/dist/do-runner/thread-do.js.map +1 -1
  187. package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
  188. package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
  189. package/dist/do-runner/workflow-snapshot-row.js +97 -0
  190. package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
  191. package/dist/goals/objective-routes.d.ts +15 -5
  192. package/dist/goals/objective-routes.d.ts.map +1 -1
  193. package/dist/goals/objective-routes.js +64 -64
  194. package/dist/goals/objective-routes.js.map +1 -1
  195. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  196. package/dist/host-kit/approval-bridge.js +10 -7
  197. package/dist/host-kit/approval-bridge.js.map +1 -1
  198. package/dist/host-kit/do-response.d.ts +16 -0
  199. package/dist/host-kit/do-response.d.ts.map +1 -1
  200. package/dist/host-kit/do-response.js +181 -0
  201. package/dist/host-kit/do-response.js.map +1 -1
  202. package/dist/host-kit/do-run-topology.d.ts +3 -0
  203. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  204. package/dist/host-kit/do-run-topology.js +36 -8
  205. package/dist/host-kit/do-run-topology.js.map +1 -1
  206. package/dist/host-kit/env-vars.d.ts.map +1 -1
  207. package/dist/host-kit/env-vars.js +5 -6
  208. package/dist/host-kit/env-vars.js.map +1 -1
  209. package/dist/host-kit/flowsafe-worker.d.ts +49 -6
  210. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  211. package/dist/host-kit/flowsafe-worker.js +409 -111
  212. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  213. package/dist/host-kit/host-approval-service.d.ts +24 -14
  214. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  215. package/dist/host-kit/host-approval-service.js +29 -40
  216. package/dist/host-kit/host-approval-service.js.map +1 -1
  217. package/dist/host-kit/index.d.ts +9 -3
  218. package/dist/host-kit/index.d.ts.map +1 -1
  219. package/dist/host-kit/index.js +5 -1
  220. package/dist/host-kit/index.js.map +1 -1
  221. package/dist/host-kit/run-route-error.d.ts +8 -4
  222. package/dist/host-kit/run-route-error.d.ts.map +1 -1
  223. package/dist/host-kit/run-route-error.js +14 -11
  224. package/dist/host-kit/run-route-error.js.map +1 -1
  225. package/dist/host-kit/run-router.d.ts +63 -2
  226. package/dist/host-kit/run-router.d.ts.map +1 -1
  227. package/dist/host-kit/run-router.js +167 -45
  228. package/dist/host-kit/run-router.js.map +1 -1
  229. package/dist/host-kit/stream-router.d.ts.map +1 -1
  230. package/dist/host-kit/stream-router.js +18 -9
  231. package/dist/host-kit/stream-router.js.map +1 -1
  232. package/dist/host-kit/thread-topology.d.ts +1 -1
  233. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  234. package/dist/host-kit/thread-topology.js +7 -3
  235. package/dist/host-kit/thread-topology.js.map +1 -1
  236. package/dist/internal-error-response.d.ts.map +1 -1
  237. package/dist/internal-error-response.js +16 -6
  238. package/dist/internal-error-response.js.map +1 -1
  239. package/dist/schedules/index.d.ts +1 -0
  240. package/dist/schedules/index.d.ts.map +1 -1
  241. package/dist/schedules/index.js +1 -7
  242. package/dist/schedules/index.js.map +1 -1
  243. package/dist/schedules/mutation-contract.d.ts +38 -0
  244. package/dist/schedules/mutation-contract.d.ts.map +1 -0
  245. package/dist/schedules/mutation-contract.js +21 -0
  246. package/dist/schedules/mutation-contract.js.map +1 -0
  247. package/dist/schedules/router.d.ts +15 -8
  248. package/dist/schedules/router.d.ts.map +1 -1
  249. package/dist/schedules/router.js +170 -59
  250. package/dist/schedules/router.js.map +1 -1
  251. package/dist/schedules/schedules-d1.d.ts +11 -5
  252. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  253. package/dist/schedules/schedules-d1.js +570 -143
  254. package/dist/schedules/schedules-d1.js.map +1 -1
  255. package/dist/schedules/storage.d.ts +0 -7
  256. package/dist/schedules/storage.d.ts.map +1 -1
  257. package/dist/schedules/storage.js +0 -27
  258. package/dist/schedules/storage.js.map +1 -1
  259. package/dist/schedules/tick.d.ts +13 -0
  260. package/dist/schedules/tick.d.ts.map +1 -1
  261. package/dist/schedules/tick.js +66 -40
  262. package/dist/schedules/tick.js.map +1 -1
  263. package/dist/signal-providers/host-do.d.ts +12 -1
  264. package/dist/signal-providers/host-do.d.ts.map +1 -1
  265. package/dist/signal-providers/host-do.js +28 -3
  266. package/dist/signal-providers/host-do.js.map +1 -1
  267. package/dist/signal-providers/webhook-route.d.ts +15 -1
  268. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  269. package/dist/signal-providers/webhook-route.js +126 -113
  270. package/dist/signal-providers/webhook-route.js.map +1 -1
  271. package/dist/signals/d1-shared.d.ts +11 -8
  272. package/dist/signals/d1-shared.d.ts.map +1 -1
  273. package/dist/signals/d1-shared.js +1 -6
  274. package/dist/signals/d1-shared.js.map +1 -1
  275. package/dist/signals/index.d.ts +1 -1
  276. package/dist/signals/index.d.ts.map +1 -1
  277. package/dist/signals/index.js +1 -1
  278. package/dist/signals/index.js.map +1 -1
  279. package/dist/signals/notification-dispatch.d.ts +109 -5
  280. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  281. package/dist/signals/notification-dispatch.js +430 -46
  282. package/dist/signals/notification-dispatch.js.map +1 -1
  283. package/dist/signals/notifications-d1.d.ts +14 -1
  284. package/dist/signals/notifications-d1.d.ts.map +1 -1
  285. package/dist/signals/notifications-d1.js +229 -18
  286. package/dist/signals/notifications-d1.js.map +1 -1
  287. package/dist/signals/router.d.ts +6 -4
  288. package/dist/signals/router.d.ts.map +1 -1
  289. package/dist/signals/router.js +49 -84
  290. package/dist/signals/router.js.map +1 -1
  291. package/dist/signals/thread-do-routes.d.ts +2 -0
  292. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  293. package/dist/signals/thread-do-routes.js +330 -83
  294. package/dist/signals/thread-do-routes.js.map +1 -1
  295. package/package.json +6 -3
  296. package/patches/@mastra__core@1.53.0.patch +54 -0
  297. package/scripts/seed-deployment-identity.mjs +34 -9
@@ -0,0 +1,1098 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The deployment execution fence — the control that lets an operator stop a
3
+ // deployment from MINTING work without stopping it from finishing the work it
4
+ // already has.
5
+ //
6
+ // WHY it exists: a flowsafe deployment is one tenant's whole execution surface
7
+ // (one Worker, one D1, its own Durable Object namespaces). Moving that surface
8
+ // to another deployment is only safe if the old one can be brought to a state
9
+ // where nothing new starts, everything outstanding drains, and then nothing
10
+ // runs at all — otherwise the two deployments execute the same run's steps
11
+ // against the same rows and every exactly-once property this package defends
12
+ // dies at the migration boundary.
13
+ //
14
+ // The states are ordered by how much they forbid, and the ORDER is the whole
15
+ // contract:
16
+ //
17
+ // open everything (the steady state)
18
+ // draining finish what exists; mint nothing new
19
+ // migration-locked execute nothing; reads and admin still answer
20
+ // proof-only migration-locked, except ONE nominated run — the proof
21
+ // that the deployment still works before it is reopened
22
+ //
23
+ // Two invariants hold everywhere the fence is consulted:
24
+ //
25
+ // NEVER MEMOIZED. The fence is an operational control an operator moves
26
+ // between requests; a memo would serve a stale answer for the length of an
27
+ // isolate, which is exactly the window a migration is trying to close. One
28
+ // read per request, or one per tick/dispatch PASS — never per row.
29
+ //
30
+ // DEGRADE CLOSED. A read that did not reach storage is not evidence that the
31
+ // deployment is open. On a request path it is a 503 (the operator's problem,
32
+ // retryable — the same answer DeploymentIdentityError gets); on an alarm path
33
+ // it is logged, swallowed, and left for the next wake, because a thrown alarm
34
+ // is retried by workerd and would answer a storage incident with a storm.
35
+ //
36
+ // An absent legacy row (or absent TABLE) reads as `open`. That is the 0.19-to-0.20
37
+ // upgrade rule and nothing more: a database seeded before this table existed
38
+ // must keep serving. Provisioning writes an explicit row from 0.20 on, so a
39
+ // deployment that means to start locked says so rather than relying on a
40
+ // default — `seed()` therefore takes the state as a REQUIRED argument.
41
+ import { decodeExecutionFenceMutationMetadata, EXECUTION_FENCE_CURRENT_SCHEMA_STAGE, EXECUTION_FENCE_ROW_ID, EXECUTION_FENCE_STATES, EXECUTION_FENCE_TABLE, initializeExecutionFenceProtocol, readExecutionFenceSchemaProtocol, } from '#deployment-identity-protocol';
42
+ import { missingTableReadsEmpty } from './cause-chain.js';
43
+ import { DoStatusError } from './do-status-error.js';
44
+ import { ExecutionFenceUnreadableError, InvalidExecutionIdentityError, normalizeD1RunExecutionIdentity, normalizeMutationEpoch, normalizeStartExecutionIdentity, } from './execution-admission.js';
45
+ import { RUN_PROVENANCE_CONTEXT_KEY } from './execution-context.js';
46
+ import { isPathSafeId } from './path-safe-id.js';
47
+ import { decodeProgressRunProvenance, decodeRunStartIdentity, } from './run-provenance.js';
48
+ import { isRunStatus } from './run-terminal-state.js';
49
+ import { captureBoundReservation, decodeStartReservationAdmissionResult, START_IDEMPOTENCY_TABLE, sameReservationIdentity, validateStartReservationAdmissionSchema, } from './start-reservation-contract.js';
50
+ import { decodeRawWorkflowSnapshotResult, prepareRawWorkflowSnapshotRead, } from './workflow-snapshot-row.js';
51
+ export { ExecutionFenceUnreadableError } from './execution-admission.js';
52
+ /**
53
+ * The suspend-payload key the executor backstop stamps on a task it parked
54
+ * because the deployment was fenced mid-dispatch. Namespaced so it cannot
55
+ * collide with a tool's own suspend payload, and read back by
56
+ * `BackgroundTaskHost.#resumeFenceSuspendedTasks` — which is what makes the
57
+ * parking reversible rather than a quieter kind of loss.
58
+ *
59
+ * PUBLISHED via `./background-tasks` because it is the only way a host can tell
60
+ * a fence-parked row from a tool-suspended one: `listTasks({ status:
61
+ * 'suspended' })` returns both, and the marker lives in the suspend payload
62
+ * where no filter can express it. The drain inventory imports this same
63
+ * definition directly, so a rename cannot silently leave a hard-coded census
64
+ * predicate behind.
65
+ */
66
+ export const EXECUTION_FENCE_SUSPEND_KEY = 'flowsafe.executionFenced';
67
+ /** The reading every unfenced surface uses — see `ExecutionFenceStore` absence. */
68
+ export const OPEN_EXECUTION_FENCE = Object.freeze({
69
+ state: 'open',
70
+ mutationEpoch: 0,
71
+ requireMutationEpoch: false,
72
+ transitionRevision: 0,
73
+ });
74
+ /**
75
+ * Read the fence a surface was wired with, resolving the typed opt-out.
76
+ *
77
+ * ONE function rather than a `fence ? await fence.read() : OPEN` at every gate,
78
+ * because those are the places a mistake is invisible: an unfenced surface and
79
+ * an open one behave identically until the day an operator closes the fence, so
80
+ * a call site that got the ternary subtly wrong would pass every test written
81
+ * against an open deployment. Every gate resolving absence through here means
82
+ * there is exactly one definition of what "no fence" does.
83
+ *
84
+ * `undefined` is admitted alongside `'none'` for the surfaces whose fence
85
+ * arrives through an object the caller may not have populated (an
86
+ * `InitResult.executionFence` on an unfenced host); it reads as open for the
87
+ * same reason `'none'` does, and never as a silent default a host can reach by
88
+ * forgetting — the option types that feed this are required.
89
+ */
90
+ export async function readExecutionFence(fence) {
91
+ if (fence === undefined || fence === 'none')
92
+ return OPEN_EXECUTION_FENCE;
93
+ return fence.read();
94
+ }
95
+ /**
96
+ * One fence store per DATABASE — not per request, and not per call site.
97
+ *
98
+ * The store holds no state of its own (a read is never memoized — see the
99
+ * module header), so this is about IDENTITY rather than caching: the admin
100
+ * route that MOVES the fence, the approval service that OBEYS it, the schedule
101
+ * tick that must not claim a fire behind it, and the runner's runtime all have
102
+ * to be looking at the same database. Keyed on the BINDING rather than on an
103
+ * env object, because a host mutates one env across requests and because the
104
+ * fence belongs to the database, not to the request that happens to reach it.
105
+ * WeakMap, so a test harness cycling bindings never leaks.
106
+ *
107
+ * Lives here rather than once per host because every composer needed the same
108
+ * three lines, and four copies of a memo are four chances for one of them to
109
+ * key on the wrong thing — an env-keyed copy hands two databases the same
110
+ * fence. A host whose call sites pass `env` keeps a one-line wrapper of its
111
+ * own; the memo itself is this one.
112
+ */
113
+ const executionFenceStores = new WeakMap();
114
+ export function executionFenceFor(db) {
115
+ const existing = executionFenceStores.get(db);
116
+ if (existing)
117
+ return existing;
118
+ const store = new ExecutionFenceStore(db);
119
+ executionFenceStores.set(db, store);
120
+ return store;
121
+ }
122
+ /**
123
+ * The refusal a fenced surface answers with: 503, because the deployment is
124
+ * deliberately not executing right now and will be again — an operator's
125
+ * condition, not the caller's mistake and not a code fault. Providers,
126
+ * schedulers, and clients that honour Retry-After semantics therefore
127
+ * redeliver rather than discard.
128
+ */
129
+ export class ExecutionFencedError extends DoStatusError {
130
+ status = 503;
131
+ reason;
132
+ constructor(state, entry) {
133
+ super(entry === undefined
134
+ ? `deployment execution is fenced ('${state}')`
135
+ : `deployment execution is fenced ('${state}'): ${entry} is refused`);
136
+ this.name = 'ExecutionFencedError';
137
+ this.reason = { code: 'EXECUTION_FENCED', state };
138
+ }
139
+ }
140
+ /**
141
+ * A fence transition whose compare-and-set found a different state. 409 rather
142
+ * than 503: the deployment is fine, the CALLER's expectation is stale — two
143
+ * control-plane actors raced, or an operator retried a transition that already
144
+ * landed. The current state rides on the reason so the caller can re-plan
145
+ * without a second round trip.
146
+ */
147
+ export class FenceTransitionConflictError extends DoStatusError {
148
+ status = 409;
149
+ reason;
150
+ constructor(expected, current, details) {
151
+ super(details === undefined
152
+ ? `execution fence transition expected state '${expected}' but found '${current}'`
153
+ : 'execution fence transition conflicts with the current reading');
154
+ this.name = 'FenceTransitionConflictError';
155
+ this.reason =
156
+ details === undefined
157
+ ? { code: 'FENCE_CAS_CONFLICT', state: current }
158
+ : {
159
+ code: 'FENCE_CAS_CONFLICT',
160
+ ...executionFenceReadingPayload(details.reading),
161
+ conflict: details.conflict,
162
+ };
163
+ }
164
+ }
165
+ /**
166
+ * Render a fence refusal as the JSON response the taxonomy specifies.
167
+ *
168
+ * For the surfaces that answer with a Response instead of throwing — a Worker
169
+ * router, or a Durable Object route whose own catch would re-map a thrown
170
+ * status. Built from the ERROR so the body a router writes and the body
171
+ * doErrorResponse writes for the same refusal cannot drift apart.
172
+ */
173
+ export function executionFencedResponse(state, entry) {
174
+ const refusal = new ExecutionFencedError(state, entry);
175
+ return new Response(JSON.stringify({ error: refusal.message, reason: refusal.reason }), {
176
+ status: refusal.status,
177
+ headers: {
178
+ 'content-type': 'application/json',
179
+ 'cache-control': 'no-store',
180
+ },
181
+ });
182
+ }
183
+ export function executionFenceReadingPayload(reading) {
184
+ return {
185
+ state: reading.state,
186
+ ...(reading.proofKey === undefined ? {} : { proofKey: reading.proofKey }),
187
+ ...(reading.proofRunId === undefined
188
+ ? {}
189
+ : { proofRunId: reading.proofRunId }),
190
+ ...(reading.mutationEpoch === undefined
191
+ ? {}
192
+ : { mutationEpoch: reading.mutationEpoch }),
193
+ ...(reading.requireMutationEpoch === undefined
194
+ ? {}
195
+ : { requireMutationEpoch: reading.requireMutationEpoch }),
196
+ ...(reading.transitionRevision === undefined
197
+ ? {}
198
+ : { transitionRevision: reading.transitionRevision }),
199
+ };
200
+ }
201
+ /** The two reason codes a fence refusal publishes, whatever carried it. */
202
+ const FENCE_REFUSAL_CODES = new Set([
203
+ 'EXECUTION_FENCED',
204
+ 'EXECUTION_FENCE_UNREADABLE',
205
+ ]);
206
+ /**
207
+ * Whether an error is the fence refusing (or failing to answer). The two are
208
+ * one class for every CALLER that must degrade closed — an alarm swallowing
209
+ * both, a tick skipping its pass — because a state it could not read and a
210
+ * state that forbids the work lead to the same action.
211
+ *
212
+ * The CODE counts as well as the class, because a refusal that crossed a
213
+ * Durable Object boundary is no longer an instance of anything: the run object
214
+ * threw ExecutionFencedError, `doErrorResponse` rendered it, and `doSummary`
215
+ * rebuilt it on the Worker side as a `RunRouteError` carrying the same status
216
+ * and the same structured reason. That rebuilt error IS the fence refusing —
217
+ * the callers most in need of recognizing one (a run router deciding whether to
218
+ * give a reservation's claim back, a tick deciding whether to skip a pass) are
219
+ * exactly the ones sitting on the far side of that boundary, and an
220
+ * instanceof-only test would answer "no" for every one of them.
221
+ *
222
+ * The two codes are matched by name rather than by any structural sniff: only
223
+ * refusals this package authors publish them, and both are declared as literals
224
+ * on the corresponding error classes, so a code arriving over the wire came from one of them.
225
+ */
226
+ export function isExecutionFenceRefusal(error) {
227
+ if (error instanceof ExecutionFencedError ||
228
+ error instanceof ExecutionFenceUnreadableError) {
229
+ return true;
230
+ }
231
+ if (error === null || typeof error !== 'object')
232
+ return false;
233
+ const { message, status, reason } = error;
234
+ // All three fields are checked, not just the code: this predicate NARROWS,
235
+ // and every render site immediately reads message/status/reason off what it
236
+ // narrowed. Asserting a shape on the strength of one field would hand them a
237
+ // `status` of undefined, and `new Response(body, { status: undefined })`
238
+ // fails inside the very catch block whose job is to never throw.
239
+ if (typeof message !== 'string' || !Number.isInteger(status))
240
+ return false;
241
+ if (reason === null || typeof reason !== 'object')
242
+ return false;
243
+ const { code } = reason;
244
+ return typeof code === 'string' && FENCE_REFUSAL_CODES.has(code);
245
+ }
246
+ function isExecutionFenceState(value) {
247
+ return (typeof value === 'string' &&
248
+ EXECUTION_FENCE_STATES.includes(value));
249
+ }
250
+ /**
251
+ * Validate a state name from a control-plane request. Exported because the
252
+ * admin route validates the WIRE shape and the package validates nothing else
253
+ * about a transition: which transitions are legal is host policy, and this
254
+ * package only enforces the state vocabulary, the CAS, and the proof-only
255
+ * key requirement.
256
+ */
257
+ export function assertExecutionFenceState(value, field) {
258
+ if (!isExecutionFenceState(value)) {
259
+ throw new InvalidExecutionFenceRequestError(`${field} must be one of ${EXECUTION_FENCE_STATES.join(', ')}`);
260
+ }
261
+ return value;
262
+ }
263
+ /** A malformed control-plane fence request — the caller's to fix. */
264
+ export class InvalidExecutionFenceRequestError extends DoStatusError {
265
+ status = 400;
266
+ reason;
267
+ constructor(message) {
268
+ super(message);
269
+ this.name = 'InvalidExecutionFenceRequestError';
270
+ this.reason = { code: 'INVALID_EXECUTION_FENCE_REQUEST' };
271
+ }
272
+ }
273
+ // ---------------------------------------------------------------------------
274
+ // Admission predicates — the semantics matrix, as four total functions.
275
+ //
276
+ // One predicate per COLUMN of behaviour rather than one per call site, so two
277
+ // surfaces that must answer the same way cannot drift apart. Resume, approval
278
+ // decide, and signal delivery share `admitsExistingRun` for exactly that
279
+ // reason: all three act on a run that already exists, so all three must stay
280
+ // open through a drain and all three must admit the proof run and nothing else.
281
+ // ---------------------------------------------------------------------------
282
+ /**
283
+ * May a NEW run be minted? Only `open`, plus the proof-only exception: a start
284
+ * whose idempotency key is the nominated proof key. The key is internal
285
+ * material (never a request-body field, never an open request-context key), so
286
+ * nothing a tenant can send reaches this branch.
287
+ */
288
+ export function admitsRunStart(reading, idempotencyKey) {
289
+ if (reading.state === 'open')
290
+ return true;
291
+ if (reading.state !== 'proof-only')
292
+ return false;
293
+ return (reading.proofKey !== undefined &&
294
+ idempotencyKey !== undefined &&
295
+ idempotencyKey === reading.proofKey);
296
+ }
297
+ /**
298
+ * May work proceed on a run that ALREADY exists — resume, approval decide,
299
+ * signal delivery? Through a drain, yes: a drain that refused these could
300
+ * never finish, because finishing is what the suspended runs are waiting for.
301
+ * In proof-only, only the nominated run.
302
+ */
303
+ export function admitsExistingRun(reading, candidate) {
304
+ if (reading.state === 'open' || reading.state === 'draining')
305
+ return true;
306
+ if (reading.state !== 'proof-only' ||
307
+ typeof candidate !== 'object' ||
308
+ candidate === null ||
309
+ candidate.tablePrefix === null)
310
+ return false;
311
+ try {
312
+ const execution = normalizeD1RunExecutionIdentity(candidate);
313
+ const proof = reading.proofExecution;
314
+ return (execution.tablePrefix === candidate.tablePrefix &&
315
+ proof !== undefined &&
316
+ proof.tablePrefix === execution.tablePrefix &&
317
+ proof.workflowId === execution.workflowId &&
318
+ proof.runId === execution.runId &&
319
+ proof.startToken === execution.startToken);
320
+ }
321
+ catch {
322
+ return false;
323
+ }
324
+ }
325
+ /**
326
+ * May standing configuration that ARMS future work be authored — a schedule
327
+ * created/updated/resumed, an objective set, a due schedule fire claimed?
328
+ * `open` only. Pausing and deleting stay allowed in every state: they remove
329
+ * future work, which is the direction a drain is going.
330
+ */
331
+ export function admitsWorkAuthoring(reading) {
332
+ return reading.state === 'open';
333
+ }
334
+ /**
335
+ * May queued, already-owned work be executed — a background task body, a
336
+ * notification dispatch pass? Through a drain, yes; that queue IS the work a
337
+ * drain exists to finish. Not in proof-only: the proof is one run, and a task
338
+ * queue re-driving itself alongside it is not a proof of anything.
339
+ */
340
+ export function admitsDrainableExecution(reading) {
341
+ return reading.state === 'open' || reading.state === 'draining';
342
+ }
343
+ const FENCE_ADMISSION_FIELDS = [
344
+ 'state',
345
+ 'mutation_epoch',
346
+ 'require_mutation_epoch',
347
+ 'transition_revision',
348
+ 'last_transition_request',
349
+ 'proof_key',
350
+ 'proof_run_id',
351
+ 'proof_table_prefix',
352
+ 'proof_workflow_id',
353
+ 'proof_start_token',
354
+ ];
355
+ /** @internal */
356
+ export function executionFenceAdmissionValues(observation) {
357
+ const values = FENCE_ADMISSION_FIELDS.map((key) => observation.raw[key]);
358
+ for (const value of values.slice(4)) {
359
+ if (value !== null && typeof value !== 'string') {
360
+ throw new ExecutionFenceUnreadableError('execution fence semantic fields are not readable');
361
+ }
362
+ }
363
+ return Object.freeze(values);
364
+ }
365
+ /** @internal */
366
+ export function executionFenceAdmissionSql(input) {
367
+ const { callerEpoch, semantic, schema, statePredicate } = input;
368
+ if (semantic.length !== FENCE_ADMISSION_FIELDS.length) {
369
+ throw new Error('execution fence admission parameter frame is invalid');
370
+ }
371
+ const nullable = FENCE_ADMISSION_FIELDS.slice(4)
372
+ .map((key, index) => {
373
+ const parameter = semantic[index + 4];
374
+ return `typeof(f.${key}) IN ('null', 'text')
375
+ AND typeof(f.${key}) = typeof(${parameter})
376
+ AND f.${key} COLLATE BINARY IS ${parameter}`;
377
+ })
378
+ .join(' AND ');
379
+ return `(SELECT json_group_array(json_array(name, type, "notnull", dflt_value, pk, hidden))
380
+ FROM (SELECT name, type, "notnull", dflt_value, pk, hidden
381
+ FROM pragma_table_xinfo('${EXECUTION_FENCE_TABLE}') ORDER BY cid)) COLLATE BINARY = ${schema}
382
+ AND (SELECT COUNT(*) FROM ${EXECUTION_FENCE_TABLE}) = 1
383
+ AND EXISTS (SELECT 1 FROM ${EXECUTION_FENCE_TABLE} AS f
384
+ WHERE typeof(f.id) = 'text' AND f.id COLLATE BINARY = 'deployment'
385
+ AND typeof(f.state) = 'text' AND f.state COLLATE BINARY IS ${semantic[0]}
386
+ AND typeof(f.mutation_epoch) = 'integer' AND f.mutation_epoch IS ${semantic[1]}
387
+ AND typeof(f.require_mutation_epoch) = 'integer' AND f.require_mutation_epoch IS ${semantic[2]}
388
+ AND typeof(f.transition_revision) = 'integer' AND f.transition_revision IS ${semantic[3]}
389
+ AND ${nullable}
390
+ AND (f.require_mutation_epoch = 0 OR f.mutation_epoch = ${callerEpoch})
391
+ AND (${statePredicate}))`;
392
+ }
393
+ function isFenceCounter(value) {
394
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
395
+ }
396
+ function decodeTransitionReceipt(text) {
397
+ const value = JSON.parse(text);
398
+ if (text.length > 512 ||
399
+ !Array.isArray(value) ||
400
+ value.length !== 7 ||
401
+ value[0] !== 1 ||
402
+ !isExecutionFenceState(value[1]) ||
403
+ !isExecutionFenceState(value[2]) ||
404
+ (value[2] === 'proof-only' ? !isPathSafeId(value[3]) : value[3] !== null) ||
405
+ !isFenceCounter(value[4]) ||
406
+ !isFenceCounter(value[5]) ||
407
+ value[5] === Number.MAX_SAFE_INTEGER ||
408
+ typeof value[6] !== 'boolean' ||
409
+ (value[6] && value[4] === Number.MAX_SAFE_INTEGER) ||
410
+ JSON.stringify(value) !== text) {
411
+ throw new Error('execution fence transition receipt is malformed');
412
+ }
413
+ return [1, value[1], value[2], value[3], value[4], value[5], value[6]];
414
+ }
415
+ function readingFromRow(row) {
416
+ row = Object.freeze(Object.fromEntries(Object.getOwnPropertyNames(row).map((key) => [key, row[key]])));
417
+ const metadata = decodeExecutionFenceMutationMetadata(row);
418
+ const { state } = row;
419
+ if (row.id !== EXECUTION_FENCE_ROW_ID || !isExecutionFenceState(state)) {
420
+ throw new Error('execution fence row is not a recognized singleton');
421
+ }
422
+ const proofKey = row.proof_key;
423
+ const proofRunId = row.proof_run_id;
424
+ let proofExecution;
425
+ if (metadata.proofStartToken !== null) {
426
+ proofExecution = normalizeD1RunExecutionIdentity({
427
+ tablePrefix: metadata.proofTablePrefix,
428
+ workflowId: metadata.proofWorkflowId,
429
+ runId: proofRunId,
430
+ startToken: metadata.proofStartToken,
431
+ });
432
+ if (proofExecution.tablePrefix !== metadata.proofTablePrefix ||
433
+ !isPathSafeId(proofKey)) {
434
+ throw new Error('execution fence proof identity is not canonical');
435
+ }
436
+ }
437
+ if (metadata.lastTransitionRequest !== null) {
438
+ const [, , next, key, epoch, revision, advance] = decodeTransitionReceipt(metadata.lastTransitionRequest);
439
+ if (state !== next ||
440
+ metadata.mutationEpoch !== epoch + Number(advance) ||
441
+ metadata.transitionRevision !== revision + 1 ||
442
+ (state === 'proof-only'
443
+ ? proofKey !== key || (proofRunId !== null && !isPathSafeId(proofRunId))
444
+ : proofKey !== null || proofRunId !== null)) {
445
+ throw new Error('execution fence row disagrees with its transition receipt');
446
+ }
447
+ }
448
+ return {
449
+ reading: {
450
+ state,
451
+ mutationEpoch: metadata.mutationEpoch,
452
+ requireMutationEpoch: metadata.requireMutationEpoch,
453
+ transitionRevision: metadata.transitionRevision,
454
+ ...(proofExecution === undefined ? {} : { proofExecution }),
455
+ ...(typeof proofKey === 'string' && proofKey.length > 0
456
+ ? { proofKey }
457
+ : {}),
458
+ ...(typeof proofRunId === 'string' && proofRunId.length > 0
459
+ ? { proofRunId }
460
+ : {}),
461
+ },
462
+ receipt: metadata.lastTransitionRequest,
463
+ schemaStage: metadata.schemaStage,
464
+ raw: row,
465
+ };
466
+ }
467
+ function fenceResultRows(result) {
468
+ if (result === null ||
469
+ typeof result !== 'object' ||
470
+ ('success' in result && result.success !== true) ||
471
+ !('results' in result)) {
472
+ throw new Error('execution fence statement returned an invalid result');
473
+ }
474
+ const rows = result.results;
475
+ if (!Array.isArray(rows))
476
+ throw new Error('execution fence statement returned an invalid result');
477
+ const length = rows.length;
478
+ if (!Number.isSafeInteger(length) || length < 0)
479
+ throw new Error('execution fence statement returned an invalid result');
480
+ return Array.from({ length }, (_, index) => {
481
+ if (!Object.hasOwn(rows, index))
482
+ throw new Error('execution fence statement returned an invalid row');
483
+ const row = rows[index];
484
+ if (row === null || typeof row !== 'object' || Array.isArray(row)) {
485
+ throw new Error('execution fence statement returned an invalid row');
486
+ }
487
+ return row;
488
+ });
489
+ }
490
+ function returningFence(result) {
491
+ const rows = fenceResultRows(result);
492
+ if (rows.length > 1)
493
+ throw new Error('execution fence UPDATE returned multiple rows');
494
+ const row = rows[0];
495
+ if (row === undefined)
496
+ return undefined;
497
+ const stored = readingFromRow(row);
498
+ if (stored.schemaStage !== EXECUTION_FENCE_CURRENT_SCHEMA_STAGE)
499
+ throw new Error('execution fence UPDATE returned a legacy row');
500
+ return stored;
501
+ }
502
+ /** @internal Validate an already-observed current-schema RETURNING row. */
503
+ export function decodeExecutionFenceAdmissionRow(row) {
504
+ const stored = readingFromRow(row);
505
+ if (stored.schemaStage !== 7)
506
+ throw new Error('initial admission requires current fence metadata');
507
+ return Object.freeze({
508
+ reading: Object.freeze(stored.reading),
509
+ schemaStage: 7,
510
+ raw: stored.raw,
511
+ });
512
+ }
513
+ /** @internal Validate actual PRAGMA rows from a consistent readback batch. */
514
+ export async function validateExecutionFenceAdmissionSchema(result) {
515
+ const columns = fenceResultRows(result);
516
+ if ((await readExecutionFenceSchemaProtocol(async () => columns)) !== 7)
517
+ throw new Error('initial admission requires the current fence schema');
518
+ }
519
+ /** @internal */
520
+ export async function captureExecutionFenceAdmissionSchema(result) {
521
+ const rows = fenceResultRows(result).map((row) => Object.freeze(Object.fromEntries(Object.getOwnPropertyNames(row).map((key) => [key, row[key]]))));
522
+ await validateExecutionFenceAdmissionSchema({ results: rows });
523
+ return JSON.stringify(rows.map(({ name, type, notnull, dflt_value, pk, hidden }) => [
524
+ name,
525
+ type,
526
+ notnull,
527
+ dflt_value,
528
+ pk,
529
+ hidden,
530
+ ]));
531
+ }
532
+ /**
533
+ * SQLite/D1's "no such table", for THIS store's table: a table that was never
534
+ * created is not a fault here — it is a pre-0.20 database, which reads as
535
+ * `open`.
536
+ *
537
+ * The rule itself (walk the cause chain, bounded and cycle-safe, and test the
538
+ * ROOT only) lives in cause-chain.ts, shared with the start-reservation store
539
+ * because both answer the same question and both are dangerous in the same
540
+ * direction. A chain with no reachable root degrades CLOSED there for the same
541
+ * reason it does here: no root was observed, and an unobserved root is not
542
+ * evidence of an absent table.
543
+ */
544
+ function isMissingFenceTable(error) {
545
+ return missingTableReadsEmpty(error, EXECUTION_FENCE_TABLE);
546
+ }
547
+ async function selectedProofObservation(db, address) {
548
+ try {
549
+ const prepared = prepareRawWorkflowSnapshotRead(db, address);
550
+ const raw = decodeRawWorkflowSnapshotResult(await prepared.statement.all(), prepared.address);
551
+ if (raw === undefined)
552
+ return undefined;
553
+ const snapshot = JSON.parse(raw.snapshot);
554
+ if (snapshot === null ||
555
+ typeof snapshot !== 'object' ||
556
+ Array.isArray(snapshot))
557
+ throw new Error('proof snapshot is malformed');
558
+ const state = snapshot;
559
+ if (state.runId !== raw.runId || !isRunStatus(state.status))
560
+ throw new Error('proof snapshot identity or status is malformed');
561
+ for (const key of ['requestContext', 'context', 'steps']) {
562
+ const value = state[key];
563
+ if (value !== undefined &&
564
+ (value === null || typeof value !== 'object' || Array.isArray(value)))
565
+ throw new Error('proof snapshot container is malformed');
566
+ }
567
+ const source = state.requestContext?.[RUN_PROVENANCE_CONTEXT_KEY];
568
+ const start = decodeRunStartIdentity(source);
569
+ if (start === undefined)
570
+ return { raw, status: state.status };
571
+ const provenance = decodeProgressRunProvenance(source);
572
+ const execution = normalizeD1RunExecutionIdentity({
573
+ ...prepared.address,
574
+ startToken: provenance.startToken,
575
+ });
576
+ return { raw, status: state.status, execution, provenance };
577
+ }
578
+ catch (cause) {
579
+ throw new ExecutionFenceUnreadableError('proof snapshot is not readable', {
580
+ cause,
581
+ });
582
+ }
583
+ }
584
+ function reservationValues(row) {
585
+ if (row.binding.kind !== 'bound')
586
+ throw new InvalidExecutionIdentityError('admission');
587
+ return [
588
+ row.key,
589
+ row.owner.kind,
590
+ row.owner.id,
591
+ row.targetKind,
592
+ row.targetId,
593
+ row.runId,
594
+ row.threadId ?? null,
595
+ row.state,
596
+ row.createdAt,
597
+ row.updatedAt,
598
+ row.binding.execution.startToken,
599
+ row.binding.execution.tablePrefix,
600
+ row.binding.execution.workflowId,
601
+ ];
602
+ }
603
+ /**
604
+ * The deployment's fence, over one D1 database — the SAME database the runner's
605
+ * snapshots and the deployment sentinel live in, so the fence cannot be
606
+ * separated from the state it fences by any binding mistake.
607
+ */
608
+ export class ExecutionFenceStore {
609
+ #db;
610
+ #now;
611
+ constructor(db, options = {}) {
612
+ this.#db = db;
613
+ this.#now = options.now ?? Date.now;
614
+ }
615
+ /**
616
+ * The current fence state. NEVER memoized (see the module header) and never
617
+ * a write: this is on every gated request path, and a read path that emits
618
+ * `CREATE TABLE IF NOT EXISTS` is a write path wearing a read's name — it
619
+ * would make a fenced deployment mutate its own database to answer a
620
+ * question, and would turn a read-only replica or a revoked-write incident
621
+ * into an outage instead of a degrade.
622
+ *
623
+ * A missing table or missing legacy row reads as `open`. A missing modern row is
624
+ * unreadable and is never silently recreated.
625
+ */
626
+ async read() {
627
+ return (await this.#readStored())?.reading ?? OPEN_EXECUTION_FENCE;
628
+ }
629
+ usesDatabase(binding) {
630
+ return this.#db === binding;
631
+ }
632
+ /** @internal Pure strict observation; seed only on the admission preparation path. */
633
+ async readForAdmission() {
634
+ try {
635
+ const rows = fenceResultRows(await this.#db
636
+ .prepare(`SELECT * FROM ${EXECUTION_FENCE_TABLE} LIMIT 2`)
637
+ .all());
638
+ const row = rows[0];
639
+ if (rows.length !== 1 || row === undefined)
640
+ throw new Error('initial admission requires an exact fence singleton');
641
+ const observation = decodeExecutionFenceAdmissionRow(row);
642
+ await validateExecutionFenceAdmissionSchema(await this.#db
643
+ .prepare(`PRAGMA table_xinfo(${EXECUTION_FENCE_TABLE})`)
644
+ .all());
645
+ return observation;
646
+ }
647
+ catch (error) {
648
+ throw new ExecutionFenceUnreadableError('initial admission requires current fence metadata', { cause: error });
649
+ }
650
+ }
651
+ /**
652
+ * Provisioning-time seeding: write the deployment's INITIAL fence state.
653
+ *
654
+ * INSERT-if-absent, never an overwrite. Seeding runs on every provisioning
655
+ * pass (including the already-owned early return), so a crash between the
656
+ * deployment sentinel and this row heals on the next attempt — but a
657
+ * re-provision of a LIVE deployment must never silently reopen a fence an
658
+ * operator closed, which an upsert would do.
659
+ *
660
+ * `state` has no default on purpose. The failure this closes is a migration
661
+ * host forgetting to ask for `migration-locked` and silently getting `open`;
662
+ * making the argument required turns that into a compile-time obligation,
663
+ * while still letting a host that wants an open deployment say so.
664
+ */
665
+ async seed(state) {
666
+ const safeState = assertExecutionFenceState(state, 'seed state');
667
+ await this.#initialize(safeState);
668
+ await this.#readStored();
669
+ }
670
+ /**
671
+ * Move the fence, compare-and-set on the CURRENT state. One conditional
672
+ * UPDATE, so two control-plane actors racing the same transition cannot both
673
+ * win: the loser changes zero rows and gets the state the winner left behind.
674
+ *
675
+ * Unlike `read()` this MAY create the table — a transition is a control-plane
676
+ * write, and a legacy database whose fence is implicitly open has no row to
677
+ * compare against. The row is materialized as `open` first, which is the
678
+ * state the implicit reading already reported, so the CAS that follows means
679
+ * exactly what it would have meant on a seeded database.
680
+ */
681
+ async transition(input) {
682
+ const expected = assertExecutionFenceState(input.expected, 'expected state');
683
+ const next = assertExecutionFenceState(input.next, 'next state');
684
+ const proofKey = this.#proofKeyFor(next, input.proofKey);
685
+ const { expectedMutationEpoch: epoch, expectedRevision: revision } = input;
686
+ const rawAdvance = input.advanceMutationEpoch;
687
+ const advance = rawAdvance ?? false;
688
+ const upgraded = epoch !== undefined || revision !== undefined;
689
+ if ((rawAdvance !== undefined && typeof rawAdvance !== 'boolean') ||
690
+ (upgraded && (!isFenceCounter(epoch) || !isFenceCounter(revision))) ||
691
+ (advance && !upgraded) ||
692
+ revision === Number.MAX_SAFE_INTEGER ||
693
+ (advance && epoch === Number.MAX_SAFE_INTEGER)) {
694
+ throw new InvalidExecutionFenceRequestError('fence expectations must be paired safe counters and advanceMutationEpoch must be boolean');
695
+ }
696
+ const receipt = upgraded
697
+ ? JSON.stringify([
698
+ 1,
699
+ expected,
700
+ next,
701
+ proofKey ?? null,
702
+ epoch,
703
+ revision,
704
+ advance,
705
+ ])
706
+ : null;
707
+ await this.#initialize('open');
708
+ await this.#readStored();
709
+ let result;
710
+ try {
711
+ const statement = upgraded
712
+ ? this.#db
713
+ .prepare(`UPDATE ${EXECUTION_FENCE_TABLE}
714
+ SET state = ?1, proof_key = ?2, proof_run_id = NULL,
715
+ proof_table_prefix = NULL, proof_workflow_id = NULL, proof_start_token = NULL,
716
+ mutation_epoch = mutation_epoch + ?3,
717
+ require_mutation_epoch = CASE WHEN ?3 = 1 THEN 1 ELSE require_mutation_epoch END,
718
+ transition_revision = transition_revision + 1,
719
+ last_transition_request = ?4, updated_at = ?5
720
+ WHERE id = ?6 AND state = ?7
721
+ AND mutation_epoch = ?8 AND transition_revision = ?9
722
+ AND require_mutation_epoch IN (0, 1)
723
+ AND transition_revision < 9007199254740991
724
+ AND (?3 = 0 OR mutation_epoch < 9007199254740991)
725
+ RETURNING *`)
726
+ .bind(next, proofKey ?? null, Number(advance), receipt, this.#now(), EXECUTION_FENCE_ROW_ID, expected, epoch, revision)
727
+ : this.#db
728
+ .prepare(`UPDATE ${EXECUTION_FENCE_TABLE}
729
+ SET state = ?, proof_key = ?, proof_run_id = NULL,
730
+ proof_table_prefix = NULL, proof_workflow_id = NULL, proof_start_token = NULL,
731
+ transition_revision = transition_revision + 1,
732
+ last_transition_request = NULL, updated_at = ?
733
+ WHERE id = ? AND state = ? AND require_mutation_epoch = 0
734
+ AND mutation_epoch = 0 AND transition_revision < 9007199254740991
735
+ RETURNING *`)
736
+ .bind(next, proofKey ?? null, this.#now(), EXECUTION_FENCE_ROW_ID, expected);
737
+ result = await statement.all();
738
+ }
739
+ catch (error) {
740
+ if (receipt !== null) {
741
+ const stored = await this.#readStored().catch(() => undefined);
742
+ if (stored?.receipt === receipt)
743
+ return stored.reading;
744
+ }
745
+ throw new ExecutionFenceUnreadableError('execution fence transition could not be recorded', { cause: error });
746
+ }
747
+ const returned = this.#decodeReturned(result);
748
+ if (returned !== undefined)
749
+ return returned.reading;
750
+ const stored = await this.#readStored();
751
+ if (receipt !== null && stored?.receipt === receipt)
752
+ return stored.reading;
753
+ const reading = stored?.reading ?? OPEN_EXECUTION_FENCE;
754
+ throw new FenceTransitionConflictError(expected, reading.state, {
755
+ reading,
756
+ conflict: !upgraded && reading.requireMutationEpoch
757
+ ? 'versioned-expectation-required'
758
+ : 'expectation-mismatch',
759
+ });
760
+ }
761
+ /**
762
+ * Bind the proof-only state to the run it admitted, conditionally.
763
+ *
764
+ * The condition is the whole point: between the read that ADMITTED a start
765
+ * and this write-back the fence may have moved, or a different run may have
766
+ * claimed the proof. Zero rows changed means the caller must refuse the
767
+ * start it was about to make — the fence is no longer the one it read.
768
+ * Re-writing the SAME runId is admitted so a retry of an interrupted start
769
+ * converges instead of deadlocking on its own earlier write.
770
+ */
771
+ async recordProofRun(proofKey, runId, admitted) {
772
+ const epoch = admitted?.mutationEpoch;
773
+ const revision = admitted?.transitionRevision;
774
+ if (!isPathSafeId(proofKey)) {
775
+ throw new InvalidExecutionFenceRequestError('proofKey must be a URL-path-safe identifier');
776
+ }
777
+ if (!isPathSafeId(runId)) {
778
+ throw new InvalidExecutionFenceRequestError('proof runId must be a URL-path-safe identifier');
779
+ }
780
+ if (admitted !== undefined &&
781
+ (admitted === null ||
782
+ typeof admitted !== 'object' ||
783
+ !isFenceCounter(epoch) ||
784
+ !isFenceCounter(revision))) {
785
+ throw new InvalidExecutionFenceRequestError('proof admission must contain safe epoch and revision counters');
786
+ }
787
+ const observed = await this.#readStored();
788
+ if (observed === undefined)
789
+ return false;
790
+ if (observed.schemaStage < EXECUTION_FENCE_CURRENT_SCHEMA_STAGE) {
791
+ await this.#initialize(observed.reading.state);
792
+ await this.#readStored();
793
+ }
794
+ let result;
795
+ try {
796
+ const statement = this.#db
797
+ .prepare(`UPDATE ${EXECUTION_FENCE_TABLE}
798
+ SET updated_at = CASE WHEN proof_run_id IS NULL THEN ? ELSE updated_at END,
799
+ proof_run_id = ?
800
+ WHERE id = ? AND state = 'proof-only' AND proof_key = ?
801
+ AND (proof_run_id IS NULL OR proof_run_id = ?)
802
+ AND proof_table_prefix IS NULL AND proof_workflow_id IS NULL AND proof_start_token IS NULL
803
+ AND ${admitted === undefined
804
+ ? 'require_mutation_epoch = 0 AND mutation_epoch = 0'
805
+ : 'mutation_epoch = ? AND transition_revision = ?'}
806
+ RETURNING *`)
807
+ .bind(this.#now(), runId, EXECUTION_FENCE_ROW_ID, proofKey, runId, ...(admitted === undefined ? [] : [epoch, revision]));
808
+ result = await statement.all();
809
+ }
810
+ catch (error) {
811
+ const stored = await this.#readStored().catch(() => undefined);
812
+ const reading = stored?.reading;
813
+ if (reading?.state === 'proof-only' &&
814
+ reading.proofKey === proofKey &&
815
+ reading.proofRunId === runId &&
816
+ reading.proofExecution === undefined &&
817
+ stored?.raw.proof_table_prefix === null &&
818
+ stored.raw.proof_workflow_id === null &&
819
+ stored.raw.proof_start_token === null &&
820
+ (admitted === undefined
821
+ ? !reading.requireMutationEpoch && reading.mutationEpoch === 0
822
+ : reading.mutationEpoch === epoch &&
823
+ reading.transitionRevision === revision)) {
824
+ return true;
825
+ }
826
+ throw new ExecutionFenceUnreadableError('execution fence proof run could not be recorded', { cause: error });
827
+ }
828
+ const returned = this.#decodeReturned(result);
829
+ if (returned !== undefined) {
830
+ if (returned.reading.proofExecution !== undefined ||
831
+ returned.raw.proof_table_prefix !== null ||
832
+ returned.raw.proof_workflow_id !== null ||
833
+ returned.raw.proof_start_token !== null)
834
+ throw new ExecutionFenceUnreadableError('legacy proof write returned a modern binding');
835
+ return true;
836
+ }
837
+ await this.#readStored();
838
+ return false;
839
+ }
840
+ async readCurrentRunExecution(address) {
841
+ return (await selectedProofObservation(this.#db, address))?.execution;
842
+ }
843
+ async rebindProofRun(options) {
844
+ const { reservation: input, execution: rawExecution, proof: rawProof, mutationEpoch, reservationStore, } = options;
845
+ const reservation = captureBoundReservation(input);
846
+ const { tablePrefix, workflowId, runId, startToken, owner, target } = rawExecution;
847
+ const normalized = normalizeStartExecutionIdentity({
848
+ tablePrefix,
849
+ workflowId,
850
+ runId,
851
+ startToken,
852
+ owner,
853
+ target,
854
+ });
855
+ const execution = normalizeD1RunExecutionIdentity(normalized);
856
+ const { key, mutationEpoch: epoch, transitionRevision: revision, } = rawProof;
857
+ const callerEpoch = normalizeMutationEpoch(mutationEpoch);
858
+ const usesDatabase = reservationStore.usesDatabase;
859
+ const now = this.#now();
860
+ if (tablePrefix !== execution.tablePrefix ||
861
+ key !== reservation.key ||
862
+ !isFenceCounter(epoch) ||
863
+ !isFenceCounter(revision) ||
864
+ typeof now !== 'number' ||
865
+ !Number.isFinite(now) ||
866
+ typeof usesDatabase !== 'function' ||
867
+ !Reflect.apply(usesDatabase, reservationStore, [this.#db]) ||
868
+ reservation.binding.kind !== 'bound' ||
869
+ normalized.owner.kind !== reservation.owner.kind ||
870
+ normalized.owner.id !== reservation.owner.id ||
871
+ normalized.target.kind !== reservation.targetKind ||
872
+ normalized.target.id !== reservation.targetId ||
873
+ (normalized.target.kind === 'agent'
874
+ ? normalized.target.threadId
875
+ : undefined) !== reservation.threadId ||
876
+ !admitsExistingRun({ state: 'proof-only', proofExecution: execution }, reservation.binding.execution))
877
+ throw new InvalidExecutionIdentityError('admission');
878
+ try {
879
+ const observed = await this.readForAdmission();
880
+ const requireSchemas = async () => {
881
+ await validateExecutionFenceAdmissionSchema(await this.#db
882
+ .prepare(`PRAGMA table_xinfo(${EXECUTION_FENCE_TABLE})`)
883
+ .all());
884
+ validateStartReservationAdmissionSchema(await this.#db
885
+ .prepare(`PRAGMA table_xinfo(${START_IDEMPOTENCY_TABLE})`)
886
+ .all());
887
+ };
888
+ await requireSchemas();
889
+ const current = decodeStartReservationAdmissionResult(await this.#db
890
+ .prepare(`SELECT * FROM ${START_IDEMPOTENCY_TABLE} WHERE key = ? LIMIT 2`)
891
+ .bind(key)
892
+ .all());
893
+ const selected = await selectedProofObservation(this.#db, execution);
894
+ const reading = observed.reading;
895
+ if (current === undefined ||
896
+ current.binding.kind !== 'bound' ||
897
+ !sameReservationIdentity(current, reservation) ||
898
+ JSON.stringify(reservationValues(current)) !==
899
+ JSON.stringify(reservationValues(reservation)) ||
900
+ selected?.execution === undefined ||
901
+ selected.status === 'pending' ||
902
+ !admitsExistingRun({ state: 'proof-only', proofExecution: execution }, selected.execution) ||
903
+ selected.provenance?.startIdentity?.owner.kind !==
904
+ reservation.owner.kind ||
905
+ selected.provenance.startIdentity.owner.id !== reservation.owner.id ||
906
+ selected.provenance.startIdentity.target.kind !==
907
+ reservation.targetKind ||
908
+ selected.provenance.startIdentity.target.id !== reservation.targetId ||
909
+ (selected.provenance.startIdentity.target.kind === 'agent'
910
+ ? selected.provenance.startIdentity.target.threadId
911
+ : undefined) !== reservation.threadId ||
912
+ reading.state !== 'proof-only' ||
913
+ reading.proofKey !== key ||
914
+ reading.mutationEpoch !== epoch ||
915
+ reading.transitionRevision !== revision ||
916
+ (reading.requireMutationEpoch && callerEpoch !== epoch) ||
917
+ (reading.proofRunId !== undefined &&
918
+ !admitsExistingRun(reading, execution)))
919
+ return false;
920
+ const raw = selected.raw;
921
+ const snapshotPredicate = `EXISTS (SELECT 1 FROM "${execution.tablePrefix}mastra_workflow_snapshot"
922
+ WHERE workflow_name = ? AND run_id = ? AND resourceId IS ? AND snapshot = ? AND createdAt = ? AND updatedAt = ?)`;
923
+ const reservationPredicate = `EXISTS (SELECT 1 FROM ${START_IDEMPOTENCY_TABLE}
924
+ WHERE key = ? AND owner_kind = ? AND owner_id = ? AND target_kind = ? AND target_id = ? AND run_id = ?
925
+ AND thread_id IS ? AND state = ? AND created_at = ? AND updated_at = ?
926
+ AND start_token = ? AND start_table_prefix IS ? AND start_workflow_id = ?)`;
927
+ const framePredicate = `id = 'deployment' AND state = 'proof-only' AND proof_key = ?
928
+ AND mutation_epoch = ? AND transition_revision = ? AND require_mutation_epoch = ? AND last_transition_request IS ?
929
+ AND (require_mutation_epoch = 0 OR mutation_epoch = ?)`;
930
+ const exactTuple = 'proof_run_id = ? AND proof_table_prefix = ? AND proof_workflow_id = ? AND proof_start_token = ?';
931
+ const emptyTuple = 'proof_run_id IS NULL AND proof_table_prefix IS NULL AND proof_workflow_id IS NULL AND proof_start_token IS NULL';
932
+ const tuple = [
933
+ execution.runId,
934
+ execution.tablePrefix,
935
+ execution.workflowId,
936
+ execution.startToken,
937
+ ];
938
+ const frame = [
939
+ key,
940
+ epoch,
941
+ revision,
942
+ Number(reading.requireMutationEpoch),
943
+ observed.raw.last_transition_request,
944
+ callerEpoch ?? null,
945
+ ];
946
+ const rowValues = [
947
+ raw.workflowId,
948
+ raw.runId,
949
+ raw.resourceId,
950
+ raw.snapshot,
951
+ raw.createdAt,
952
+ raw.updatedAt,
953
+ ...reservationValues(reservation),
954
+ ];
955
+ const expectedTime = reading.proofRunId === undefined ? now : observed.raw.updated_at;
956
+ const validateReturned = (result) => {
957
+ const returned = this.#decodeReturned(result);
958
+ if (returned === undefined)
959
+ return false;
960
+ const next = returned.reading;
961
+ if (next.state !== 'proof-only' ||
962
+ next.proofKey !== key ||
963
+ next.mutationEpoch !== epoch ||
964
+ next.transitionRevision !== revision ||
965
+ next.requireMutationEpoch !== reading.requireMutationEpoch ||
966
+ returned.receipt !== observed.raw.last_transition_request ||
967
+ !admitsExistingRun(next, execution) ||
968
+ returned.raw.updated_at !== expectedTime)
969
+ throw new ExecutionFenceUnreadableError('proof nomination returned an unexpected fence');
970
+ return true;
971
+ };
972
+ let result;
973
+ try {
974
+ result = await this.#db
975
+ .prepare(`UPDATE ${EXECUTION_FENCE_TABLE}
976
+ SET updated_at = CASE WHEN proof_run_id IS NULL THEN ? ELSE updated_at END,
977
+ proof_run_id = ?, proof_table_prefix = ?, proof_workflow_id = ?, proof_start_token = ?
978
+ WHERE ${framePredicate} AND ((${emptyTuple}) OR (${exactTuple}))
979
+ AND ${snapshotPredicate} AND ${reservationPredicate} RETURNING *`)
980
+ .bind(now, ...tuple, ...frame, ...tuple, ...rowValues)
981
+ .all();
982
+ }
983
+ catch (cause) {
984
+ try {
985
+ const converged = await this.#db
986
+ .prepare(`SELECT * FROM ${EXECUTION_FENCE_TABLE}
987
+ WHERE ${framePredicate} AND ${exactTuple} AND ${snapshotPredicate} AND ${reservationPredicate} LIMIT 2`)
988
+ .bind(...frame, ...tuple, ...rowValues)
989
+ .all();
990
+ await requireSchemas();
991
+ if (validateReturned(converged))
992
+ return true;
993
+ }
994
+ catch {
995
+ /* Preserve the failed write's cause. */
996
+ }
997
+ throw new ExecutionFenceUnreadableError('proof nomination could not be recorded', { cause });
998
+ }
999
+ const nominated = validateReturned(result);
1000
+ if (!nominated) {
1001
+ await requireSchemas();
1002
+ await this.readForAdmission();
1003
+ }
1004
+ return nominated;
1005
+ }
1006
+ catch (cause) {
1007
+ if (cause instanceof ExecutionFenceUnreadableError)
1008
+ throw cause;
1009
+ throw new ExecutionFenceUnreadableError('proof nomination is not readable', { cause });
1010
+ }
1011
+ }
1012
+ #proofKeyFor(next, proofKey) {
1013
+ if (next === 'proof-only') {
1014
+ if (!isPathSafeId(proofKey)) {
1015
+ throw new InvalidExecutionFenceRequestError("a URL-path-safe proofKey is required to enter 'proof-only'");
1016
+ }
1017
+ return proofKey;
1018
+ }
1019
+ if (proofKey !== undefined) {
1020
+ // Rejected rather than ignored: a caller passing a key for a state that
1021
+ // has no proof believes something about this transition that is false.
1022
+ throw new InvalidExecutionFenceRequestError(`proofKey applies only to 'proof-only' transitions, not '${next}'`);
1023
+ }
1024
+ return undefined;
1025
+ }
1026
+ #execute = async (statement) => {
1027
+ const prepared = this.#db
1028
+ .prepare(statement.sql)
1029
+ .bind(...statement.bindings);
1030
+ if (statement.mode === 'write') {
1031
+ await prepared.run();
1032
+ return [];
1033
+ }
1034
+ return fenceResultRows(await prepared.all());
1035
+ };
1036
+ async #initialize(state) {
1037
+ try {
1038
+ await initializeExecutionFenceProtocol(this.#execute, {
1039
+ state,
1040
+ seededAt: this.#now(),
1041
+ });
1042
+ }
1043
+ catch (error) {
1044
+ throw new ExecutionFenceUnreadableError('execution fence could not be initialized', { cause: error });
1045
+ }
1046
+ }
1047
+ #decodeReturned(result) {
1048
+ try {
1049
+ return returningFence(result);
1050
+ }
1051
+ catch (error) {
1052
+ throw new ExecutionFenceUnreadableError('execution fence UPDATE result is not readable', { cause: error });
1053
+ }
1054
+ }
1055
+ async #readStored() {
1056
+ try {
1057
+ let minimumStage = 0;
1058
+ for (let attempt = 0; attempt < 2; attempt += 1) {
1059
+ let rows;
1060
+ try {
1061
+ rows = await this.#execute({
1062
+ mode: 'read',
1063
+ sql: `SELECT * FROM ${EXECUTION_FENCE_TABLE} LIMIT 2`,
1064
+ bindings: [],
1065
+ });
1066
+ }
1067
+ catch (error) {
1068
+ if (attempt === 0 && isMissingFenceTable(error))
1069
+ return undefined;
1070
+ throw error;
1071
+ }
1072
+ const stage = await readExecutionFenceSchemaProtocol(this.#execute);
1073
+ if (!Array.isArray(rows) ||
1074
+ stage === undefined ||
1075
+ stage < minimumStage) {
1076
+ throw new Error('execution fence row observation has no compatible schema');
1077
+ }
1078
+ if (rows.length === 0 && attempt === 0) {
1079
+ if (stage === 0)
1080
+ return undefined;
1081
+ minimumStage = stage;
1082
+ continue;
1083
+ }
1084
+ if (rows.length !== 1)
1085
+ throw new Error('execution fence row is not an exact singleton');
1086
+ const stored = readingFromRow(rows[0]);
1087
+ if (stored.schemaStage > stage)
1088
+ throw new Error('execution fence schema observation precedes row metadata');
1089
+ return stored;
1090
+ }
1091
+ throw new Error('execution fence row is missing');
1092
+ }
1093
+ catch (error) {
1094
+ throw new ExecutionFenceUnreadableError('execution fence state is not readable', { cause: error });
1095
+ }
1096
+ }
1097
+ }
1098
+ //# sourceMappingURL=execution-fence.js.map