@proofoftech/flowsafe 0.20.0 → 0.22.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 (238) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +55 -10
  3. package/deployment-identity-protocol.d.mts +28 -3
  4. package/deployment-identity-protocol.mjs +275 -21
  5. package/dist/agent-host/router.d.ts.map +1 -1
  6. package/dist/agent-host/router.js +11 -2
  7. package/dist/agent-host/router.js.map +1 -1
  8. package/dist/agent-host/thread-host.d.ts +3 -1
  9. package/dist/agent-host/thread-host.d.ts.map +1 -1
  10. package/dist/agent-host/thread-host.js +858 -351
  11. package/dist/agent-host/thread-host.js.map +1 -1
  12. package/dist/agent-host/thread-topology.d.ts +8 -0
  13. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  14. package/dist/agent-host/thread-topology.js +243 -64
  15. package/dist/agent-host/thread-topology.js.map +1 -1
  16. package/dist/agent-runner/durable-agent-runner.d.ts +89 -14
  17. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  18. package/dist/agent-runner/durable-agent-runner.js +369 -44
  19. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  20. package/dist/agent-runner/index.d.ts +1 -1
  21. package/dist/agent-runner/index.d.ts.map +1 -1
  22. package/dist/agent-runner/index.js.map +1 -1
  23. package/dist/approval-api/actor-context.d.ts +4 -0
  24. package/dist/approval-api/actor-context.d.ts.map +1 -1
  25. package/dist/approval-api/actor-context.js +53 -5
  26. package/dist/approval-api/actor-context.js.map +1 -1
  27. package/dist/approval-api/principal.d.ts +1 -1
  28. package/dist/approval-api/principal.js +1 -1
  29. package/dist/approval-api/retention.d.ts +1 -2
  30. package/dist/approval-api/retention.d.ts.map +1 -1
  31. package/dist/approval-api/retention.js.map +1 -1
  32. package/dist/approval-api/service.d.ts +13 -20
  33. package/dist/approval-api/service.d.ts.map +1 -1
  34. package/dist/approval-api/service.js +52 -28
  35. package/dist/approval-api/service.js.map +1 -1
  36. package/dist/audit-export/index.d.ts +2 -2
  37. package/dist/audit-export/index.js +2 -2
  38. package/dist/background-tasks/d1-storage.d.ts +4 -3
  39. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  40. package/dist/background-tasks/d1-storage.js +8 -14
  41. package/dist/background-tasks/d1-storage.js.map +1 -1
  42. package/dist/background-tasks/host.d.ts.map +1 -1
  43. package/dist/background-tasks/host.js +3 -2
  44. package/dist/background-tasks/host.js.map +1 -1
  45. package/dist/do-runner/constants.d.ts +3 -0
  46. package/dist/do-runner/constants.d.ts.map +1 -0
  47. package/dist/do-runner/constants.js +3 -0
  48. package/dist/do-runner/constants.js.map +1 -0
  49. package/dist/do-runner/d1-storage.d.ts +34 -158
  50. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  51. package/dist/do-runner/d1-storage.js +935 -402
  52. package/dist/do-runner/d1-storage.js.map +1 -1
  53. package/dist/do-runner/durable-object.d.ts.map +1 -1
  54. package/dist/do-runner/durable-object.js +472 -185
  55. package/dist/do-runner/durable-object.js.map +1 -1
  56. package/dist/do-runner/execution-admission.d.ts +114 -0
  57. package/dist/do-runner/execution-admission.d.ts.map +1 -0
  58. package/dist/do-runner/execution-admission.js +206 -0
  59. package/dist/do-runner/execution-admission.js.map +1 -0
  60. package/dist/do-runner/execution-context.d.ts +5 -1
  61. package/dist/do-runner/execution-context.d.ts.map +1 -1
  62. package/dist/do-runner/execution-context.js +6 -1
  63. package/dist/do-runner/execution-context.js.map +1 -1
  64. package/dist/do-runner/execution-fence.d.ts +74 -30
  65. package/dist/do-runner/execution-fence.d.ts.map +1 -1
  66. package/dist/do-runner/execution-fence.js +684 -120
  67. package/dist/do-runner/execution-fence.js.map +1 -1
  68. package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
  69. package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
  70. package/dist/do-runner/fenced-workflow-capability.js +3 -0
  71. package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
  72. package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
  73. package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
  74. package/dist/do-runner/fenced-workflows-d1.js +894 -0
  75. package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
  76. package/dist/do-runner/index.d.ts +13 -8
  77. package/dist/do-runner/index.d.ts.map +1 -1
  78. package/dist/do-runner/index.js +6 -2
  79. package/dist/do-runner/index.js.map +1 -1
  80. package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
  81. package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
  82. package/dist/do-runner/initial-admission-refusal.js +41 -0
  83. package/dist/do-runner/initial-admission-refusal.js.map +1 -0
  84. package/dist/do-runner/inventory.d.ts +2 -1
  85. package/dist/do-runner/inventory.d.ts.map +1 -1
  86. package/dist/do-runner/inventory.js +28 -39
  87. package/dist/do-runner/inventory.js.map +1 -1
  88. package/dist/do-runner/notification-predicate.d.ts +7 -7
  89. package/dist/do-runner/notification-predicate.d.ts.map +1 -1
  90. package/dist/do-runner/notification-predicate.js +134 -7
  91. package/dist/do-runner/notification-predicate.js.map +1 -1
  92. package/dist/do-runner/run-lifecycle.d.ts +20 -1
  93. package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
  94. package/dist/do-runner/run-lifecycle.js +69 -15
  95. package/dist/do-runner/run-lifecycle.js.map +1 -1
  96. package/dist/do-runner/run-provenance.d.ts +38 -0
  97. package/dist/do-runner/run-provenance.d.ts.map +1 -0
  98. package/dist/do-runner/run-provenance.js +152 -0
  99. package/dist/do-runner/run-provenance.js.map +1 -0
  100. package/dist/do-runner/run-storage-tables.d.ts +2 -0
  101. package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
  102. package/dist/do-runner/run-storage-tables.js +4 -0
  103. package/dist/do-runner/run-storage-tables.js.map +1 -0
  104. package/dist/do-runner/run-terminal-state.d.ts +29 -0
  105. package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
  106. package/dist/do-runner/run-terminal-state.js +105 -0
  107. package/dist/do-runner/run-terminal-state.js.map +1 -0
  108. package/dist/do-runner/runtime.d.ts +108 -46
  109. package/dist/do-runner/runtime.d.ts.map +1 -1
  110. package/dist/do-runner/runtime.js +927 -438
  111. package/dist/do-runner/runtime.js.map +1 -1
  112. package/dist/do-runner/start-idempotency.d.ts +35 -258
  113. package/dist/do-runner/start-idempotency.d.ts.map +1 -1
  114. package/dist/do-runner/start-idempotency.js +606 -498
  115. package/dist/do-runner/start-idempotency.js.map +1 -1
  116. package/dist/do-runner/start-reservation-contract.d.ts +103 -0
  117. package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
  118. package/dist/do-runner/start-reservation-contract.js +338 -0
  119. package/dist/do-runner/start-reservation-contract.js.map +1 -0
  120. package/dist/do-runner/suspension-deadline.d.ts +4 -11
  121. package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
  122. package/dist/do-runner/suspension-deadline.js +8 -12
  123. package/dist/do-runner/suspension-deadline.js.map +1 -1
  124. package/dist/do-runner/table-prefix.d.ts.map +1 -1
  125. package/dist/do-runner/table-prefix.js +2 -1
  126. package/dist/do-runner/table-prefix.js.map +1 -1
  127. package/dist/do-runner/testing.d.ts +3 -0
  128. package/dist/do-runner/testing.d.ts.map +1 -0
  129. package/dist/do-runner/testing.js +3 -0
  130. package/dist/do-runner/testing.js.map +1 -0
  131. package/dist/do-runner/thread-do.d.ts +2 -1
  132. package/dist/do-runner/thread-do.d.ts.map +1 -1
  133. package/dist/do-runner/thread-do.js +14 -10
  134. package/dist/do-runner/thread-do.js.map +1 -1
  135. package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
  136. package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
  137. package/dist/do-runner/workflow-snapshot-row.js +97 -0
  138. package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
  139. package/dist/goals/objective-routes.d.ts +1 -5
  140. package/dist/goals/objective-routes.d.ts.map +1 -1
  141. package/dist/goals/objective-routes.js +32 -53
  142. package/dist/goals/objective-routes.js.map +1 -1
  143. package/dist/host-kit/approval-bridge.d.ts +8 -8
  144. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  145. package/dist/host-kit/approval-bridge.js +18 -15
  146. package/dist/host-kit/approval-bridge.js.map +1 -1
  147. package/dist/host-kit/do-response.d.ts +16 -0
  148. package/dist/host-kit/do-response.d.ts.map +1 -1
  149. package/dist/host-kit/do-response.js +181 -0
  150. package/dist/host-kit/do-response.js.map +1 -1
  151. package/dist/host-kit/do-run-topology.d.ts +2 -14
  152. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  153. package/dist/host-kit/do-run-topology.js +31 -24
  154. package/dist/host-kit/do-run-topology.js.map +1 -1
  155. package/dist/host-kit/env-vars.d.ts.map +1 -1
  156. package/dist/host-kit/env-vars.js +5 -6
  157. package/dist/host-kit/env-vars.js.map +1 -1
  158. package/dist/host-kit/flowsafe-worker.d.ts +38 -6
  159. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  160. package/dist/host-kit/flowsafe-worker.js +115 -93
  161. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  162. package/dist/host-kit/host-approval-service.d.ts +4 -14
  163. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  164. package/dist/host-kit/host-approval-service.js +23 -40
  165. package/dist/host-kit/host-approval-service.js.map +1 -1
  166. package/dist/host-kit/index.d.ts +7 -1
  167. package/dist/host-kit/index.d.ts.map +1 -1
  168. package/dist/host-kit/index.js +4 -0
  169. package/dist/host-kit/index.js.map +1 -1
  170. package/dist/host-kit/run-route-error.d.ts +3 -17
  171. package/dist/host-kit/run-route-error.d.ts.map +1 -1
  172. package/dist/host-kit/run-route-error.js +4 -24
  173. package/dist/host-kit/run-route-error.js.map +1 -1
  174. package/dist/host-kit/run-router.d.ts +6 -2
  175. package/dist/host-kit/run-router.d.ts.map +1 -1
  176. package/dist/host-kit/run-router.js +93 -80
  177. package/dist/host-kit/run-router.js.map +1 -1
  178. package/dist/host-kit/thread-topology.d.ts +1 -1
  179. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  180. package/dist/host-kit/thread-topology.js +7 -3
  181. package/dist/host-kit/thread-topology.js.map +1 -1
  182. package/dist/internal-error-response.d.ts.map +1 -1
  183. package/dist/internal-error-response.js +16 -6
  184. package/dist/internal-error-response.js.map +1 -1
  185. package/dist/schedules/index.d.ts +1 -0
  186. package/dist/schedules/index.d.ts.map +1 -1
  187. package/dist/schedules/index.js +1 -7
  188. package/dist/schedules/index.js.map +1 -1
  189. package/dist/schedules/mutation-contract.d.ts +38 -0
  190. package/dist/schedules/mutation-contract.d.ts.map +1 -0
  191. package/dist/schedules/mutation-contract.js +21 -0
  192. package/dist/schedules/mutation-contract.js.map +1 -0
  193. package/dist/schedules/router.d.ts +11 -19
  194. package/dist/schedules/router.d.ts.map +1 -1
  195. package/dist/schedules/router.js +130 -49
  196. package/dist/schedules/router.js.map +1 -1
  197. package/dist/schedules/schedules-d1.d.ts +11 -5
  198. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  199. package/dist/schedules/schedules-d1.js +571 -144
  200. package/dist/schedules/schedules-d1.js.map +1 -1
  201. package/dist/schedules/storage.d.ts +0 -7
  202. package/dist/schedules/storage.d.ts.map +1 -1
  203. package/dist/schedules/storage.js +0 -27
  204. package/dist/schedules/storage.js.map +1 -1
  205. package/dist/schedules/tick.d.ts +1 -8
  206. package/dist/schedules/tick.d.ts.map +1 -1
  207. package/dist/schedules/tick.js +15 -20
  208. package/dist/schedules/tick.js.map +1 -1
  209. package/dist/signal-providers/webhook-route.d.ts +1 -1
  210. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  211. package/dist/signal-providers/webhook-route.js +99 -109
  212. package/dist/signal-providers/webhook-route.js.map +1 -1
  213. package/dist/signals/d1-shared.d.ts +11 -8
  214. package/dist/signals/d1-shared.d.ts.map +1 -1
  215. package/dist/signals/d1-shared.js +2 -7
  216. package/dist/signals/d1-shared.js.map +1 -1
  217. package/dist/signals/index.d.ts +1 -1
  218. package/dist/signals/index.d.ts.map +1 -1
  219. package/dist/signals/index.js +1 -1
  220. package/dist/signals/index.js.map +1 -1
  221. package/dist/signals/notification-dispatch.d.ts +84 -4
  222. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  223. package/dist/signals/notification-dispatch.js +365 -53
  224. package/dist/signals/notification-dispatch.js.map +1 -1
  225. package/dist/signals/notifications-d1.d.ts +6 -1
  226. package/dist/signals/notifications-d1.d.ts.map +1 -1
  227. package/dist/signals/notifications-d1.js +215 -10
  228. package/dist/signals/notifications-d1.js.map +1 -1
  229. package/dist/signals/router.d.ts +6 -4
  230. package/dist/signals/router.d.ts.map +1 -1
  231. package/dist/signals/router.js +49 -84
  232. package/dist/signals/router.js.map +1 -1
  233. package/dist/signals/thread-do-routes.d.ts +2 -0
  234. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  235. package/dist/signals/thread-do-routes.js +250 -81
  236. package/dist/signals/thread-do-routes.js.map +1 -1
  237. package/package.json +9 -7
  238. package/scripts/seed-deployment-identity.mjs +27 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,106 @@
1
1
  # @proofoftech/flowsafe
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 36c60c8: Require `@mastra/core` 1.67.0 exactly (previously 1.53.0). The peer is exact, so every consumer must move to 1.67.0 as well; this is breaking for consumers pinned to 1.53.0. 1.67.0 bundles for Cloudflare Workers and Vite again — mastra-ai/mastra#20638, the dynamic-import regression that held the pin at 1.53.0, closed upstream.
8
+
9
+ `@mastra/cloudflare-d1` moves from 1.1.1 to 1.3.2, whose own peer requires a core newer than 1.53.0. FlowSafe's `@proofoftech/breakwater` peer floor rises to `>=0.15.0 <1.0.0` in step, that being the first Breakwater release built against the same core.
10
+
11
+ The `@mastra/core` patch FlowSafe shipped under `patches/` is retired: 1.67.0 carries both fixes upstream (mastra-ai/mastra#23693, mastra-ai/mastra#23694). The patch file is gone from the published package, and so are the two refusals that required it — FlowSafe no longer refuses to construct a delivering notification dispatch tick, nor notification ingestion and dispatch requests, on an install whose core lacks the patch. Consequence for anyone running a core outside the declared peer without having applied the patch: a notification `source` named after an `Object.prototype` member is miscounted in the summary core renders, and its source delivery policy resolves the inherited member instead of the configured priority or default action. That configuration was unsupported before and remains so, but it now fails silently rather than loudly. Application roots that copied the patch into their own `patches/` should drop it along with the `patchedDependencies` entry or `postinstall` script that applied it.
12
+
13
+ `createD1Storage({ domains })` composes the two storage domains 1.67.0 adds, `workflowDefinitions` and `knowledge`, through the same override seam as the other domains. `@mastra/cloudflare-d1` backs neither, so each resolves `undefined` unless a host supplies one through that seam.
14
+
15
+ The workspace lockfile behind this release was resolved once with pnpm's seven-day minimum-release-age gate overridden for that resolution only. Five newly resolved versions were younger than the gate at resolution on 2026-09-19: `@mastra/core` 1.67.0 and `@mastra/schema-compat` 1.3.10 (published 2026-09-15), which the workspace's standing `@mastra/*` exclude admits with the gate on, and `posthog-node` 5.52.4 (2026-09-15), `@posthog/types` 1.412.2 (2026-09-17) and `@posthog/core` 1.55.0 (2026-09-18), which the override alone admitted. None of the five declares a lifecycle script or ships a native component; all five carry npm provenance attestations (SLSA v1, published from GitHub Actions); and `posthog-node`, with `@posthog/core` and `@posthog/types` beneath it, is a hard dependency of `@mastra/core` that ships inside a bundled Worker.
16
+
17
+ The private `showcase` and `anchorage-agent-starter` packages move to the same core.
18
+
19
+ ### Patch Changes
20
+
21
+ - 36cfdc2: Keep `flowsafe-provision` inert when imported from stdin, eval or print programs, and virtual workers, even when an entry name aliases the script. Direct execution, file and directory symlinks, and file workers under eval parents continue to invoke the CLI.
22
+
23
+ ## 0.21.0
24
+
25
+ ### Minor Changes
26
+
27
+ - c8c5039: The pending-notifications inventory lists pending agent-inbox notifications whether due, scheduled for later, or carrying no due timestamp. Its count includes these rows, its notDue total identifies those not yet due, and entry details expose summaryAt alongside deliverAt.
28
+
29
+ Pending notifications keep the deployment drain proof open until delivered, discarded, or deleted. Rescheduling alone does not clear the proof; a pending notification with neither timestamp requires a direct write or deletion because dispatch and retention leave it pending.
30
+
31
+ - 4cb59a1: Bound notification delivery to ten failed attempts by default, configurable through `maxDeliveryAttempts` on tick and thread-route factories. Discard exhausted rows before another send, retain their error/count receipts, and remove them from due scans while preserving retry delays below the bound.
32
+
33
+ Require conditional failure writes through `NotificationDeliveryStorage` for dispatch. `D1NotificationsStorage` implements the atomic operation; custom stores must adopt it. Preserve newer summary, delivery and content-denial receipts after response loss, and count each local outcome once without inferring unconfirmed success. Ordinary Core storage still serves notification ingestion; the `@mastra/core` patch is required for either path. Require a custom `SignalDatabase` or `ScheduleDatabase` `batch()` to resolve elements carrying `results`, as a real `D1Result` does; `SnapshotDatabase` and `InitialAdmissionDatabase` `batch()` declare the same element.
34
+
35
+ Compare notification dates chronologically before bounded selection and retention, including expanded years and numeric offsets. Direct database writers must use ISO dates or explicitly zoned ISO date-times; conditional failure writes reject raw timestamp text outside that grammar, and neither due selection nor retention matches such a value.
36
+
37
+ Ship the `@mastra/core@1.53.0` patch under `patches/`. Application roots must apply it for own-property-safe summary source counts and source delivery policies; `@mastra/core@1.53.0` otherwise reads inherited `Object.prototype` members at both sites (mastra-ai/mastra#23693, mastra-ai/mastra#23694). The getting-started guide documents the pnpm, npm and Yarn routes. Flowsafe refuses to construct a notification dispatch tick that does delivery work, and refuses notification ingestion and dispatch requests, when the installed `@mastra/core` lacks the patch.
38
+
39
+ - f05e598: Refuse two `Agent` entry points that `@mastra/core` releases newer than the declared peer expose. `FlowsafeDurableAgent.listActiveThreadRuns()` throws instead of returning the run, thread and resource ids of every thread on the pubsub instance with a run in flight, which Core scopes by neither principal nor agent. `FlowsafeDurableAgent.__setThreadRuntimeAgent()` throws instead of installing another agent as the target the thread-runtime paths resolve through — on `@mastra/core` 1.67.0 these are `subscribeToThread()`, `claimThreadOwnership()`, `sendMessage()`, `queueMessage()`, `sendStateSignal()`, `sendNotificationSignal()` and `sendSignal()` — where one call would move every run those paths start, and `subscribeToThread()`'s replay target with them, onto an agent that carries none of the wrapper's guards. Both refusals carry the reason table's message; an installed 1.53.0 exposes neither member on Core, so no call that resolves today changes, and a caller that feature-detects either member now finds it on the wrapper and takes the refusal where the call was a `TypeError` before.
40
+
41
+ The durable-agent surface inventory now holds against the pinned peer and against newer 1.x releases together.
42
+
43
+ - 6f54bc6: Require the retention cursor seam on the purge duty. `runMaintenanceDuty('purge', env, context)` takes the new `MaintenancePurgeDutyContext`, whose `advanceRetentionCursor` is required, matching the `advanceCursor` the run-retention purge itself requires; the other duties keep the optional `MaintenanceDutyContext`. `FlowsafeWorker.runMaintenanceDuty` declares that split as two overloads — `'purge'` with a required `MaintenancePurgeDutyContext`, and `Exclude<MaintenanceDuty, 'purge'>` with the optional `MaintenanceDutyContext` — so a caller holding a union-typed `duty` narrows it to one branch before calling: a single call spanning the whole union matches neither overload and no longer compiles. A purge invocation whose context omits the callback is refused under a `config-error` naming `maintenance.purge.advanceRetentionCursor` before any purge surface runs, rather than purging the remaining surfaces and reporting a `retention-purge` failure.
44
+ - 6f54bc6: Capture the conditional-delivery capability when a notification dispatch tick is built, whatever its `limit`. `createNotificationDispatchTick()` reads `storage` and refuses one without `updateNotificationDeliveryIfUnchanged` for every configuration, including `limit: 0`, so the `NotificationDeliveryStorage` requirement no longer depends on the limit. A `limit: 0` tick still resolves `{ due: 0, delivered: 0, failed: 0 }` without reading due rows, calling storage, or needing the `@mastra/core` patch; invalid numeric policy still fails ahead of the capture.
45
+
46
+ The notification ingestion route refuses when the installed `@mastra/core` lacks the delivery-policy half of that patch. `createThreadSignalRoutes()` probes `resolveNotificationDeliveryDecision` at the ingestion gate, where delivery runs through `agent.sendNotificationSignal` and reaches the delivery-policy lookup, and answers 502 with the message naming the patch on the server log. The dispatch route carries the synchronous source-key probe its summaries need, and delivers through `agent.sendSignal`, which never reaches that lookup. The probe resolves once per isolate; tick construction keeps its synchronous probe and is unaffected.
47
+
48
+ - 647092e: Expose `isArmableSuspensionDeadlineMs` and `suspensionDeadlinesOf` from `do-runner`, together with the `SuspensionDeadlineEntry` and `RejectedSuspensionDeadline` types that projection returns. Add the lightweight `do-runner/constants` entry for deadline values and timeout detection, and `do-runner/testing` for constructing fixtures with the same timeout envelope as the alarm path.
49
+
50
+ Reuse the existing arming bounds, derivation and alarm payload factory. The test helper does not authorize a resume or mint an approval grant.
51
+
52
+ - e79b92a: Accept optional non-reserved `requestContext` on authenticated run starts and carry it through the protected Durable Object topology into stored application context. Expose the validated value to router and Worker start-policy hooks while preserving shorter hook signatures.
53
+
54
+ Reject malformed context and reserved keys with HTTP 400. Verified schedule targets retain precedence, including absent context; provider application values override stored values and trusted capabilities retain their authority. Application context survives resume. Keyed replay validates input and runs host policy again, then preserves the first writer's context without comparing or overwriting it.
55
+
56
+ Correct public agent status, stream and ordinary termination lookups to return not found for a coherent snapshot belonging to another agent or thread. Private replay, proof and recovery retain strict failures so a foreign snapshot cannot be treated as absent.
57
+
58
+ - 6bd8bfc: Add versioned execution-fence administration with artifact epochs, a sticky epoch requirement, transition revisions and exact last-command retry receipts. Upgrade supported legacy schemas additively without changing existing state or timestamps. Missing rows in new-format schemas fail closed. Admin responses omit receipts, proof execution identity and tokens; legacy commands remain compatible only while the epoch requirement is optional.
59
+
60
+ Activate v2 Runtime generations with independently generated execution tokens and preserved original principal, logical target, caller epoch and agent mode across resume legs. Fenced starts require the actual D1 domain's positive initial-write witness before engine entry, binding the winning reservation and proof in the same admission transaction. Capable D1 without a fence keeps its actual namespace and ordinary persistence options; custom storage explicitly asserts no D1 namespace. Unfenced keyed starts bind their prepared identity before creation and retain uncertain outcomes.
61
+
62
+ Persist preparing, prepared and prepared-unfenced journals in both managed hosts. Recover exact owned initial generations through the existing raw-row conditional repair without replaying effects or deleting tokenless snapshots. Require strict terminal reservation settlement before approval, dispatch, owner and lifecycle cleanup, then clear only the matching journal. Cold agent alarms initialize actual wrappers with the verified instance scope. Legacy journals and uncertain unfenced pending/absent outcomes remain unresolved.
63
+
64
+ Keep the thread blocking-run check and run-record installation under the same lock. Validate workflow journals against the owning object's address and recheck complete agent journals after recovery waits before releasing reservations. Keyed recovery requires its configured reservation store before bookkeeping, including nonterminal outcomes.
65
+
66
+ Share cold agent-wrapper initialization across concurrent requests. Probe the owning execution's liveness before reclaiming an existing reserved key, so a stream awaiting Core cleanup keeps retries pending without stranding the key. Unreadable liveness replies refuse the retry instead of authorizing a claim.
67
+
68
+ Require a matching nonpending durable observation before modern start/resume success or the agent persistence acknowledgement. Return `RUN_START_PENDING` for a valid initial generation, preserving journals, watchdogs and pending schedule/deadline budgets. Project root-local summaries from the same selected observation, retaining detailed nested resume preparation and legacy compatibility.
69
+
70
+ Preserve valid v1 and absent-provenance ordinary status, resume and lifecycle completion through one authoritative observation. Apply the existing binding, canonical-record and principal checks to legacy status. Legacy terminal cleanup requires no recovery journal and a confirmed raw terminal outcome; it never manufactures generation identity or spends a start key. Normal termination retains canonical agent records until lifecycle completion confirms.
71
+
72
+ Create modern-unbound reservations and replace run-only claim, release and settlement with exact observed-row operations. Claim/release stamps advance without serving as generation tokens; only the caller's own valid write result proves a winning claim. Private replay compares the full generation before pending/result classification and preserves the value from its one authoritative read. Alias binding and prepared binding retain their distinct response-loss rules. Remove `claim`, `release`, `settleRun` and `rollbackFencedStart`; custom router wiring must provide the private `persistedStart` callback.
73
+
74
+ Guard replay proof nomination with its original proof round/caller epoch, current exact snapshot and bound reservation at the final SQL write. Legacy proof setters cannot overwrite modern identity. Runtime, workflow-host, approval and signal re-entry gates compare complete physical generations and retain their original expectation through relevant waits. Direct approval compositions now pass an explicit trusted workflow namespace. External effects are not transactional with these checks.
75
+
76
+ Capture trusted authority before asynchronous work across Worker configuration, protected JSON/header transport and the eighth agent-start authority argument. Keep public bodies and application context from supplying a winning claim. Preserve source-owner versus initiating-principal attribution, exact lifecycle counter exhaustion checks and rejection of sparse economic-operation lists.
77
+
78
+ Make workflow retention generation-aware, protect run owners across supported snapshot namespaces, and pair reservation cleanup with the complete bound execution. Preserve reserved owners, uncertain generations and legacy keys that cannot be safely associated. Recheck schema and selected identity at the mutation; keep artifact deletion ahead of D1 cleanup.
79
+
80
+ Custom `purgeExpiredWorkflowRuns` callers must now provide transactional `database.batch()` and an `advanceCursor` callback, retain its exported `RunRetentionCursor`, and supply that cursor on the next call. Composed maintenance persists the cursor across alarms and restarts. Finite scan cycles revisit skipped candidates without letting continuous inserts extend the current cycle; unproved D1 outcomes and failed cursor writes do not advance progress.
81
+
82
+ Enforce captured caller epochs and semantic fence/schema observations in final D1 schedule mutations. Guard owned deletion participants independently, preserve admitted trigger settlement, and provide fixed pause/resume methods plus guarded no-op observations. Resume rejects a concurrent cron/timezone change. Fenced custom facades require the same-binding `FENCED_SCHEDULE_STORAGE` capability before activation; direct D1 authoring requires `batch()` and refuses omitted epochs once enforcement is active. Publish structured schedule conflict and unknown-outcome errors, retain server-side causes, and contain route audit failures without changing the selected response.
83
+
84
+ Apply the shared final schema, singleton and typed semantic fence check to Runtime initial admission. Refuse unreadable authority before snapshot or dependent reservation/proof writes while preserving exact committed-write recovery.
85
+
86
+ - 323c2ce: Add optional `SignalRouterOptions.validateThreadTarget` using the existing bound-thread validator contract, with captured actor context before asynchronous validation. Hosts can enforce strict ownership before forwarding. Normalize thread refusals with status 404 and audit the final downstream result.
87
+
88
+ Contain audit and diagnostic failures in signal, objective, subscription and webhook routes so they preserve the selected response. Use own-property lookup for signal channels, objective methods and webhook provider configuration.
89
+
90
+ ### Patch Changes
91
+
92
+ - a027f13: Return a generic internal-error response for unexpected run-router failures while retaining the original error in server diagnostics. Preserve typed refusal status, message and reason contracts. Contain diagnostic conversion and logging failures so they cannot prevent the generic HTTP response.
93
+ - a086f24: `flowsafe-provision` sets a 64 MiB `maxBuffer` on the `wrangler d1 execute --json` child process whose output it parses. Node's default is 1 MiB counted across the captured stdout and stderr together, so a response past that was truncated and the run surfaced as `failed to execute Wrangler 4` with an `ENOBUFS` cause instead of the parsed rows.
94
+ - 8c43533: Support signed maintenance for platform-authored Workers for Platforms catalogs. Catalog signing profiles can supply the maintenance keys without external-state artifacts. Catalog uploads receive their public verifier and local identity; FlowSafe relays capabilities while retaining the local receipt secret and validates the catalog script and digest before maintenance work.
95
+
96
+ Existing catalog artifacts need a rebuilt FlowSafe runtime and explicit maintenance enrollment. The host configures the matching global dispatcher verifier.
97
+
98
+ Persist catalog ownership explicitly in Fleet records and preserve it through native D1 migration and export-backed teardown. Catalog cleanup checks its own script and namespace authority. Force re-entry on completed or reserved records uses claim-releasing deletion when the store supports it.
99
+
100
+ Preserve the prior mutable Worker schema identity while D1 advances and retain migration authority through compatibility teardown retries. Permit declared catalog binding changes with exact owner and uploaded-target checks.
101
+
102
+ Allow ordinary spec-free force recovery after a candidate upload by clearing migration-only scalar fields when teardown begins, while preserving the recorded resource identity.
103
+
3
104
  ## 0.20.0
4
105
 
5
106
  ### Minor Changes
package/README.md CHANGED
@@ -9,7 +9,7 @@ Flowsafe runs Mastra workflows and agents through Cloudflare Durable Objects, st
9
9
  ## Install
10
10
 
11
11
  ```bash
12
- npm install @mastra/core@1.53.0 @proofoftech/flowsafe
12
+ npm install @mastra/core@1.67.0 @proofoftech/flowsafe
13
13
  ```
14
14
 
15
15
  Install `@proofoftech/breakwater` when resumed steps call approval-protected connectors:
@@ -25,9 +25,9 @@ Compatibility:
25
25
  - Node.js 22.13.0 or later (engine range `>=22.13.0`)
26
26
  - ESM only
27
27
  - TypeScript `moduleResolution: "NodeNext"`, `"Node16"`, or `"Bundler"`
28
- - `@mastra/core` `1.53.0`
28
+ - `@mastra/core` `1.67.0`
29
29
  - `react` and `react-dom` `>=18 <20` (React 18 or 19) for the optional approval UI
30
- - `@proofoftech/breakwater` `>=0.13.0 <1.0.0` when used
30
+ - `@proofoftech/breakwater` `>=0.15.0 <1.0.0` when used
31
31
  - host-provided Wrangler `>=4.118 <5` for the optional `flowsafe-provision` CLI
32
32
 
33
33
  ## Choose an export
@@ -38,6 +38,8 @@ Compatibility:
38
38
  | `@proofoftech/flowsafe/agent-host` | Server-only guarded-agent catalogs, authenticated run routes, thread hosting, NDJSON observation, and approval-only resume |
39
39
  | `@proofoftech/flowsafe/approval-api` | Approval records, actor resolver, service, deployment store, REST router, grants, SLA, retention, notifications, and stream events |
40
40
  | `@proofoftech/flowsafe/do-runner` | Durable Object runner, D1 storage, deployment sentinel, run summaries, snapshot provenance, identities, pub/sub, and retention |
41
+ | `@proofoftech/flowsafe/do-runner/constants` | Suspension deadline values, duration validation, and timeout detection |
42
+ | `@proofoftech/flowsafe/do-runner/testing` | Timeout resume fixtures for workflow tests |
41
43
  | `@proofoftech/flowsafe/approval-ui` | Styling-library-agnostic React dashboard, DOM-free API client, headless hook, and live transport |
42
44
  | `@proofoftech/flowsafe/host-kit` | Authenticator and verifier seams, topologies, run/stream routers, approval bridges, and composed Worker |
43
45
  | `@proofoftech/flowsafe/host-kit/module` | Import-safe workflow module contract |
@@ -101,7 +103,7 @@ export class AppRunner extends DurableObjectRunner<Env> {
101
103
  }
102
104
  ```
103
105
 
104
- `init()` creates D1-backed Mastra storage from the conventional `DB` binding unless you inject storage. Workflow definitions use the same `createWorkflow()` and `createStep()` shape as Mastra. Flowsafe pins `@mastra/cloudflare-d1` 1.1.1 because the shipped D1 storage is written against that release's domain surface: it subclasses the adapter's background-tasks domain to apply the `TaskFilter.resourceId` predicate the adapter declares but omits from its SQL builder, and hand-writes the schedules, notifications, and thread-state domains the adapter does not ship at all. The pin also holds the adapter on its `@cloudflare/workers-types` v4 peer, which is the major Flowsafe and Agent Starter still build against.
106
+ `init()` creates D1-backed Mastra storage from the conventional `DB` binding unless you inject storage. Workflow definitions use the same `createWorkflow()` and `createStep()` shape as Mastra. Flowsafe pins `@mastra/cloudflare-d1` 1.3.2 because the shipped D1 storage is written against that release's domain surface: it subclasses the adapter's background-tasks domain to apply the `TaskFilter.resourceId` predicate the adapter accepts but omits from its SQL builder, and hand-writes the schedules, notifications, and thread-state domains the adapter does not ship at all. `D1StorageOptions.domains` accepts host-supplied `workflowDefinitions` and `knowledge` domains, which have no D1-backed defaults. The pin also holds the adapter on its `@cloudflare/workers-types` v4 peer, which is the major Flowsafe still builds against.
105
107
 
106
108
  If the deployment uses a table prefix, pass one shared constant to storage and host maintenance:
107
109
 
@@ -176,7 +178,7 @@ A suspended step can carry its own deadline. It arms one by adding the reserved
176
178
  import {
177
179
  isSuspensionTimeoutResumeData,
178
180
  SUSPENSION_DEADLINE_PAYLOAD_KEY,
179
- } from '@proofoftech/flowsafe/do-runner';
181
+ } from '@proofoftech/flowsafe/do-runner/constants';
180
182
  import { z } from 'zod';
181
183
 
182
184
  const gate = createStep({
@@ -200,7 +202,11 @@ const gate = createStep({
200
202
  });
201
203
  ```
202
204
 
203
- The value is relative milliseconds between `MIN_SUSPENSION_DEADLINE_MS` and `MAX_SUSPENSION_DEADLINE_MS`. A step that declares a Zod `suspendSchema` must declare the reserved field or use a loose object, because Mastra substitutes the parsed suspend payload and a strict schema strips unknown keys. A step that declares a `resumeSchema` must accept the timeout envelope as well as its own signal shape, or the timeout resume fails validation and the deadline is abandoned after the runner's retries. The timeout resume delivers `SUSPENSION_TIMEOUT_RESUME_KEY` wrapping the expired step, its deadline, and the expiry time; branch on `isSuspensionTimeoutResumeData()` instead of the literal key, and build the same envelope in your own tests from that key and the `SuspensionTimeoutEnvelope` and `SuspensionTimeoutResumeData` types. Only the runner mints it: a resume request that carries the reserved key is rejected. It records `requestedByKind: 'system'` with the reserved `SUSPENSION_DEADLINE_PRINCIPAL_ID`, and it is not an approval decision: it mints no grant and records no reviewer.
205
+ Use `isArmableSuspensionDeadlineMs(value)` to validate relative milliseconds against the runner's safe-integer and inclusive duration bounds. Import it, those duration bounds and the reserved payload keys from `@proofoftech/flowsafe/do-runner/constants` to avoid loading the runner graph; the per-run cap `MAX_SUSPENSION_DEADLINES_PER_RUN` comes from `@proofoftech/flowsafe/do-runner`. A step declaring a Zod `suspendSchema` must declare the reserved field or use a loose object, because Mastra replaces the suspend payload with parsed output. Its `resumeSchema` must accept the timeout envelope as well as the signal shape.
206
+
207
+ For workflow tests, import `suspensionTimeoutResumeData` from `@proofoftech/flowsafe/do-runner/testing` and call it with `{ step, deadlineAt }` and an expiry time. It returns the alarm's envelope shape; `isSuspensionTimeoutResumeData` checks that shape without authenticating its origin. Public resume requests containing the reserved key are rejected. Alarm resumes record system provenance and do not grant approval.
208
+
209
+ Import `suspensionDeadlinesOf` from `@proofoftech/flowsafe/do-runner` to inspect a `RunSummary`. It returns derived entries and rejected requests without scheduling a wake or mutating the summary. See the [acceptance rules](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#inspect-and-test-suspension-deadlines).
204
210
 
205
211
  Only a top-level suspended step can arm a deadline. A step suspended inside a nested workflow is reported under the nested path while its suspension time is recorded against the enclosing step, so there is nothing to fence the resume against; the deadline is refused and logged instead of armed.
206
212
 
@@ -302,9 +308,19 @@ Fleet control planes can import the same fail-closed sentinel implementation fro
302
308
 
303
309
  One Flowsafe deployment is one tenant, so the execution fence controls the complete deployment. `open` admits all work. `draining` refuses new run mints and future-work authoring while existing runs and deliveries finish. It still accepts new background-task enqueues and dispatches queued tasks because both are drainable work. Background-task enqueue, dispatch, and stale-task re-drive are refused in `migration-locked` and `proof-only`. Signal wakes that would mint a run persist instead. `migration-locked` refuses execution, and `proof-only` admits only the nominated start and its bound run. The fence never preempts compute already in flight.
304
310
 
305
- Provisioning requires `--initial-fence-state open` or `--initial-fence-state migration-locked`; it never chooses a default. A pre-0.20 database without a fence row reads as `open`. For locked-at-birth provisioning, read `GET /admin/execution-fence` afterward and fail unless it reports `migration-locked`.
311
+ Provisioning requires `--initial-fence-state open` or `--initial-fence-state migration-locked`; it never chooses a default. An absent pre-0.20 table or empty five-column legacy table reads as optional `open`. Initialization adds epoch/revision metadata without reopening existing state. A missing row once any metadata column exists is unreadable and is never silently refilled. For locked-at-birth provisioning, read `GET /admin/execution-fence` afterward and fail unless it reports `migration-locked`.
312
+
313
+ Administrative readings include `mutationEpoch`, `requireMutationEpoch`, and `transitionRevision`. Upgraded commands compare expected state, epoch, and revision; exact retries preserve proof bindings and timestamps while that command remains the last applied command. Advancing the epoch also sets its sticky requirement; ordinary lock, proof, and reopen transitions preserve both. Upgrade the deployment's writers and configure their trusted artifact epoch before activation. See the [administration contract](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/deployment-reference.md#control-plane-routes) for request fields, compatibility, and conflicts.
314
+
315
+ The `do-runner` and `host-kit` entry points export `normalizeRunExecutionIdentity`, `normalizeD1RunExecutionIdentity`, `normalizeStartIdentity`, `normalizeStartExecutionIdentity`, and mutation-epoch validation/header helpers. They copy validated identity data without authenticating it. String D1 prefixes normalize to lowercase; null explicitly means no D1 namespace and differs from the empty default prefix.
316
+
317
+ New reservations are unbound until an exact winning claim or an observed result binds their physical execution. Runtime generates a separate execution token for each new run generation, and proof-only re-entry compares its namespace, workflow, run and generation. Stored `proofExecution` stays server-side and is omitted from admin JSON.
306
318
 
307
- Use `GET /admin/inventory` while the fence remains `draining`. A drain is proven only after every work category is empty across two complete sweeps at least 60 seconds apart. Readings are point-in-time observations rather than snapshots and can move in either direction while draining admits work. Empty results cannot over-count, and keyset pagination never skips a row that existed before the sweep began. If you need a hard guarantee, re-sweep once after transitioning to `migration-locked`: an empty post-lock sweep is conclusive; a non-empty one means work is still outstanding, either because it entered after the proof or because the lock parked it before it finished. Return to `draining` and repeat the proof. An inventory read taken under `migration-locked` measures what the fence parked rather than what the deployment would otherwise be doing. Schedules and signal subscriptions are standing configuration and need not empty. Persisted idle signals are deliberately unenumerable and carry into the replacement deployment.
319
+ D1 schedule mutations enforce the captured caller epoch at their final SQL boundary. A fenced custom facade must provide `FENCED_SCHEDULE_STORAGE` on the same database as its configured fence. Direct D1 methods require `batch()` and accept a trailing `MutationEpochContext`; omission refuses after activation. Pause/delete and HTTP no-ops retain epoch checks. Use the [schedule guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md#add-schedules) for fixed pause/resume methods, custom facade compatibility and uncertain-write outcomes.
320
+
321
+ With a configured fence, Runtime requires the actual D1 domain's positive initial-write witness before engine entry. Without a fence, capable D1 keeps its real namespace and ordinary persistence behavior; custom storage explicitly asserts no D1 namespace. Managed hosts persist preparation journals and require a matching nonpending durable outcome before acknowledging execution. A valid pending generation returns `RUN_START_PENDING` with status 503; keyed retries use the idempotent-start refusal contract. See the [runner design](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#execution-fence-and-start-reservations) for exact claims, replay and recovery.
322
+
323
+ Use `GET /admin/inventory` while the fence remains `draining`. A drain is proven only after every work category is empty across two complete sweeps at least 60 seconds apart. A pending agent-inbox notification scheduled for later, or carrying no due timestamp, is work and keeps the proof open. Readings are point-in-time observations rather than snapshots and can move in either direction while draining admits work. Empty results cannot over-count, and keyset pagination never skips a row that existed before the sweep began. If you need a hard guarantee, re-sweep once after transitioning to `migration-locked`: an empty post-lock sweep is conclusive; a non-empty one means work is still outstanding, either because it entered after the proof or because the lock parked it before it finished. Return to `draining` and repeat the proof. An inventory read taken under `migration-locked` measures what the fence parked rather than what the deployment would otherwise be doing. Schedules and signal subscriptions are standing configuration and need not empty. Persisted idle signals are deliberately unenumerable and carry into the replacement deployment.
308
324
 
309
325
  ### Runtime ids are opaque
310
326
 
@@ -312,6 +328,23 @@ The host mints opaque, path-safe run and thread ids. `RunnerRuntime.start()` req
312
328
 
313
329
  Callers that need exactly-once start behavior supply an `idempotencyKey`, never a run ID. The key is available on `POST /runs`, trusted agent-host starts, and `streamUntilPersisted()`. A retry returns the same persisted run. `IDEMPOTENT_START_PENDING` includes `pendingSince`; re-probe the point-in-time `IDEMPOTENT_START_UNRESOLVABLE` result before acting. A key remains valid until its reservation-retention horizon expires.
314
330
 
331
+ ### Pass application context at start
332
+
333
+ An authenticated `POST /runs` can supply a non-reserved application context:
334
+
335
+ ```json
336
+ {
337
+ "workflowId": "publish",
338
+ "inputData": { "topic": "release notes" },
339
+ "idempotencyKey": "publish-request-123",
340
+ "requestContext": { "app.agentId": "agent_123" }
341
+ }
342
+ ```
343
+
344
+ `requestContext` must be an object when present. Invalid shapes and reserved keys return HTTP 400 with `reason: "reserved-context-key"`. The router validates it after authentication and workflow authorization, then passes it to the host's `beforeStart` policy. Use that hook for application-specific attribution rules; possession of a run token does not establish an arbitrary context value's business meaning.
345
+
346
+ The protected topology carries this value into `storedRequestContext`. Provider application values override stored values, while trusted execution identity and capabilities retain their authority. Verified schedule targets supply their own context, including an omitted value. Persisted application values survive resume; a keyed replay retains the winning run's context and still performs validation and host policy checks. See the [request-context guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#request-context) and [host policy signatures](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/deployment-reference.md#host-composition).
347
+
315
348
  ### Stores are deployment-wide
316
349
 
317
350
  `D1ApprovalStoreFactory.store()` and `D1SubscriptionStoreFactory.store()` return the store for the bound database. Tables and indexes contain no tenant column. Legacy pooled schemas require a fresh database.
@@ -406,13 +439,21 @@ Agent event replay lasts only as long as the configured Mastra cache. The defaul
406
439
 
407
440
  ### Signals and notifications
408
441
 
409
- `createThreadSignalRoutes()` hosts message, queue, signal, state, and notification delivery in the thread Durable Object. `createSignalRouter()` is the Worker trust boundary: authenticate, authorize, ownership-check, cap, parse, reject memory ids, allowlist attributes, rate-limit, audit, then forward.
442
+ `createThreadSignalRoutes()` hosts message, queue, signal, state, and notification delivery in the thread Durable Object. `createSignalRouter()` authenticates Worker requests before reaching those routes. Its optional `validateThreadTarget` uses the existing `BoundThreadTargetValidator` type for host-specific binding or ownership restrictions. See the [signal-ingress guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md#expose-signal-ingestion) for strict-owner composition.
443
+
444
+ Signal acceptance is audited after the downstream response succeeds. Thread refusals with status 404 use a consistent public response across registry, validator and downstream checks. An audit-sink failure retains the selected response.
410
445
 
411
446
  The thread routes reject a signal whose `tagName` is not an XML name, and drop an attributes object carrying a value Mastra cannot render or a key that is not an XML name. Both are what core would otherwise throw on while rendering the signal inside the agent turn.
412
447
 
413
448
  Configure `ThreadSignalRoutesOptions.contentPolicy` when signal content needs a domain policy before it becomes model input. The Thread Durable Object invokes this structural callback for direct ingestion, provider delivery, schedule fires, and notification dispatch. Its `text` is Mastra's canonical escaped XML representation. A denial stops direct delivery with 422, settles a scheduled fire as discarded, or terminally discards the affected notification.
414
449
 
415
- A policy failure is opaque, and each lane recovers the way it already recovers from any other failure: direct delivery returns 503, schedule state is left unsettled so the lease expires and a later tick retries, and notification dispatch uses its existing backoff. A webhook whose matched deliveries the deployment could not decide is answered with 503 so the provider's own at-least-once redelivery recovers it; each delivery carries a dedupe key derived from the signed bytes and the subscription, so a redelivery coalesces into a still-pending row rather than duplicating it. A content denial is terminal and answers 2xx, because redelivering the identical bytes would only be denied again. Poll deliveries report the same three outcomes and depend on the adapter re-reporting state it has not seen accepted. Give a network-backed policy its own timeout and failure budget inside the callback; FlowSafe imposes neither.
450
+ A policy failure is opaque: direct delivery returns 503, schedule state is left unsettled so the lease expires and a later tick retries, and notification dispatch records a bounded retry. A webhook whose matched deliveries the deployment could not decide is answered with 503 so the provider's own at-least-once redelivery recovers it; each delivery carries a dedupe key derived from the signed bytes and the subscription, so a redelivery coalesces into a still-pending row rather than duplicating it. A content denial is terminal and answers 2xx, because redelivering the identical bytes would only be denied again. Poll deliveries report the same three outcomes and depend on the adapter re-reporting state it has not seen accepted. Give a network-backed policy its own timeout and failure budget inside the callback; FlowSafe imposes neither.
451
+
452
+ Configure the same positive safe-integer `maxDeliveryAttempts` on `createNotificationDispatchTick()` and `createThreadSignalRoutes()`. Both default to `DEFAULT_MAX_NOTIFICATION_DELIVERY_ATTEMPTS`. A recorded failure at the bound discards the notification with `deliveryReason: "delivery-attempts-exhausted"`, retaining its count and last error. An already-exhausted row is never sent; its discard is conditional on the observed record remaining current. Below the bound, existing retry delays apply.
453
+
454
+ Dispatch requires `NotificationDeliveryStorage`; `D1NotificationsStorage` implements it. A custom store's `updateNotificationDeliveryIfUnchanged()` must compare the captured observation and apply the failure patch atomically against its other writers. Ordinary Core storage still serves notification ingestion. See the [delivery and receipt guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md#bound-notification-delivery) for custom-store migration, lost responses and receipt retention.
455
+
456
+ Summary source counts and a configured source delivery policy read own properties: the declared `@mastra/core` peer guards both lookups, so a source named after an `Object.prototype` member is counted under its own key and resolves the configured priority or default action. A core outside the declared peer range that predates [mastra-ai/mastra#23693](https://github.com/mastra-ai/mastra/issues/23693) and [mastra-ai/mastra#23694](https://github.com/mastra-ai/mastra/issues/23694) miscounts such a source and selects the inherited policy entry instead.
416
457
 
417
458
  Adapt Breakwater without adding a FlowSafe runtime dependency on it:
418
459
 
@@ -495,6 +536,10 @@ Complete wiring is in the [durable-agents guide](https://github.com/ProofOfTechO
495
536
 
496
537
  The composed `createFlowsafeWorker()` owns the shared route and maintenance-duty pipeline. Hosts inject workflows, identity verification, topology-backed optional routers, budget wrappers, notification transport, an invocation-scoped artifact-store factory, the storage table prefix, schedule tick, and extra purge duties.
497
538
 
539
+ Configure `mutationEpoch` with a nonnegative safe integer or a synchronous environment callback. The Worker captures it before deployment verification or authentication, then forwards it through trusted contexts and protected internal headers. Start paths preserve the original actor, principal, epoch and selectors across waits, including class-backed context method receivers. Do not accept the epoch from public headers or start JSON.
540
+
541
+ The internal durable-agent host start requires an eighth `AgentStartAuthority` argument, with an explicit `onPreparedStartIdentity` property. Built-in hosts supply `undefined` while Runtime and owner journals remain v1. This transport does not activate final-write epoch checks or managed recovery; the [deployment reference](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/deployment-reference.md#configure-the-trusted-caller-epoch) and [durable-agents guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md) describe the boundary.
542
+
498
543
  Protect `GET` and `POST /admin/execution-fence` plus `GET /admin/inventory` with a distinct `MAINTENANCE_ADMIN_SECRET`. Fence transitions use CAS and return `409` with `FENCE_CAS_CONFLICT` when the expected state is stale. Fenced execution returns `503` with an `EXECUTION_FENCED` reason. The agent-host and stream routers preserve structured `503` and `409` refusals instead of collapsing them to a generic `500`.
499
544
 
500
545
  Every leaf option that accepts `ExecutionFenceWiring` requires an explicit store or `'none'`. Run-router, agent-thread-topology, and storage initialization also require explicit start-idempotency wiring. Use `'none'` only when no database exists. `BackgroundTaskHost` no longer exposes its manager; call `enqueue()`, `getTask()`, `listTasks()`, or `stream()` on the host and use `BackgroundTaskReads` for read-only route composition.
@@ -33,6 +33,7 @@ export const DEPLOYMENT_SENTINEL_COLUMNS: readonly Readonly<{
33
33
  export const EXECUTION_FENCE_TABLE: 'flowsafe_execution_fence';
34
34
  /** The fence row's fixed primary key — one deployment, one database, one row. */
35
35
  export const EXECUTION_FENCE_ROW_ID: 'deployment';
36
+ export const EXECUTION_FENCE_CURRENT_SCHEMA_STAGE: 7;
36
37
  /** Every fence state, ordered from most to least permissive. */
37
38
  export const EXECUTION_FENCE_STATES: readonly [
38
39
  'open',
@@ -46,12 +47,36 @@ export const INITIAL_EXECUTION_FENCE_STATES: readonly [
46
47
  'migration-locked',
47
48
  ];
48
49
  /**
49
- * The fence table's schema. `do-runner/execution-fence.ts` issues this exact
50
- * string, so the store and the provisioning protocol cannot create differently
51
- * shaped tables.
50
+ * The current fence schema. Runtime and provisioning initialize the legacy
51
+ * singleton before adding its metadata columns through the shared protocol.
52
52
  */
53
53
  export const EXECUTION_FENCE_DDL: string;
54
54
 
55
+ export type ExecutionFenceSchemaStage = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
56
+ export interface ExecutionFenceMutationMetadata {
57
+ readonly mutationEpoch: number;
58
+ readonly requireMutationEpoch: boolean;
59
+ readonly transitionRevision: number;
60
+ readonly lastTransitionRequest: string | null;
61
+ readonly schemaStage: ExecutionFenceSchemaStage;
62
+ readonly proofTablePrefix: string | null;
63
+ readonly proofWorkflowId: string | null;
64
+ readonly proofStartToken: string | null;
65
+ }
66
+ export function readExecutionFenceSchemaProtocol(
67
+ execute: DeploymentIdentityProtocolExecutor,
68
+ ): Promise<ExecutionFenceSchemaStage | undefined>;
69
+ export function decodeExecutionFenceMutationMetadata(
70
+ row: DeploymentIdentityProtocolRow,
71
+ ): ExecutionFenceMutationMetadata;
72
+ export function initializeExecutionFenceProtocol(
73
+ execute: DeploymentIdentityProtocolExecutor,
74
+ options: {
75
+ state: (typeof EXECUTION_FENCE_STATES)[number];
76
+ seededAt: number;
77
+ },
78
+ ): Promise<void>;
79
+
55
80
  /** The fence state a deployment is provisioned into. Required; no default. */
56
81
  export type InitialExecutionFenceState =
57
82
  (typeof INITIAL_EXECUTION_FENCE_STATES)[number];