@lostgradient/weft 0.3.0 → 0.5.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/README.md +79 -24
- package/dist/cli/conformance.js +7 -1
- package/dist/cli/generated/operation-client.generated.d.ts +28 -13
- package/dist/cli/generated/operation-client.generated.js +1 -0
- package/dist/cli/help-text.d.ts +1 -1
- package/dist/cli/help-text.js +1 -0
- package/dist/cli/operation-catalog-snapshot.d.ts +8 -0
- package/dist/cli/operation-catalog-snapshot.js +11 -0
- package/dist/cli/parse-schedule-arguments.js +3 -1
- package/dist/cli/schedule.js +2 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli-main.js +79 -78
- package/dist/client/handle-delegation.d.ts +3 -2
- package/dist/client/handle-delegation.js +3 -1
- package/dist/client/http-client-requests.d.ts +2 -1
- package/dist/client/http-client-requests.js +7 -0
- package/dist/client/http-client.d.ts +9 -6
- package/dist/client/http-client.js +10 -1
- package/dist/client/http-request.d.ts +11 -1
- package/dist/client/http-request.js +17 -7
- package/dist/client/index.d.ts +1 -1
- package/dist/client/interface.d.ts +61 -5
- package/dist/client/local-handles.d.ts +22 -0
- package/dist/client/local-handles.js +23 -0
- package/dist/client/local.d.ts +6 -3
- package/dist/client/local.js +12 -26
- package/dist/client/start-body.d.ts +4 -3
- package/dist/core/byte-arrays.d.ts +5 -0
- package/dist/core/byte-arrays.js +5 -0
- package/dist/core/checkpoint/lifecycle.d.ts +3 -0
- package/dist/core/checkpoint/lifecycle.js +9 -4
- package/dist/core/checkpoint/serialization.js +12 -5
- package/dist/core/codec/extension-codec.d.ts +16 -0
- package/dist/core/codec/extension-codec.js +100 -6
- package/dist/core/context/activity-retry-state.d.ts +38 -0
- package/dist/core/context/activity-retry-state.js +89 -0
- package/dist/core/context/activity-schedule-to-close.d.ts +159 -0
- package/dist/core/context/activity-schedule-to-close.js +69 -0
- package/dist/core/context/child-workflow-pipe.d.ts +5 -5
- package/dist/core/context/child-workflow-pipe.js +15 -2
- package/dist/core/context/context-presence.d.ts +19 -0
- package/dist/core/context/context-presence.js +13 -0
- package/dist/core/context/durable-operations.d.ts +25 -0
- package/dist/core/context/durable-operations.js +64 -0
- package/dist/core/context/index.d.ts +9 -5
- package/dist/core/context/index.js +17 -12
- package/dist/core/context/internals.d.ts +20 -0
- package/dist/core/context/internals.js +3 -1
- package/dist/core/context/operation-request.d.ts +35 -0
- package/dist/core/context/parallel-cache-entry.d.ts +14 -5
- package/dist/core/context/run-operation.d.ts +6 -1
- package/dist/core/context/run-operation.js +41 -87
- package/dist/core/context/session-state.js +7 -8
- package/dist/core/context/speculative-child.js +2 -0
- package/dist/core/context/types.d.ts +15 -0
- package/dist/core/context/version-patching.d.ts +8 -0
- package/dist/core/context/version-patching.js +40 -0
- package/dist/core/context/workflow-logger.d.ts +98 -0
- package/dist/core/context/workflow-logger.js +68 -0
- package/dist/core/engine/activity-heartbeat-tracking.d.ts +64 -0
- package/dist/core/engine/activity-heartbeat-tracking.js +42 -0
- package/dist/core/engine/activity-per-attempt-timeout.d.ts +46 -0
- package/dist/core/engine/activity-per-attempt-timeout.js +36 -0
- package/dist/core/engine/activity-reconciliation.d.ts +1 -0
- package/dist/core/engine/activity-reconciliation.js +12 -1
- package/dist/core/engine/activity-resolution.d.ts +23 -0
- package/dist/core/engine/activity-resolution.js +37 -0
- package/dist/core/engine/aggregate.js +66 -30
- package/dist/core/engine/async-activity-completion.d.ts +23 -6
- package/dist/core/engine/async-activity-completion.js +53 -12
- package/dist/core/engine/attributes-tags.js +9 -4
- package/dist/core/engine/bulk-operations-purge.d.ts +26 -0
- package/dist/core/engine/bulk-operations-purge.js +38 -3
- package/dist/core/engine/bulk-operations-shared.d.ts +2 -0
- package/dist/core/engine/bulk-operations-shared.js +8 -2
- package/dist/core/engine/bulk-operations.d.ts +4 -1
- package/dist/core/engine/bulk-operations.js +235 -24
- package/dist/core/engine/callback-creators-bundles.d.ts +9 -0
- package/dist/core/engine/callback-creators-bundles.js +30 -2
- package/dist/core/engine/callback-creators-core.js +6 -4
- package/dist/core/engine/callback-creators-router.js +10 -0
- package/dist/core/engine/callback-creators-schedule.d.ts +2 -2
- package/dist/core/engine/callback-creators-schedule.js +12 -8
- package/dist/core/engine/candidate-read-batching.d.ts +6 -0
- package/dist/core/engine/candidate-read-batching.js +1 -0
- package/dist/core/engine/checkpoint-io.js +61 -25
- package/dist/core/engine/checkpoint-reads.js +3 -2
- package/dist/core/engine/checkpoint-replay.d.ts +20 -0
- package/dist/core/engine/checkpoint-replay.js +242 -0
- package/dist/core/engine/checkpoint-side-effects.d.ts +23 -0
- package/dist/core/engine/checkpoint-side-effects.js +35 -0
- package/dist/core/engine/child-workflow-cancellation.d.ts +10 -0
- package/dist/core/engine/child-workflow-cancellation.js +40 -0
- package/dist/core/engine/child-workflow.js +27 -4
- package/dist/core/engine/condition-waiters.d.ts +14 -0
- package/dist/core/engine/condition-waiters.js +5 -0
- package/dist/core/engine/construction.d.ts +3 -0
- package/dist/core/engine/construction.js +21 -8
- package/dist/core/engine/coordination-branch-executors.d.ts +70 -0
- package/dist/core/engine/coordination-branch-executors.js +107 -0
- package/dist/core/engine/deferred-consume-envelope.d.ts +59 -0
- package/dist/core/engine/deferred-consume-envelope.js +14 -0
- package/dist/core/engine/disposal.js +13 -0
- package/dist/core/engine/engine-create-types.d.ts +14 -4
- package/dist/core/engine/engine-internal-types.d.ts +26 -3
- package/dist/core/engine/errors.d.ts +47 -0
- package/dist/core/engine/errors.js +20 -0
- package/dist/core/engine/event-log-compaction.d.ts +8 -0
- package/dist/core/engine/event-log-compaction.js +20 -2
- package/dist/core/engine/fenced-write.d.ts +65 -0
- package/dist/core/engine/fenced-write.js +71 -0
- package/dist/core/engine/finalizer-state.d.ts +28 -0
- package/dist/core/engine/finalizer-state.js +16 -0
- package/dist/core/engine/handles.d.ts +8 -0
- package/dist/core/engine/index.d.ts +34 -16
- package/dist/core/engine/index.js +136 -9
- package/dist/core/engine/inline-parking.js +3 -2
- package/dist/core/engine/internals.d.ts +107 -3
- package/dist/core/engine/lease-codec.d.ts +35 -0
- package/dist/core/engine/lease-codec.js +32 -0
- package/dist/core/engine/lease-deposition.d.ts +66 -0
- package/dist/core/engine/lease-deposition.js +10 -0
- package/dist/core/engine/lease-errors.d.ts +99 -0
- package/dist/core/engine/lease-errors.js +30 -0
- package/dist/core/engine/lease-manager.d.ts +114 -0
- package/dist/core/engine/lease-manager.js +135 -0
- package/dist/core/engine/lifecycle/persist.js +10 -32
- package/dist/core/engine/lifecycle/recovered-services.d.ts +8 -6
- package/dist/core/engine/lifecycle/recovered-services.js +18 -3
- package/dist/core/engine/lifecycle/resume.js +16 -9
- package/dist/core/engine/lifecycle/shared.d.ts +8 -1
- package/dist/core/engine/lifecycle/start-batch.d.ts +1 -1
- package/dist/core/engine/lifecycle/start-batch.js +2 -1
- package/dist/core/engine/lifecycle/start-commit.d.ts +9 -0
- package/dist/core/engine/lifecycle/start-commit.js +50 -8
- package/dist/core/engine/lifecycle/start-or-signal-create.d.ts +58 -0
- package/dist/core/engine/lifecycle/start-or-signal-create.js +95 -0
- package/dist/core/engine/lifecycle/start-or-signal.d.ts +3 -2
- package/dist/core/engine/lifecycle/start-or-signal.js +11 -81
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +39 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +28 -0
- package/dist/core/engine/lifecycle/start.d.ts +4 -4
- package/dist/core/engine/lifecycle/start.js +17 -9
- package/dist/core/engine/lifecycle/transition.js +17 -5
- package/dist/core/engine/lifecycle.d.ts +1 -1
- package/dist/core/engine/list-candidate-resolution.js +2 -2
- package/dist/core/engine/listing.js +9 -5
- package/dist/core/engine/operations-activity.d.ts +6 -13
- package/dist/core/engine/operations-activity.js +26 -53
- package/dist/core/engine/operations-coordination.d.ts +10 -0
- package/dist/core/engine/operations-coordination.js +44 -9
- package/dist/core/engine/operations-router.d.ts +6 -0
- package/dist/core/engine/operations-router.js +2 -0
- package/dist/core/engine/operations-speculate.js +6 -2
- package/dist/core/engine/operations-stream.js +12 -2
- package/dist/core/engine/operations-time.d.ts +4 -2
- package/dist/core/engine/operations-time.js +14 -2
- package/dist/core/engine/operations-wait-condition.d.ts +23 -0
- package/dist/core/engine/operations-wait-condition.js +62 -0
- package/dist/core/engine/ownership-options.d.ts +23 -0
- package/dist/core/engine/ownership-options.js +26 -0
- package/dist/core/engine/payload-size-policy.d.ts +3 -0
- package/dist/core/engine/payload-size-policy.js +4 -0
- package/dist/core/engine/pending-updates.d.ts +17 -0
- package/dist/core/engine/pending-updates.js +33 -11
- package/dist/core/engine/queries.js +1 -1
- package/dist/core/engine/registration.d.ts +1 -0
- package/dist/core/engine/registration.js +18 -3
- package/dist/core/engine/schedule-jitter.d.ts +5 -0
- package/dist/core/engine/schedule-jitter.js +10 -0
- package/dist/core/engine/schedule-run.d.ts +17 -0
- package/dist/core/engine/schedule-run.js +38 -0
- package/dist/core/engine/schedule-timer.js +81 -17
- package/dist/core/engine/schedules.d.ts +7 -4
- package/dist/core/engine/schedules.js +37 -16
- package/dist/core/engine/search-attribute-records.d.ts +4 -0
- package/dist/core/engine/search-attribute-records.js +17 -0
- package/dist/core/engine/signals.d.ts +18 -2
- package/dist/core/engine/signals.js +42 -21
- package/dist/core/engine/state-utilities.d.ts +49 -2
- package/dist/core/engine/state-utilities.js +114 -3
- package/dist/core/engine/storage-io.d.ts +16 -2
- package/dist/core/engine/storage-io.js +26 -5
- package/dist/core/engine/stream-chunk-loading.d.ts +2 -0
- package/dist/core/engine/stream-chunk-loading.js +24 -1
- package/dist/core/engine/sub-operation.js +25 -6
- package/dist/core/engine/termination/cleanup.d.ts +3 -1
- package/dist/core/engine/termination/cleanup.js +25 -1
- package/dist/core/engine/termination/complete.js +44 -6
- package/dist/core/engine/termination/finalizer-activity.d.ts +53 -0
- package/dist/core/engine/termination/finalizer-activity.js +30 -0
- package/dist/core/engine/termination/finalizer-claim.d.ts +110 -0
- package/dist/core/engine/termination/finalizer-claim.js +80 -0
- package/dist/core/engine/termination/finalizer.d.ts +48 -0
- package/dist/core/engine/termination/finalizer.js +159 -0
- package/dist/core/engine/termination/suspend.d.ts +3 -1
- package/dist/core/engine/termination.d.ts +1 -0
- package/dist/core/engine/termination.js +4 -0
- package/dist/core/engine/updates.js +5 -25
- package/dist/core/engine/validation/schedule.d.ts +2 -1
- package/dist/core/engine/validation/schedule.js +51 -2
- package/dist/core/engine/validation.js +32 -5
- package/dist/core/engine/waiting-update-response.d.ts +8 -0
- package/dist/core/engine/waiting-update-response.js +22 -0
- package/dist/core/engine/workflow-concurrency.d.ts +10 -0
- package/dist/core/engine/workflow-concurrency.js +136 -0
- package/dist/core/engine/workflow-feed.d.ts +4 -5
- package/dist/core/engine/workflow-feed.js +4 -1
- package/dist/core/engine/workflow-indexes.d.ts +9 -0
- package/dist/core/engine/workflow-indexes.js +10 -0
- package/dist/core/engine/workflow-state-stream.js +33 -13
- package/dist/core/engine/workflow-visibility-queries.d.ts +2 -2
- package/dist/core/engine-helpers.js +1 -0
- package/dist/core/events/activity-events.d.ts +43 -12
- package/dist/core/events/activity-events.js +28 -0
- package/dist/core/events/attribute-events.d.ts +2 -3
- package/dist/core/events/event-map.d.ts +18 -12
- package/dist/core/events/index.d.ts +1 -0
- package/dist/core/events/index.js +1 -0
- package/dist/core/events/schedule-events.d.ts +71 -0
- package/dist/core/events/schedule-events.js +29 -0
- package/dist/core/events/signal-events.d.ts +4 -6
- package/dist/core/events/system-events.d.ts +29 -19
- package/dist/core/events/system-events.js +26 -0
- package/dist/core/events/update-events.d.ts +6 -8
- package/dist/core/events/workflow-events.d.ts +88 -23
- package/dist/core/events/workflow-events.js +26 -0
- package/dist/core/failure-categories.js +5 -17
- package/dist/core/fault-code.d.ts +9 -3
- package/dist/core/fault-code.js +1 -0
- package/dist/core/inline-execution-strategy.context-options.d.ts +69 -0
- package/dist/core/inline-execution-strategy.context-options.js +56 -0
- package/dist/core/inline-execution-strategy.d.ts +31 -36
- package/dist/core/inline-execution-strategy.js +16 -27
- package/dist/core/list-filter-validation.d.ts +1 -1
- package/dist/core/payload-size.d.ts +1 -1
- package/dist/core/persisted-data-incompatible-error.d.ts +9 -7
- package/dist/core/review/events.d.ts +6 -8
- package/dist/core/scheduler/scheduler-class.d.ts +10 -1
- package/dist/core/scheduler/scheduler-class.js +38 -11
- package/dist/core/scheduler/timer-batch.js +9 -1
- package/dist/core/scheduler/timer-sources.d.ts +1 -0
- package/dist/core/scheduler/timer-sources.js +11 -5
- package/dist/core/session-state.d.ts +0 -1
- package/dist/core/session-state.js +2 -2
- package/dist/core/start-workflow-validation.d.ts +34 -0
- package/dist/core/start-workflow-validation.js +19 -0
- package/dist/core/types/activity-verification.d.ts +67 -0
- package/dist/core/types/activity-verification.js +0 -0
- package/dist/core/types/activity.d.ts +80 -61
- package/dist/core/types/bulk.d.ts +50 -9
- package/dist/core/types/checkpoint.d.ts +44 -8
- package/dist/core/types/list-options.d.ts +146 -0
- package/dist/core/types/list-options.js +0 -0
- package/dist/core/types/options.d.ts +121 -165
- package/dist/core/types/schedules.d.ts +39 -3
- package/dist/core/types/services-resolution.d.ts +2 -2
- package/dist/core/types/workflow-builder-runtime.d.ts +12 -3
- package/dist/core/types/workflow-builder-runtime.js +11 -2
- package/dist/core/types/workflow-builder.d.ts +42 -11
- package/dist/core/types/workflow-concurrency.d.ts +39 -0
- package/dist/core/types/workflow-concurrency.js +0 -0
- package/dist/core/types/workflow-context.d.ts +157 -14
- package/dist/core/types/workflow-definition.d.ts +53 -10
- package/dist/core/types/workflow-function.d.ts +84 -9
- package/dist/core/types/workflow-log.d.ts +98 -0
- package/dist/core/types/workflow-log.js +0 -0
- package/dist/core/types/workflow-registries.d.ts +14 -3
- package/dist/core/types/workflow-registry.d.ts +3 -0
- package/dist/core/types.d.ts +4 -0
- package/dist/core/types.js +4 -0
- package/dist/core/versioning.d.ts +9 -39
- package/dist/core/versioning.js +2 -12
- package/dist/core/weft-error.d.ts +44 -1
- package/dist/core/weft-error.js +16 -0
- package/dist/core/worker-execution-strategy-options.d.ts +26 -0
- package/dist/core/worker-execution-strategy.js +40 -36
- package/dist/core/worker-inbound-message.d.ts +38 -0
- package/dist/core/worker-inbound-message.js +37 -0
- package/dist/core/worker-log-abuse-counter.d.ts +175 -0
- package/dist/core/worker-log-abuse-counter.js +107 -0
- package/dist/core/worker-message-helpers.d.ts +47 -0
- package/dist/core/worker-message-helpers.js +26 -0
- package/dist/core/worker-protocol-guard.js +1 -1
- package/dist/core/worker-protocol-log.d.ts +56 -0
- package/dist/core/worker-protocol-log.js +18 -0
- package/dist/core/worker-protocol.d.ts +23 -0
- package/dist/core/worker-protocol.js +12 -2
- package/dist/core/workflow-version-tuple.d.ts +3 -9
- package/dist/core/workflow-version-tuple.js +2 -3
- package/dist/diagnostics/format.js +1 -6
- package/dist/diagnostics/types.d.ts +4 -5
- package/dist/diagnostics/validate.d.ts +0 -1
- package/dist/diagnostics/version-check.d.ts +1 -1
- package/dist/diagnostics/version-check.js +4 -9
- package/dist/index.d.ts +12 -10
- package/dist/index.js +29 -3
- package/dist/json-schema.js +3 -3
- package/dist/mcp/cli.js +19 -19
- package/dist/mcp/dispatcher.js +1 -1
- package/dist/mcp/http.js +16 -6
- package/dist/mcp/protocol.d.ts +2 -0
- package/dist/mcp/protocol.js +1 -1
- package/dist/mcp/session.d.ts +16 -0
- package/dist/mcp/session.js +59 -6
- package/dist/mcp/tools.js +73 -6
- package/dist/observability/index.js +2 -2
- package/dist/server/asyncapi-channels.js +5 -2
- package/dist/server/attribute-filters.d.ts +8 -3
- package/dist/server/attribute-filters.js +6 -1
- package/dist/server/authentication/api-key.d.ts +2 -1
- package/dist/server/authentication/api-key.js +5 -2
- package/dist/server/authentication/constant-time-api-key.d.ts +15 -0
- package/dist/server/authentication/constant-time-api-key.js +24 -0
- package/dist/server/authentication/index.d.ts +1 -1
- package/dist/server/authentication/index.js +7 -4
- package/dist/server/authentication/rotating-api-key-store.d.ts +5 -3
- package/dist/server/authentication/rotating-api-key-store.js +19 -11
- package/dist/server/engine-event-feed-backend.d.ts +4 -5
- package/dist/server/fault-to-http.js +8 -1
- package/dist/server/fault-to-json-rpc.js +1 -0
- package/dist/server/fleet-event-feed.d.ts +31 -0
- package/dist/server/fleet-event-feed.js +157 -0
- package/dist/server/handler/index.js +1 -1
- package/dist/server/handler/response-helpers.js +2 -1
- package/dist/server/handler/route-dispatch.d.ts +6 -3
- package/dist/server/handler/route-dispatch.js +2 -2
- package/dist/server/handler.js +23 -23
- package/dist/server/index.d.ts +32 -2
- package/dist/server/index.js +32 -32
- package/dist/server/json-rpc-transport-helpers.d.ts +1 -0
- package/dist/server/json-rpc-transport-helpers.js +2 -1
- package/dist/server/json-rpc-websocket-runtime.d.ts +11 -2
- package/dist/server/json-rpc-websocket-runtime.js +1 -0
- package/dist/server/json-rpc-websocket-subscriptions.d.ts +10 -0
- package/dist/server/json-rpc-websocket-subscriptions.js +29 -0
- package/dist/server/json-rpc-websocket-types.d.ts +22 -0
- package/dist/server/json-rpc-websocket-types.js +0 -0
- package/dist/server/json-rpc-websocket-validation.js +20 -4
- package/dist/server/json-rpc-websocket.d.ts +2 -43
- package/dist/server/json-rpc-websocket.js +57 -74
- package/dist/server/openapi.d.ts +2 -1
- package/dist/server/openapi.js +1 -3
- package/dist/server/openrpc-document-schema.d.ts +78 -0
- package/dist/server/openrpc-document-schema.js +27 -1
- package/dist/server/openrpc-errors.d.ts +3 -0
- package/dist/server/openrpc-errors.js +2 -1
- package/dist/server/openrpc.js +32 -0
- package/dist/server/operation-catalog/index.d.ts +1 -1
- package/dist/server/operation-catalog/pipeline-helpers.js +1 -0
- package/dist/server/operation-catalog/pipeline-stages.js +26 -12
- package/dist/server/operation-catalog/pipeline.js +8 -1
- package/dist/server/operation-catalog/registry.js +13 -0
- package/dist/server/operation-catalog/types.d.ts +20 -9
- package/dist/server/operation-fault.d.ts +10 -0
- package/dist/server/operation-fault.js +2 -0
- package/dist/server/operation-registry.d.ts +12 -11
- package/dist/server/operation-registry.js +12 -3
- package/dist/server/operations/aggregate-workflows.d.ts +15 -15
- package/dist/server/operations/async-activity.d.ts +2 -2
- package/dist/server/operations/async-activity.js +12 -7
- package/dist/server/operations/bulk-cancel-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-cancel-workflows.js +2 -2
- package/dist/server/operations/bulk-delete-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-delete-workflows.js +2 -2
- package/dist/server/operations/bulk-filter-helpers.d.ts +8 -6
- package/dist/server/operations/bulk-filter-helpers.js +54 -24
- package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +11 -9
- package/dist/server/operations/bulk-mutate-workflow-tags.js +2 -2
- package/dist/server/operations/bulk-operation-helpers.d.ts +2 -2
- package/dist/server/operations/bulk-retry-failed-workflows.d.ts +7 -0
- package/dist/server/operations/bulk-retry-failed-workflows.js +64 -0
- package/dist/server/operations/bulk-signal-workflows.d.ts +11 -9
- package/dist/server/operations/bulk-signal-workflows.js +2 -2
- package/dist/server/operations/cancel-schedule.d.ts +1 -1
- package/dist/server/operations/create-schedule.d.ts +3 -1
- package/dist/server/operations/create-schedule.js +29 -11
- package/dist/server/operations/fleet-events-subscription.d.ts +54 -0
- package/dist/server/operations/fleet-events-subscription.js +99 -0
- package/dist/server/operations/fork-workflow.d.ts +1 -1
- package/dist/server/operations/fork-workflow.js +3 -2
- package/dist/server/operations/get-checkpoint-at.d.ts +1 -1
- package/dist/server/operations/get-registry.d.ts +1 -1
- package/dist/server/operations/get-retention-overview.d.ts +1 -1
- package/dist/server/operations/get-review.d.ts +1 -1
- package/dist/server/operations/get-schedule.d.ts +1 -1
- package/dist/server/operations/get-stream-chunks.d.ts +1 -1
- package/dist/server/operations/get-system-metrics.d.ts +2 -2
- package/dist/server/operations/get-task-diagnostics.d.ts +45 -6
- package/dist/server/operations/get-task-diagnostics.js +101 -7
- package/dist/server/operations/get-update-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/get-workflow-events.d.ts +1 -1
- package/dist/server/operations/get-workflow-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-timeline.d.ts +1 -1
- package/dist/server/operations/get-workflow.d.ts +1 -1
- package/dist/server/operations/list-checkpoints.d.ts +1 -1
- package/dist/server/operations/list-reviews.d.ts +1 -1
- package/dist/server/operations/list-schedules.d.ts +1 -1
- package/dist/server/operations/list-task-queues.d.ts +2 -2
- package/dist/server/operations/list-workers.d.ts +2 -2
- package/dist/server/operations/list-workflows.d.ts +1 -1
- package/dist/server/operations/operation-helpers.d.ts +16 -1
- package/dist/server/operations/operation-helpers.js +15 -3
- package/dist/server/operations/pause-schedule.d.ts +1 -1
- package/dist/server/operations/purge-workflows.d.ts +5 -5
- package/dist/server/operations/purge-workflows.js +2 -2
- package/dist/server/operations/query-workflow.d.ts +1 -1
- package/dist/server/operations/query-workflow.js +3 -2
- package/dist/server/operations/recover-all.d.ts +1 -1
- package/dist/server/operations/replay-workflow.d.ts +1 -1
- package/dist/server/operations/resume-schedule.d.ts +1 -1
- package/dist/server/operations/set-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/set-workflow-attributes.js +6 -3
- package/dist/server/operations/signal-workflow.js +8 -3
- package/dist/server/operations/single-workflow-tag-mutation.js +13 -3
- package/dist/server/operations/start-or-signal-workflow.d.ts +6 -1
- package/dist/server/operations/start-or-signal-workflow.js +14 -24
- package/dist/server/operations/start-workflow-options.d.ts +6 -0
- package/dist/server/operations/start-workflow-rest-input.d.ts +14 -0
- package/dist/server/operations/start-workflow-rest-input.js +31 -0
- package/dist/server/operations/start-workflow.d.ts +1 -1
- package/dist/server/operations/start-workflow.js +8 -23
- package/dist/server/operations/storage.d.ts +6 -6
- package/dist/server/operations/storage.js +24 -14
- package/dist/server/operations/stream-workflow-sse.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.js +6 -3
- package/dist/server/operations/update-schedule.d.ts +1 -1
- package/dist/server/operations/update-schedule.js +7 -4
- package/dist/server/operations/update-workflow.d.ts +1 -1
- package/dist/server/operations/update-workflow.js +7 -3
- package/dist/server/operations/worker-drain.d.ts +8 -8
- package/dist/server/operations/worker-drain.js +11 -8
- package/dist/server/operations/workflow-events-subscription.d.ts +7 -8
- package/dist/server/operations/workflow-events-subscription.js +43 -8
- package/dist/server/rest-binding.d.ts +3 -1
- package/dist/server/rest-bindings.js +12 -0
- package/dist/server/rest-body.d.ts +10 -0
- package/dist/server/rest-body.js +80 -0
- package/dist/server/runtime/authentication-bridge.d.ts +1 -0
- package/dist/server/runtime/authentication-bridge.js +33 -6
- package/dist/server/runtime/client-visible-events.d.ts +3 -0
- package/dist/server/runtime/client-visible-events.js +65 -0
- package/dist/server/runtime/context.d.ts +7 -0
- package/dist/server/runtime/event-broadcasting.d.ts +6 -0
- package/dist/server/runtime/event-broadcasting.js +72 -38
- package/dist/server/runtime/retry.d.ts +1 -0
- package/dist/server/runtime/retry.js +14 -0
- package/dist/server/runtime/shutdown.d.ts +7 -6
- package/dist/server/runtime/shutdown.js +6 -1
- package/dist/server/runtime/task-polling.js +61 -20
- package/dist/server/runtime/task-reconciliation.js +9 -1
- package/dist/server/runtime/task-result-resolution.d.ts +15 -0
- package/dist/server/runtime/task-result-resolution.js +81 -0
- package/dist/server/runtime/websocket-stream.d.ts +20 -1
- package/dist/server/runtime/websocket-stream.js +173 -7
- package/dist/server/runtime/websocket-upgrade.js +22 -3
- package/dist/server/runtime/websocket-worker.d.ts +1 -1
- package/dist/server/runtime/websocket-worker.js +38 -30
- package/dist/server/serve-internals.d.ts +3 -1
- package/dist/server/serve-internals.js +18 -2
- package/dist/server/task-state.d.ts +30 -0
- package/dist/server/task-state.js +28 -0
- package/dist/server/workflow-event-feed.d.ts +36 -115
- package/dist/server/workflow-event-feed.js +92 -27
- package/dist/service-worker/index.js +30 -30
- package/dist/storage/auto.js +1 -1
- package/dist/storage/bun-sql.js +24 -0
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/default-scope.d.ts +7 -4
- package/dist/storage/http.js +2 -2
- package/dist/storage/index.d.ts +76 -4
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +163 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +10 -0
- package/dist/storage/lmdb.d.ts +4 -3
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon-batch.d.ts +30 -0
- package/dist/storage/neon-batch.js +30 -0
- package/dist/storage/neon-value-mapping.d.ts +30 -3
- package/dist/storage/neon-value-mapping.js +12 -0
- package/dist/storage/neon.d.ts +16 -0
- package/dist/storage/neon.js +9 -4
- package/dist/storage/node-sqlite.js +23 -0
- package/dist/storage/postgres-key-value-queries.d.ts +69 -44
- package/dist/storage/postgres-key-value-queries.js +62 -24
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/testing.d.ts +168 -0
- package/dist/storage/testing.js +2 -0
- package/dist/storage/turso.d.ts +8 -0
- package/dist/storage/turso.js +2 -2
- package/dist/storage/typed-storage.js +1 -1
- package/dist/storage/web-extension.js +1 -1
- package/dist/testing/index.js +20 -20
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/protocol.js +1 -1
- package/dist/workers/worker-replay-state.d.ts +32 -0
- package/dist/workers/worker-replay-state.js +35 -0
- package/dist/workers/worker-state-namespace.d.ts +21 -0
- package/dist/workers/worker-state-namespace.js +13 -0
- package/dist/workers/workflow-runner.d.ts +19 -15
- package/dist/workers/workflow-runner.js +72 -60
- package/dist/workers/workflow-worker-entry.js +5 -2
- package/package.json +5 -1
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* across replay. After an engine restart, `recoverAll()` replays the workflow
|
|
23
23
|
* from its checkpoint; the deferred activity re-runs, re-defers, and produces
|
|
24
24
|
* the *same* token. A callback that arrives after the crash therefore still
|
|
25
|
-
* resolves the correct activity.
|
|
25
|
+
* resolves the correct activity. If that callback races `recoverAll()` and
|
|
26
|
+
* arrives after token recovery but before replay has adopted the workflow
|
|
27
|
+
* generator, the engine buffers the completion or failure outcome and drains it
|
|
28
|
+
* when replay reaches the same deterministic token.
|
|
26
29
|
*
|
|
27
30
|
* Internal-only. Imported from `src/core/engine/**` and the `ActivityContext`
|
|
28
31
|
* construction path.
|
|
@@ -30,6 +33,12 @@
|
|
|
30
33
|
import type { OperationOutcome } from '../types.ts';
|
|
31
34
|
import { WeftError } from '../weft-error.ts';
|
|
32
35
|
import type { EngineInternals } from './internals.ts';
|
|
36
|
+
type AsyncActivityResolutionCallbacks = {
|
|
37
|
+
feedOperationResult: (workflowId: string, outcome: OperationOutcome, originalReason?: {
|
|
38
|
+
value: unknown;
|
|
39
|
+
}) => void;
|
|
40
|
+
finalizeTimeline: (workflowId: string, status: 'completed' | 'failed', output: unknown) => void;
|
|
41
|
+
};
|
|
33
42
|
/**
|
|
34
43
|
* Per-workflow prefix for all async-activity storage keys. Used by cleanup and
|
|
35
44
|
* purge paths that need to sweep every async-activity record for a workflow
|
|
@@ -80,6 +89,15 @@ export type PendingAsyncActivity = {
|
|
|
80
89
|
readonly attempt: number;
|
|
81
90
|
readonly createdAt: number;
|
|
82
91
|
};
|
|
92
|
+
export type PendingAsyncActivityResolution = {
|
|
93
|
+
readonly token: string;
|
|
94
|
+
readonly outcome: OperationOutcome;
|
|
95
|
+
readonly originalReason?: {
|
|
96
|
+
value: unknown;
|
|
97
|
+
};
|
|
98
|
+
readonly timelineStatus: 'completed' | 'failed';
|
|
99
|
+
readonly timelineOutput: unknown;
|
|
100
|
+
};
|
|
83
101
|
/**
|
|
84
102
|
* Derive the durable, deterministic task token for an async activity.
|
|
85
103
|
*
|
|
@@ -106,7 +124,7 @@ export declare function registerPendingAsyncActivity(internals: EngineInternals,
|
|
|
106
124
|
* out-of-band completion resumes it. Keeps the operation-pipeline catch site a
|
|
107
125
|
* one-liner.
|
|
108
126
|
*/
|
|
109
|
-
export declare function parkDeferredAsyncActivity(internals: EngineInternals, deferral: AsyncActivityDeferral, details: Omit<PendingAsyncActivity, 'token' | 'createdAt'
|
|
127
|
+
export declare function parkDeferredAsyncActivity(internals: EngineInternals, deferral: AsyncActivityDeferral, details: Omit<PendingAsyncActivity, 'token' | 'createdAt'>, callbacks: AsyncActivityResolutionCallbacks): Promise<never>;
|
|
110
128
|
/**
|
|
111
129
|
* Reload pending async-activity records from storage into memory. Called by
|
|
112
130
|
* `recoverAll()` so a token minted before a crash is resolvable again — even
|
|
@@ -117,7 +135,7 @@ export declare function recoverPendingAsyncActivities(internals: EngineInternals
|
|
|
117
135
|
* Complete a deferred activity out-of-band with `result`, resuming the parked
|
|
118
136
|
* workflow as though the activity had returned `result` inline.
|
|
119
137
|
*/
|
|
120
|
-
export declare function completeAsyncActivity(internals: EngineInternals, token: string, result: unknown,
|
|
138
|
+
export declare function completeAsyncActivity(internals: EngineInternals, token: string, result: unknown, callbacks: AsyncActivityResolutionCallbacks): Promise<void>;
|
|
121
139
|
/**
|
|
122
140
|
* Drive a generator that may yield promises — the workflow interceptor's
|
|
123
141
|
* `activity` hook returns such a generator. Forwards rejections into the
|
|
@@ -136,6 +154,5 @@ export declare function driveWorkflowInterceptorGenerator(generator: Generator<u
|
|
|
136
154
|
* that threw — so the workflow's own try/catch and any configured retry policy
|
|
137
155
|
* apply unchanged.
|
|
138
156
|
*/
|
|
139
|
-
export declare function failAsyncActivity(internals: EngineInternals, token: string, error: unknown,
|
|
140
|
-
|
|
141
|
-
}) => void, finalizeTimeline: (workflowId: string, status: 'completed' | 'failed', output: unknown) => void): Promise<void>;
|
|
157
|
+
export declare function failAsyncActivity(internals: EngineInternals, token: string, error: unknown, callbacks: AsyncActivityResolutionCallbacks): Promise<void>;
|
|
158
|
+
export {};
|
|
@@ -53,7 +53,12 @@ export async function registerPendingAsyncActivity(internals, pending) {
|
|
|
53
53
|
if (!alreadyRegistered)
|
|
54
54
|
internals.engine.dispatchEvent(new ActivityAsyncPendingEvent(pending.token, pending.operationId, pending.workflowId, pending.activityName, pending.attempt));
|
|
55
55
|
}
|
|
56
|
-
export async function parkDeferredAsyncActivity(internals, deferral, details) {
|
|
56
|
+
export async function parkDeferredAsyncActivity(internals, deferral, details, callbacks) {
|
|
57
|
+
const queuedResolution = takePendingAsyncActivityResolution(internals, details.workflowId, deferral.token);
|
|
58
|
+
if (queuedResolution !== void 0) {
|
|
59
|
+
deliverPendingAsyncActivityResolution(details.workflowId, queuedResolution, callbacks);
|
|
60
|
+
return new Promise(() => {});
|
|
61
|
+
}
|
|
57
62
|
await registerPendingAsyncActivity(internals, {
|
|
58
63
|
token: deferral.token,
|
|
59
64
|
createdAt: internals.options.getNow(),
|
|
@@ -90,14 +95,52 @@ async function consumePendingAsyncActivity(internals, token) {
|
|
|
90
95
|
}
|
|
91
96
|
return pending;
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
function shouldBufferPendingAsyncActivityResolution(internals, workflowId) {
|
|
99
|
+
return internals.inlineStrategy !== null && !internals.inlineStrategy.hasGenerator(workflowId);
|
|
100
|
+
}
|
|
101
|
+
function queuePendingAsyncActivityResolution(internals, workflowId, resolution) {
|
|
102
|
+
internals.pendingAsyncActivityResolutions ??= new Map;
|
|
103
|
+
const queued = internals.pendingAsyncActivityResolutions.get(workflowId) ?? [];
|
|
104
|
+
queued.push(resolution);
|
|
105
|
+
internals.pendingAsyncActivityResolutions.set(workflowId, queued);
|
|
106
|
+
}
|
|
107
|
+
function takePendingAsyncActivityResolution(internals, workflowId, token) {
|
|
108
|
+
internals.pendingAsyncActivityResolutions ??= new Map;
|
|
109
|
+
const queued = internals.pendingAsyncActivityResolutions.get(workflowId);
|
|
110
|
+
if (queued === void 0)
|
|
111
|
+
return;
|
|
112
|
+
const index = queued.findIndex((resolution) => resolution.token === token);
|
|
113
|
+
if (index === -1)
|
|
114
|
+
return;
|
|
115
|
+
const resolution = queued[index];
|
|
116
|
+
if (resolution === void 0)
|
|
117
|
+
return;
|
|
118
|
+
queued.splice(index, 1);
|
|
119
|
+
if (queued.length === 0)
|
|
120
|
+
internals.pendingAsyncActivityResolutions.delete(workflowId);
|
|
121
|
+
return resolution;
|
|
122
|
+
}
|
|
123
|
+
function deliverPendingAsyncActivityResolution(workflowId, resolution, callbacks) {
|
|
124
|
+
callbacks.finalizeTimeline(workflowId, resolution.timelineStatus, resolution.timelineOutput);
|
|
125
|
+
callbacks.feedOperationResult(workflowId, resolution.outcome, resolution.originalReason);
|
|
126
|
+
}
|
|
127
|
+
async function resolvePendingAsyncActivity(internals, token, outcome, callbacks, originalReason) {
|
|
128
|
+
const pending = await consumePendingAsyncActivity(internals, token), timelineOutput = outcome.status === "completed" ? outcome.value : outcome.error, resolution = {
|
|
129
|
+
token,
|
|
130
|
+
outcome,
|
|
131
|
+
timelineStatus: outcome.status,
|
|
132
|
+
timelineOutput,
|
|
133
|
+
...originalReason !== void 0 ? { originalReason } : {}
|
|
134
|
+
};
|
|
135
|
+
if (shouldBufferPendingAsyncActivityResolution(internals, pending.workflowId)) {
|
|
136
|
+
queuePendingAsyncActivityResolution(internals, pending.workflowId, resolution);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
deliverPendingAsyncActivityResolution(pending.workflowId, resolution, callbacks);
|
|
97
140
|
}
|
|
98
|
-
export async function completeAsyncActivity(internals, token, result,
|
|
141
|
+
export async function completeAsyncActivity(internals, token, result, callbacks) {
|
|
99
142
|
assertPayloadWithinLimit(result, internals.options.payloadSizePolicy.maxBytes, "activity result");
|
|
100
|
-
await resolvePendingAsyncActivity(internals, token, { status: "completed", value: result },
|
|
143
|
+
await resolvePendingAsyncActivity(internals, token, { status: "completed", value: result }, callbacks);
|
|
101
144
|
}
|
|
102
145
|
export async function driveWorkflowInterceptorGenerator(generator) {
|
|
103
146
|
let current = generator.next();
|
|
@@ -117,15 +160,13 @@ export async function driveWorkflowInterceptorGenerator(generator) {
|
|
|
117
160
|
}
|
|
118
161
|
return current.value;
|
|
119
162
|
}
|
|
120
|
-
export async function failAsyncActivity(internals, token, error,
|
|
163
|
+
export async function failAsyncActivity(internals, token, error, callbacks) {
|
|
121
164
|
const message = error instanceof Error ? error.message : String(error), errorName = error instanceof Error ? error.name : void 0;
|
|
122
165
|
assertPayloadWithinLimit({ message, name: errorName }, internals.options.payloadSizePolicy.maxBytes, "activity result");
|
|
123
|
-
|
|
124
|
-
finalizeTimeline(pending.workflowId, "failed", message);
|
|
125
|
-
feedOperationResult(pending.workflowId, {
|
|
166
|
+
await resolvePendingAsyncActivity(internals, token, {
|
|
126
167
|
status: "failed",
|
|
127
168
|
error: message,
|
|
128
169
|
...error instanceof Error ? { errorName: error.name } : {},
|
|
129
170
|
failureCategory: "application"
|
|
130
|
-
}, { value: error });
|
|
171
|
+
}, callbacks, { value: error });
|
|
131
172
|
}
|
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
import { assertWorkflowTagCount, coerceStartWorkflowTags } from "../start-workflow-validation.js";
|
|
10
10
|
import { buildWorkflowTagIndexOperations, normalizeWorkflowTags } from "../workflow-tags.js";
|
|
11
11
|
import { WorkflowNotFoundError } from "./errors.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
commitFencedWorkflowStateOperations,
|
|
14
|
+
runSerializedWorkflowStateWrite
|
|
15
|
+
} from "./storage-io.js";
|
|
13
16
|
import {
|
|
14
17
|
decodeWorkflowState,
|
|
15
18
|
isTerminalWorkflowStatus,
|
|
@@ -73,12 +76,14 @@ export async function updateWorkflowState(internals, workflowId, updates, option
|
|
|
73
76
|
...updates,
|
|
74
77
|
updatedAt
|
|
75
78
|
}, additionalOperations = options.buildAdditionalOperations?.(state, updatedAt) ?? [];
|
|
76
|
-
await
|
|
79
|
+
await commitFencedWorkflowStateOperations(internals, state, [
|
|
77
80
|
...buildTerminalWorkflowIndexOperations(state, updated),
|
|
78
81
|
{ type: "put", key: KEYS.workflow(workflowId), value: encode(updated) },
|
|
79
82
|
...buildWorkflowVisibilityIndexTransition(workflowId, state, updated).batchOps,
|
|
80
83
|
...additionalOperations
|
|
81
|
-
]
|
|
84
|
+
], {
|
|
85
|
+
includePendingAtomicSideEffects: isTerminalWorkflowStatus(updated.status)
|
|
86
|
+
});
|
|
82
87
|
return {
|
|
83
88
|
previousState: state,
|
|
84
89
|
updatedAt
|
|
@@ -172,7 +177,7 @@ async function snapshotMatchingWorkflowIds(internals, filter) {
|
|
|
172
177
|
if (remainingLimit !== void 0)
|
|
173
178
|
remainingLimit -= 1;
|
|
174
179
|
if (remainingLimit === 0)
|
|
175
|
-
|
|
180
|
+
return workflowIds;
|
|
176
181
|
}
|
|
177
182
|
return workflowIds;
|
|
178
183
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BatchOperation } from '../../storage/interface.ts';
|
|
1
2
|
import type { ListFilter, PurgeResult, WorkflowState } from '../types.ts';
|
|
2
3
|
import type { EngineInternals } from './internals.ts';
|
|
3
4
|
export declare const TERMINAL_CLEANUP_DELAY_MS = 60000;
|
|
@@ -9,3 +10,28 @@ export type PurgeParameters = {
|
|
|
9
10
|
export type CleanupWaiters = (workflowId: string) => void;
|
|
10
11
|
export declare function purgeInternal(internals: EngineInternals, filter: ListFilter | undefined, parameters: PurgeParameters, cleanupWaiters: CleanupWaiters): Promise<PurgeResult>;
|
|
11
12
|
export declare function purgeWorkflow(internals: EngineInternals, state: WorkflowState, cleanupWaiters: CleanupWaiters): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Collect every storage delete operation that removing a workflow id entails —
|
|
15
|
+
* index deletes (search attributes + tags), the explicit key set (state,
|
|
16
|
+
* checkpoint, headers, services marker, update requests/responses, and the
|
|
17
|
+
* `wf:`/`ev:`/`sig:`/... prefix sweeps), and the visibility-index transition to
|
|
18
|
+
* `null`. Pure: it reads storage to discover keys but writes nothing, so a caller
|
|
19
|
+
* can fold the returned ops into a larger atomic batch instead of committing them
|
|
20
|
+
* standalone. {@link purgeWorkflow} commits them on their own; the
|
|
21
|
+
* `onTerminalConflict: 'start-new'` restart path prepends them to the create batch
|
|
22
|
+
* so purge-and-recreate land as one atomic unit (no window where the prior run is
|
|
23
|
+
* gone but the new one has not committed). Keep this the single source of truth
|
|
24
|
+
* for "what a purge deletes" — do not fork the delete-set.
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectWorkflowPurgeDeleteOperations(internals: EngineInternals, state: WorkflowState): Promise<BatchOperation[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Drop every in-memory cache entry a purged workflow id owns (checkpoints,
|
|
29
|
+
* heartbeat details, event-log heads, version tuples, handle cache, result
|
|
30
|
+
* resolvers, headers, nesting depths, type map, pending async activities) and run
|
|
31
|
+
* `cleanupWaiters` to settle any pending signal/update/sleep waiters. Split from
|
|
32
|
+
* the storage batch in {@link collectWorkflowPurgeDeleteOperations} so the restart
|
|
33
|
+
* path can clear the OLD run's in-memory state up front — before the new run's
|
|
34
|
+
* caches are written under the reused id — while the durable delete still commits
|
|
35
|
+
* atomically with the create.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clearPurgedWorkflowInMemoryState(internals: EngineInternals, workflowId: string, cleanupWaiters: CleanupWaiters): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
KEYS,
|
|
3
3
|
encodeStorageKeyComponent,
|
|
4
|
+
storageHas,
|
|
4
5
|
storageKeys,
|
|
5
6
|
tryDecodeStorageKeyComponent
|
|
6
7
|
} from "../../storage/interface.js";
|
|
@@ -25,7 +26,7 @@ export async function purgeInternal(internals, filter, parameters, cleanupWaiter
|
|
|
25
26
|
let remainingOffset = manualOffset, deleted = 0;
|
|
26
27
|
const workflowStateStream = parameters.expiredOnly && filter === void 0 ? streamExpiredRetentionWorkflowStates(internals, parameters.now) : streamWorkflowStates(internals, filter);
|
|
27
28
|
for await (const state of workflowStateStream) {
|
|
28
|
-
if (!shouldPurgeWorkflowState(internals, state, parameters.expiredOnly, parameters.now))
|
|
29
|
+
if (!await shouldPurgeWorkflowState(internals, state, parameters.expiredOnly, parameters.now))
|
|
29
30
|
continue;
|
|
30
31
|
if (remainingOffset > 0) {
|
|
31
32
|
remainingOffset -= 1;
|
|
@@ -110,9 +111,11 @@ function resolvePurgeLimit(manualLimit, fallbackLimit) {
|
|
|
110
111
|
return manualLimit;
|
|
111
112
|
return Math.min(manualLimit, fallbackLimit);
|
|
112
113
|
}
|
|
113
|
-
function shouldPurgeWorkflowState(internals, state, expiredOnly, now) {
|
|
114
|
+
async function shouldPurgeWorkflowState(internals, state, expiredOnly, now) {
|
|
114
115
|
if (!isTerminalWorkflowStatus(state.status))
|
|
115
116
|
return !1;
|
|
117
|
+
if (await storageHas(internals.storage, KEYS.teardownOwed(state.id)))
|
|
118
|
+
return !1;
|
|
116
119
|
if (!expiredOnly)
|
|
117
120
|
return !0;
|
|
118
121
|
const deadline = getWorkflowRetentionDeadline(internals, state);
|
|
@@ -127,16 +130,25 @@ function getWorkflowRetentionDeadline(internals, state) {
|
|
|
127
130
|
return state.updatedAt + retentionMs;
|
|
128
131
|
}
|
|
129
132
|
export async function purgeWorkflow(internals, state, cleanupWaiters) {
|
|
133
|
+
const deleteOperations = await collectWorkflowPurgeDeleteOperations(internals, state);
|
|
134
|
+
await internals.storage.batch(deleteOperations);
|
|
135
|
+
clearPurgedWorkflowInMemoryState(internals, state.id, cleanupWaiters);
|
|
136
|
+
}
|
|
137
|
+
export async function collectWorkflowPurgeDeleteOperations(internals, state) {
|
|
130
138
|
const workflowId = state.id, attributeBytes = await internals.storage.get(KEYS.attribute(workflowId)), deleteOperations = buildWorkflowIndexDeleteOperations(state, attributeBytes), deleteKeys = await collectWorkflowPurgeDeleteKeys(internals, state);
|
|
131
139
|
appendKeyDeleteOperations(deleteOperations, deleteKeys);
|
|
132
140
|
deleteOperations.push(...buildWorkflowVisibilityIndexTransition(workflowId, state, null).batchOps);
|
|
133
|
-
|
|
141
|
+
return deleteOperations;
|
|
142
|
+
}
|
|
143
|
+
export function clearPurgedWorkflowInMemoryState(internals, workflowId, cleanupWaiters) {
|
|
134
144
|
forgetCommittedCheckpointBytes(internals, workflowId);
|
|
135
145
|
internals.checkpoints.delete(workflowId);
|
|
136
146
|
internals.heartbeatDetails.delete(workflowId);
|
|
147
|
+
internals.lastHeartbeatDetailsByStep.delete(workflowId);
|
|
137
148
|
for (const [token, pending] of internals.pendingAsyncActivities)
|
|
138
149
|
if (pending.workflowId === workflowId)
|
|
139
150
|
internals.pendingAsyncActivities.delete(token);
|
|
151
|
+
internals.pendingAsyncActivityResolutions.delete(workflowId);
|
|
140
152
|
internals.eventLogHeads.delete(workflowId);
|
|
141
153
|
internals.workflowVersionTuples.delete(workflowId);
|
|
142
154
|
internals.handleCache.delete(workflowId);
|
|
@@ -178,7 +190,10 @@ function buildBaseWorkflowDeleteKeys(state) {
|
|
|
178
190
|
KEYS.checkpoint(state.id),
|
|
179
191
|
KEYS.workflowHeaders(state.id),
|
|
180
192
|
KEYS.terminalCleanupNeeded(state.id),
|
|
193
|
+
KEYS.workflowConcurrencyHolder(state.id),
|
|
181
194
|
KEYS.workflowHasServices(state.id),
|
|
195
|
+
KEYS.finalizerState(state.id),
|
|
196
|
+
KEYS.teardownOwed(state.id),
|
|
182
197
|
KEYS.attribute(state.id),
|
|
183
198
|
KEYS.terminalWorkflow(state.updatedAt, state.id)
|
|
184
199
|
]);
|
|
@@ -216,11 +231,31 @@ async function addWorkflowPrefixDeleteKeys(storage, deleteKeys, workflowId) {
|
|
|
216
231
|
for (const key of keys)
|
|
217
232
|
deleteKeys.add(key);
|
|
218
233
|
}
|
|
234
|
+
await addWorkflowLinkedFleetEventDeleteKeys(storage, deleteKeys, workflowId);
|
|
235
|
+
}
|
|
236
|
+
async function addWorkflowLinkedFleetEventDeleteKeys(storage, deleteKeys, workflowId) {
|
|
237
|
+
const prefix = KEYS.fleetEventByWorkflowPrefix(workflowId);
|
|
238
|
+
for await (const [key] of storage.scan(prefix)) {
|
|
239
|
+
deleteKeys.add(key);
|
|
240
|
+
const sequence = parseFleetEventSequenceFromWorkflowIndexKey(prefix, key);
|
|
241
|
+
if (sequence !== null)
|
|
242
|
+
deleteKeys.add(KEYS.fleetEvent(sequence));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function parseFleetEventSequenceFromWorkflowIndexKey(prefix, key) {
|
|
246
|
+
if (!key.startsWith(prefix))
|
|
247
|
+
return null;
|
|
248
|
+
const rawSequence = key.slice(prefix.length);
|
|
249
|
+
if (!/^\d+$/.test(rawSequence))
|
|
250
|
+
return null;
|
|
251
|
+
const sequence = Number(rawSequence);
|
|
252
|
+
return Number.isSafeInteger(sequence) ? sequence : null;
|
|
219
253
|
}
|
|
220
254
|
function workflowPurgePrefixes(workflowId) {
|
|
221
255
|
const encodedWorkflowId = encodeStorageKeyComponent(workflowId);
|
|
222
256
|
return [
|
|
223
257
|
`wf:${encodedWorkflowId}:ckpt:`,
|
|
258
|
+
`wf:${encodedWorkflowId}:timeline:`,
|
|
224
259
|
`ev:${encodedWorkflowId}:`,
|
|
225
260
|
`sig:${encodedWorkflowId}:`,
|
|
226
261
|
`review:${encodedWorkflowId}:`,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BulkOperationAction, BulkOperationAuditEvent, BulkOperationCommitOptions, BulkOperationDryRunResult, BulkOperationError, BulkOperationOptions, BulkOperationScopeSummary, ListFilter, WorkflowState, WorkflowStatus } from '../types.ts';
|
|
2
2
|
import type { EngineInternals } from './internals.ts';
|
|
3
3
|
export declare const BULK_OPERATION_SAMPLE_LIMIT = 20;
|
|
4
|
+
export declare const DEFAULT_BULK_OPERATION_CONCURRENCY = 1;
|
|
4
5
|
export type BulkWorkflowSnapshot = {
|
|
5
6
|
id: string;
|
|
6
7
|
type: string;
|
|
@@ -22,6 +23,7 @@ export declare function withBulkAuditEvent<TResult extends object>(internals: En
|
|
|
22
23
|
auditEvent: BulkOperationAuditEvent;
|
|
23
24
|
}>;
|
|
24
25
|
export declare function normalizeBulkOperationOptions<TOptions extends BulkOperationOptions>(options: TOptions): TOptions;
|
|
26
|
+
export declare function resolveBulkOperationConcurrency(options: BulkOperationOptions): number;
|
|
25
27
|
export declare function toBulkOperationError(_internals: EngineInternals, workflowId: string, error: unknown): BulkOperationError;
|
|
26
28
|
export declare function snapshotMatchingWorkflowSnapshots(internals: EngineInternals, filter?: ListFilter): Promise<BulkWorkflowSnapshot[]>;
|
|
27
29
|
export declare function workflowStateToBulkSnapshot(state: WorkflowState): BulkWorkflowSnapshot;
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./errors.js";
|
|
14
14
|
import { streamWorkflowStateBatches } from "./listing.js";
|
|
15
15
|
import { isTerminalWorkflowStatus } from "./validation.js";
|
|
16
|
-
export const BULK_OPERATION_SAMPLE_LIMIT = 20;
|
|
16
|
+
export const BULK_OPERATION_SAMPLE_LIMIT = 20, DEFAULT_BULK_OPERATION_CONCURRENCY = 1;
|
|
17
17
|
const DEFAULT_BULK_OPERATION_PRINCIPAL = { method: "in-process" };
|
|
18
18
|
export function buildActionableBulkWorkflowFilter(_internals, filter, actionableStatuses) {
|
|
19
19
|
const effectiveStatuses = (filter.status === void 0 ? actionableStatuses : Array.isArray(filter.status) ? filter.status : [filter.status]).filter((status) => actionableStatuses.includes(status));
|
|
@@ -69,7 +69,7 @@ function summarizeBulkFilter(filter) {
|
|
|
69
69
|
if (filter.attributes !== void 0)
|
|
70
70
|
summary.attributes = filter.attributes.map((attribute) => ({
|
|
71
71
|
key: searchAttributeName(attribute.key),
|
|
72
|
-
...attribute.value === void 0 ? {} : { value: attribute.value },
|
|
72
|
+
...attribute.value === void 0 ? {} : { value: Array.isArray(attribute.value) ? [...attribute.value] : attribute.value },
|
|
73
73
|
...attribute.gt === void 0 ? {} : { gt: attribute.gt },
|
|
74
74
|
...attribute.lt === void 0 ? {} : { lt: attribute.lt },
|
|
75
75
|
...attribute.gte === void 0 ? {} : { gte: attribute.gte },
|
|
@@ -136,6 +136,9 @@ async function persistBulkOperationAuditEvent(internals, preparation, options, a
|
|
|
136
136
|
return auditEvent;
|
|
137
137
|
}
|
|
138
138
|
export function normalizeBulkOperationOptions(options) {
|
|
139
|
+
const bulkConcurrency = options.bulkConcurrency;
|
|
140
|
+
if (bulkConcurrency !== void 0 && (!Number.isSafeInteger(bulkConcurrency) || bulkConcurrency < 1))
|
|
141
|
+
throw Error('Field "bulkConcurrency" must be a positive integer');
|
|
139
142
|
const confirmationToken = "confirmationToken" in options ? options.confirmationToken : void 0;
|
|
140
143
|
if (confirmationToken !== void 0 && confirmationToken.length > MAX_BULK_CONFIRMATION_TOKEN_LENGTH)
|
|
141
144
|
throw Error(`Field "confirmationToken" must be at most ${String(MAX_BULK_CONFIRMATION_TOKEN_LENGTH)} characters`);
|
|
@@ -143,6 +146,9 @@ export function normalizeBulkOperationOptions(options) {
|
|
|
143
146
|
throw Error(`Field "requestId" must be at most ${String(MAX_BULK_OPERATION_REQUEST_ID_LENGTH)} characters`);
|
|
144
147
|
return options;
|
|
145
148
|
}
|
|
149
|
+
export function resolveBulkOperationConcurrency(options) {
|
|
150
|
+
return options.bulkConcurrency ?? DEFAULT_BULK_OPERATION_CONCURRENCY;
|
|
151
|
+
}
|
|
146
152
|
export function toBulkOperationError(_internals, workflowId, error) {
|
|
147
153
|
return {
|
|
148
154
|
id: workflowId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BulkCancelResult, BulkDeleteResult, BulkOperationCommitOptions, BulkOperationDryRunOptions, BulkOperationDryRunResult, BulkOperationOptions, BulkSignalAllCommitOptions, BulkSignalAllDryRunOptions, BulkSignalResult, BulkTagResult, ListFilter, PurgeResult } from '../types.ts';
|
|
1
|
+
import type { BulkCancelResult, BulkDeleteResult, BulkOperationCommitOptions, BulkOperationDryRunOptions, BulkOperationDryRunResult, BulkOperationOptions, BulkRetryFailedResult, BulkSignalAllCommitOptions, BulkSignalAllDryRunOptions, BulkSignalResult, BulkTagResult, ListFilter, PurgeResult } from '../types.ts';
|
|
2
2
|
import { type CleanupWaiters } from './bulk-operations-purge.ts';
|
|
3
3
|
import type { EngineInternals } from './internals.ts';
|
|
4
4
|
export { purgeInternal, TERMINAL_CLEANUP_DELAY_MS } from './bulk-operations-purge.ts';
|
|
@@ -6,6 +6,9 @@ export declare function purge(internals: EngineInternals, filter: ListFilter | u
|
|
|
6
6
|
export declare function cancelAll(internals: EngineInternals, filter: ListFilter, options: BulkOperationDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
7
7
|
export declare function cancelAll(internals: EngineInternals, filter: ListFilter, options?: BulkOperationCommitOptions): Promise<BulkCancelResult>;
|
|
8
8
|
export declare function cancelAll(internals: EngineInternals, filter: ListFilter, options?: BulkOperationDryRunOptions | BulkOperationCommitOptions): Promise<BulkCancelResult | BulkOperationDryRunResult>;
|
|
9
|
+
export declare function retryFailedAll(internals: EngineInternals, filter: ListFilter, options: BulkOperationDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
10
|
+
export declare function retryFailedAll(internals: EngineInternals, filter: ListFilter, options?: BulkOperationCommitOptions): Promise<BulkRetryFailedResult>;
|
|
11
|
+
export declare function retryFailedAll(internals: EngineInternals, filter: ListFilter, options?: BulkOperationDryRunOptions | BulkOperationCommitOptions): Promise<BulkRetryFailedResult | BulkOperationDryRunResult>;
|
|
9
12
|
export declare function signalAll(internals: EngineInternals, filter: ListFilter, name: string, payload: unknown, options: BulkSignalAllDryRunOptions): Promise<BulkOperationDryRunResult>;
|
|
10
13
|
export declare function signalAll(internals: EngineInternals, filter: ListFilter, name: string, payload: unknown, options: BulkSignalAllCommitOptions): Promise<BulkSignalResult>;
|
|
11
14
|
export declare function signalAll(internals: EngineInternals, filter: ListFilter, name: string, payload?: unknown, options?: BulkOperationCommitOptions): Promise<BulkSignalResult>;
|