@proofoftech/flowsafe 0.11.0 → 0.13.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.
- package/CHANGELOG.md +54 -0
- package/README.md +91 -44
- package/deployment-identity-protocol.d.mts +52 -0
- package/deployment-identity-protocol.mjs +231 -0
- package/dist/agent-host/approval-resumer.d.ts +3 -3
- package/dist/agent-host/approval-resumer.d.ts.map +1 -1
- package/dist/agent-host/approval-resumer.js +6 -7
- package/dist/agent-host/approval-resumer.js.map +1 -1
- package/dist/agent-host/catalog.js +2 -2
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +2 -2
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/router.d.ts +2 -2
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +22 -54
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +42 -8
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +533 -106
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +28 -7
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +97 -39
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-host/trusted-context.d.ts.map +1 -1
- package/dist/agent-host/trusted-context.js +3 -1
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +2 -0
- package/dist/agent-host/types.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.d.ts +9 -8
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.js +78 -40
- package/dist/agent-runner/agent-run-state.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +120 -43
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +67 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -0
- package/dist/approval-api/actor-context.js +120 -0
- package/dist/approval-api/actor-context.js.map +1 -0
- package/dist/approval-api/contract.d.ts +12 -23
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/d1-store.d.ts +7 -15
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +83 -159
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +3 -17
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +19 -39
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +8 -8
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +5 -5
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/principal.d.ts +29 -30
- package/dist/approval-api/principal.d.ts.map +1 -1
- package/dist/approval-api/principal.js +73 -54
- package/dist/approval-api/principal.js.map +1 -1
- package/dist/approval-api/resource-ownership.d.ts +64 -0
- package/dist/approval-api/resource-ownership.d.ts.map +1 -0
- package/dist/approval-api/resource-ownership.js +329 -0
- package/dist/approval-api/resource-ownership.js.map +1 -0
- package/dist/approval-api/retention.d.ts +6 -11
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js +7 -12
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/router.d.ts +9 -8
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +50 -18
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +26 -36
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +104 -166
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store-factory.d.ts +19 -0
- package/dist/approval-api/store-factory.d.ts.map +1 -0
- package/dist/approval-api/store-factory.js +49 -0
- package/dist/approval-api/store-factory.js.map +1 -0
- package/dist/approval-api/store.d.ts +22 -36
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +48 -66
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/types.d.ts +28 -22
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +51 -3
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/client.js +3 -3
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +4 -4
- package/dist/approval-ui/stream.d.ts.map +1 -1
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/tips.d.ts +1 -1
- package/dist/approval-ui/tips.js +1 -1
- package/dist/approval-ui/tips.js.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
- package/dist/approval-ui/use-approval-dashboard.js +1 -1
- package/dist/artifacts/index.d.ts +2 -3
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +9 -8
- package/dist/artifacts/index.js.map +1 -1
- package/dist/audit-export/audit-proxy.d.ts +71 -0
- package/dist/audit-export/audit-proxy.d.ts.map +1 -0
- package/dist/audit-export/audit-proxy.js +142 -0
- package/dist/audit-export/audit-proxy.js.map +1 -0
- package/dist/audit-export/index.d.ts +4 -7
- package/dist/audit-export/index.d.ts.map +1 -1
- package/dist/audit-export/index.js +1 -4
- package/dist/audit-export/index.js.map +1 -1
- package/dist/audit-export/queue-types.d.ts +5 -0
- package/dist/audit-export/queue-types.d.ts.map +1 -0
- package/dist/audit-export/queue-types.js +3 -0
- package/dist/audit-export/queue-types.js.map +1 -0
- package/dist/background-tasks/d1-storage.d.ts +9 -19
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +22 -52
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/background-tasks/host.d.ts +4 -6
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +14 -17
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/background-tasks/index.d.ts +1 -1
- package/dist/background-tasks/index.d.ts.map +1 -1
- package/dist/background-tasks/index.js +3 -3
- package/dist/background-tasks/index.js.map +1 -1
- package/dist/background-tasks/routes.d.ts +8 -4
- package/dist/background-tasks/routes.d.ts.map +1 -1
- package/dist/background-tasks/routes.js +33 -31
- package/dist/background-tasks/routes.js.map +1 -1
- package/dist/deployment-identity-protocol.d.ts +3 -0
- package/dist/deployment-identity-protocol.d.ts.map +1 -0
- package/dist/deployment-identity-protocol.js +3 -0
- package/dist/deployment-identity-protocol.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +7 -5
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +7 -5
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/cf-types.d.ts +18 -12
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +51 -189
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +111 -362
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/deployment-identity.d.ts +121 -0
- package/dist/do-runner/deployment-identity.d.ts.map +1 -0
- package/dist/do-runner/deployment-identity.js +272 -0
- package/dist/do-runner/deployment-identity.js.map +1 -0
- package/dist/do-runner/do-error-response.d.ts +1 -1
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +7 -1
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +23 -16
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +303 -70
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts +1 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +4 -7
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-principal-header.d.ts +16 -0
- package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
- package/dist/do-runner/execution-principal-header.js +20 -0
- package/dist/do-runner/execution-principal-header.js.map +1 -0
- package/dist/do-runner/hub-do.d.ts +17 -25
- package/dist/do-runner/hub-do.d.ts.map +1 -1
- package/dist/do-runner/hub-do.js +63 -59
- package/dist/do-runner/hub-do.js.map +1 -1
- package/dist/do-runner/index.d.ts +12 -10
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +10 -9
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +0 -7
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +1 -2
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +8 -25
- package/dist/do-runner/memory-id.d.ts.map +1 -1
- package/dist/do-runner/memory-id.js +25 -52
- package/dist/do-runner/memory-id.js.map +1 -1
- package/dist/do-runner/path-safe-id.d.ts +2 -48
- package/dist/do-runner/path-safe-id.d.ts.map +1 -1
- package/dist/do-runner/path-safe-id.js +3 -93
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/pubsub.d.ts +1 -1
- package/dist/do-runner/pubsub.js +1 -1
- package/dist/do-runner/runtime.d.ts +47 -34
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +281 -143
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/schedule-source.d.ts +81 -0
- package/dist/do-runner/schedule-source.d.ts.map +1 -0
- package/dist/do-runner/schedule-source.js +64 -0
- package/dist/do-runner/schedule-source.js.map +1 -0
- package/dist/do-runner/table-prefix.d.ts +3 -0
- package/dist/do-runner/table-prefix.d.ts.map +1 -0
- package/dist/do-runner/table-prefix.js +17 -0
- package/dist/do-runner/table-prefix.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +18 -32
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +52 -74
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/goals/objective-routes.d.ts +7 -4
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +58 -43
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +18 -21
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -37
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +3 -4
- package/dist/host-kit/bearer-auth.d.ts.map +1 -1
- package/dist/host-kit/bearer-auth.js +7 -11
- package/dist/host-kit/bearer-auth.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +14 -5
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +47 -15
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +1 -1
- package/dist/host-kit/env-vars.js +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +159 -80
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +629 -142
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +62 -54
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +90 -61
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +6 -7
- package/dist/host-kit/hub-topology.d.ts.map +1 -1
- package/dist/host-kit/hub-topology.js +16 -12
- package/dist/host-kit/hub-topology.js.map +1 -1
- package/dist/host-kit/index.d.ts +13 -11
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +9 -12
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/maintenance-capability.d.ts +58 -0
- package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
- package/dist/host-kit/maintenance-capability.js +268 -0
- package/dist/host-kit/maintenance-capability.js.map +1 -0
- package/dist/host-kit/memory-boundary.d.ts +4 -19
- package/dist/host-kit/memory-boundary.d.ts.map +1 -1
- package/dist/host-kit/memory-boundary.js +12 -27
- package/dist/host-kit/memory-boundary.js.map +1 -1
- package/dist/host-kit/resource-access.d.ts +4 -0
- package/dist/host-kit/resource-access.d.ts.map +1 -0
- package/dist/host-kit/resource-access.js +12 -0
- package/dist/host-kit/resource-access.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +25 -15
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +61 -46
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/state-egress.d.ts +51 -0
- package/dist/host-kit/state-egress.d.ts.map +1 -0
- package/dist/host-kit/state-egress.js +120 -0
- package/dist/host-kit/state-egress.js.map +1 -0
- package/dist/host-kit/stream-router.d.ts +9 -4
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-router.js +45 -38
- package/dist/host-kit/stream-router.js.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +10 -10
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +60 -90
- package/dist/host-kit/stream-ticket.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +17 -11
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +33 -59
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/host-kit/verifier.d.ts +6 -6
- package/dist/host-kit/verifier.d.ts.map +1 -1
- package/dist/host-kit/verifier.js +51 -119
- package/dist/host-kit/verifier.js.map +1 -1
- package/dist/http-body.d.ts +20 -0
- package/dist/http-body.d.ts.map +1 -0
- package/dist/http-body.js +67 -0
- package/dist/http-body.js.map +1 -0
- package/dist/schedules/index.d.ts +3 -2
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +5 -4
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/router.d.ts +16 -10
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +153 -91
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +88 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +411 -50
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/target-policy.d.ts +29 -0
- package/dist/schedules/target-policy.d.ts.map +1 -0
- package/dist/schedules/target-policy.js +70 -0
- package/dist/schedules/target-policy.js.map +1 -0
- package/dist/schedules/tick.d.ts +125 -21
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +637 -160
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +0 -19
- package/dist/signal-providers/delivery.d.ts.map +1 -1
- package/dist/signal-providers/delivery.js +5 -54
- package/dist/signal-providers/delivery.js.map +1 -1
- package/dist/signal-providers/github-provider.d.ts.map +1 -1
- package/dist/signal-providers/github-provider.js +9 -16
- package/dist/signal-providers/github-provider.js.map +1 -1
- package/dist/signal-providers/host-do.d.ts +3 -45
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +86 -106
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/host-topology.d.ts +5 -14
- package/dist/signal-providers/host-topology.d.ts.map +1 -1
- package/dist/signal-providers/host-topology.js +11 -25
- package/dist/signal-providers/host-topology.js.map +1 -1
- package/dist/signal-providers/index.d.ts +3 -3
- package/dist/signal-providers/index.d.ts.map +1 -1
- package/dist/signal-providers/index.js +3 -3
- package/dist/signal-providers/index.js.map +1 -1
- package/dist/signal-providers/provider.d.ts +4 -5
- package/dist/signal-providers/provider.d.ts.map +1 -1
- package/dist/signal-providers/provider.js +5 -6
- package/dist/signal-providers/provider.js.map +1 -1
- package/dist/signal-providers/subscription-d1.d.ts +10 -57
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
- package/dist/signal-providers/subscription-d1.js +208 -155
- package/dist/signal-providers/subscription-d1.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +28 -14
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +117 -88
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/client.js +8 -8
- package/dist/signals/client.js.map +1 -1
- package/dist/signals/d1-shared.js +1 -1
- package/dist/signals/d1-shared.js.map +1 -1
- package/dist/signals/index.d.ts +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +12 -6
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +37 -21
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +5 -8
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +8 -13
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +10 -10
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -51
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +74 -15
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +484 -41
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/dist/signals/thread-state-d1.d.ts.map +1 -1
- package/dist/signals/thread-state-d1.js +2 -3
- package/dist/signals/thread-state-d1.js.map +1 -1
- package/package.json +29 -6
- package/scripts/seed-deployment-identity.mjs +252 -0
- package/dist/approval-api/tenant-brand.d.ts +0 -35
- package/dist/approval-api/tenant-brand.d.ts.map +0 -1
- package/dist/approval-api/tenant-brand.js +0 -19
- package/dist/approval-api/tenant-brand.js.map +0 -1
- package/dist/approval-api/tenant-context.d.ts +0 -84
- package/dist/approval-api/tenant-context.d.ts.map +0 -1
- package/dist/approval-api/tenant-context.js +0 -112
- package/dist/approval-api/tenant-context.js.map +0 -1
- package/dist/approval-api/tenant-store.d.ts +0 -36
- package/dist/approval-api/tenant-store.d.ts.map +0 -1
- package/dist/approval-api/tenant-store.js +0 -129
- package/dist/approval-api/tenant-store.js.map +0 -1
- package/dist/do-runner/resume-ledger.d.ts +0 -48
- package/dist/do-runner/resume-ledger.d.ts.map +0 -1
- package/dist/do-runner/resume-ledger.js +0 -60
- package/dist/do-runner/resume-ledger.js.map +0 -1
- package/dist/do-runner/thread-header.d.ts +0 -31
- package/dist/do-runner/thread-header.d.ts.map +0 -1
- package/dist/do-runner/thread-header.js +0 -39
- package/dist/do-runner/thread-header.js.map +0 -1
- package/dist/host-kit/subdomain-check.d.ts +0 -23
- package/dist/host-kit/subdomain-check.d.ts.map +0 -1
- package/dist/host-kit/subdomain-check.js +0 -61
- package/dist/host-kit/subdomain-check.js.map +0 -1
- package/dist/host-kit/tenant-registry.d.ts +0 -51
- package/dist/host-kit/tenant-registry.d.ts.map +0 -1
- package/dist/host-kit/tenant-registry.js +0 -88
- package/dist/host-kit/tenant-registry.js.map +0 -1
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
// (see durable-object.ts).
|
|
20
20
|
import { Mastra } from '@mastra/core/mastra';
|
|
21
21
|
import { RequestContext } from '@mastra/core/request-context';
|
|
22
|
-
import {
|
|
22
|
+
import { isExecutionPrincipalId, isExecutionPrincipalKind, } from '../approval-api/principal.js';
|
|
23
|
+
import { BREAKWATER_ACTOR_KEY, BREAKWATER_CONNECTOR_EXECUTION_KEY, BREAKWATER_ISOLATION_SCOPE_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from './breakwater-keys.js';
|
|
24
|
+
import { isReservedExecutionContextKey, RUN_PROVENANCE_CONTEXT_KEY, stripReservedExecutionContext, } from './execution-context.js';
|
|
23
25
|
import { mastraRegistryEntries } from './mastra-registry.js';
|
|
24
|
-
import {
|
|
25
|
-
import { InMemoryResumeLedger } from './resume-ledger.js';
|
|
26
|
+
import { isPathSafeId } from './path-safe-id.js';
|
|
26
27
|
export class UnknownWorkflowError extends Error {
|
|
27
28
|
constructor(workflowId) {
|
|
28
29
|
super(`unknown workflow '${workflowId}'`);
|
|
@@ -75,6 +76,58 @@ function asClientError(error) {
|
|
|
75
76
|
? new InvalidRunRequestError(error.message)
|
|
76
77
|
: undefined;
|
|
77
78
|
}
|
|
79
|
+
const RUN_STATE_FIELDS = [
|
|
80
|
+
'result',
|
|
81
|
+
'error',
|
|
82
|
+
'steps',
|
|
83
|
+
'suspendedPaths',
|
|
84
|
+
'requestContext',
|
|
85
|
+
];
|
|
86
|
+
function runProvenance(state) {
|
|
87
|
+
const value = state.requestContext?.[RUN_PROVENANCE_CONTEXT_KEY];
|
|
88
|
+
if (value === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
if (value === null || typeof value !== 'object') {
|
|
91
|
+
throw new Error('stored run provenance is malformed');
|
|
92
|
+
}
|
|
93
|
+
const candidate = value;
|
|
94
|
+
if (candidate.version !== 1 ||
|
|
95
|
+
(candidate.requestedBy !== undefined &&
|
|
96
|
+
!isExecutionPrincipalId(candidate.requestedBy)) ||
|
|
97
|
+
(candidate.requestedByKind !== undefined &&
|
|
98
|
+
!isExecutionPrincipalKind(candidate.requestedByKind)) ||
|
|
99
|
+
(candidate.requestedBy === undefined &&
|
|
100
|
+
candidate.requestedByKind !== undefined) ||
|
|
101
|
+
!isPathSafeId(candidate.attemptToken) ||
|
|
102
|
+
(candidate.startToken !== undefined &&
|
|
103
|
+
!isPathSafeId(candidate.startToken)) ||
|
|
104
|
+
!Array.isArray(candidate.resumeCounts)) {
|
|
105
|
+
throw new Error('stored run provenance is malformed');
|
|
106
|
+
}
|
|
107
|
+
const counts = [];
|
|
108
|
+
for (const entry of candidate.resumeCounts) {
|
|
109
|
+
if (!Array.isArray(entry) ||
|
|
110
|
+
entry.length !== 2 ||
|
|
111
|
+
typeof entry[0] !== 'string' ||
|
|
112
|
+
!Number.isSafeInteger(entry[1]) ||
|
|
113
|
+
entry[1] < 1) {
|
|
114
|
+
throw new Error('stored run provenance is malformed');
|
|
115
|
+
}
|
|
116
|
+
counts.push([entry[0], entry[1]]);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
version: 1,
|
|
120
|
+
...(candidate.requestedBy === undefined
|
|
121
|
+
? {}
|
|
122
|
+
: { requestedBy: candidate.requestedBy }),
|
|
123
|
+
...(candidate.requestedByKind === undefined
|
|
124
|
+
? {}
|
|
125
|
+
: { requestedByKind: candidate.requestedByKind }),
|
|
126
|
+
attemptToken: candidate.attemptToken,
|
|
127
|
+
startToken: candidate.startToken ?? candidate.attemptToken,
|
|
128
|
+
resumeCounts: counts,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
78
131
|
const NONTERMINAL_RUN_STATUSES = new Set([
|
|
79
132
|
'running',
|
|
80
133
|
'suspended',
|
|
@@ -147,18 +200,21 @@ function errorText(error) {
|
|
|
147
200
|
}
|
|
148
201
|
return String(error);
|
|
149
202
|
}
|
|
150
|
-
function summarize(runId, result, counts) {
|
|
203
|
+
function summarize(runId, result, counts, requestedBy, requestedByKind) {
|
|
204
|
+
let summary;
|
|
151
205
|
switch (result.status) {
|
|
152
206
|
case 'success':
|
|
153
|
-
|
|
207
|
+
summary = { runId, status: result.status, result: result.result };
|
|
208
|
+
break;
|
|
154
209
|
case 'failed':
|
|
155
|
-
|
|
210
|
+
summary = {
|
|
156
211
|
runId,
|
|
157
212
|
status: result.status,
|
|
158
213
|
error: errorText(result.error),
|
|
159
214
|
};
|
|
215
|
+
break;
|
|
160
216
|
case 'suspended': {
|
|
161
|
-
|
|
217
|
+
summary = {
|
|
162
218
|
runId,
|
|
163
219
|
status: result.status,
|
|
164
220
|
suspended: result.suspended,
|
|
@@ -171,17 +227,28 @@ function summarize(runId, result, counts) {
|
|
|
171
227
|
const resumedAt = byStep(suspendedKeys, (key) => resumedAtOf(result.steps, key));
|
|
172
228
|
if (resumedAt !== undefined)
|
|
173
229
|
summary.resumedAt = resumedAt;
|
|
174
|
-
// resumeCount is runtime-owned
|
|
230
|
+
// resumeCount is runtime-owned snapshot provenance, not core step state.
|
|
175
231
|
const resumeCount = byStep(suspendedKeys, (key) => counts?.get(key));
|
|
176
232
|
if (resumeCount !== undefined)
|
|
177
233
|
summary.resumeCount = resumeCount;
|
|
178
|
-
|
|
234
|
+
break;
|
|
179
235
|
}
|
|
180
236
|
case 'tripwire':
|
|
181
|
-
|
|
237
|
+
summary = {
|
|
238
|
+
runId,
|
|
239
|
+
status: result.status,
|
|
240
|
+
error: result.tripwire.reason,
|
|
241
|
+
};
|
|
242
|
+
break;
|
|
182
243
|
default:
|
|
183
|
-
|
|
244
|
+
summary = { runId, status: result.status };
|
|
184
245
|
}
|
|
246
|
+
if (requestedBy !== undefined)
|
|
247
|
+
summary.requestedBy = requestedBy;
|
|
248
|
+
if (requestedByKind !== undefined) {
|
|
249
|
+
summary.requestedByKind = requestedByKind;
|
|
250
|
+
}
|
|
251
|
+
return summary;
|
|
185
252
|
}
|
|
186
253
|
// Storage may hand timestamps back as Date or as a serialized string
|
|
187
254
|
// depending on the adapter's snapshot round-trip; normalize defensively.
|
|
@@ -218,7 +285,7 @@ function suspendedAtOf(steps, stepKey) {
|
|
|
218
285
|
* Epoch-ms resume time of the step's latest attempt, if recorded. Feeds the
|
|
219
286
|
* INFORMATIONAL RunSummary.resumedAt only — Mastra stamps it solely on a
|
|
220
287
|
* payload-bearing resume, so it is unreliable as a first-vs-re-suspension
|
|
221
|
-
* signal. The grant binding uses `resumeCount`
|
|
288
|
+
* signal. The grant binding uses snapshot provenance `resumeCount` instead.
|
|
222
289
|
*/
|
|
223
290
|
function resumedAtOf(steps, stepKey) {
|
|
224
291
|
return latestAttempt(steps, stepKey)?.resumedAt;
|
|
@@ -232,7 +299,7 @@ function resumedAtOf(steps, stepKey) {
|
|
|
232
299
|
* object literal a step named '__proto__' would route into the
|
|
233
300
|
* Object.prototype setter and silently vanish (or, for an object-valued
|
|
234
301
|
* payload, rewire the accumulator's prototype) — the same hazard
|
|
235
|
-
*
|
|
302
|
+
* snapshot provenance stores [stepKey, count] pairs to avoid.
|
|
236
303
|
*/
|
|
237
304
|
function byStep(suspendedKeys, lookup) {
|
|
238
305
|
const map = Object.create(null);
|
|
@@ -255,13 +322,18 @@ function byStep(suspendedKeys, lookup) {
|
|
|
255
322
|
// (isFromInMemory), steps are empty and timestamps are current-time; the
|
|
256
323
|
// projection truthfully degrades to status-only rather than fabricating
|
|
257
324
|
// detail.
|
|
258
|
-
function summarizeState(runId, state, counts) {
|
|
325
|
+
function summarizeState(runId, state, counts, requestedBy, requestedByKind) {
|
|
259
326
|
const summary = {
|
|
260
327
|
runId,
|
|
261
328
|
status: state.status,
|
|
262
329
|
createdAt: toIso(state.createdAt),
|
|
263
330
|
updatedAt: toIso(state.updatedAt),
|
|
264
331
|
};
|
|
332
|
+
if (requestedBy !== undefined)
|
|
333
|
+
summary.requestedBy = requestedBy;
|
|
334
|
+
if (requestedByKind !== undefined) {
|
|
335
|
+
summary.requestedByKind = requestedByKind;
|
|
336
|
+
}
|
|
265
337
|
if (state.status === 'success') {
|
|
266
338
|
summary.result = state.result;
|
|
267
339
|
}
|
|
@@ -293,8 +365,8 @@ const TRUSTED_IDENTITY_CONTEXT_KEYS = new Set([
|
|
|
293
365
|
'threadId',
|
|
294
366
|
'resourceId',
|
|
295
367
|
]);
|
|
296
|
-
function orderedRequestContext(runtimeContext, provided) {
|
|
297
|
-
const
|
|
368
|
+
function orderedRequestContext(runtimeContext, provided, scheduled) {
|
|
369
|
+
const application = [];
|
|
298
370
|
const capabilities = [];
|
|
299
371
|
const identity = [];
|
|
300
372
|
for (const entry of Object.entries(provided ?? {})) {
|
|
@@ -302,23 +374,23 @@ function orderedRequestContext(runtimeContext, provided) {
|
|
|
302
374
|
if (key === BREAKWATER_WORKFLOW_SCOPE_KEY ||
|
|
303
375
|
key === BREAKWATER_ISOLATION_SCOPE_KEY ||
|
|
304
376
|
key === BREAKWATER_CONNECTOR_EXECUTION_KEY ||
|
|
377
|
+
key === RUN_PROVENANCE_CONTEXT_KEY ||
|
|
305
378
|
key === 'runId') {
|
|
306
379
|
continue;
|
|
307
380
|
}
|
|
308
381
|
if (TRUSTED_IDENTITY_CONTEXT_KEYS.has(key)) {
|
|
309
382
|
identity.push(entry);
|
|
310
383
|
}
|
|
311
|
-
else if (key
|
|
312
|
-
key.startsWith('breakwater.') ||
|
|
313
|
-
key === 'mastra:goal') {
|
|
384
|
+
else if (isReservedExecutionContextKey(key)) {
|
|
314
385
|
capabilities.push(entry);
|
|
315
386
|
}
|
|
316
387
|
else {
|
|
317
|
-
|
|
388
|
+
application.push(entry);
|
|
318
389
|
}
|
|
319
390
|
}
|
|
320
391
|
return new RequestContext([
|
|
321
|
-
...
|
|
392
|
+
...Object.entries(stripReservedExecutionContext(scheduled)),
|
|
393
|
+
...application,
|
|
322
394
|
...Object.entries(runtimeContext),
|
|
323
395
|
...capabilities,
|
|
324
396
|
...identity,
|
|
@@ -331,25 +403,6 @@ export class RunnerRuntime {
|
|
|
331
403
|
#agents = new Map();
|
|
332
404
|
#workflows = new Map();
|
|
333
405
|
#runLocks = new Map();
|
|
334
|
-
// Per-run resume ledger: #runKey(workflowId, runId) -> (stepKey -> times that
|
|
335
|
-
// step has been resumed). Keyed by the run's FULL identity, never runId alone
|
|
336
|
-
// (see #runKey): a shared caller runId under two workflows are distinct runs.
|
|
337
|
-
// The runtime increments it on every resume (regardless of
|
|
338
|
-
// payload) and projects it as RunSummary.resumeCount / RunLeg.resumeCount —
|
|
339
|
-
// the collision-free grant-binding tie-breaker that Mastra's
|
|
340
|
-
// payload-conditional resumedAt cannot provide.
|
|
341
|
-
//
|
|
342
|
-
// Durability: a lost ledger is fail-closed for grants (leg.resumeCount
|
|
343
|
-
// undefined vs an approval's captured ordinal -> mismatch -> deny, see
|
|
344
|
-
// grants.ts) — never a leak, but an AVAILABILITY bug: the approved action
|
|
345
|
-
// silently no-ops. DO eviction (~70-140s idle), hibernation, and code
|
|
346
|
-
// deploys all wipe in-memory state while ctx.storage survives, so the DO
|
|
347
|
-
// shell adopts a DurableStorageResumeLedger (durable-object.ts); the
|
|
348
|
-
// in-memory default covers node tests and non-DO hosts. Entries are
|
|
349
|
-
// deleted on terminal status below; a resumed-then-abandoned suspended run
|
|
350
|
-
// keeps one small entry until the run is purged.
|
|
351
|
-
#resumeLedger;
|
|
352
|
-
#resumeLedgerExplicit;
|
|
353
406
|
// The host DO's pubsub identity (RunnerRuntimeOptions.pubsub), threaded into
|
|
354
407
|
// both createRun sites below (CI-M-002-002) so a configured host publishes and
|
|
355
408
|
// replays on ONE shared feed. Undefined ⇒ core defaults a fresh emitter per
|
|
@@ -360,8 +413,6 @@ export class RunnerRuntime {
|
|
|
360
413
|
this.#storage = options.storage;
|
|
361
414
|
this.#logger = options.logger ?? false;
|
|
362
415
|
this.#requestContextForRun = options.requestContextForRun;
|
|
363
|
-
this.#resumeLedgerExplicit = options.resumeLedger !== undefined;
|
|
364
|
-
this.#resumeLedger = options.resumeLedger ?? new InMemoryResumeLedger();
|
|
365
416
|
this.#pubsub = options.pubsub;
|
|
366
417
|
}
|
|
367
418
|
/**
|
|
@@ -373,22 +424,6 @@ export class RunnerRuntime {
|
|
|
373
424
|
get pubsub() {
|
|
374
425
|
return this.#pubsub;
|
|
375
426
|
}
|
|
376
|
-
/**
|
|
377
|
-
* Host-shell seam: replace the DEFAULT in-memory ledger with a durable one.
|
|
378
|
-
* The DO shell calls this with a ctx.storage-backed ledger right after
|
|
379
|
-
* build(), so every DO host gets eviction-proof ordinals without threading
|
|
380
|
-
* a parameter (a forgettable thread is how the durability guarantee rots).
|
|
381
|
-
* A ledger explicitly injected via options wins; adoption is rejected once
|
|
382
|
-
* runs may have consulted the ledger.
|
|
383
|
-
*/
|
|
384
|
-
adoptDefaultResumeLedger(ledger) {
|
|
385
|
-
if (this.#mastra) {
|
|
386
|
-
throw new Error('RunnerRuntime: adopt the resume ledger before the first run — ordinals already read from the default ledger would be lost');
|
|
387
|
-
}
|
|
388
|
-
if (this.#resumeLedgerExplicit)
|
|
389
|
-
return;
|
|
390
|
-
this.#resumeLedger = ledger;
|
|
391
|
-
}
|
|
392
427
|
/**
|
|
393
428
|
* Register an agent that a runtime-owned workflow resolves by id.
|
|
394
429
|
*
|
|
@@ -409,7 +444,7 @@ export class RunnerRuntime {
|
|
|
409
444
|
if (this.#mastra) {
|
|
410
445
|
throw new Error('RunnerRuntime: register all workflows before the first run — the Mastra instance is frozen once runs start');
|
|
411
446
|
}
|
|
412
|
-
if (!
|
|
447
|
+
if (!isPathSafeId(workflow.id)) {
|
|
413
448
|
throw new Error(`RunnerRuntime: workflow id '${workflow.id}' must be URL-path-safe (letters, digits, '.', '_', '~', '-'; 1-200 chars) — it feeds the DO name join and the /runs/:workflowId/:runId path`);
|
|
414
449
|
}
|
|
415
450
|
if (this.#workflows.has(workflow.id)) {
|
|
@@ -432,11 +467,26 @@ export class RunnerRuntime {
|
|
|
432
467
|
// mint a run keyed by the number 123, unreachable by the string "123" the
|
|
433
468
|
// URL path later carries. There is NO generation fallback (INV-1): a
|
|
434
469
|
// missing/null runId is a client error, not a request for one.
|
|
435
|
-
if (
|
|
436
|
-
!PATH_SAFE_ID_PATTERN.test(options.runId)) {
|
|
470
|
+
if (!isPathSafeId(options.runId)) {
|
|
437
471
|
throw new InvalidRunRequestError("runId is required and must be URL-path-safe (letters, digits, '.', '_', '~', '-'; 1–200 chars)");
|
|
438
472
|
}
|
|
439
473
|
const runId = options.runId;
|
|
474
|
+
if (options.requestedBy !== undefined &&
|
|
475
|
+
!isExecutionPrincipalId(options.requestedBy)) {
|
|
476
|
+
throw new InvalidRunRequestError('requestedBy is malformed');
|
|
477
|
+
}
|
|
478
|
+
if (options.requestedByKind !== undefined &&
|
|
479
|
+
!isExecutionPrincipalKind(options.requestedByKind)) {
|
|
480
|
+
throw new InvalidRunRequestError('requestedByKind is malformed');
|
|
481
|
+
}
|
|
482
|
+
if ((options.requestedBy === undefined) !==
|
|
483
|
+
(options.requestedByKind === undefined)) {
|
|
484
|
+
throw new InvalidRunRequestError('requestedBy and requestedByKind must be provided together');
|
|
485
|
+
}
|
|
486
|
+
if (options.attemptToken !== undefined &&
|
|
487
|
+
!isPathSafeId(options.attemptToken)) {
|
|
488
|
+
throw new InvalidRunRequestError('attemptToken is malformed');
|
|
489
|
+
}
|
|
440
490
|
return this.#withRunLock(workflowId, runId, async () => {
|
|
441
491
|
// Supplied ids can collide with an existing run; starting it
|
|
442
492
|
// again would re-execute already-executed steps.
|
|
@@ -448,9 +498,20 @@ export class RunnerRuntime {
|
|
|
448
498
|
// initial snapshot, so a provider failure after it would strand a
|
|
449
499
|
// pending-but-never-started run (a supplied runId would then be locked
|
|
450
500
|
// out by RunAlreadyExistsError on retry). Failing here leaves no state.
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
501
|
+
const startAttemptToken = options.attemptToken ?? crypto.randomUUID();
|
|
502
|
+
const provenance = {
|
|
503
|
+
version: 1,
|
|
504
|
+
...(options.requestedBy === undefined
|
|
505
|
+
? {}
|
|
506
|
+
: {
|
|
507
|
+
requestedBy: options.requestedBy,
|
|
508
|
+
requestedByKind: options.requestedByKind,
|
|
509
|
+
}),
|
|
510
|
+
startToken: startAttemptToken,
|
|
511
|
+
attemptToken: startAttemptToken,
|
|
512
|
+
resumeCounts: [],
|
|
513
|
+
};
|
|
514
|
+
const requestContext = await this.#requestContextFor(workflowId, runId, { kind: 'start' }, provenance, options.storedRequestContext);
|
|
454
515
|
// Thread the host DO's pubsub identity into the run (CI-M-002-002). Core
|
|
455
516
|
// accepts `createRun({ runId, pubsub })` at every one of its OWN call
|
|
456
517
|
// sites (agent/durable index.js:5224/5541) and stamps it straight onto
|
|
@@ -465,14 +526,26 @@ export class RunnerRuntime {
|
|
|
465
526
|
try {
|
|
466
527
|
result = await run.start({
|
|
467
528
|
inputData: options.inputData,
|
|
529
|
+
initialState: options.initialState,
|
|
468
530
|
requestContext,
|
|
469
531
|
});
|
|
470
532
|
}
|
|
471
533
|
catch (error) {
|
|
534
|
+
const recovered = await this.#summaryForAttempt(workflow, runId, provenance.attemptToken);
|
|
535
|
+
if (recovered)
|
|
536
|
+
return recovered;
|
|
472
537
|
throw asClientError(error) ?? error;
|
|
473
538
|
}
|
|
474
|
-
|
|
475
|
-
|
|
539
|
+
try {
|
|
540
|
+
await this.#reconcileTerminalState(workflowId, run.runId, result, requestContext);
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
const recovered = await this.#summaryForAttempt(workflow, runId, provenance.attemptToken);
|
|
544
|
+
if (recovered)
|
|
545
|
+
return recovered;
|
|
546
|
+
throw error;
|
|
547
|
+
}
|
|
548
|
+
return summarize(run.runId, result, undefined, provenance.requestedBy, provenance.requestedByKind);
|
|
476
549
|
});
|
|
477
550
|
}
|
|
478
551
|
/**
|
|
@@ -483,8 +556,7 @@ export class RunnerRuntime {
|
|
|
483
556
|
async resume(workflowId, runId, options = {}) {
|
|
484
557
|
const workflow = this.#getWorkflow(workflowId);
|
|
485
558
|
return this.#withRunLock(workflowId, runId, async () => {
|
|
486
|
-
const
|
|
487
|
-
const state = await workflow.getWorkflowRunById(runId);
|
|
559
|
+
const state = await this.#workflowState(workflow, runId);
|
|
488
560
|
if (!state)
|
|
489
561
|
throw new UnknownRunError(workflowId, runId);
|
|
490
562
|
if (state.status !== 'suspended') {
|
|
@@ -493,7 +565,11 @@ export class RunnerRuntime {
|
|
|
493
565
|
// Provider before createRun for symmetry with start(): a resume-time
|
|
494
566
|
// createRun only reattaches (no snapshot write), but failing before it
|
|
495
567
|
// still does the least work and keeps the ordering invariant uniform.
|
|
496
|
-
const {
|
|
568
|
+
const { nextCounts, provenance, requestContext } = await this.#trustedResumePreparation(workflowId, runId, state, options.step, options.requestedBy, options.requestedByKind);
|
|
569
|
+
if (options.prepareExecution) {
|
|
570
|
+
const preparationValues = structuredClone(Object.fromEntries(requestContext.entries()));
|
|
571
|
+
await options.prepareExecution(new RequestContext(Object.entries(preparationValues)));
|
|
572
|
+
}
|
|
497
573
|
// Same host pubsub identity as start() (CI-M-002-002) — see the note
|
|
498
574
|
// there; undefined stays byte-identical to `createRun({ runId })`.
|
|
499
575
|
const run = await workflow.createRun({ runId, pubsub: this.#pubsub });
|
|
@@ -506,58 +582,64 @@ export class RunnerRuntime {
|
|
|
506
582
|
});
|
|
507
583
|
}
|
|
508
584
|
catch (error) {
|
|
509
|
-
|
|
510
|
-
|
|
585
|
+
const recovered = await this.#summaryForAttempt(workflow, runId, provenance.attemptToken);
|
|
586
|
+
if (recovered)
|
|
587
|
+
return recovered;
|
|
588
|
+
// No authoritative snapshot carries this attempt token: the run stayed
|
|
589
|
+
// on its prior suspension, so neither requester nor ordinal advances.
|
|
511
590
|
throw asClientError(error) ?? error;
|
|
512
591
|
}
|
|
513
|
-
//
|
|
514
|
-
//
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
let counts = priorCounts;
|
|
519
|
-
if (stepKey !== undefined) {
|
|
520
|
-
counts = await this.#resumeLedger.increment(runKey, stepKey, priorCounts ?? new Map());
|
|
592
|
+
// A re-suspension produced by this resume carries the incremented ordinal
|
|
593
|
+
// in the same authoritative snapshot as the new workflow state.
|
|
594
|
+
const summary = summarize(run.runId, result, nextCounts, provenance.requestedBy, provenance.requestedByKind);
|
|
595
|
+
try {
|
|
596
|
+
await this.#reconcileTerminalState(workflowId, run.runId, result, requestContext);
|
|
521
597
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
598
|
+
catch (error) {
|
|
599
|
+
const recovered = await this.#summaryForAttempt(workflow, runId, provenance.attemptToken);
|
|
600
|
+
if (recovered)
|
|
601
|
+
return recovered;
|
|
602
|
+
throw error;
|
|
527
603
|
}
|
|
528
604
|
return summary;
|
|
529
605
|
});
|
|
530
606
|
}
|
|
531
607
|
async status(workflowId, runId) {
|
|
532
608
|
const workflow = this.#getWorkflow(workflowId);
|
|
533
|
-
const state = await workflow
|
|
609
|
+
const state = await this.#workflowState(workflow, runId);
|
|
534
610
|
if (!state)
|
|
535
611
|
return null;
|
|
536
|
-
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const counts = state.status === 'suspended'
|
|
542
|
-
? await this.#resumeLedger.counts(this.#runKey(workflowId, runId))
|
|
543
|
-
: undefined;
|
|
544
|
-
return summarizeState(runId, state, counts);
|
|
612
|
+
const provenance = runProvenance(state);
|
|
613
|
+
// Snapshot provenance projects requester and resume ordinal alongside the
|
|
614
|
+
// authoritative workflow state, including after isolate eviction.
|
|
615
|
+
const counts = provenance ? new Map(provenance.resumeCounts) : undefined;
|
|
616
|
+
return summarizeState(runId, state, counts, provenance?.requestedBy, provenance?.requestedByKind);
|
|
545
617
|
}
|
|
546
618
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
619
|
+
* Reconcile an interrupted start against the token stored in the
|
|
620
|
+
* authoritative workflow snapshot. Mastra's `createRun()` first persists a
|
|
621
|
+
* tokenless pending shell; if no executed snapshot replaced it, the shell is
|
|
622
|
+
* abandoned and must not become a successful FlowSafe run.
|
|
551
623
|
*/
|
|
552
|
-
async
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if (!state)
|
|
556
|
-
throw new UnknownRunError(workflowId, runId);
|
|
557
|
-
if (state.status !== 'suspended') {
|
|
558
|
-
throw new RunNotSuspendedError(workflowId, runId, state.status);
|
|
624
|
+
async recoverStartAttempt(workflowId, runId, attemptToken) {
|
|
625
|
+
if (!isPathSafeId(attemptToken)) {
|
|
626
|
+
throw new InvalidRunRequestError('attemptToken is malformed');
|
|
559
627
|
}
|
|
560
|
-
|
|
628
|
+
const workflow = this.#getWorkflow(workflowId);
|
|
629
|
+
return this.#withRunLock(workflowId, runId, async () => {
|
|
630
|
+
const state = await this.#workflowState(workflow, runId);
|
|
631
|
+
if (!state)
|
|
632
|
+
return null;
|
|
633
|
+
const provenance = runProvenance(state);
|
|
634
|
+
if (provenance?.startToken === attemptToken) {
|
|
635
|
+
return summarizeState(runId, state, new Map(provenance.resumeCounts), provenance.requestedBy, provenance.requestedByKind);
|
|
636
|
+
}
|
|
637
|
+
if (state.status === 'pending' && provenance === undefined) {
|
|
638
|
+
await workflow.deleteWorkflowRunById(runId);
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
throw new Error(`run '${runId}' snapshot belongs to another start attempt`);
|
|
642
|
+
});
|
|
561
643
|
}
|
|
562
644
|
// A provider crash propagates (fail loud): silently starting the leg with
|
|
563
645
|
// fewer capabilities than intended would mask the fault. Missing grants can
|
|
@@ -569,41 +651,27 @@ export class RunnerRuntime {
|
|
|
569
651
|
// the scope is never client-suppliable. Provider values are partitioned into
|
|
570
652
|
// stored application context, capabilities, and trusted identity so every
|
|
571
653
|
// layer has an explicit order and a provider cannot replace runtime scope.
|
|
572
|
-
async #requestContextFor(workflowId, runId, leg) {
|
|
654
|
+
async #requestContextFor(workflowId, runId, leg, provenance, storedRequestContext) {
|
|
573
655
|
const base = {
|
|
574
656
|
[BREAKWATER_WORKFLOW_SCOPE_KEY]: workflowId,
|
|
575
657
|
runId,
|
|
576
658
|
};
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
// rate-limit keys per tenant. Server-authoritative like the workflow
|
|
580
|
-
// scope above — the runId was minted from the AUTHENTICATED tenant, so
|
|
581
|
-
// its prefix is trustworthy here.
|
|
582
|
-
//
|
|
583
|
-
// Structural, not flagged: a runId shaped `<inv3-slug>_<rest>` mints a
|
|
584
|
-
// scope. For this repo's hosts that is exactly the tenant (they all mint
|
|
585
|
-
// via TenantContext.newRunId). CONSTRAINT for standalone OSS consumers
|
|
586
|
-
// minting their own runIds: the scope segments breakwater's CROSS-RUN
|
|
587
|
-
// idempotency and rate-limit keys, so one logical account must keep ONE
|
|
588
|
-
// stable pre-`_` prefix (or avoid `_`-prefixed runIds entirely) — ids
|
|
589
|
-
// like `daily_<uuid>` vs `weekly_<uuid>` would split that account's key
|
|
590
|
-
// namespace per prefix, and a cross-run business key ("invoice-2026-07")
|
|
591
|
-
// would fire once per prefix instead of once. Never a cross-tenant leak
|
|
592
|
-
// (splitting only narrows sharing), but a real duplication hazard.
|
|
593
|
-
// Non-matching runIds mint nothing: the single-tenant keys stay
|
|
594
|
-
// byte-identical, and deployments that must never run scope-less enforce
|
|
595
|
-
// that with breakwater's tenantIsolation evaluator (which binds dry-run
|
|
596
|
-
// too, unlike the idempotency path).
|
|
597
|
-
const tenantId = tenantOfRunId(runId);
|
|
598
|
-
if (tenantId !== undefined) {
|
|
599
|
-
base[BREAKWATER_ISOLATION_SCOPE_KEY] = tenantId;
|
|
659
|
+
if (provenance !== undefined) {
|
|
660
|
+
base[RUN_PROVENANCE_CONTEXT_KEY] = provenance;
|
|
600
661
|
}
|
|
662
|
+
// No isolation scope is minted here: a deployment serves exactly one
|
|
663
|
+
// organization, so breakwater's connector idempotency and rate-limit keys
|
|
664
|
+
// are deployment-wide by construction. Budget partitioning within a
|
|
665
|
+
// deployment stays available
|
|
666
|
+
// through breakwater's crossWorkflowIsolation, which reads the workflow
|
|
667
|
+
// scope minted above. The isolation-scope context key remains RESERVED —
|
|
668
|
+
// orderedRequestContext drops it from provider values — so a provider can
|
|
669
|
+
// never mint a scope that desyncs from the execution identity below.
|
|
601
670
|
if (leg.kind === 'start') {
|
|
602
671
|
base[BREAKWATER_CONNECTOR_EXECUTION_KEY] = {
|
|
603
672
|
kind: 'start',
|
|
604
673
|
workflowId,
|
|
605
674
|
runId,
|
|
606
|
-
...(tenantId === undefined ? {} : { isolationScope: tenantId }),
|
|
607
675
|
};
|
|
608
676
|
}
|
|
609
677
|
else if (leg.step !== undefined && leg.suspendedAt !== undefined) {
|
|
@@ -611,7 +679,6 @@ export class RunnerRuntime {
|
|
|
611
679
|
kind: 'resume',
|
|
612
680
|
workflowId,
|
|
613
681
|
runId,
|
|
614
|
-
...(tenantId === undefined ? {} : { isolationScope: tenantId }),
|
|
615
682
|
suspension: {
|
|
616
683
|
stepPath: [...leg.step],
|
|
617
684
|
suspendedAt: leg.suspendedAt,
|
|
@@ -627,24 +694,75 @@ export class RunnerRuntime {
|
|
|
627
694
|
const values = this.#requestContextForRun
|
|
628
695
|
? await this.#requestContextForRun(workflowId, runId, leg)
|
|
629
696
|
: undefined;
|
|
630
|
-
return orderedRequestContext(base, values);
|
|
697
|
+
return orderedRequestContext(base, values, storedRequestContext);
|
|
631
698
|
}
|
|
632
|
-
async #trustedResumePreparation(workflowId, runId, state, selectedStep) {
|
|
699
|
+
async #trustedResumePreparation(workflowId, runId, state, selectedStep, requestedBy, requestedByKind) {
|
|
700
|
+
if (requestedBy !== undefined && !isExecutionPrincipalId(requestedBy)) {
|
|
701
|
+
throw new InvalidRunRequestError('requestedBy is malformed');
|
|
702
|
+
}
|
|
703
|
+
if (requestedByKind !== undefined &&
|
|
704
|
+
!isExecutionPrincipalKind(requestedByKind)) {
|
|
705
|
+
throw new InvalidRunRequestError('requestedByKind is malformed');
|
|
706
|
+
}
|
|
707
|
+
if ((requestedBy === undefined) !== (requestedByKind === undefined)) {
|
|
708
|
+
throw new InvalidRunRequestError('requestedBy and requestedByKind must be provided together');
|
|
709
|
+
}
|
|
633
710
|
const step = resolveResumeStep(selectedStep, state);
|
|
634
711
|
const stepKey = step?.join('.');
|
|
635
712
|
// resumeCount is read BEFORE this resume increments it: it is the count
|
|
636
713
|
// of prior resumes = the ordinal of the CURRENT suspension being resumed
|
|
637
714
|
// (undefined for a first suspension), which the minting approval captured.
|
|
638
|
-
const
|
|
715
|
+
const storedProvenance = runProvenance(state);
|
|
716
|
+
if (requestedBy === undefined &&
|
|
717
|
+
storedProvenance?.requestedBy !== undefined &&
|
|
718
|
+
storedProvenance.requestedByKind === undefined) {
|
|
719
|
+
throw new InvalidRunRequestError('legacy requestedBy provenance requires an explicit requestedBy and requestedByKind to resume');
|
|
720
|
+
}
|
|
721
|
+
const requester = requestedBy ?? storedProvenance?.requestedBy;
|
|
722
|
+
const requesterKind = requestedBy === undefined
|
|
723
|
+
? storedProvenance?.requestedByKind
|
|
724
|
+
: requestedByKind;
|
|
725
|
+
const priorCounts = new Map(storedProvenance?.resumeCounts ?? []);
|
|
726
|
+
const nextCounts = new Map(priorCounts);
|
|
727
|
+
if (stepKey !== undefined) {
|
|
728
|
+
nextCounts.set(stepKey, (nextCounts.get(stepKey) ?? 0) + 1);
|
|
729
|
+
}
|
|
730
|
+
const provenance = {
|
|
731
|
+
version: 1,
|
|
732
|
+
...(requester === undefined
|
|
733
|
+
? {}
|
|
734
|
+
: { requestedBy: requester, requestedByKind: requesterKind }),
|
|
735
|
+
startToken: storedProvenance?.startToken ?? crypto.randomUUID(),
|
|
736
|
+
attemptToken: crypto.randomUUID(),
|
|
737
|
+
resumeCounts: [...nextCounts],
|
|
738
|
+
};
|
|
639
739
|
const requestContext = await this.#requestContextFor(workflowId, runId, {
|
|
640
740
|
kind: 'resume',
|
|
641
741
|
step,
|
|
642
|
-
suspendedAt: stepKey !== undefined
|
|
742
|
+
suspendedAt: stepKey !== undefined
|
|
743
|
+
? suspendedAtOf(state.steps, stepKey)
|
|
744
|
+
: undefined,
|
|
643
745
|
resumeCount: stepKey !== undefined ? priorCounts?.get(stepKey) : undefined,
|
|
644
|
-
});
|
|
645
|
-
return {
|
|
746
|
+
}, provenance);
|
|
747
|
+
return {
|
|
748
|
+
nextCounts,
|
|
749
|
+
provenance,
|
|
750
|
+
requestContext,
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
#workflowState(workflow, runId) {
|
|
754
|
+
return workflow.getWorkflowRunById(runId, { fields: RUN_STATE_FIELDS });
|
|
646
755
|
}
|
|
647
|
-
async #
|
|
756
|
+
async #summaryForAttempt(workflow, runId, attemptToken) {
|
|
757
|
+
const persisted = await this.#workflowState(workflow, runId);
|
|
758
|
+
if (!persisted)
|
|
759
|
+
return undefined;
|
|
760
|
+
const provenance = runProvenance(persisted);
|
|
761
|
+
if (provenance?.attemptToken !== attemptToken)
|
|
762
|
+
return undefined;
|
|
763
|
+
return summarizeState(runId, persisted, new Map(provenance.resumeCounts), provenance.requestedBy, provenance.requestedByKind);
|
|
764
|
+
}
|
|
765
|
+
async #reconcileTerminalState(workflowId, runId, result, requestContext) {
|
|
648
766
|
const opts = terminalStateUpdate(result);
|
|
649
767
|
if (!opts)
|
|
650
768
|
return;
|
|
@@ -659,14 +777,34 @@ export class RunnerRuntime {
|
|
|
659
777
|
if (!snapshot) {
|
|
660
778
|
throw new Error(`RunnerRuntime: run '${runId}' of workflow '${workflowId}' completed without a durable snapshot`);
|
|
661
779
|
}
|
|
662
|
-
|
|
780
|
+
const persistedContext = snapshot.requestContext !== null &&
|
|
781
|
+
typeof snapshot.requestContext === 'object' &&
|
|
782
|
+
!Array.isArray(snapshot.requestContext)
|
|
783
|
+
? snapshot.requestContext
|
|
784
|
+
: {};
|
|
785
|
+
// Core merges resume context over the prior snapshot. Terminal-only repair
|
|
786
|
+
// must persist that same effective context, including application keys the
|
|
787
|
+
// current provider intentionally omitted.
|
|
788
|
+
const authoritativeContext = {
|
|
789
|
+
...persistedContext,
|
|
790
|
+
...Object.fromEntries(requestContext.entries()),
|
|
791
|
+
};
|
|
792
|
+
const persistedToken = runProvenance(snapshot)?.attemptToken;
|
|
793
|
+
const authoritativeToken = runProvenance({
|
|
794
|
+
...snapshot,
|
|
795
|
+
requestContext: authoritativeContext,
|
|
796
|
+
})?.attemptToken;
|
|
797
|
+
if (snapshot.status === result.status &&
|
|
798
|
+
persistedToken === authoritativeToken) {
|
|
663
799
|
return;
|
|
800
|
+
}
|
|
664
801
|
await workflows.persistWorkflowSnapshot({
|
|
665
802
|
workflowName: workflowId,
|
|
666
803
|
runId,
|
|
667
804
|
snapshot: {
|
|
668
805
|
...snapshot,
|
|
669
806
|
...opts,
|
|
807
|
+
requestContext: authoritativeContext,
|
|
670
808
|
timestamp: Date.now(),
|
|
671
809
|
},
|
|
672
810
|
});
|
|
@@ -696,9 +834,9 @@ export class RunnerRuntime {
|
|
|
696
834
|
// The run's full identity as a single map key: workflowId + runId, never runId
|
|
697
835
|
// alone. The same caller-supplied runId under two workflows are DISTINCT
|
|
698
836
|
// persisted runs (Mastra snapshots key on workflowName+runId) and must never
|
|
699
|
-
// share a per-run entry
|
|
700
|
-
//
|
|
701
|
-
//
|
|
837
|
+
// share a per-run FIFO entry. Composing the key in ONE place keeps every
|
|
838
|
+
// per-run map keyed identically, so a future map cannot reintroduce a
|
|
839
|
+
// runId-only key and cross workflow boundaries.
|
|
702
840
|
// This is the exact string the DO name join produces
|
|
703
841
|
// (idFromName(`${workflowId}:${runId}`)); PATH_SAFE_ID_PATTERN excludes ':'
|
|
704
842
|
// from both ids, so the join is unambiguous.
|