@atolis-hq/wake 0.3.36 → 0.3.37
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/src/bootstrap/composition-root.js +4 -1
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/advance-once.js +3 -12
- package/dist/src/control-plane/application/execution-reconciliation.js +13 -0
- package/dist/src/integrations/github/application/inbound-comment-syntax.js +21 -0
- package/dist/src/integrations/github/application/inbound-review-signals.js +19 -18
- package/dist/src/orchestration/application/orchestration-service.js +33 -9
- package/dist/src/orchestration/application/request-child.js +49 -2
- package/dist/src/orchestration/application/watch-child-transitions.js +13 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createPullRequestService } from '../activities/index.js';
|
|
2
2
|
import { ControlStreamKind, DispatchPolicy, createAdvanceOnce, createControlPlaneService, createRunnerControlService, ineligibleRunners, } from '../control-plane/index.js';
|
|
3
|
-
import { ExternalExecutionState, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, } from '../execution/index.js';
|
|
3
|
+
import { ExecutionCancellationReason, ExternalExecutionState, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, } from '../execution/index.js';
|
|
4
4
|
import { createGitHubAgentContextReader, gitHubProviderDefinition, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
|
|
5
5
|
import { SystemClock, UlidIdGenerator, } from '../kernel/index.js';
|
|
6
6
|
import { compileWorkflow, createOrchestrationService } from '../orchestration/index.js';
|
|
@@ -73,6 +73,9 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
73
73
|
: {}),
|
|
74
74
|
workspaces,
|
|
75
75
|
});
|
|
76
|
+
orchestration.setWatchChildCancellation({
|
|
77
|
+
cancelSupersededWatchChildren: (workflowInstanceIds) => execution.cancelActive(workflowInstanceIds, ExecutionCancellationReason.WorkflowSuperseded),
|
|
78
|
+
});
|
|
76
79
|
const recovery = new RecoveryService(journal, clock, {
|
|
77
80
|
async inspect() {
|
|
78
81
|
// Unknown external work follows the safe ambiguity path until runners expose inspection.
|
|
@@ -4,6 +4,7 @@ import { WorkflowStatus } from '../../orchestration/index.js';
|
|
|
4
4
|
import { WorkStatus } from '../../work/index.js';
|
|
5
5
|
import { ControlStreamKind } from '../contracts/streams.js';
|
|
6
6
|
import { DispatchPolicy } from '../domain/dispatch-policy.js';
|
|
7
|
+
import { findUnresolvedTerminal, isExecutionFailureTerminal } from './execution-reconciliation.js';
|
|
7
8
|
export function createAdvanceOnce(orchestration, execution, resources, clock, dependencies) {
|
|
8
9
|
const runnerIneligibility = dependencies.runnerIneligibility ?? (async () => new Set());
|
|
9
10
|
const isDispatchPaused = dependencies.isDispatchPaused ?? (async () => false);
|
|
@@ -133,6 +134,8 @@ export function createAdvanceOnce(orchestration, execution, resources, clock, de
|
|
|
133
134
|
// Recheck at the dispatch boundary so maintenance cannot race a selected activation.
|
|
134
135
|
if (await isDispatchPaused())
|
|
135
136
|
return { kind: 'paused' };
|
|
137
|
+
if ((await orchestration.validateActivationDispatch?.(selected.workflow.workflowInstanceId, context(selected.activation.activationId))) === false)
|
|
138
|
+
return { kind: 'no-work' };
|
|
136
139
|
await orchestration.markActivationStarted(selected.workflow.workflowInstanceId, selected.activation.activationId, context(selected.activation.activationId));
|
|
137
140
|
const correlated = await resources.correlationsForWork(selected.workflow.workItemId);
|
|
138
141
|
const resourceViews = (await Promise.all(correlated.map((entry) => resources.get(entry.resourceId)))).filter((resource) => resource !== null);
|
|
@@ -170,15 +173,3 @@ export function createAdvanceOnce(orchestration, execution, resources, clock, de
|
|
|
170
173
|
};
|
|
171
174
|
};
|
|
172
175
|
}
|
|
173
|
-
async function findUnresolvedTerminal(pending, execution) {
|
|
174
|
-
for (const item of pending) {
|
|
175
|
-
const run = (await execution.list(item.activation.activationId)).find((candidate) => (candidate.status === RunStatus.Succeeded && candidate.outcome !== undefined) ||
|
|
176
|
-
isExecutionFailureTerminal(candidate.status));
|
|
177
|
-
if (run !== undefined && !item.workflow.acceptedOutcomes.includes(item.activation.activationId))
|
|
178
|
-
return { item, run };
|
|
179
|
-
}
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
function isExecutionFailureTerminal(status) {
|
|
183
|
-
return (status === RunStatus.Failed || status === RunStatus.Cancelled || status === RunStatus.Ambiguous);
|
|
184
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RunStatus } from '../../execution/index.js';
|
|
2
|
+
export async function findUnresolvedTerminal(pending, execution) {
|
|
3
|
+
for (const item of pending) {
|
|
4
|
+
const run = (await execution.list(item.activation.activationId)).find((candidate) => (candidate.status === RunStatus.Succeeded && candidate.outcome !== undefined) ||
|
|
5
|
+
isExecutionFailureTerminal(candidate.status));
|
|
6
|
+
if (run !== undefined && !item.workflow.acceptedOutcomes.includes(item.activation.activationId))
|
|
7
|
+
return { item, run };
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
export function isExecutionFailureTerminal(status) {
|
|
12
|
+
return (status === RunStatus.Failed || status === RunStatus.Cancelled || status === RunStatus.Ambiguous);
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReviewActorKind } from '../../../activities/index.js';
|
|
2
|
+
export function isHumanNonWakeReply(actorKind, body) {
|
|
3
|
+
return actorKind === ReviewActorKind.Human && !body.includes('<!-- wake:');
|
|
4
|
+
}
|
|
5
|
+
export function recognizedCommand(body) {
|
|
6
|
+
const normalized = body.trim().toLowerCase();
|
|
7
|
+
if (normalized === '/approved')
|
|
8
|
+
return '/approved';
|
|
9
|
+
if (normalized === '/changes' || normalized.startsWith('/changes '))
|
|
10
|
+
return '/changes';
|
|
11
|
+
if (normalized === '/retry')
|
|
12
|
+
return '/retry';
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export function isPlainReply(body) {
|
|
16
|
+
const normalized = body.trim();
|
|
17
|
+
return normalized.length > 0 && !normalized.startsWith('/');
|
|
18
|
+
}
|
|
19
|
+
export function shouldResumeBlockedStage(command, plainReply) {
|
|
20
|
+
return command === '/changes' || plainReply;
|
|
21
|
+
}
|
|
@@ -3,6 +3,7 @@ import { ApprovalAuthorityKind } from '../../../orchestration/index.js';
|
|
|
3
3
|
import { BuiltInResourceKind, ResourceCorrelationRole, ResourceStreamKind, resourceId, } from '../../../resources/index.js';
|
|
4
4
|
import { WorkStatus } from '../../../work/index.js';
|
|
5
5
|
import { UnknownGitHubIdentity } from '../contracts/vocabulary.js';
|
|
6
|
+
import { isHumanNonWakeReply, isPlainReply, recognizedCommand, shouldResumeBlockedStage, } from './inbound-comment-syntax.js';
|
|
6
7
|
import { commandContext } from './inbound-context.js';
|
|
7
8
|
import { ignoreIneligibleOperatorRetry } from './operator-retry-command.js';
|
|
8
9
|
import { translateGitHubReviewCommand } from './review-command-translator.js';
|
|
@@ -61,7 +62,7 @@ async function applyFormalReviewSignal(input) {
|
|
|
61
62
|
}
|
|
62
63
|
async function applyIssueReviewSignal(input) {
|
|
63
64
|
const { event, resources, work, lookup, orchestration, adapter } = input;
|
|
64
|
-
if (event.payload.actor.kind
|
|
65
|
+
if (!isHumanNonWakeReply(event.payload.actor.kind, event.payload.body))
|
|
65
66
|
return;
|
|
66
67
|
if (resources === undefined || lookup === undefined || orchestration === undefined)
|
|
67
68
|
return;
|
|
@@ -73,15 +74,15 @@ async function applyIssueReviewSignal(input) {
|
|
|
73
74
|
return;
|
|
74
75
|
const resource = await resources.get(resourceIdValue);
|
|
75
76
|
const command = recognizedCommand(event.payload.body);
|
|
77
|
+
const plainReply = isPlainReply(event.payload.body);
|
|
76
78
|
if (command === '/retry') {
|
|
77
|
-
|
|
79
|
+
return applyIssueRetrySignal({
|
|
78
80
|
event,
|
|
79
81
|
resources,
|
|
80
82
|
work,
|
|
81
83
|
orchestration,
|
|
82
84
|
resourceId: resourceIdValue,
|
|
83
85
|
});
|
|
84
|
-
return;
|
|
85
86
|
}
|
|
86
87
|
if (resource?.kind === BuiltInResourceKind.PullRequest) {
|
|
87
88
|
await applyWorkflowSignal({
|
|
@@ -90,11 +91,24 @@ async function applyIssueReviewSignal(input) {
|
|
|
90
91
|
orchestration,
|
|
91
92
|
resourceId: resourceIdValue,
|
|
92
93
|
outcome: command === '/approved' ? ActivityOutcomeKind.Done : ActivityOutcomeKind.Rejected,
|
|
94
|
+
acceptWaitingSignal: command !== null,
|
|
95
|
+
resumeBlockedOnChanges: shouldResumeBlockedStage(command, plainReply),
|
|
93
96
|
});
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
96
99
|
if (command !== null)
|
|
97
100
|
await applyIssueApprovalSignal({ ...input, command });
|
|
101
|
+
else if (plainReply) {
|
|
102
|
+
await applyWorkflowSignal({
|
|
103
|
+
event,
|
|
104
|
+
resources,
|
|
105
|
+
orchestration,
|
|
106
|
+
resourceId: resourceIdValue,
|
|
107
|
+
outcome: ActivityOutcomeKind.Rejected,
|
|
108
|
+
acceptWaitingSignal: false,
|
|
109
|
+
resumeBlockedOnChanges: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
98
112
|
}
|
|
99
113
|
async function applyIssueRetrySignal(input) {
|
|
100
114
|
const { event, resources, work, orchestration, resourceId: resourceIdValue } = input;
|
|
@@ -161,14 +175,14 @@ async function applyPullRequestWorkflowSignal(input) {
|
|
|
161
175
|
});
|
|
162
176
|
}
|
|
163
177
|
async function applyWorkflowSignal(input) {
|
|
164
|
-
const { event, resources, orchestration, resourceId: resourceIdValue, outcome, resumeBlockedOnChanges = false, } = input;
|
|
178
|
+
const { event, resources, orchestration, resourceId: resourceIdValue, outcome, acceptWaitingSignal = true, resumeBlockedOnChanges = false, } = input;
|
|
165
179
|
const workItemIds = (await resources.correlations(resourceIdValue))
|
|
166
180
|
.filter((correlation) => correlation.role === ResourceCorrelationRole.Primary)
|
|
167
181
|
.map((correlation) => correlation.workItemId);
|
|
168
182
|
for (const workflow of await orchestration.listAll()) {
|
|
169
183
|
if (!workItemIds.includes(workflow.workItemId))
|
|
170
184
|
continue;
|
|
171
|
-
if (workflow.waitingFor !== undefined) {
|
|
185
|
+
if (workflow.waitingFor !== undefined && acceptWaitingSignal) {
|
|
172
186
|
await orchestration.acceptSignal(workflow.workflowInstanceId, {
|
|
173
187
|
kind: workflow.waitingFor.signalKind,
|
|
174
188
|
outcome,
|
|
@@ -188,16 +202,3 @@ async function applyWorkflowSignal(input) {
|
|
|
188
202
|
}
|
|
189
203
|
}
|
|
190
204
|
}
|
|
191
|
-
function isWakeDelivery(body) {
|
|
192
|
-
return body.includes('<!-- wake:');
|
|
193
|
-
}
|
|
194
|
-
function recognizedCommand(body) {
|
|
195
|
-
const normalized = body.trim().toLowerCase();
|
|
196
|
-
if (normalized === '/approved')
|
|
197
|
-
return '/approved';
|
|
198
|
-
if (normalized === '/changes' || normalized.startsWith('/changes '))
|
|
199
|
-
return '/changes';
|
|
200
|
-
if (normalized === '/retry')
|
|
201
|
-
return '/retry';
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
@@ -6,6 +6,7 @@ import { GroupBudgetRecorder } from './group-budget-recorder.js';
|
|
|
6
6
|
import { OrchestrationRepository } from './orchestration-repository.js';
|
|
7
7
|
import { RequestChild } from './request-child.js';
|
|
8
8
|
import { StartWorkflow } from './start-workflow.js';
|
|
9
|
+
import { continuesWaitingForSameWatchGate } from './watch-child-transitions.js';
|
|
9
10
|
import { WorkflowDefinitionRegistry } from './workflow-definition-registry.js';
|
|
10
11
|
export class OrchestrationService {
|
|
11
12
|
startWorkflow;
|
|
@@ -14,6 +15,7 @@ export class OrchestrationService {
|
|
|
14
15
|
advanceWorkflow;
|
|
15
16
|
childWorkflows;
|
|
16
17
|
coordinateAcceptSignal = (operation) => operation();
|
|
18
|
+
watchChildCancellation;
|
|
17
19
|
constructor(journal, work, definitions, projections) {
|
|
18
20
|
const repository = new OrchestrationRepository(journal);
|
|
19
21
|
const claims = new CoordinationClaims(journal);
|
|
@@ -33,34 +35,40 @@ export class OrchestrationService {
|
|
|
33
35
|
return this.childWorkflows.rejectCausalActivation(request, context);
|
|
34
36
|
}
|
|
35
37
|
acceptOutcome(command, context) {
|
|
36
|
-
return this.acceptActivityOutcome.execute(command, context);
|
|
38
|
+
return this.transitionWatchChildren(context, () => this.acceptActivityOutcome.execute(command, context));
|
|
37
39
|
}
|
|
38
40
|
waitForSignal(workflowInstanceId, expectation, context) {
|
|
39
|
-
return this.acceptWorkflowSignal.wait(workflowInstanceId, expectation, context);
|
|
41
|
+
return this.transitionWatchChildren(context, () => this.acceptWorkflowSignal.wait(workflowInstanceId, expectation, context));
|
|
40
42
|
}
|
|
41
43
|
acceptSignal(workflowInstanceId, signal, context) {
|
|
42
|
-
return this.coordinateAcceptSignal(() => this.acceptWorkflowSignal.execute(workflowInstanceId, signal, context));
|
|
44
|
+
return this.coordinateAcceptSignal(() => this.transitionWatchChildren(context, () => this.acceptWorkflowSignal.execute(workflowInstanceId, signal, context)));
|
|
43
45
|
}
|
|
44
46
|
setAcceptSignalOperationCoordinator(coordinator) {
|
|
45
47
|
this.coordinateAcceptSignal = coordinator;
|
|
46
48
|
}
|
|
49
|
+
setWatchChildCancellation(cancellation) {
|
|
50
|
+
this.watchChildCancellation = cancellation;
|
|
51
|
+
}
|
|
47
52
|
requestSupplementalActivity(workflowInstanceId, request, context) {
|
|
48
53
|
return this.advanceWorkflow.requestSupplementalActivity(workflowInstanceId, request, context);
|
|
49
54
|
}
|
|
50
55
|
markActivationStarted(workflowInstanceId, activationId, context) {
|
|
51
56
|
return this.advanceWorkflow.markActivationStarted(workflowInstanceId, activationId, context);
|
|
52
57
|
}
|
|
58
|
+
validateActivationDispatch(workflowInstanceId, context) {
|
|
59
|
+
return this.childWorkflows.validateChildDispatch(workflowInstanceId, context);
|
|
60
|
+
}
|
|
53
61
|
block(workflowInstanceId, reason, context) {
|
|
54
|
-
return this.advanceWorkflow.block(workflowInstanceId, reason, context);
|
|
62
|
+
return this.transitionWatchChildren(context, () => this.advanceWorkflow.block(workflowInstanceId, reason, context));
|
|
55
63
|
}
|
|
56
64
|
resolveExecutionFailure(workflowInstanceId, input, context) {
|
|
57
|
-
return this.advanceWorkflow.resolveExecutionFailure(workflowInstanceId, input, context);
|
|
65
|
+
return this.transitionWatchChildren(context, () => this.advanceWorkflow.resolveExecutionFailure(workflowInstanceId, input, context));
|
|
58
66
|
}
|
|
59
67
|
retryBlockedFailedStage(workflowInstanceId, context) {
|
|
60
|
-
return this.advanceWorkflow.retryBlockedFailedStage(workflowInstanceId, context);
|
|
68
|
+
return this.transitionWatchChildren(context, () => this.advanceWorkflow.retryBlockedFailedStage(workflowInstanceId, context));
|
|
61
69
|
}
|
|
62
70
|
resumeBlockedStageForChanges(workflowInstanceId, context) {
|
|
63
|
-
return this.advanceWorkflow.resumeBlockedStageForChanges(workflowInstanceId, context);
|
|
71
|
+
return this.transitionWatchChildren(context, () => this.advanceWorkflow.resumeBlockedStageForChanges(workflowInstanceId, context));
|
|
64
72
|
}
|
|
65
73
|
get(id) {
|
|
66
74
|
return this.advanceWorkflow.get(id);
|
|
@@ -78,7 +86,23 @@ export class OrchestrationService {
|
|
|
78
86
|
return this.advanceWorkflow.listAll();
|
|
79
87
|
}
|
|
80
88
|
reconcileChildCompletions(context) {
|
|
81
|
-
return this.childWorkflows.reconcileChildCompletions(context);
|
|
89
|
+
return this.transitionWatchChildren(context, () => this.childWorkflows.reconcileChildCompletions(context));
|
|
90
|
+
}
|
|
91
|
+
async transitionWatchChildren(context, operation) {
|
|
92
|
+
const before = await this.advanceWorkflow.listAll();
|
|
93
|
+
const result = await operation();
|
|
94
|
+
const after = new Map((await this.advanceWorkflow.listAll()).map((workflow) => [
|
|
95
|
+
workflow.workflowInstanceId,
|
|
96
|
+
workflow,
|
|
97
|
+
]));
|
|
98
|
+
for (const prior of before) {
|
|
99
|
+
if (continuesWaitingForSameWatchGate(prior, after.get(prior.workflowInstanceId) ?? null))
|
|
100
|
+
continue;
|
|
101
|
+
const superseded = await this.childWorkflows.supersedeChildrenForWait(prior.workflowInstanceId, prior.waitingFor, context);
|
|
102
|
+
if (superseded.length > 0)
|
|
103
|
+
await this.watchChildCancellation?.cancelSupersededWatchChildren(superseded);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
82
106
|
}
|
|
83
107
|
isCausalRepeat(workflowInstanceId, triggerId, causalCycleId, requestId) {
|
|
84
108
|
return this.childWorkflows.isCausalRepeat(workflowInstanceId, triggerId, causalCycleId, requestId);
|
|
@@ -90,7 +114,7 @@ export class OrchestrationService {
|
|
|
90
114
|
return this.advanceWorkflow.listResourceTransitionMatches(event);
|
|
91
115
|
}
|
|
92
116
|
applyResourceTransition(workflowInstanceId, target, evidenceId, context) {
|
|
93
|
-
return this.advanceWorkflow.applyResourceTransition(workflowInstanceId, target, evidenceId, context);
|
|
117
|
+
return this.transitionWatchChildren(context, () => this.advanceWorkflow.applyResourceTransition(workflowInstanceId, target, evidenceId, context));
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
120
|
export const createOrchestrationService = (journal, work, definitions, projections) => new OrchestrationService(journal, work, definitions, projections);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
2
|
-
import { signalName } from '../contracts/identifiers.js';
|
|
2
|
+
import { signalName, watchId } from '../contracts/identifiers.js';
|
|
3
3
|
import { childOrchestrationGroupStream } from '../contracts/streams.js';
|
|
4
|
-
import { WorkflowStatus } from '../contracts/vocabulary.js';
|
|
4
|
+
import { ApprovalAuthorityKind, WorkflowStatus } from '../contracts/vocabulary.js';
|
|
5
5
|
import { childMetadata, childRequestId, coordinationMetadata } from '../domain/child-policy.js';
|
|
6
6
|
import { coordinationDraft } from '../domain/coordination-events.js';
|
|
7
7
|
import { stateDraft } from '../domain/decision-events.js';
|
|
@@ -65,6 +65,39 @@ export class RequestChild {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
async supersedeChildrenForWait(parentWorkflowInstanceId, wait, context) {
|
|
69
|
+
const watchIds = watchIdsFor(wait);
|
|
70
|
+
if (watchIds.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
const children = (await this.advance.listAll()).filter((child) => child.parentWorkflowInstanceId === parentWorkflowInstanceId &&
|
|
73
|
+
child.watchId !== undefined &&
|
|
74
|
+
watchIds.includes(child.watchId) &&
|
|
75
|
+
child.status !== WorkflowStatus.Completed &&
|
|
76
|
+
child.status !== WorkflowStatus.Superseded);
|
|
77
|
+
for (const child of children) {
|
|
78
|
+
const loaded = await this.repository.loadRequired(child.workflowInstanceId);
|
|
79
|
+
if (loaded.view.status === WorkflowStatus.Completed ||
|
|
80
|
+
loaded.view.status === WorkflowStatus.Superseded)
|
|
81
|
+
continue;
|
|
82
|
+
await this.repository.append(child.workflowInstanceId, loaded.sequence, [
|
|
83
|
+
stateDraft(loaded.view, { occurredAt: context.occurredAt, causationId: context.commandId }, OrchestrationEventType.InstanceSuperseded, {}, 1),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
return children.map((child) => child.workflowInstanceId);
|
|
87
|
+
}
|
|
88
|
+
async validateChildDispatch(childWorkflowInstanceId, context) {
|
|
89
|
+
const child = await this.repository.loadRequired(childWorkflowInstanceId);
|
|
90
|
+
if (child.view.parentWorkflowInstanceId === undefined)
|
|
91
|
+
return true;
|
|
92
|
+
const parent = await this.repository.loadRequired(child.view.parentWorkflowInstanceId);
|
|
93
|
+
if (child.view.watchId !== undefined && parentWaitsForWatch(parent.view, child.view.watchId))
|
|
94
|
+
return true;
|
|
95
|
+
if (child.view.status !== WorkflowStatus.Superseded)
|
|
96
|
+
await this.repository.append(childWorkflowInstanceId, child.sequence, [
|
|
97
|
+
stateDraft(child.view, { occurredAt: context.occurredAt, causationId: context.commandId }, OrchestrationEventType.InstanceSuperseded, {}, 1),
|
|
98
|
+
]);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
68
101
|
async isCausalRepeat(workflowInstanceId, triggerId, causalCycleId, requestId) {
|
|
69
102
|
const parent = await this.repository.loadRequired(workflowInstanceId);
|
|
70
103
|
return (await this.advance.listAll()).some((view) => view.orchestrationGroupId === parent.view.orchestrationGroupId &&
|
|
@@ -78,6 +111,8 @@ export class RequestChild {
|
|
|
78
111
|
}
|
|
79
112
|
async complete(child, context) {
|
|
80
113
|
const metadata = childMetadata(child);
|
|
114
|
+
if (child.watchId === undefined)
|
|
115
|
+
throw new Error('Child workflow is missing watch provenance');
|
|
81
116
|
const childLoaded = await this.repository.loadRequired(child.workflowInstanceId);
|
|
82
117
|
if (!childLoaded.view.childCompletionRecorded)
|
|
83
118
|
await this.repository.append(child.workflowInstanceId, childLoaded.sequence, [
|
|
@@ -91,6 +126,7 @@ export class RequestChild {
|
|
|
91
126
|
actorId: 'orchestration',
|
|
92
127
|
actorDecision: { authorized: true, evidenceId: child.workflowInstanceId },
|
|
93
128
|
providerEventId: child.workflowInstanceId,
|
|
129
|
+
authority: { kind: ApprovalAuthorityKind.Watch, watch: watchId(child.watchId) },
|
|
94
130
|
childWorkflowInstanceId: child.workflowInstanceId,
|
|
95
131
|
requestId: metadata.requestId,
|
|
96
132
|
};
|
|
@@ -119,3 +155,14 @@ export class RequestChild {
|
|
|
119
155
|
}, eventType, payload, ordinal);
|
|
120
156
|
}
|
|
121
157
|
}
|
|
158
|
+
function parentWaitsForWatch(parent, watchId) {
|
|
159
|
+
if (parent.status !== WorkflowStatus.Waiting)
|
|
160
|
+
return false;
|
|
161
|
+
const watchIds = watchIdsFor(parent.waitingFor);
|
|
162
|
+
return watchIds.includes(watchId);
|
|
163
|
+
}
|
|
164
|
+
function watchIdsFor(wait) {
|
|
165
|
+
if (wait?.from === undefined)
|
|
166
|
+
return [];
|
|
167
|
+
return (wait.from ?? []).flatMap((authority) => authority.kind === ApprovalAuthorityKind.Watch ? [authority.watch] : []);
|
|
168
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ApprovalAuthorityKind } from '../contracts/vocabulary.js';
|
|
2
|
+
export function continuesWaitingForSameWatchGate(before, after) {
|
|
3
|
+
if (before.waitingFor === undefined || after?.waitingFor === undefined)
|
|
4
|
+
return false;
|
|
5
|
+
if (before.status !== after.status ||
|
|
6
|
+
before.waitingFor.signalKind !== after.waitingFor.signalKind)
|
|
7
|
+
return false;
|
|
8
|
+
const watches = (wait) => (wait.from ?? [])
|
|
9
|
+
.filter((authority) => authority.kind === ApprovalAuthorityKind.Watch)
|
|
10
|
+
.map((authority) => authority.watch)
|
|
11
|
+
.sort();
|
|
12
|
+
return JSON.stringify(watches(before.waitingFor)) === JSON.stringify(watches(after.waitingFor));
|
|
13
|
+
}
|