@memberjunction/task-graph 6.2.2 → 6.3.0-edge.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/dist/TaskGraphDispatcher.d.ts +289 -2
- package/dist/TaskGraphDispatcher.d.ts.map +1 -1
- package/dist/TaskGraphDispatcher.js +1275 -330
- package/dist/TaskGraphDispatcher.js.map +1 -1
- package/dist/TaskGraphService.d.ts +68 -1
- package/dist/TaskGraphService.d.ts.map +1 -1
- package/dist/TaskGraphService.js +226 -24
- package/dist/TaskGraphService.js.map +1 -1
- package/dist/TaskGraphSubmitterImpl.d.ts +1 -0
- package/dist/TaskGraphSubmitterImpl.d.ts.map +1 -1
- package/dist/TaskGraphSubmitterImpl.js +5 -0
- package/dist/TaskGraphSubmitterImpl.js.map +1 -1
- package/dist/decision-node.d.ts +21 -0
- package/dist/decision-node.d.ts.map +1 -1
- package/dist/decision-node.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/operations/TaskGraphDebugOperations.d.ts +23 -0
- package/dist/operations/TaskGraphDebugOperations.d.ts.map +1 -1
- package/dist/operations/TaskGraphDebugOperations.js +13 -13
- package/dist/operations/TaskGraphDebugOperations.js.map +1 -1
- package/dist/operations/TaskGraphOperations.d.ts.map +1 -1
- package/dist/operations/TaskGraphOperations.js +12 -7
- package/dist/operations/TaskGraphOperations.js.map +1 -1
- package/dist/saga-compensation.d.ts +167 -0
- package/dist/saga-compensation.d.ts.map +1 -0
- package/dist/saga-compensation.js +392 -0
- package/dist/saga-compensation.js.map +1 -0
- package/dist/task-security.d.ts +96 -0
- package/dist/task-security.d.ts.map +1 -0
- package/dist/task-security.js +187 -0
- package/dist/task-security.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +57 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +12 -12
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
19
19
|
import { MJTaskEntity } from '@memberjunction/core-entities';
|
|
20
|
-
import { type TaskGraphInvocationEnvelope, type TaskGraphSpec, type TaskGraphSpecNode, type ForEachOperation, type WhileOperation } from '@memberjunction/ai-core-plus';
|
|
20
|
+
import { type TaskGraphFailurePolicy, type TaskGraphInvocationEnvelope, type TaskGraphSpec, type TaskGraphSpecNode, type TaskSecurityEnvelope, type ForEachOperation, type WhileOperation } from '@memberjunction/ai-core-plus';
|
|
21
21
|
import { type DecisionTaskRow, type TaskStepConfiguration } from './decision-node.js';
|
|
22
|
+
import { type SagaExecutionState } from './saga-compensation.js';
|
|
22
23
|
import { type EdgeOverrideVerdict, type StepTarget, type TaskGraphDebugState } from './debug-state.js';
|
|
23
24
|
/**
|
|
24
25
|
* Normalizes a caller-supplied reinvoke depth to a safe cap seed.
|
|
@@ -63,7 +64,14 @@ export type TaskGraphSubmitContext = {
|
|
|
63
64
|
/** Seed `$.debug` on the parent at insert. See `TaskGraphStartDebug`. */
|
|
64
65
|
Debug?: {
|
|
65
66
|
paused?: boolean;
|
|
67
|
+
breakpointStepIDs?: string[];
|
|
66
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* The submitting run's security envelope. Written to `Task.SecurityEnvelope` on the parent and on
|
|
71
|
+
* every child row at insert, never afterwards (`MJTaskEntityServer` refuses a change), and enforced
|
|
72
|
+
* by the dispatcher on every node.
|
|
73
|
+
*/
|
|
74
|
+
SecurityEnvelope?: TaskSecurityEnvelope;
|
|
67
75
|
};
|
|
68
76
|
/**
|
|
69
77
|
* What the parent Task row remembers about the graph beyond its tasks.
|
|
@@ -103,6 +111,13 @@ export type TaskGraphParentMetadata = {
|
|
|
103
111
|
* run they are watching.
|
|
104
112
|
*/
|
|
105
113
|
submittedByUserID?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Set on every graph submitted since steps record their output taint. The taint walk then reads a step that is
|
|
116
|
+
* Complete with nothing recorded, and no person recorded as completing it, as tainted: it did not finish through the
|
|
117
|
+
* dispatcher. A graph without it was submitted before the upgrade, when no step recorded taint, so its steps are
|
|
118
|
+
* read through to what fed them instead. Only the service writes this metadata, and it cannot be changed after.
|
|
119
|
+
*/
|
|
120
|
+
recordsTaint?: boolean;
|
|
106
121
|
/**
|
|
107
122
|
* Set once the completion handler has delivered. Written with a compare-and-swap guard, which is
|
|
108
123
|
* what turns at-least-once delivery into effectively-once: a crash between "graph complete" and
|
|
@@ -140,6 +155,14 @@ export type TaskGraphParentMetadata = {
|
|
|
140
155
|
data?: unknown;
|
|
141
156
|
context?: unknown;
|
|
142
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* Workflow-level saga failure policy (`'Halt'` default, or `'CompensateCompleted'`).
|
|
160
|
+
*/
|
|
161
|
+
failurePolicy?: TaskGraphFailurePolicy;
|
|
162
|
+
/**
|
|
163
|
+
* Current saga lifecycle state when `failurePolicy === 'CompensateCompleted'`.
|
|
164
|
+
*/
|
|
165
|
+
sagaState?: SagaExecutionState;
|
|
143
166
|
};
|
|
144
167
|
/**
|
|
145
168
|
* Continuation chains are bounded separately from graph nesting.
|
|
@@ -172,6 +195,8 @@ export declare function BuildTaskGraphParentInputPayload(args: {
|
|
|
172
195
|
continuation: TaskGraphParentMetadata['continuation'];
|
|
173
196
|
reinvokeDepth: number;
|
|
174
197
|
failureSemantics: NonNullable<TaskGraphParentMetadata['failureSemantics']>;
|
|
198
|
+
failurePolicy?: TaskGraphFailurePolicy;
|
|
199
|
+
sagaState?: SagaExecutionState;
|
|
175
200
|
submittedByAgentRunID: string | null;
|
|
176
201
|
submittedByUserID: string | null;
|
|
177
202
|
parentAgentHierarchy?: string[];
|
|
@@ -181,6 +206,11 @@ export declare function BuildTaskGraphParentInputPayload(args: {
|
|
|
181
206
|
} | null;
|
|
182
207
|
startPaused?: boolean;
|
|
183
208
|
}): Record<string, unknown>;
|
|
209
|
+
/**
|
|
210
|
+
* #3798 — maps remembered breakpoints, held as stable step IDs (the spec's `tempId`), to this run's task IDs.
|
|
211
|
+
* A step ID the graph no longer has (the step was removed) is dropped.
|
|
212
|
+
*/
|
|
213
|
+
export declare function MapBreakpointStepIDs(stepIDs: readonly string[] | undefined, taskIDsByStepID: ReadonlyMap<string, string>): string[];
|
|
184
214
|
/** What a cancellation actually managed to do. */
|
|
185
215
|
export type TaskGraphCancelResult = {
|
|
186
216
|
/** False when anything the caller asked to stop is still running. */
|
|
@@ -193,6 +223,12 @@ export type TaskGraphCancelResult = {
|
|
|
193
223
|
};
|
|
194
224
|
/** True when a continuation chain has gone as far as it may. */
|
|
195
225
|
export declare function IsReinvokeCapReached(meta: TaskGraphParentMetadata): boolean;
|
|
226
|
+
/** The outcome of {@link TaskGraphService.RetryTask}. */
|
|
227
|
+
export type TaskGraphRetryOutcome = {
|
|
228
|
+
Success: boolean;
|
|
229
|
+
/** Why the retry was refused or failed, fit to show the person who asked. */
|
|
230
|
+
ErrorMessage?: string;
|
|
231
|
+
};
|
|
196
232
|
export type TaskGraphSubmitResult = {
|
|
197
233
|
Success: boolean;
|
|
198
234
|
/** The parent task representing the whole graph — the handle for status, cancel and retry. */
|
|
@@ -295,6 +331,12 @@ export declare class TaskGraphService {
|
|
|
295
331
|
* holds it.
|
|
296
332
|
*/
|
|
297
333
|
private readonly claims;
|
|
334
|
+
/**
|
|
335
|
+
* Saves a row of a graph inside {@link TASK_GRAPH_RUNTIME_SECURITY_OPERATION}, bound to the caller: a workflow, its
|
|
336
|
+
* steps and its edges are written only by this service and the dispatcher (`MJTaskEntityServer`,
|
|
337
|
+
* `MJTaskDependencyEntityServer`), so a graph is created and changed through the service, never by an ordinary save.
|
|
338
|
+
*/
|
|
339
|
+
private saveAsService;
|
|
298
340
|
/**
|
|
299
341
|
* Validates and persists a task graph, returning as soon as it is durable.
|
|
300
342
|
*
|
|
@@ -386,6 +428,16 @@ export declare class TaskGraphService {
|
|
|
386
428
|
* past this node.
|
|
387
429
|
*/
|
|
388
430
|
Retry(taskID: string, context: TaskGraphSubmitContext, inputPayload?: unknown): Promise<boolean>;
|
|
431
|
+
/** {@link Retry}, with the reason when the retry is refused, for a caller that shows it to a person. */
|
|
432
|
+
RetryTask(taskID: string, context: TaskGraphSubmitContext, inputPayload?: unknown): Promise<TaskGraphRetryOutcome>;
|
|
433
|
+
/**
|
|
434
|
+
* Why no step of this graph may be retried, or null (S9): its rollback has started. A saga
|
|
435
|
+
* (`failurePolicy: 'CompensateCompleted'`) undoes the completed steps after a failure, so re-running
|
|
436
|
+
* the failed step would act on state the rollback has already reversed, and its dependents would
|
|
437
|
+
* run on top of that. Started means a compensation or escalation row exists, or the graph records
|
|
438
|
+
* a saga state.
|
|
439
|
+
*/
|
|
440
|
+
private rollbackStartedRefusal;
|
|
389
441
|
/**
|
|
390
442
|
* Store for the guarded JSON_MODIFY writes. The instance identity and TTL are claim-protocol
|
|
391
443
|
* concerns this class never exercises — the debug writes are instance-free.
|
|
@@ -513,6 +565,14 @@ export declare class TaskGraphService {
|
|
|
513
565
|
* agents and actions — a name in JSON cannot be joined, checked, or survive a rename.
|
|
514
566
|
*/
|
|
515
567
|
private resolvePrompts;
|
|
568
|
+
/**
|
|
569
|
+
* Refuses a graph whose node names a compensation action by an ID that is not an action (S7).
|
|
570
|
+
*
|
|
571
|
+
* The ID is written by the model and stays in the node's JSON until a rollback inserts the
|
|
572
|
+
* compensation task — the first point a foreign key sees it. There an unknown ID failed the insert
|
|
573
|
+
* on every pass, so the step was never undone. Checked here, as the caller, before anything is written.
|
|
574
|
+
*/
|
|
575
|
+
private validateCompensationActionIDs;
|
|
516
576
|
private resolveActions;
|
|
517
577
|
/**
|
|
518
578
|
* Finds or creates the task type used for orchestrated graphs — exactly one of it, ever.
|
|
@@ -539,6 +599,13 @@ export declare class TaskGraphService {
|
|
|
539
599
|
* situation visible rather than merely survivable.
|
|
540
600
|
*/
|
|
541
601
|
private findTaskTypeID;
|
|
602
|
+
/** Why the submitted envelope cannot be stored and enforced, or null when it can (or there is none). */
|
|
603
|
+
private envelopeRefusal;
|
|
604
|
+
/**
|
|
605
|
+
* Writes the starting breakpoints into the parent's `$.debug` after the children exist. Inside the Submit
|
|
606
|
+
* transaction, so a graph never becomes visible to a dispatcher without them.
|
|
607
|
+
*/
|
|
608
|
+
private seedBreakpoints;
|
|
542
609
|
/** Writes the parent task that represents the graph as a whole. */
|
|
543
610
|
private persistParent;
|
|
544
611
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskGraphService.d.ts","sourceRoot":"","sources":["../src/TaskGraphService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACH,iBAAiB,
|
|
1
|
+
{"version":3,"file":"TaskGraphService.d.ts","sourceRoot":"","sources":["../src/TaskGraphService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACH,iBAAiB,EAMjB,QAAQ,EAEX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,YAAY,EAMf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAUH,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAEtB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAAuB,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAA4C,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAExG,OAAO,EAA4B,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAG9H;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG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M,CAAA;KAAE,CAAC;IAU5H;;;;;;OAMG;IACU,iBAAiB,CAC1B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,EACtB,OAAO,EAAE,sBAAsB,GAChC,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAoBvD;;;;;;;;;;OAUG;IACU,eAAe,CACxB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,sBAAsB,GAChC,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBvD;;;;;OAKG;YACW,aAAa;IA+E3B;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAmC5B;;;;;OAKG;YACW,cAAc;IA+B5B;;;;;;OAMG;YACW,6BAA6B;YAsC7B,cAAc;IA6B5B;;;;;;;;;;;;;OAaG;YACW,cAAc;IAmB5B;;;;;;;;OAQG;YACW,cAAc;IAuB5B,wGAAwG;IACxG,OAAO,CAAC,eAAe;IAKvB;;;OAGG;YACW,eAAe;IAc7B,mEAAmE;YACrD,aAAa;IAwD3B;;;;;;;OAOG;YACW,eAAe;IAyJ7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,mBAAmB;IAI3B,qFAAqF;YACvE,mBAAmB;YA8CnB,YAAY;CAsB7B"}
|
package/dist/TaskGraphService.js
CHANGED
|
@@ -15,14 +15,15 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module @memberjunction/task-graph
|
|
17
17
|
*/
|
|
18
|
-
import { LogError, LogStatus, RunInEntityTransaction, RunView, } from '@memberjunction/core';
|
|
19
|
-
import { FormatValidationErrors, NormalizeDependency, RankGraphNodes, SanitizeInvocationEnvelope, ValidateTaskGraphSpec, ConfigOf, } from '@memberjunction/ai-core-plus';
|
|
20
|
-
import { EscapeSQLString, UUIDsEqual } from '@memberjunction/global';
|
|
18
|
+
import { LogError, LogStatus, RunInEntityTransaction, RunView, ServerOperationScopeManager, } from '@memberjunction/core';
|
|
19
|
+
import { FormatValidationErrors, NormalizeDependency, ParseTaskSecurityEnvelope, RankGraphNodes, SerializeTaskSecurityEnvelope, SanitizeInvocationEnvelope, TASK_GRAPH_RUNTIME_SECURITY_OPERATION, TASK_GRAPH_WORKFLOW_TYPE_NAME, ValidateTaskGraphSpec, ConfigOf, } from '@memberjunction/ai-core-plus';
|
|
20
|
+
import { EscapeSQLString, IsValidUUID, UUIDSet, UUIDsEqual } from '@memberjunction/global';
|
|
21
21
|
import { AIAgentPermissionHelper } from '@memberjunction/ai-engine-base';
|
|
22
22
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
23
23
|
import { AgentDecisionService } from '@memberjunction/ai-agents';
|
|
24
24
|
import { ResolveRecordsByNameOrToolName } from './resolve-by-tool-name.js';
|
|
25
25
|
import { HeldDecisionAnswers } from './decision-node.js';
|
|
26
|
+
import { CompensationFromSpec, IsCompensationTask } from './saga-compensation.js';
|
|
26
27
|
import { TaskClaimStore } from './TaskClaimStore.js';
|
|
27
28
|
import { ParseTaskGraphDebugState } from './debug-state.js';
|
|
28
29
|
import { KickTaskGraphDispatchers } from './task-graph-kick.js';
|
|
@@ -59,6 +60,13 @@ const DEFAULT_PARENT_METADATA = {
|
|
|
59
60
|
submittedByAgentRunID: null,
|
|
60
61
|
submittedByUserID: null,
|
|
61
62
|
};
|
|
63
|
+
const VALID_SAGA_STATES = new Set([
|
|
64
|
+
'Running',
|
|
65
|
+
'Compensating',
|
|
66
|
+
'Compensated',
|
|
67
|
+
'CompensationEscalated',
|
|
68
|
+
'CompensationFailed',
|
|
69
|
+
]);
|
|
62
70
|
/**
|
|
63
71
|
* Parses a parent Task's continuation metadata.
|
|
64
72
|
*
|
|
@@ -83,7 +91,13 @@ export function ParseTaskGraphParentMetadata(raw) {
|
|
|
83
91
|
.map((name) => name.trim())
|
|
84
92
|
.filter((name) => name.length > 0)
|
|
85
93
|
: undefined;
|
|
86
|
-
|
|
94
|
+
const failurePolicy = parsed.failurePolicy === 'CompensateCompleted' || parsed.failurePolicy === 'Halt'
|
|
95
|
+
? parsed.failurePolicy
|
|
96
|
+
: undefined;
|
|
97
|
+
const sagaState = VALID_SAGA_STATES.has(parsed.sagaState)
|
|
98
|
+
? parsed.sagaState
|
|
99
|
+
: undefined;
|
|
100
|
+
const out = {
|
|
87
101
|
...DEFAULT_PARENT_METADATA,
|
|
88
102
|
...parsed,
|
|
89
103
|
// Guard the two fields the dispatcher branches on. A JSON round-trip, a hand edit, or a
|
|
@@ -102,7 +116,14 @@ export function ParseTaskGraphParentMetadata(raw) {
|
|
|
102
116
|
parentAgentHierarchy: parentAgentHierarchy && parentAgentHierarchy.length > 0
|
|
103
117
|
? parentAgentHierarchy
|
|
104
118
|
: undefined,
|
|
119
|
+
...(failurePolicy !== undefined ? { failurePolicy } : {}),
|
|
120
|
+
...(sagaState !== undefined ? { sagaState } : {}),
|
|
105
121
|
};
|
|
122
|
+
if (failurePolicy === undefined)
|
|
123
|
+
delete out.failurePolicy;
|
|
124
|
+
if (sagaState === undefined)
|
|
125
|
+
delete out.sagaState;
|
|
126
|
+
return out;
|
|
106
127
|
}
|
|
107
128
|
catch {
|
|
108
129
|
return { ...DEFAULT_PARENT_METADATA };
|
|
@@ -124,8 +145,11 @@ export function BuildTaskGraphParentInputPayload(args) {
|
|
|
124
145
|
continuation: args.continuation,
|
|
125
146
|
reinvokeDepth: args.reinvokeDepth,
|
|
126
147
|
failureSemantics: args.failureSemantics,
|
|
148
|
+
...(args.failurePolicy && args.failurePolicy !== 'Halt' ? { failurePolicy: args.failurePolicy } : {}),
|
|
149
|
+
...(args.sagaState ? { sagaState: args.sagaState } : {}),
|
|
127
150
|
submittedByAgentRunID: args.submittedByAgentRunID,
|
|
128
151
|
submittedByUserID: args.submittedByUserID,
|
|
152
|
+
recordsTaint: true,
|
|
129
153
|
...(parentAgentHierarchy.length > 0 ? { parentAgentHierarchy } : {}),
|
|
130
154
|
...(args.invocation
|
|
131
155
|
? { invocation: { data: args.invocation.data, context: args.invocation.context } }
|
|
@@ -141,6 +165,31 @@ export function BuildTaskGraphParentInputPayload(args) {
|
|
|
141
165
|
: {}),
|
|
142
166
|
};
|
|
143
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* #3798 — maps remembered breakpoints, held as stable step IDs (the spec's `tempId`), to this run's task IDs.
|
|
170
|
+
* A step ID the graph no longer has (the step was removed) is dropped.
|
|
171
|
+
*/
|
|
172
|
+
export function MapBreakpointStepIDs(stepIDs, taskIDsByStepID) {
|
|
173
|
+
const out = [];
|
|
174
|
+
for (const stepID of stepIDs ?? []) {
|
|
175
|
+
const taskID = taskIDsByStepID.get(stepID);
|
|
176
|
+
if (taskID && !out.includes(taskID))
|
|
177
|
+
out.push(taskID);
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
/** A JSON object from a payload column, or `{}` for empty or unparseable text. */
|
|
182
|
+
function SafeParseObject(raw) {
|
|
183
|
+
if (!raw)
|
|
184
|
+
return {};
|
|
185
|
+
try {
|
|
186
|
+
const parsed = JSON.parse(raw);
|
|
187
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
144
193
|
/**
|
|
145
194
|
* How a settlement's announcement ended — the values `TryClaimContinuation` may record.
|
|
146
195
|
*
|
|
@@ -155,7 +204,7 @@ export function IsReinvokeCapReached(meta) {
|
|
|
155
204
|
return meta.reinvokeDepth >= MAX_REINVOKE_DEPTH;
|
|
156
205
|
}
|
|
157
206
|
/** Name of the task type used for agent-orchestrated graphs. */
|
|
158
|
-
export const TASK_TYPE_NAME =
|
|
207
|
+
export const TASK_TYPE_NAME = TASK_GRAPH_WORKFLOW_TYPE_NAME;
|
|
159
208
|
/**
|
|
160
209
|
* The node kinds a `Task` row can actually represent, and therefore the ones the dispatcher can run.
|
|
161
210
|
*
|
|
@@ -244,6 +293,11 @@ export function BuildStepConfiguration(node) {
|
|
|
244
293
|
config.inputMapping = inputMapping;
|
|
245
294
|
if (outputMapping)
|
|
246
295
|
config.outputMapping = outputMapping;
|
|
296
|
+
// Every setting the spec's compensation names travels, `retryCount` and the `compensationInputMapping`
|
|
297
|
+
// alias included (folded into `inputMapping`): dropping them made a spec's retry and mapping vanish.
|
|
298
|
+
const compensation = CompensationFromSpec(action?.compensation);
|
|
299
|
+
if (compensation)
|
|
300
|
+
config.compensation = compensation;
|
|
247
301
|
if (node.policy) {
|
|
248
302
|
config.policy = {
|
|
249
303
|
timeoutSeconds: node.policy.timeoutSeconds,
|
|
@@ -297,11 +351,25 @@ export function DecisionPromptNameOf(node) {
|
|
|
297
351
|
return null;
|
|
298
352
|
return decision.promptName?.trim() || AgentDecisionService.DEFAULT_PROMPT_NAME;
|
|
299
353
|
}
|
|
300
|
-
/**
|
|
354
|
+
/** The distinct non-blank IDs in `values`, compared as UUIDs, in first-seen order. */
|
|
355
|
+
function uniqueIDs(values) {
|
|
356
|
+
const seen = new UUIDSet();
|
|
357
|
+
const out = [];
|
|
358
|
+
for (const value of values) {
|
|
359
|
+
if (!value || seen.Has(value))
|
|
360
|
+
continue;
|
|
361
|
+
seen.Add(value);
|
|
362
|
+
out.push(value);
|
|
363
|
+
}
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
/** Every action name a node references, including the action(s) a loop repeats and any named compensation action. */
|
|
301
367
|
function actionNamesIn(node) {
|
|
302
368
|
const loopOp = LoopOperationOf(node);
|
|
369
|
+
const actionCfg = ConfigOf(node, 'Action');
|
|
303
370
|
const names = [
|
|
304
|
-
|
|
371
|
+
actionCfg?.actionName,
|
|
372
|
+
actionCfg?.compensation?.compensationActionName,
|
|
305
373
|
loopOp?.action?.name,
|
|
306
374
|
...(loopOp?.steps?.map((s) => s.name) ?? []),
|
|
307
375
|
];
|
|
@@ -443,6 +511,14 @@ export class TaskGraphService {
|
|
|
443
511
|
*/
|
|
444
512
|
this.debugWrites = new TaskClaimStore('task-graph-service', 0);
|
|
445
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Saves a row of a graph inside {@link TASK_GRAPH_RUNTIME_SECURITY_OPERATION}, bound to the caller: a workflow, its
|
|
516
|
+
* steps and its edges are written only by this service and the dispatcher (`MJTaskEntityServer`,
|
|
517
|
+
* `MJTaskDependencyEntityServer`), so a graph is created and changed through the service, never by an ordinary save.
|
|
518
|
+
*/
|
|
519
|
+
saveAsService(row, entityName, context) {
|
|
520
|
+
return ServerOperationScopeManager.Instance.RunWithAuthority({ operationKey: TASK_GRAPH_RUNTIME_SECURITY_OPERATION, source: 'ServerEngine', allowedEntities: [entityName], userId: context.ContextUser.ID }, () => row.Save());
|
|
521
|
+
}
|
|
446
522
|
/**
|
|
447
523
|
* Validates and persists a task graph, returning as soon as it is durable.
|
|
448
524
|
*
|
|
@@ -490,6 +566,13 @@ export class TaskGraphService {
|
|
|
490
566
|
LogError(`[TaskGraphService] ${message}`);
|
|
491
567
|
return { Success: false, ErrorMessage: message };
|
|
492
568
|
}
|
|
569
|
+
// 1d. The security envelope must read back as the one written, or every node would be refused
|
|
570
|
+
// after the graph is already persisted. Refused here, before anything is written.
|
|
571
|
+
const envelopeRefusal = this.envelopeRefusal(context.SecurityEnvelope);
|
|
572
|
+
if (envelopeRefusal) {
|
|
573
|
+
LogError(`[TaskGraphService] "${spec.workflowName}" was not started: ${envelopeRefusal}`);
|
|
574
|
+
return { Success: false, ErrorMessage: envelopeRefusal };
|
|
575
|
+
}
|
|
493
576
|
try {
|
|
494
577
|
// 2. Resolve every agent, action, and prompt in parallel BEFORE writing anything. An
|
|
495
578
|
// unresolvable name is a hard error, not a skipped node: silently dropping a task
|
|
@@ -512,6 +595,11 @@ export class TaskGraphService {
|
|
|
512
595
|
if (!promptIDsByName.Success) {
|
|
513
596
|
return { Success: false, ErrorMessage: promptIDsByName.ErrorMessage };
|
|
514
597
|
}
|
|
598
|
+
const compensationCheck = await this.validateCompensationActionIDs(spec, context);
|
|
599
|
+
if (!compensationCheck.Success) {
|
|
600
|
+
LogError(`[TaskGraphService] ${compensationCheck.ErrorMessage}`);
|
|
601
|
+
return { Success: false, ErrorMessage: compensationCheck.ErrorMessage };
|
|
602
|
+
}
|
|
515
603
|
const taskTypeID = await this.ensureTaskType(context);
|
|
516
604
|
// 3. Persist — ALL of it, or none of it.
|
|
517
605
|
//
|
|
@@ -545,6 +633,11 @@ export class TaskGraphService {
|
|
|
545
633
|
const parentID = await this.persistParent(spec, taskTypeID, context);
|
|
546
634
|
const map = await this.persistChildren(spec, parentID, taskTypeID, agentIDsByName.Map, actionIDsByName.Map, promptIDsByName.Map, context);
|
|
547
635
|
await this.persistDependencies(spec, map, context);
|
|
636
|
+
// Remembered breakpoints arrive as stable step IDs; seed them now that task IDs exist (#3798).
|
|
637
|
+
const breakpoints = MapBreakpointStepIDs(context.Debug?.breakpointStepIDs, map);
|
|
638
|
+
if (breakpoints.length > 0) {
|
|
639
|
+
await this.seedBreakpoints(parentID, breakpoints, context);
|
|
640
|
+
}
|
|
548
641
|
return { parentTaskID: parentID, taskIDMap: map };
|
|
549
642
|
});
|
|
550
643
|
LogStatus(`[TaskGraphService] Submitted "${spec.workflowName}": parent ${parentTaskID}, ${taskIDMap.size} task(s). ` +
|
|
@@ -792,17 +885,27 @@ export class TaskGraphService {
|
|
|
792
885
|
* past this node.
|
|
793
886
|
*/
|
|
794
887
|
async Retry(taskID, context, inputPayload) {
|
|
888
|
+
return (await this.RetryTask(taskID, context, inputPayload)).Success;
|
|
889
|
+
}
|
|
890
|
+
/** {@link Retry}, with the reason when the retry is refused, for a caller that shows it to a person. */
|
|
891
|
+
async RetryTask(taskID, context, inputPayload) {
|
|
795
892
|
try {
|
|
796
893
|
const task = await context.Provider.GetEntityObject('MJ: Tasks', context.ContextUser);
|
|
797
894
|
if (!(await task.Load(taskID)))
|
|
798
|
-
return false;
|
|
895
|
+
return { Success: false, ErrorMessage: 'The task could not be loaded.' };
|
|
799
896
|
const editedInput = inputPayload === undefined
|
|
800
897
|
? undefined
|
|
801
898
|
: typeof inputPayload === 'string' ? inputPayload : JSON.stringify(inputPayload);
|
|
802
899
|
const refusal = RetryRefusal(task, editedInput);
|
|
803
900
|
if (refusal) {
|
|
804
901
|
LogError(`[TaskGraphService] Cannot retry task ${taskID}: ${refusal}.`);
|
|
805
|
-
return false;
|
|
902
|
+
return { Success: false, ErrorMessage: `The task cannot be retried: ${refusal}.` };
|
|
903
|
+
}
|
|
904
|
+
const siblings = task.ParentID ? await this.loadChildren(task.ParentID, context) : [];
|
|
905
|
+
const rollingBack = task.ParentID ? await this.rollbackStartedRefusal(task.ParentID, siblings, context) : null;
|
|
906
|
+
if (rollingBack) {
|
|
907
|
+
LogError(`[TaskGraphService] Cannot retry task ${taskID}: ${rollingBack}`);
|
|
908
|
+
return { Success: false, ErrorMessage: rollingBack };
|
|
806
909
|
}
|
|
807
910
|
const expectedStatus = task.Status === 'Complete' ? 'Complete' : 'Failed';
|
|
808
911
|
// An edited input rides the retry: the operator saw WHY it failed and is re-running the
|
|
@@ -820,30 +923,49 @@ export class TaskGraphService {
|
|
|
820
923
|
const wrote = await this.debugWrites.TryUpdateInputPayload(context.Provider, taskID, json, expectedStatus, typeID, context.ContextUser);
|
|
821
924
|
if (!wrote) {
|
|
822
925
|
LogError(`[TaskGraphService] Could not apply the edited input to task ${taskID}; retry refused rather than re-running the old brief.`);
|
|
823
|
-
return false;
|
|
926
|
+
return { Success: false, ErrorMessage: 'The edited input could not be saved, so the task was not retried.' };
|
|
824
927
|
}
|
|
825
928
|
// Keep the in-memory row in step with what was just written, so the save below does
|
|
826
929
|
// not put the old input back.
|
|
827
930
|
task.InputPayload = json;
|
|
828
931
|
}
|
|
829
932
|
PrepareTaskForRetry(task);
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
933
|
+
// A workflow step's status and data are the dispatcher's (`MJTaskEntityServer`): this save carries the
|
|
934
|
+
// input the guarded statement above just wrote and a retried Decision's cleared output, and the
|
|
935
|
+
// unblocking below changes siblings' status, so they run in the service's scope.
|
|
936
|
+
if (!(await this.saveAsService(task, 'MJ: Tasks', context)))
|
|
937
|
+
return { Success: false, ErrorMessage: 'The task could not be saved.' };
|
|
938
|
+
for (const sibling of siblings) {
|
|
939
|
+
if (sibling.Status === 'Blocked') {
|
|
940
|
+
sibling.Status = 'Pending';
|
|
941
|
+
await this.saveAsService(sibling, 'MJ: Tasks', context);
|
|
838
942
|
}
|
|
839
943
|
}
|
|
840
|
-
return true;
|
|
944
|
+
return { Success: true };
|
|
841
945
|
}
|
|
842
946
|
catch (e) {
|
|
843
947
|
LogError(`[TaskGraphService] Retry failed for ${taskID}: ${e instanceof Error ? e.message : String(e)}`);
|
|
844
|
-
return false;
|
|
948
|
+
return { Success: false, ErrorMessage: 'The retry failed.' };
|
|
845
949
|
}
|
|
846
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* Why no step of this graph may be retried, or null (S9): its rollback has started. A saga
|
|
953
|
+
* (`failurePolicy: 'CompensateCompleted'`) undoes the completed steps after a failure, so re-running
|
|
954
|
+
* the failed step would act on state the rollback has already reversed, and its dependents would
|
|
955
|
+
* run on top of that. Started means a compensation or escalation row exists, or the graph records
|
|
956
|
+
* a saga state.
|
|
957
|
+
*/
|
|
958
|
+
async rollbackStartedRefusal(parentTaskID, siblings, context) {
|
|
959
|
+
const refusal = 'The workflow has started rolling back the steps that completed, so a step cannot be retried: ' +
|
|
960
|
+
'it would run against state the rollback has undone. Submit the workflow again instead.';
|
|
961
|
+
if (siblings.some((t) => IsCompensationTask(t)))
|
|
962
|
+
return refusal;
|
|
963
|
+
const parent = await context.Provider.GetEntityObject('MJ: Tasks', context.ContextUser);
|
|
964
|
+
if (!(await parent.Load(parentTaskID)))
|
|
965
|
+
return null;
|
|
966
|
+
const sagaState = ParseTaskGraphParentMetadata(parent.InputPayload).sagaState;
|
|
967
|
+
return sagaState && sagaState !== 'Running' ? refusal : null;
|
|
968
|
+
}
|
|
847
969
|
/** Result shape shared by the control verbs: what happened, and the state that now holds. */
|
|
848
970
|
controlResult(success, debug, errorMessage) {
|
|
849
971
|
return { Success: success, Debug: debug, ErrorMessage: errorMessage };
|
|
@@ -1242,6 +1364,44 @@ export class TaskGraphService {
|
|
|
1242
1364
|
}
|
|
1243
1365
|
return { Success: true, Map: found };
|
|
1244
1366
|
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Refuses a graph whose node names a compensation action by an ID that is not an action (S7).
|
|
1369
|
+
*
|
|
1370
|
+
* The ID is written by the model and stays in the node's JSON until a rollback inserts the
|
|
1371
|
+
* compensation task — the first point a foreign key sees it. There an unknown ID failed the insert
|
|
1372
|
+
* on every pass, so the step was never undone. Checked here, as the caller, before anything is written.
|
|
1373
|
+
*/
|
|
1374
|
+
async validateCompensationActionIDs(spec, context) {
|
|
1375
|
+
const ids = uniqueIDs(spec.tasks.map((node) => ConfigOf(node, 'Action')?.compensation?.compensationActionId?.trim() ?? ''));
|
|
1376
|
+
if (ids.length === 0)
|
|
1377
|
+
return { Success: true };
|
|
1378
|
+
const notIDs = ids.filter((id) => !IsValidUUID(id));
|
|
1379
|
+
if (notIDs.length > 0) {
|
|
1380
|
+
return {
|
|
1381
|
+
Success: false,
|
|
1382
|
+
ErrorMessage: `Task graph "${spec.workflowName}" was not started: ${notIDs.length} compensationActionId value(s) are not action IDs (${notIDs.join(', ')}). Name the action with compensationActionName instead.`,
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
const result = await RunView.FromMetadataProvider(context.Provider).RunView({
|
|
1386
|
+
EntityName: 'MJ: Actions',
|
|
1387
|
+
ExtraFilter: `ID IN (${ids.map((id) => `'${EscapeSQLString(id)}'`).join(',')})`,
|
|
1388
|
+
Fields: ['ID'],
|
|
1389
|
+
ResultType: 'simple',
|
|
1390
|
+
}, context.ContextUser);
|
|
1391
|
+
if (!result.Success) {
|
|
1392
|
+
return { Success: false, ErrorMessage: `Task graph "${spec.workflowName}" was not started: its compensation actions could not be checked (${result.ErrorMessage}).` };
|
|
1393
|
+
}
|
|
1394
|
+
const found = new UUIDSet((result.Results ?? []).map((row) => row.ID));
|
|
1395
|
+
const missing = ids.filter((id) => !found.Has(id));
|
|
1396
|
+
if (missing.length > 0) {
|
|
1397
|
+
return {
|
|
1398
|
+
Success: false,
|
|
1399
|
+
ErrorMessage: `Task graph "${spec.workflowName}" was not started: it names ${missing.length} compensation action(s) that do not exist (${missing.join(', ')}). ` +
|
|
1400
|
+
`Its rollback could never run them.`,
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
return { Success: true };
|
|
1404
|
+
}
|
|
1245
1405
|
async resolveActions(spec, context) {
|
|
1246
1406
|
// Includes a loop's repeated action(s) — see the note in resolveAgents.
|
|
1247
1407
|
const names = [...new Set(spec.tasks.flatMap(actionNamesIn))];
|
|
@@ -1324,6 +1484,28 @@ export class TaskGraphService {
|
|
|
1324
1484
|
}
|
|
1325
1485
|
return rows[0]?.ID ?? null;
|
|
1326
1486
|
}
|
|
1487
|
+
/** Why the submitted envelope cannot be stored and enforced, or null when it can (or there is none). */
|
|
1488
|
+
envelopeRefusal(envelope) {
|
|
1489
|
+
const parsed = ParseTaskSecurityEnvelope(SerializeTaskSecurityEnvelope(envelope));
|
|
1490
|
+
return parsed.Status === 'Invalid' ? parsed.Reason : null;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Writes the starting breakpoints into the parent's `$.debug` after the children exist. Inside the Submit
|
|
1494
|
+
* transaction, so a graph never becomes visible to a dispatcher without them.
|
|
1495
|
+
*/
|
|
1496
|
+
async seedBreakpoints(parentID, taskIDs, context) {
|
|
1497
|
+
const parent = await context.Provider.GetEntityObject('MJ: Tasks', context.ContextUser);
|
|
1498
|
+
if (!(await parent.Load(parentID))) {
|
|
1499
|
+
throw new Error(`Could not load parent task ${parentID} to seed breakpoints`);
|
|
1500
|
+
}
|
|
1501
|
+
const bag = SafeParseObject(parent.InputPayload);
|
|
1502
|
+
const debug = bag.debug && typeof bag.debug === 'object' && !Array.isArray(bag.debug) ? bag.debug : {};
|
|
1503
|
+
bag.debug = { ...debug, breakpoints: taskIDs };
|
|
1504
|
+
parent.InputPayload = JSON.stringify(bag);
|
|
1505
|
+
if (!(await this.saveAsService(parent, 'MJ: Tasks', context))) {
|
|
1506
|
+
throw new Error(`Could not seed breakpoints on parent task ${parentID}: ${parent.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1327
1509
|
/** Writes the parent task that represents the graph as a whole. */
|
|
1328
1510
|
async persistParent(spec, taskTypeID, context) {
|
|
1329
1511
|
const parent = await context.Provider.GetEntityObject('MJ: Tasks', context.ContextUser);
|
|
@@ -1363,6 +1545,7 @@ export class TaskGraphService {
|
|
|
1363
1545
|
continuation: spec.continuation ?? 'message',
|
|
1364
1546
|
reinvokeDepth: context.ReinvokeDepth ?? 0,
|
|
1365
1547
|
failureSemantics: spec.failureSemantics ?? 'block',
|
|
1548
|
+
failurePolicy: spec.failurePolicy ?? 'Halt',
|
|
1366
1549
|
submittedByAgentRunID: context.AgentRunID ?? null,
|
|
1367
1550
|
submittedByUserID: context.ContextUser?.ID ?? null,
|
|
1368
1551
|
parentAgentHierarchy: context.ParentAgentHierarchy,
|
|
@@ -1371,7 +1554,8 @@ export class TaskGraphService {
|
|
|
1371
1554
|
: null,
|
|
1372
1555
|
startPaused: context.Debug?.paused === true,
|
|
1373
1556
|
}));
|
|
1374
|
-
|
|
1557
|
+
parent.SecurityEnvelope = SerializeTaskSecurityEnvelope(context.SecurityEnvelope);
|
|
1558
|
+
if (!(await this.saveAsService(parent, 'MJ: Tasks', context))) {
|
|
1375
1559
|
throw new Error(`Could not create parent task: ${parent.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
1376
1560
|
}
|
|
1377
1561
|
return parent.ID;
|
|
@@ -1479,15 +1663,33 @@ export class TaskGraphService {
|
|
|
1479
1663
|
.map((s) => [s.name, actionIDsByName.get(s.name)])
|
|
1480
1664
|
.filter((entry) => typeof entry[1] === 'string' && entry[1].length > 0))
|
|
1481
1665
|
: undefined;
|
|
1666
|
+
const builtConfig = buildStepConfiguration(node);
|
|
1667
|
+
const resolvedCompensation = builtConfig?.compensation
|
|
1668
|
+
? {
|
|
1669
|
+
...builtConfig.compensation,
|
|
1670
|
+
...(!builtConfig.compensation.compensationActionId &&
|
|
1671
|
+
builtConfig.compensation.compensationActionName &&
|
|
1672
|
+
actionIDsByName.get(builtConfig.compensation.compensationActionName)
|
|
1673
|
+
? { compensationActionId: actionIDsByName.get(builtConfig.compensation.compensationActionName) }
|
|
1674
|
+
: {}),
|
|
1675
|
+
}
|
|
1676
|
+
: undefined;
|
|
1482
1677
|
const configuration = {
|
|
1483
|
-
...
|
|
1678
|
+
...builtConfig,
|
|
1679
|
+
...(resolvedCompensation ? { compensation: resolvedCompensation } : {}),
|
|
1484
1680
|
...(stepActionIds && Object.keys(stepActionIds).length > 0 ? { stepActionIds } : {}),
|
|
1485
1681
|
sequence: ranks.get(node.tempId),
|
|
1682
|
+
// The step's identity across runs of the same workflow (task IDs are per run), so a
|
|
1683
|
+
// person's remembered breakpoints can find this step next time (#3798).
|
|
1684
|
+
stepId: node.tempId,
|
|
1486
1685
|
};
|
|
1487
1686
|
task.Configuration = JSON.stringify(configuration);
|
|
1687
|
+
// Every child carries the envelope, not only the parent: a node is enforced from its
|
|
1688
|
+
// own row too, so losing the parent row can never run it unconstrained.
|
|
1689
|
+
task.SecurityEnvelope = SerializeTaskSecurityEnvelope(context.SecurityEnvelope);
|
|
1488
1690
|
// Input rides in its own column; Description stays human-readable.
|
|
1489
1691
|
task.InputPayload = node.inputPayload ? JSON.stringify(node.inputPayload) : null;
|
|
1490
|
-
if (!(await
|
|
1692
|
+
if (!(await this.saveAsService(task, 'MJ: Tasks', context))) {
|
|
1491
1693
|
throw new Error(`Could not create task "${node.name}": ${task.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
1492
1694
|
}
|
|
1493
1695
|
map.set(node.tempId, task.ID);
|
|
@@ -1543,7 +1745,7 @@ export class TaskGraphService {
|
|
|
1543
1745
|
dep.ExclusiveGroup = edge.exclusiveGroup ?? null;
|
|
1544
1746
|
dep.Priority = edge.priority ?? 0;
|
|
1545
1747
|
dep.Sequence = edge.sequence ?? 0;
|
|
1546
|
-
if (!(await
|
|
1748
|
+
if (!(await this.saveAsService(dep, 'MJ: Task Dependencies', context))) {
|
|
1547
1749
|
throw new Error(`Could not create dependency ${node.tempId} -> ${edge.tempId}: ${dep.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
1548
1750
|
}
|
|
1549
1751
|
})());
|