@gobing-ai/ts-dual-workflow-engine 0.4.69 → 0.5.1
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 +40 -2
- package/dist/action-step.d.ts.map +1 -1
- package/dist/action-step.js +5 -8
- package/dist/config.js +14 -0
- package/dist/events.d.ts +11 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/persistence.d.ts +9 -1
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +74 -10
- package/dist/run-lifecycle.d.ts +7 -4
- package/dist/run-lifecycle.d.ts.map +1 -1
- package/dist/run-lifecycle.js +50 -14
- package/dist/schema-sql.d.ts +2 -0
- package/dist/schema-sql.d.ts.map +1 -1
- package/dist/schema-sql.js +10 -1
- package/dist/schema.d.ts +4 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +4 -0
- package/dist/service.d.ts +9 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +62 -12
- package/dist/state-machine.d.ts.map +1 -1
- package/dist/state-machine.js +24 -7
- package/dist/transition-flow.d.ts.map +1 -1
- package/dist/transition-flow.js +18 -7
- package/dist/types.d.ts +63 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/action-step.ts +12 -16
- package/src/config.ts +14 -0
- package/src/events.ts +11 -1
- package/src/index.ts +2 -0
- package/src/persistence.ts +96 -9
- package/src/run-lifecycle.ts +64 -22
- package/src/schema-sql.ts +11 -1
- package/src/schema.ts +4 -0
- package/src/service.ts +85 -12
- package/src/state-machine.ts +27 -7
- package/src/transition-flow.ts +21 -7
- package/src/types.ts +69 -1
package/README.md
CHANGED
|
@@ -848,7 +848,8 @@ output or control events without widening the persisted action schema.
|
|
|
848
848
|
| `workflow.transition.requested` | `{ runId, from, to, trigger, externalKey? }` | When an external transition request is allowed and committed |
|
|
849
849
|
| `workflow.transition.denied` | `{ runId, from, to, reason, externalKey? }` | When an external transition request is denied |
|
|
850
850
|
| `workflow.run.paused` | `{ runId, node, transitionsTaken, externalKey? }` | When a run pauses at a declared pause point |
|
|
851
|
-
| `workflow.run.resumed` | `{ runId, node, externalKey? }` | When a paused run is resumed |
|
|
851
|
+
| `workflow.run.resumed` | `{ runId, node, resumeMode, ownerAttemptId, externalKey? }` | When a paused or interrupted run is resumed (`resumeMode`: `skip-enter` \| `rerun-enter`) |
|
|
852
|
+
| `workflow.run.interrupted` | `{ runId, node?, reason, externalKey?, severity }` | When a running run is marked interrupted (crash marker / external stop) |
|
|
852
853
|
### Compatibility Policy
|
|
853
854
|
|
|
854
855
|
The event map is a **cross-package public contract**. Policy: **additive-only** — new events allowed, new optional payload fields allowed; never rename, remove, or repurpose an existing event or field.
|
|
@@ -874,6 +875,21 @@ This design keeps the EventBus zero-config and test-friendly: no message broker,
|
|
|
874
875
|
delivery guarantees. A subscriber in one process never receives events from another process's run
|
|
875
876
|
execution.
|
|
876
877
|
|
|
878
|
+
### Interruption & resume ownership (ADR-025)
|
|
879
|
+
|
|
880
|
+
Durable runs survive crashes. A crashed owner leaves its run in `running`; an operator (or watchdog) marks
|
|
881
|
+
it via `service.interruptRun(runId, reason)` — a CAS that only interrupts genuinely running runs — flipping
|
|
882
|
+
status to `interrupted` with a persisted `interrupt_reason`.
|
|
883
|
+
|
|
884
|
+
Resuming an interrupted run re-executes actions by default (`rerun-enter`), but only into states/nodes
|
|
885
|
+
marked `resumeRerun: true`; anything else is refused loudly with `FSMError` before any mutation. Paused runs
|
|
886
|
+
resume with `skip-enter` by default (pause-point actions treated as complete, execution advances past the
|
|
887
|
+
pause). Both modes accept an explicit `resumeMode` override.
|
|
888
|
+
|
|
889
|
+
Concurrent resumes are settled by the adapter's `claimRunOwnership` CAS: exactly one attempt flips the run
|
|
890
|
+
to `running` and records its `owner_attempt`/`owner_pid`; losers receive `WorkflowResumeError` naming the
|
|
891
|
+
winner. Never retry a lost claim blindly — interrupt the stale owner first.
|
|
892
|
+
|
|
877
893
|
### Usage
|
|
878
894
|
|
|
879
895
|
Pass an `EventBus` via `WorkflowRunOptions.events`:
|
|
@@ -940,7 +956,9 @@ await lifecycle.enter(targetState, transitionsTaken, false);
|
|
|
940
956
|
| `FSMError` | Runtime state-machine driver error (missing state/node, invalid target) |
|
|
941
957
|
| `RunCollisionError` | Duplicate `runId` when creating a new run |
|
|
942
958
|
|
|
943
|
-
|
|
959
|
+
Action failures, including thrown action exceptions, follow `onError` and normally return a
|
|
960
|
+
`WorkflowRunResult` with `status: 'failed'`. Unexpected guard or persistence exceptions finalize
|
|
961
|
+
the run as failed and reject the call; see the recovery contract below.
|
|
944
962
|
|
|
945
963
|
### Error Policy (`onError`)
|
|
946
964
|
|
|
@@ -954,6 +972,26 @@ The resolved policy follows precedence `action.onError ?? workflow.defaultOnErro
|
|
|
954
972
|
|
|
955
973
|
## Boundary Notes
|
|
956
974
|
|
|
975
|
+
### Recovery and persistence contract
|
|
976
|
+
|
|
977
|
+
- Action exceptions become failed results and follow `onError`. Action audit finalization is
|
|
978
|
+
awaited before subsequent actions or guards; a persistence rejection is not swallowed.
|
|
979
|
+
Unexpected execution failures finalize the run as failed and rethrow. If that finalization
|
|
980
|
+
also fails, an `AggregateError` preserves both errors.
|
|
981
|
+
- Paused snapshots restore effective variables, the run-wide transition counter, and the last
|
|
982
|
+
action's `ok` bit for `action-ok`. Additional guard evidence belongs in saved variables or an
|
|
983
|
+
application-owned record; raw action payloads are not copied around the redactor.
|
|
984
|
+
- External transitions use workflow defaults, then saved variables, then caller overrides, and
|
|
985
|
+
preserve the resulting variables and counter in the next snapshot.
|
|
986
|
+
- Calling `run` with an existing `externalKey` attaches and returns the recorded position/status;
|
|
987
|
+
it does not execute that run again. Use `resumeRun` for paused/interrupted continuation. An
|
|
988
|
+
attachment before the creator's first snapshot may return `running` with an empty `finalState`.
|
|
989
|
+
Original failure reasons are not recoverable from existing run records.
|
|
990
|
+
- Persistence adapters must preserve `owner_attempt` on create/attach: it identifies the creator
|
|
991
|
+
or latest resume attempt and prevents duplicate execution when callers race on an external key.
|
|
992
|
+
DB and memory adapters implement this contract. Wrappers that swallow persistence failures
|
|
993
|
+
retain their own weaker durability guarantee.
|
|
994
|
+
|
|
957
995
|
- The engine executes workflows; it does not provide a scheduler. Use `@gobing-ai/ts-infra` scheduler or an external cron trigger to start runs.
|
|
958
996
|
- Persistence is adapter-based. Downstream apps own DB lifecycle and migration ordering.
|
|
959
997
|
- Action and guard runners are the extension points. Keep domain behavior there, not in workflow parsing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-step.d.ts","sourceRoot":"","sources":["../src/action-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,0BAA0B,EAC1B,kBAAkB,EACrB,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAElE,0JAA0J;AAC1J,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,YAAY,EAA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;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC;CACtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAC/B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CA8C3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAc3B"}
|
package/dist/action-step.js
CHANGED
|
@@ -36,17 +36,14 @@ export async function runActionStep(action, vars, deps) {
|
|
|
36
36
|
events: deps.options.events,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
result = { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
41
|
+
}
|
|
39
42
|
finally {
|
|
40
43
|
const durationMs = Date.now() - actionStartMs;
|
|
41
44
|
lifecycle.actionDone(stateOrNodeId, action.kind, durationMs, result?.ok ?? false);
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
// depends on it, so it must not block or fail the control loop. A swallowed `.catch`
|
|
45
|
-
// keeps a rejected write from surfacing as an unhandledRejection (repo convention,
|
|
46
|
-
// see runtime/process-executor.ts).
|
|
47
|
-
void persistence
|
|
48
|
-
.saveActionFinalize(actionId, result?.ok !== false ? 'done' : 'failed', durationMs, result?.ok ?? false, action.kind, result, deps.options.redactor ?? defaultActionRedactor)
|
|
49
|
-
.catch(() => undefined);
|
|
45
|
+
// Await the evidence write before any guard or subsequent action can run.
|
|
46
|
+
await persistence.saveActionFinalize(actionId, result?.ok === true ? 'done' : 'failed', durationMs, result?.ok ?? false, action.kind, result, deps.options.redactor ?? defaultActionRedactor);
|
|
50
47
|
}
|
|
51
48
|
if (result.terminal === true)
|
|
52
49
|
return { outcome: 'terminal', result };
|
package/dist/config.js
CHANGED
|
@@ -134,6 +134,20 @@ function validateTransitionFlow(workflow) {
|
|
|
134
134
|
errors.push(`Duplicate edge "${key}"`);
|
|
135
135
|
seenEdges.add(key);
|
|
136
136
|
}
|
|
137
|
+
for (const terminal of workflow.terminalNodes ?? []) {
|
|
138
|
+
if (!nodes.has(terminal))
|
|
139
|
+
errors.push(`Terminal node "${terminal}" is not declared`);
|
|
140
|
+
if (workflow.edges.some((edge) => edge.from === terminal)) {
|
|
141
|
+
errors.push(`Terminal node "${terminal}" must not declare edges`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const node of workflow.nodes) {
|
|
145
|
+
const outbound = workflow.edges.filter((edge) => edge.from === node.id);
|
|
146
|
+
const unconditional = outbound.findIndex((edge) => edge.condition === undefined);
|
|
147
|
+
if (unconditional !== -1 && unconditional < outbound.length - 1) {
|
|
148
|
+
errors.push(`Node "${node.id}" has an unconditional edge that is not last; later edges are unreachable`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
137
151
|
// Template variable references must resolve.
|
|
138
152
|
errors.push(...checkVariableReferences(collectActionOptions(workflow), workflow.vars, workflow.env));
|
|
139
153
|
throwIfErrors(workflow, errors);
|
package/dist/events.d.ts
CHANGED
|
@@ -138,10 +138,20 @@ export type WorkflowEngineEvents = {
|
|
|
138
138
|
externalKey?: string;
|
|
139
139
|
severity: EventSeverity;
|
|
140
140
|
}) => void;
|
|
141
|
-
/** Emitted when a
|
|
141
|
+
/** Emitted when a run is resumed. */
|
|
142
142
|
'workflow.run.resumed': (data: {
|
|
143
143
|
runId: string;
|
|
144
144
|
node: string;
|
|
145
|
+
resumeMode: 'skip-enter' | 'rerun-enter';
|
|
146
|
+
ownerAttemptId: string;
|
|
147
|
+
externalKey?: string;
|
|
148
|
+
severity: EventSeverity;
|
|
149
|
+
}) => void;
|
|
150
|
+
/** Emitted when a running run is marked interrupted (crash/lost-owner reconciliation). */
|
|
151
|
+
'workflow.run.interrupted': (data: {
|
|
152
|
+
runId: string;
|
|
153
|
+
node?: string;
|
|
154
|
+
reason: string;
|
|
145
155
|
externalKey?: string;
|
|
146
156
|
severity: EventSeverity;
|
|
147
157
|
}) => void;
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,8FAA8F;AAC9F,MAAM,MAAM,oBAAoB,GAAG;IAC/B,mDAAmD;IACnD,sBAAsB,EAAE,CAAC,IAAI,EAAE;QAC3B,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,OAAO,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,aAAa,CAAC;KAC3B,KAAK,IAAI,CAAC;IACX,iDAAiD;IACjD,mBAAmB,EAAE,CAAC,IAAI,EAAE;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C3B,KAAK,IAAI,CAAC;IACX,6DAA6D;IAC7D,4BAA4B,EAAE,CAAC,IAAI,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,aAAa,CAAC;KAC3B,KAAK,IAAI,CAAC;IACX,2DAA2D;IAC3D,qBAAqB,EAAE,CAAC,IAAI,EAAE;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,aAAa,CAAC;KAC3B,KAAK,IAAI,CAAC;IACX,qCAAqC;IACrC,sBAAsB,EAAE,CAAC,IAAI,EAAE;QAC3B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,YAAY,GAAG,aAAa,CAAC;QACzC,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,aAAa,CAAC;KAC3B,KAAK,IAAI,CAAC;IACX,0FAA0F;IAC1F,0BAA0B,EAAE,CAAC,IAAI,EAAE;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,aAAa,CAAC;KAC3B,KAAK,IAAI,CAAC;CACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export { WORKFLOW_ENGINE_SCHEMA_SQL } from './schema-sql';
|
|
|
11
11
|
export { WorkflowService } from './service';
|
|
12
12
|
export { StateMachineDriver, type StateMachineDriverOptions } from './state-machine';
|
|
13
13
|
export { TransitionFlowDriver, type TransitionFlowDriverOptions } from './transition-flow';
|
|
14
|
-
export type { ActionDef, ActionRedactor, ActionResult, ActionRunContext, ActionRunner, ActionRunRecord, Env, FlowEdgeDef, FlowNodeDef, GuardContext, GuardDef, GuardEvaluationResult, GuardRunner, OnErrorPolicy, StateDef, StateMachineWorkflowDef, TransitionAllowed, TransitionDef, TransitionDenied, TransitionDeniedReason, TransitionFlowWorkflowDef, TransitionRequestResult, Vars, WorkflowDef, WorkflowExtensions, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunRecord, WorkflowRunResult, WorkflowStatus, } from './types';
|
|
14
|
+
export type { ActionDef, ActionRedactor, ActionResult, ActionRunContext, ActionRunner, ActionRunRecord, Env, FlowEdgeDef, FlowNodeDef, GuardContext, GuardDef, GuardEvaluationResult, GuardRunner, OnErrorPolicy, ResumeOwnership, StateDef, StateMachineWorkflowDef, TransitionAllowed, TransitionDef, TransitionDenied, TransitionDeniedReason, TransitionFlowWorkflowDef, TransitionRequestResult, Vars, WorkflowDef, WorkflowExtensions, WorkflowPersistenceAdapter, WorkflowResumeMode, WorkflowRunOptions, WorkflowRunRecord, WorkflowRunResult, WorkflowStatus, } from './types';
|
|
15
15
|
export { mergeSetVars, mergeVars, resolveOnErrorPolicy, resolveTemplateString, resolveTemplates, type VariableContext, } from './variables';
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACrG,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EACH,yBAAyB,EACz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AC1D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,KAAK,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAC3F,YAAY,EACR,SAAS,EACT,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,GAAG,EACH,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,IAAI,EACJ,WAAW,EACX,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACH,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,eAAe,GACvB,MAAM,aAAa,CAAC"}
|
package/dist/persistence.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DbAdapter } from '@gobing-ai/ts-db';
|
|
2
|
-
import type { ActionRedactor, WorkflowPersistenceAdapter, WorkflowReseedResult, WorkflowRunRecord, WorkflowStatus } from './types';
|
|
2
|
+
import type { ActionRedactor, ResumeOwnership, WorkflowPersistenceAdapter, WorkflowReseedResult, WorkflowRunRecord, WorkflowStatus } from './types';
|
|
3
3
|
/** Apply workflow-engine-owned schema to a database adapter. */
|
|
4
4
|
export declare function applyWorkflowEngineSchema(db: DbAdapter): Promise<void>;
|
|
5
5
|
/**
|
|
@@ -26,6 +26,10 @@ export declare class DbWorkflowPersistenceAdapter implements WorkflowPersistence
|
|
|
26
26
|
createRun(record: WorkflowRunRecord): Promise<void>;
|
|
27
27
|
/** Finalize a run with terminal status and timestamp. */
|
|
28
28
|
finalizeRun(runId: string, status: WorkflowStatus, completedAt: string): Promise<void>;
|
|
29
|
+
/** CAS-claim a resumable run to running, recording the owner at the mutation. */
|
|
30
|
+
claimRunOwnership(runId: string, owner: ResumeOwnership, expectedStatuses: readonly ('paused' | 'interrupted')[]): Promise<WorkflowRunRecord | undefined>;
|
|
31
|
+
/** CAS running → interrupted with a reason (lost-owner / crash reconciliation). */
|
|
32
|
+
interruptRun(runId: string, reason: string): Promise<WorkflowRunRecord | undefined>;
|
|
29
33
|
/** Save one phase/state execution record. */
|
|
30
34
|
savePhase(runId: string, phase: string, status: WorkflowStatus): Promise<void>;
|
|
31
35
|
/** Save one transition record. */
|
|
@@ -90,6 +94,10 @@ export declare class MemoryWorkflowPersistenceAdapter implements WorkflowPersist
|
|
|
90
94
|
createRun(record: WorkflowRunRecord): Promise<void>;
|
|
91
95
|
/** Finalize a run with terminal status and timestamp. */
|
|
92
96
|
finalizeRun(runId: string, status: WorkflowStatus, completedAt: string): Promise<void>;
|
|
97
|
+
/** CAS-claim a resumable run to running, recording the owner at the mutation. */
|
|
98
|
+
claimRunOwnership(runId: string, owner: ResumeOwnership, expectedStatuses: readonly ('paused' | 'interrupted')[]): Promise<WorkflowRunRecord | undefined>;
|
|
99
|
+
/** CAS running → interrupted with a reason (lost-owner / crash reconciliation). */
|
|
100
|
+
interruptRun(runId: string, reason: string): Promise<WorkflowRunRecord | undefined>;
|
|
93
101
|
readonly actionRuns: Array<{
|
|
94
102
|
id: string;
|
|
95
103
|
runId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,kBAAkB,CAAC;AAG7D,OAAO,KAAK,EACR,cAAc,EACd,0BAA0B,EAC1B,oBAAoB,EACpB,iBA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,GAAG,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC;CASnH"}
|
package/dist/persistence.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunCollisionError } from './errors.js';
|
|
2
|
-
import { WORKFLOW_ENGINE_SCHEMA_SQL } from './schema-sql.js';
|
|
2
|
+
import { WORKFLOW_ENGINE_MIGRATIONS_SQL, WORKFLOW_ENGINE_SCHEMA_SQL } from './schema-sql.js';
|
|
3
3
|
/** Apply workflow-engine-owned schema to a database adapter. */
|
|
4
4
|
export async function applyWorkflowEngineSchema(db) {
|
|
5
5
|
for (const statement of WORKFLOW_ENGINE_SCHEMA_SQL.split(';')) {
|
|
@@ -7,6 +7,20 @@ export async function applyWorkflowEngineSchema(db) {
|
|
|
7
7
|
if (sql.length > 0)
|
|
8
8
|
await db.exec(sql);
|
|
9
9
|
}
|
|
10
|
+
// Fresh databases already have the new columns (duplicate-column error → ignored);
|
|
11
|
+
// pre-0.5.0 databases get them via these guarded ALTERs.
|
|
12
|
+
for (const statement of WORKFLOW_ENGINE_MIGRATIONS_SQL.split(';')) {
|
|
13
|
+
const sql = statement.trim();
|
|
14
|
+
if (sql.length === 0)
|
|
15
|
+
continue;
|
|
16
|
+
try {
|
|
17
|
+
await db.exec(sql);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (!/duplicate column/i.test(String(error)))
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
10
24
|
}
|
|
11
25
|
/** Narrow to a non-array object record. */
|
|
12
26
|
function isRecord(value) {
|
|
@@ -57,13 +71,29 @@ export class DbWorkflowPersistenceAdapter {
|
|
|
57
71
|
if (existing !== undefined)
|
|
58
72
|
throw new RunCollisionError(record.id);
|
|
59
73
|
await this.ensureSchema();
|
|
60
|
-
await this.db.run(`INSERT INTO runs (id, workflow_name, mode, status, external_key, started_at, completed_at, metadata_json, created_at, updated_at)
|
|
61
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, record.id, record.workflow_name, record.mode, record.status, record.external_key ?? null, record.started_at, record.completed_at, record.metadata_json, Date.now(), Date.now());
|
|
74
|
+
await this.db.run(`INSERT INTO runs (id, workflow_name, mode, status, external_key, started_at, completed_at, metadata_json, owner_attempt, owner_pid, created_at, updated_at)
|
|
75
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, record.id, record.workflow_name, record.mode, record.status, record.external_key ?? null, record.started_at, record.completed_at, record.metadata_json, record.owner_attempt ?? null, record.owner_pid ?? null, Date.now(), Date.now());
|
|
62
76
|
}
|
|
63
77
|
/** Finalize a run with terminal status and timestamp. */
|
|
64
78
|
async finalizeRun(runId, status, completedAt) {
|
|
65
79
|
await this.db.run('UPDATE runs SET status = ?, completed_at = ?, updated_at = ? WHERE id = ?', status, completedAt, Date.now(), runId);
|
|
66
80
|
}
|
|
81
|
+
/** CAS-claim a resumable run to running, recording the owner at the mutation. */
|
|
82
|
+
async claimRunOwnership(runId, owner, expectedStatuses) {
|
|
83
|
+
await this.ensureSchema();
|
|
84
|
+
const placeholders = expectedStatuses.map(() => '?').join(', ');
|
|
85
|
+
await this.db.run(`UPDATE runs SET status = 'running', completed_at = NULL, owner_attempt = ?, owner_pid = ?, updated_at = ?
|
|
86
|
+
WHERE id = ? AND status IN (${placeholders})`, owner.attemptId, owner.pid ?? null, Date.now(), runId, ...expectedStatuses);
|
|
87
|
+
const run = await this.loadRun(runId);
|
|
88
|
+
return run !== undefined && run.status === 'running' && run.owner_attempt === owner.attemptId ? run : undefined;
|
|
89
|
+
}
|
|
90
|
+
/** CAS running → interrupted with a reason (lost-owner / crash reconciliation). */
|
|
91
|
+
async interruptRun(runId, reason) {
|
|
92
|
+
await this.ensureSchema();
|
|
93
|
+
await this.db.run("UPDATE runs SET status = 'interrupted', interrupt_reason = ?, completed_at = NULL, updated_at = ? WHERE id = ? AND status = 'running'", reason, Date.now(), runId);
|
|
94
|
+
const run = await this.loadRun(runId);
|
|
95
|
+
return run !== undefined && run.status === 'interrupted' ? run : undefined;
|
|
96
|
+
}
|
|
67
97
|
/** Save one phase/state execution record. */
|
|
68
98
|
async savePhase(runId, phase, status) {
|
|
69
99
|
const op = this.phaseRow(runId, phase, status, Date.now());
|
|
@@ -167,7 +197,7 @@ export class DbWorkflowPersistenceAdapter {
|
|
|
167
197
|
/** Create a run or attach to an existing one by external key. */
|
|
168
198
|
async createOrAttachRun(record) {
|
|
169
199
|
await this.ensureSchema();
|
|
170
|
-
if (record.external_key) {
|
|
200
|
+
if (record.external_key !== undefined && record.external_key !== null) {
|
|
171
201
|
const existing = await this.findRunByKey(record.workflow_name, record.external_key);
|
|
172
202
|
if (existing)
|
|
173
203
|
return existing;
|
|
@@ -176,7 +206,7 @@ export class DbWorkflowPersistenceAdapter {
|
|
|
176
206
|
await this.createRun(record);
|
|
177
207
|
}
|
|
178
208
|
catch (error) {
|
|
179
|
-
if (record.external_key) {
|
|
209
|
+
if (record.external_key !== undefined && record.external_key !== null) {
|
|
180
210
|
const existing = await this.findRunByKey(record.workflow_name, record.external_key);
|
|
181
211
|
if (existing)
|
|
182
212
|
return existing;
|
|
@@ -255,6 +285,35 @@ export class MemoryWorkflowPersistenceAdapter {
|
|
|
255
285
|
if (run !== undefined)
|
|
256
286
|
this.runs.set(runId, { ...run, status, completed_at: completedAt });
|
|
257
287
|
}
|
|
288
|
+
/** CAS-claim a resumable run to running, recording the owner at the mutation. */
|
|
289
|
+
async claimRunOwnership(runId, owner, expectedStatuses) {
|
|
290
|
+
const run = this.runs.get(runId);
|
|
291
|
+
if (run === undefined || !expectedStatuses.includes(run.status)) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
const claimed = {
|
|
295
|
+
...run,
|
|
296
|
+
status: 'running',
|
|
297
|
+
completed_at: null,
|
|
298
|
+
owner_attempt: owner.attemptId,
|
|
299
|
+
owner_pid: owner.pid ?? null,
|
|
300
|
+
};
|
|
301
|
+
this.runs.set(runId, claimed);
|
|
302
|
+
return claimed;
|
|
303
|
+
}
|
|
304
|
+
/** CAS running → interrupted with a reason (lost-owner / crash reconciliation). */
|
|
305
|
+
async interruptRun(runId, reason) {
|
|
306
|
+
const run = this.runs.get(runId);
|
|
307
|
+
if (run === undefined || run.status !== 'running')
|
|
308
|
+
return undefined;
|
|
309
|
+
const interrupted = {
|
|
310
|
+
...run,
|
|
311
|
+
status: 'interrupted',
|
|
312
|
+
interrupt_reason: reason,
|
|
313
|
+
};
|
|
314
|
+
this.runs.set(runId, interrupted);
|
|
315
|
+
return interrupted;
|
|
316
|
+
}
|
|
258
317
|
actionRuns = [];
|
|
259
318
|
/** Insert a running action row. The `options` arg is mirror-only (observability seam) and deliberately ignored by the in-memory adapter. */
|
|
260
319
|
async saveActionStart(runId, node, kind, _options) {
|
|
@@ -319,12 +378,17 @@ export class MemoryWorkflowPersistenceAdapter {
|
|
|
319
378
|
}
|
|
320
379
|
/** Create a run or attach to an existing one by external key. */
|
|
321
380
|
async createOrAttachRun(record) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
381
|
+
// Keep lookup and insertion in one synchronous turn, matching the DB unique constraint.
|
|
382
|
+
if (record.external_key !== undefined && record.external_key !== null) {
|
|
383
|
+
for (const existing of this.runs.values()) {
|
|
384
|
+
if (existing.workflow_name === record.workflow_name && existing.external_key === record.external_key) {
|
|
385
|
+
return existing;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
326
388
|
}
|
|
327
|
-
|
|
389
|
+
if (this.runs.has(record.id))
|
|
390
|
+
throw new RunCollisionError(record.id);
|
|
391
|
+
this.runs.set(record.id, record);
|
|
328
392
|
return { ...record };
|
|
329
393
|
}
|
|
330
394
|
/** Force-set the current state of a run (reseed). */
|
package/dist/run-lifecycle.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type BusLifecycleEvents, EventBus, type Logger } from '@gobing-ai/ts-infra';
|
|
2
2
|
import type { WorkflowEngineEvents } from './events';
|
|
3
|
-
import type { Vars, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunResult, WorkflowStatus } from './types';
|
|
3
|
+
import type { ActionResult, Vars, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunResult, WorkflowStatus } from './types';
|
|
4
4
|
/** Workflow dialect carried on every run, span, and persisted record. */
|
|
5
5
|
export type WorkflowMode = WorkflowRunResult['mode'];
|
|
6
6
|
/** Keys of the runtime builtin namespace, single-sourced for resolver + validator. */
|
|
@@ -55,6 +55,7 @@ export declare class RunLifecycle {
|
|
|
55
55
|
* The caller is responsible for ensuring the run exists and emitting the resumed event.
|
|
56
56
|
*/
|
|
57
57
|
static resume(workflowName: string, mode: WorkflowMode, deps: RunLifecycleDeps, runId: string, externalKey: string | undefined, loop: (lifecycle: RunLifecycle) => Promise<WorkflowRunResult>): Promise<WorkflowRunResult>;
|
|
58
|
+
private execute;
|
|
58
59
|
/**
|
|
59
60
|
* Persist the current state/node snapshot and mark its phase running.
|
|
60
61
|
* When `persist` is false (set by driver loops after `commitHop` already
|
|
@@ -86,9 +87,7 @@ export declare class RunLifecycle {
|
|
|
86
87
|
* would otherwise be lost because the prior snapshot predates this state's
|
|
87
88
|
* action execution (R3 of 0366).
|
|
88
89
|
*/
|
|
89
|
-
pause(stateOrNodeId: string, transitionsTaken: number, vars?: Vars): Promise<WorkflowRunResult>;
|
|
90
|
-
/** Emit the resumed event (called by WorkflowService after re-creating a lifecycle for resume). */
|
|
91
|
-
emitResumed(node: string): void;
|
|
90
|
+
pause(stateOrNodeId: string, transitionsTaken: number, vars?: Vars, lastActionResult?: ActionResult): Promise<WorkflowRunResult>;
|
|
92
91
|
/** Emit action-level observability before a host action is invoked. */
|
|
93
92
|
actionStart(stateOrNodeId: string, kind: string): void;
|
|
94
93
|
/** Emit action-level observability after a host action settles. */
|
|
@@ -104,4 +103,8 @@ export declare class RunLifecycle {
|
|
|
104
103
|
private result;
|
|
105
104
|
private static runRecord;
|
|
106
105
|
}
|
|
106
|
+
/** Older snapshots have no run-wide counter or guard context. */
|
|
107
|
+
export declare function snapshotTransitions(data: Record<string, unknown> | undefined): number;
|
|
108
|
+
/** Restore only the persisted guard success bit, never unredacted action data. */
|
|
109
|
+
export declare function snapshotActionResult(data: Record<string, unknown> | undefined): ActionResult | undefined;
|
|
107
110
|
//# sourceMappingURL=run-lifecycle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-lifecycle.d.ts","sourceRoot":"","sources":["../src/run-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,kBAAkB,EACvB,QAAQ,EAER,KAAK,MAAM,EAEd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EACR,IAAI,EACJ,0BAA0B,EAC1B,kBAAkB,EAElB,iBAAiB,EACjB,cAAc,EACjB,MAAM,SAAS,CAAC;AAEjB,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAErD,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,wFASvB,CAAC;AAEX,mGAAmG;AACnG,wBAAgB,eAAe,CAC3B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,YAAY,GACnB,MAAM,CAAC,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAWhE;AAED,yEAAyE;AACzE,wBAAgB,UAAU,CACtB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAmB,GAC7D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIxB;AAED,2DAA2D;AAC3D,MAAM,WAAW,gBAAgB;IAC7B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1D,qDAAqD;IACrD,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI;IAS7C,OAAO,CAAC,MAAM;IAiBd,OAAO,CAAC,MAAM,CAAC,SAAS;CAmB3B;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAGrF;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAKxG"}
|
package/dist/run-lifecycle.js
CHANGED
|
@@ -73,13 +73,29 @@ export class RunLifecycle {
|
|
|
73
73
|
static async run(workflowName, mode, deps, options, loop) {
|
|
74
74
|
return await traceAsync('workflow.run', async () => {
|
|
75
75
|
const startedAt = new Date().toISOString();
|
|
76
|
-
const proposed =
|
|
76
|
+
const proposed = {
|
|
77
|
+
...RunLifecycle.runRecord(options.runId ?? crypto.randomUUID(), workflowName, mode, startedAt, options.metadata, options.externalKey),
|
|
78
|
+
owner_attempt: crypto.randomUUID(),
|
|
79
|
+
};
|
|
77
80
|
let record = proposed;
|
|
78
81
|
if (options.externalKey === undefined) {
|
|
79
82
|
await deps.persistence.createRun(proposed);
|
|
80
83
|
}
|
|
81
84
|
else {
|
|
82
85
|
record = await deps.persistence.createOrAttachRun(proposed);
|
|
86
|
+
if (record.owner_attempt !== proposed.owner_attempt) {
|
|
87
|
+
const snapshot = await deps.persistence.loadLatestStateSnapshot(record.id);
|
|
88
|
+
return {
|
|
89
|
+
runId: record.id,
|
|
90
|
+
workflowName: record.workflow_name,
|
|
91
|
+
mode: record.mode === 'transition-flow'
|
|
92
|
+
? 'transition-flow'
|
|
93
|
+
: 'state-machine',
|
|
94
|
+
status: record.status,
|
|
95
|
+
finalState: snapshot?.state ?? '',
|
|
96
|
+
transitionsTaken: snapshotTransitions(snapshot?.data),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
83
99
|
}
|
|
84
100
|
const extKey = record.external_key ?? undefined;
|
|
85
101
|
const lifecycle = new RunLifecycle(record.id, workflowName, mode, deps, extKey);
|
|
@@ -98,7 +114,7 @@ export class RunLifecycle {
|
|
|
98
114
|
externalKey: extKey,
|
|
99
115
|
severity: 'info',
|
|
100
116
|
});
|
|
101
|
-
return await loop
|
|
117
|
+
return await lifecycle.execute(loop);
|
|
102
118
|
}, { attributes: { 'workflow.name': workflowName, 'workflow.mode': mode } });
|
|
103
119
|
}
|
|
104
120
|
/**
|
|
@@ -109,9 +125,24 @@ export class RunLifecycle {
|
|
|
109
125
|
return await traceAsync('workflow.run', async () => {
|
|
110
126
|
const lifecycle = new RunLifecycle(runId, workflowName, mode, deps, externalKey);
|
|
111
127
|
lifecycle.logger.info('workflow run resumed');
|
|
112
|
-
return await loop
|
|
128
|
+
return await lifecycle.execute(loop);
|
|
113
129
|
}, { attributes: { 'workflow.name': workflowName, 'workflow.mode': mode } });
|
|
114
130
|
}
|
|
131
|
+
async execute(loop) {
|
|
132
|
+
try {
|
|
133
|
+
return await loop(this);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
// Preserve the original failure, including a failed attempt to mark the run failed.
|
|
137
|
+
try {
|
|
138
|
+
await this.persistence.finalizeRun(this.runId, 'failed', new Date().toISOString());
|
|
139
|
+
}
|
|
140
|
+
catch (finalizeError) {
|
|
141
|
+
throw new AggregateError([error, finalizeError], 'Workflow execution and failure persistence failed');
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
115
146
|
/**
|
|
116
147
|
* Persist the current state/node snapshot and mark its phase running.
|
|
117
148
|
* When `persist` is false (set by driver loops after `commitHop` already
|
|
@@ -220,10 +251,13 @@ export class RunLifecycle {
|
|
|
220
251
|
* would otherwise be lost because the prior snapshot predates this state's
|
|
221
252
|
* action execution (R3 of 0366).
|
|
222
253
|
*/
|
|
223
|
-
async pause(stateOrNodeId, transitionsTaken, vars) {
|
|
254
|
+
async pause(stateOrNodeId, transitionsTaken, vars, lastActionResult) {
|
|
224
255
|
const data = { transitionsTaken };
|
|
225
256
|
if (vars !== undefined)
|
|
226
257
|
data.effectiveVars = vars;
|
|
258
|
+
// Only persist the control bit: raw action data must not bypass result redaction.
|
|
259
|
+
if (lastActionResult !== undefined)
|
|
260
|
+
data.lastActionResult = { ok: lastActionResult.ok };
|
|
227
261
|
await this.persistence.saveWorkflowState(this.runId, stateOrNodeId, data);
|
|
228
262
|
await this.persistence.savePhase(this.runId, stateOrNodeId, 'paused');
|
|
229
263
|
await this.persistence.finalizeRun(this.runId, 'paused', new Date().toISOString());
|
|
@@ -238,16 +272,6 @@ export class RunLifecycle {
|
|
|
238
272
|
});
|
|
239
273
|
return this.result('paused', stateOrNodeId, transitionsTaken);
|
|
240
274
|
}
|
|
241
|
-
/** Emit the resumed event (called by WorkflowService after re-creating a lifecycle for resume). */
|
|
242
|
-
emitResumed(node) {
|
|
243
|
-
addSpanEvent('workflow.run.resumed', { runId: this.runId, node });
|
|
244
|
-
void this.events?.emit('workflow.run.resumed', {
|
|
245
|
-
runId: this.runId,
|
|
246
|
-
node,
|
|
247
|
-
externalKey: this.externalKey,
|
|
248
|
-
severity: 'info',
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
275
|
/** Emit action-level observability before a host action is invoked. */
|
|
252
276
|
actionStart(stateOrNodeId, kind) {
|
|
253
277
|
addSpanEvent('workflow.action.start', { runId: this.runId, node: stateOrNodeId, kind });
|
|
@@ -336,3 +360,15 @@ export class RunLifecycle {
|
|
|
336
360
|
};
|
|
337
361
|
}
|
|
338
362
|
}
|
|
363
|
+
/** Older snapshots have no run-wide counter or guard context. */
|
|
364
|
+
export function snapshotTransitions(data) {
|
|
365
|
+
const value = data?.transitionsTaken;
|
|
366
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
367
|
+
}
|
|
368
|
+
/** Restore only the persisted guard success bit, never unredacted action data. */
|
|
369
|
+
export function snapshotActionResult(data) {
|
|
370
|
+
const value = data?.lastActionResult;
|
|
371
|
+
return value !== null && typeof value === 'object' && 'ok' in value && typeof value.ok === 'boolean'
|
|
372
|
+
? { ok: value.ok }
|
|
373
|
+
: undefined;
|
|
374
|
+
}
|
package/dist/schema-sql.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/** SQL DDL for the dual-workflow engine's persistent schema — runs, phase_runs, transition_runs, workflow_states, and action_runs tables. */
|
|
2
2
|
export declare const WORKFLOW_ENGINE_SCHEMA_SQL: string;
|
|
3
|
+
/** Guarded ALTERs adding the 0.5.0 ownership/interruption columns for databases created before them. */
|
|
4
|
+
export declare const WORKFLOW_ENGINE_MIGRATIONS_SQL: string;
|
|
3
5
|
//# sourceMappingURL=schema-sql.d.ts.map
|
package/dist/schema-sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-sql.d.ts","sourceRoot":"","sources":["../src/schema-sql.ts"],"names":[],"mappings":"AAAA,6IAA6I;AAC7I,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"schema-sql.d.ts","sourceRoot":"","sources":["../src/schema-sql.ts"],"names":[],"mappings":"AAAA,6IAA6I;AAC7I,eAAO,MAAM,0BAA0B,QAsE/B,CAAC;AAET,wGAAwG;AACxG,eAAO,MAAM,8BAA8B,QAInC,CAAC"}
|
package/dist/schema-sql.js
CHANGED
|
@@ -11,7 +11,10 @@ CREATE TABLE IF NOT EXISTS runs (
|
|
|
11
11
|
completed_at TEXT,
|
|
12
12
|
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
13
13
|
created_at INTEGER NOT NULL DEFAULT 0,
|
|
14
|
-
updated_at INTEGER NOT NULL DEFAULT 0
|
|
14
|
+
updated_at INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
owner_attempt TEXT,
|
|
16
|
+
owner_pid INTEGER,
|
|
17
|
+
interrupt_reason TEXT
|
|
15
18
|
);
|
|
16
19
|
|
|
17
20
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_runs_external_key
|
|
@@ -67,3 +70,9 @@ CREATE TABLE IF NOT EXISTS action_runs (
|
|
|
67
70
|
FOREIGN KEY (run_id) REFERENCES runs(id)
|
|
68
71
|
);
|
|
69
72
|
`.trim();
|
|
73
|
+
/** Guarded ALTERs adding the 0.5.0 ownership/interruption columns for databases created before them. */
|
|
74
|
+
export const WORKFLOW_ENGINE_MIGRATIONS_SQL = `
|
|
75
|
+
ALTER TABLE runs ADD COLUMN owner_attempt TEXT;
|
|
76
|
+
ALTER TABLE runs ADD COLUMN owner_pid INTEGER;
|
|
77
|
+
ALTER TABLE runs ADD COLUMN interrupt_reason TEXT;
|
|
78
|
+
`.trim();
|
package/dist/schema.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare const StateMachineWorkflowDefSchema: z.ZodObject<{
|
|
|
61
61
|
}>>;
|
|
62
62
|
}, z.core.$strip>>>;
|
|
63
63
|
pause: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
resumeRerun: z.ZodOptional<z.ZodBoolean>;
|
|
64
65
|
}, z.core.$strict>>;
|
|
65
66
|
transitions: z.ZodArray<z.ZodObject<{
|
|
66
67
|
from: z.ZodString;
|
|
@@ -113,6 +114,7 @@ export declare const TransitionFlowWorkflowDefSchema: z.ZodObject<{
|
|
|
113
114
|
}>>;
|
|
114
115
|
}, z.core.$strip>>;
|
|
115
116
|
pause: z.ZodOptional<z.ZodBoolean>;
|
|
117
|
+
resumeRerun: z.ZodOptional<z.ZodBoolean>;
|
|
116
118
|
}, z.core.$strict>>;
|
|
117
119
|
edges: z.ZodArray<z.ZodObject<{
|
|
118
120
|
from: z.ZodString;
|
|
@@ -167,6 +169,7 @@ export declare const WorkflowDefSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
167
169
|
}>>;
|
|
168
170
|
}, z.core.$strip>>>;
|
|
169
171
|
pause: z.ZodOptional<z.ZodBoolean>;
|
|
172
|
+
resumeRerun: z.ZodOptional<z.ZodBoolean>;
|
|
170
173
|
}, z.core.$strict>>;
|
|
171
174
|
transitions: z.ZodArray<z.ZodObject<{
|
|
172
175
|
from: z.ZodString;
|
|
@@ -217,6 +220,7 @@ export declare const WorkflowDefSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
217
220
|
}>>;
|
|
218
221
|
}, z.core.$strip>>;
|
|
219
222
|
pause: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
resumeRerun: z.ZodOptional<z.ZodBoolean>;
|
|
220
224
|
}, z.core.$strict>>;
|
|
221
225
|
edges: z.ZodArray<z.ZodObject<{
|
|
222
226
|
from: z.ZodString;
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA6CxB;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;kBAKxB,CAAC;AAEd,kDAAkD;AAClD,eAAO,MAAM,eAAe;;;;;;;iBAI1B,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,cAAc;;;iBAGzB,CAAC;AAEH,yDAAyD;AACzD,eAAO,MAAM,6BAA6B
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA6CxB;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;kBAKxB,CAAC;AAEd,kDAAkD;AAClD,eAAO,MAAM,eAAe;;;;;;;iBAI1B,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,cAAc;;;iBAGzB,CAAC;AAEH,yDAAyD;AACzD,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0C7B,CAAC;AAEd,2DAA2D;AAC3D,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAwC/B,CAAC;AAEd,iEAAiE;AACjE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAA4E,CAAC"}
|