@atolis-hq/wake 0.4.80 → 0.4.82
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/activities/contracts/event-schema.d.ts +30 -8
- package/dist/src/activities/contracts/event-schema.js +1 -0
- package/dist/src/activities/pr/activity-support.js +1 -0
- package/dist/src/activities/pr/policy.js +1 -1
- package/dist/src/activities/pr/vocabulary.d.ts +1 -0
- package/dist/src/activities/pr/vocabulary.js +1 -0
- package/dist/src/bootstrap/config/root-schema.d.ts +10 -0
- package/dist/src/bootstrap/integration-runtime.js +7 -1
- package/dist/src/bootstrap/surface-api-trigger-applications.js +1 -1
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler.js +3 -0
- package/dist/src/control-plane/application/trigger-diagnostics.d.ts +1 -1
- package/dist/src/control-plane/application/trigger-diagnostics.js +6 -3
- package/dist/src/control-plane/application/trigger-inspection.d.ts +2 -0
- package/dist/src/control-plane/application/trigger-manual-request.js +6 -17
- package/dist/src/control-plane/application/trigger-pending.d.ts +16 -0
- package/dist/src/control-plane/application/trigger-pending.js +58 -0
- package/dist/src/control-plane/application/trigger-projection.d.ts +3 -0
- package/dist/src/control-plane/application/trigger-projection.js +72 -12
- package/dist/src/control-plane/application/trigger-recovery.js +1 -1
- package/dist/src/control-plane/application/trigger-service.js +10 -28
- package/dist/src/integrations/delivery/application/delivery-service.js +14 -3
- package/dist/src/integrations/delivery/application/merged-delivery-evidence.d.ts +12 -0
- package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +67 -0
- package/dist/src/integrations/fake/durable-delivery-provider.d.ts +7 -0
- package/dist/src/integrations/fake/durable-delivery-provider.js +9 -0
- package/dist/src/integrations/github/infrastructure/delivery.d.ts +1 -1
- package/dist/src/integrations/github/infrastructure/delivery.js +26 -1
- package/dist/src/integrations/github/provider.js +12 -0
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/orchestration/contracts/config.d.ts +15 -0
- package/dist/src/orchestration/contracts/config.js +15 -2
- package/dist/src/orchestration/contracts/event-decoder.d.ts +1 -0
- package/dist/src/orchestration/contracts/event-decoder.js +1 -0
- package/dist/src/orchestration/contracts/events.d.ts +1 -0
- package/dist/src/orchestration/contracts/views.d.ts +1 -0
- package/dist/src/orchestration/domain/retry-policy.js +17 -4
- package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
- package/dist/src/surfaces/api/contracts/triggers.d.ts +1 -1
- package/dist/src/surfaces/web-assets/assets/{index-QnREfUBG.js → index-BuVkTveW.js} +2 -2
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControlEventType, TriggerRequestDisposition, selectControlEvent, } from '../contracts/events.js';
|
|
1
|
+
import { ControlEventType, TriggerRequestDisposition, TriggerSourceKind, selectControlEvent, } from '../contracts/events.js';
|
|
2
2
|
export const triggerProjectionName = 'control-plane-triggers';
|
|
3
3
|
export const maximumTriggerSources = 64;
|
|
4
4
|
export const triggerProjection = {
|
|
@@ -26,13 +26,7 @@ export const triggerProjection = {
|
|
|
26
26
|
coalesced: request.disposition === TriggerRequestDisposition.Coalesced
|
|
27
27
|
? {
|
|
28
28
|
...previous.coalesced,
|
|
29
|
-
[request.coordinationKey]:
|
|
30
|
-
...request,
|
|
31
|
-
sources: [
|
|
32
|
-
...(previous.coalesced[request.coordinationKey]?.sources ?? []),
|
|
33
|
-
request.source,
|
|
34
|
-
].slice(0, maximumTriggerSources),
|
|
35
|
-
},
|
|
29
|
+
[request.coordinationKey]: pendingRequest(previous, request),
|
|
36
30
|
}
|
|
37
31
|
: request.disposition === TriggerRequestDisposition.Started
|
|
38
32
|
? previous.coalesced
|
|
@@ -71,7 +65,7 @@ export const triggerProjection = {
|
|
|
71
65
|
...previous,
|
|
72
66
|
pauses: { ...previous.pauses, [payload.triggerId]: payload.reason },
|
|
73
67
|
invocations: pausedInvocations(previous, payload),
|
|
74
|
-
coalesced:
|
|
68
|
+
coalesced: pendingAfterPause(previous.coalesced, payload.coordinationKey),
|
|
75
69
|
};
|
|
76
70
|
}
|
|
77
71
|
case ControlEventType.TriggerResumed: {
|
|
@@ -83,12 +77,43 @@ export const triggerProjection = {
|
|
|
83
77
|
}
|
|
84
78
|
},
|
|
85
79
|
};
|
|
80
|
+
/** A manual head is consumed alone while other manual or automatic work is still queued. */
|
|
81
|
+
function consumesWholeRequest(pending, request) {
|
|
82
|
+
if (pending?.triggerId !== request.triggerId)
|
|
83
|
+
return false;
|
|
84
|
+
if (JSON.stringify(pending.source) !== JSON.stringify(request.source))
|
|
85
|
+
return false;
|
|
86
|
+
return (request.source.kind !== TriggerSourceKind.Manual ||
|
|
87
|
+
(pending.automaticRequests.length === 0 && pending.manualRequests.length <= 1));
|
|
88
|
+
}
|
|
86
89
|
function withoutCoalesced(coalesced, request) {
|
|
87
90
|
const key = request.coordinationKey;
|
|
88
91
|
// An ineligible new occurrence does not discard another trigger's coalesced request.
|
|
89
|
-
if (coalesced[key]
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
if (!consumesWholeRequest(coalesced[key], request)) {
|
|
93
|
+
const pending = coalesced[key];
|
|
94
|
+
if (pending === undefined || request.source.kind !== TriggerSourceKind.Manual)
|
|
95
|
+
return coalesced;
|
|
96
|
+
const commandId = request.source.commandId;
|
|
97
|
+
const retained = pending.manualRequests.filter((manual) => manual.triggerId !== request.triggerId ||
|
|
98
|
+
manual.source.kind !== TriggerSourceKind.Manual ||
|
|
99
|
+
manual.source.commandId !== commandId);
|
|
100
|
+
if (retained.length === pending.manualRequests.length)
|
|
101
|
+
return coalesced;
|
|
102
|
+
// Skipping a manual command must not discard other queued work; the head stays pending work.
|
|
103
|
+
const head = pending.automaticRequests.at(-1) ?? retained.at(-1);
|
|
104
|
+
const removedHead = JSON.stringify(pending.source) === JSON.stringify(request.source);
|
|
105
|
+
return {
|
|
106
|
+
...coalesced,
|
|
107
|
+
[key]: {
|
|
108
|
+
...pending,
|
|
109
|
+
...(removedHead && head !== undefined
|
|
110
|
+
? { ...head, manualOutcome: head.manualOutcome }
|
|
111
|
+
: {}),
|
|
112
|
+
manualRequests: retained,
|
|
113
|
+
sources: pending.sources.filter((source) => source.kind !== TriggerSourceKind.Manual || source.commandId !== commandId),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
92
117
|
const { [key]: _, ...rest } = coalesced;
|
|
93
118
|
return rest;
|
|
94
119
|
}
|
|
@@ -98,3 +123,38 @@ function pausedInvocations(previous, payload) {
|
|
|
98
123
|
? { ...invocation, failureOutcomeCount: payload.outcomeCount }
|
|
99
124
|
: invocation);
|
|
100
125
|
}
|
|
126
|
+
function pendingRequest(previous, request) {
|
|
127
|
+
return {
|
|
128
|
+
...request,
|
|
129
|
+
manualRequests: [
|
|
130
|
+
...(previous.coalesced[request.coordinationKey]?.manualRequests ?? []),
|
|
131
|
+
...(request.source.kind === TriggerSourceKind.Manual ? [request] : []),
|
|
132
|
+
].slice(0, maximumTriggerSources),
|
|
133
|
+
automaticRequests: [
|
|
134
|
+
...(previous.coalesced[request.coordinationKey]?.automaticRequests ?? []),
|
|
135
|
+
...(request.source.kind === TriggerSourceKind.Manual ? [] : [request]),
|
|
136
|
+
].slice(-maximumTriggerSources),
|
|
137
|
+
sources: [
|
|
138
|
+
...(previous.coalesced[request.coordinationKey]?.sources ?? []),
|
|
139
|
+
request.source,
|
|
140
|
+
].slice(0, maximumTriggerSources),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function pendingAfterPause(coalesced, coordinationKey) {
|
|
144
|
+
const request = coalesced[coordinationKey];
|
|
145
|
+
if (request === undefined)
|
|
146
|
+
return coalesced;
|
|
147
|
+
const { [coordinationKey]: _, ...rest } = coalesced;
|
|
148
|
+
const manualRequest = request.manualRequests.at(-1);
|
|
149
|
+
if (manualRequest === undefined)
|
|
150
|
+
return rest;
|
|
151
|
+
return {
|
|
152
|
+
...rest,
|
|
153
|
+
[coordinationKey]: {
|
|
154
|
+
...request,
|
|
155
|
+
...manualRequest,
|
|
156
|
+
automaticRequests: [],
|
|
157
|
+
sources: request.sources.filter((source) => source.kind === TriggerSourceKind.Manual),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -32,7 +32,7 @@ export async function recoverTriggerInvocation(dependencies, invocation, context
|
|
|
32
32
|
return;
|
|
33
33
|
if (exhaustedFailures(instance) &&
|
|
34
34
|
invocation.failureOutcomeCount !== instance.acceptedOutcomes.length) {
|
|
35
|
-
//
|
|
35
|
+
// Workflow retries remain explicit; pause suppresses subsequent automatic sources.
|
|
36
36
|
await dependencies.emit({
|
|
37
37
|
eventType: ControlEventType.TriggerPaused,
|
|
38
38
|
payload: {
|
|
@@ -3,9 +3,10 @@ import { ControlEventType, TriggerRequestDisposition, TriggerSourceKind, } from
|
|
|
3
3
|
import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
|
|
4
4
|
import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
|
|
5
5
|
import { TriggerDiagnostics } from './trigger-diagnostics.js';
|
|
6
|
-
import { appendTriggerFact,
|
|
6
|
+
import { appendTriggerFact, hasTriggerRequest, sourceIdentity, } from './trigger-facts.js';
|
|
7
7
|
import { inspectTriggers } from './trigger-inspection.js';
|
|
8
8
|
import { requestManualTrigger } from './trigger-manual-request.js';
|
|
9
|
+
import { advancePendingTriggers } from './trigger-pending.js';
|
|
9
10
|
import { maximumTriggerSources } from './trigger-projection.js';
|
|
10
11
|
import { recoverTriggerInvocation } from './trigger-recovery.js';
|
|
11
12
|
import { hasActiveInvocation, isOwnScopeSource } from './trigger-rules.js';
|
|
@@ -165,33 +166,14 @@ export class TriggerService {
|
|
|
165
166
|
return eligible;
|
|
166
167
|
}
|
|
167
168
|
async advanceCoalesced(context) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
await this.diagnostics.record(request.triggerId, request.source, reason ?? TriggerSkipReason.Removed);
|
|
177
|
-
// This recorded request was reconsidered and consumed; later eligibility is not a source.
|
|
178
|
-
await this.emit(consumedTriggerRequest(request, reason ?? TriggerSkipReason.Removed), context, `trigger:consume:${request.triggerId}:${sourceIdentity(request.source)}`);
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
await this.emit({
|
|
182
|
-
eventType: ControlEventType.TriggerInvocationClaimed,
|
|
183
|
-
payload: {
|
|
184
|
-
triggerId: config.id,
|
|
185
|
-
coordinationKey: request.coordinationKey,
|
|
186
|
-
source: request.source,
|
|
187
|
-
sources: request.sources,
|
|
188
|
-
workItemId: this.dependencies.ids.next('work'),
|
|
189
|
-
workflowInstanceId: `workflow-${encodeURIComponent(identity)}`,
|
|
190
|
-
workflowName: config.workflow,
|
|
191
|
-
},
|
|
192
|
-
}, context, `${identity}:claim`);
|
|
193
|
-
await this.recover(context);
|
|
194
|
-
}
|
|
169
|
+
await advancePendingTriggers({
|
|
170
|
+
dependencies: this.dependencies,
|
|
171
|
+
diagnostics: this.diagnostics,
|
|
172
|
+
view: () => this.reader.get(),
|
|
173
|
+
configured: (id) => this.configured(id),
|
|
174
|
+
emit: (input, command, id) => this.emit(input, command, id),
|
|
175
|
+
recover: (command) => this.recover(command),
|
|
176
|
+
}, context);
|
|
195
177
|
}
|
|
196
178
|
async recover(context) {
|
|
197
179
|
for (const invocation of (await this.reader.get()).invocations) {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { EventActorKind, EventSourceKind, } from '@atolis-hq/eventing';
|
|
3
3
|
import { deliveryStream, IntegrationStreamKind } from '../../contracts/streams.js';
|
|
4
4
|
import { createDeliveryEventData, } from '../contracts/event-factory.js';
|
|
5
|
-
import { DeliveryEventType } from '../contracts/events.js';
|
|
6
|
-
import { DeliveryResultKind, DeliveryState } from '../contracts/vocabulary.js';
|
|
5
|
+
import { DeliveryEventType, selectDeliveryEvent } from '../contracts/events.js';
|
|
6
|
+
import { DeliveryIntentKind, DeliveryResultKind, DeliveryState } from '../contracts/vocabulary.js';
|
|
7
7
|
export class DeliveryService {
|
|
8
8
|
dependencies;
|
|
9
9
|
constructor(dependencies) {
|
|
@@ -92,7 +92,18 @@ export class DeliveryService {
|
|
|
92
92
|
}
|
|
93
93
|
async append(intent, draft) {
|
|
94
94
|
const stream = deliveryStream(intent.intentEventId);
|
|
95
|
-
const
|
|
95
|
+
const facts = await this.dependencies.journal.readStream(stream);
|
|
96
|
+
// A durable confirmation from merged evidence can win while provider I/O is in flight.
|
|
97
|
+
if (intent.kind === DeliveryIntentKind.PrMerge &&
|
|
98
|
+
facts.some((fact) => {
|
|
99
|
+
const delivery = selectDeliveryEvent(fact);
|
|
100
|
+
return (delivery?.event.eventType === DeliveryEventType.Confirmed ||
|
|
101
|
+
delivery?.event.eventType === DeliveryEventType.Failed ||
|
|
102
|
+
(delivery?.event.eventType === DeliveryEventType.Reconciled &&
|
|
103
|
+
delivery.event.payload.result === DeliveryResultKind.Confirmed));
|
|
104
|
+
}))
|
|
105
|
+
return;
|
|
106
|
+
const sequence = facts.length;
|
|
96
107
|
await this.dependencies.journal.appendToStream(stream, sequence, [
|
|
97
108
|
createDeliveryEventData(draft),
|
|
98
109
|
]);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EventJournal, type ProjectionStore } from '@atolis-hq/eventing';
|
|
2
|
+
import { type PullRequestService } from '../../../activities/index.js';
|
|
3
|
+
import { type OrchestrationService } from '../../../orchestration/index.js';
|
|
4
|
+
import type { DeliveryIntentView } from '../contracts/views.js';
|
|
5
|
+
export declare function reconcileMergedDeliveries(input: {
|
|
6
|
+
readonly journal: EventJournal;
|
|
7
|
+
readonly projections: ProjectionStore;
|
|
8
|
+
readonly orchestration: Pick<OrchestrationService, 'get'>;
|
|
9
|
+
readonly pullRequests: PullRequestService;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
/** Reconcile durable merged evidence only after the exact intent's wait exists. */
|
|
12
|
+
export declare function confirmMergedDelivery(intent: DeliveryIntentView, journal: EventJournal, orchestration: Pick<OrchestrationService, 'get'>, pullRequests: PullRequestService): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { EventActorKind, EventSourceKind, } from '@atolis-hq/eventing';
|
|
2
|
+
import { ActivityEventType, PullRequestState, selectPrimaryPullRequest, } from '../../../activities/index.js';
|
|
3
|
+
import { ActivityActivationStatus, workflowInstanceId, } from '../../../orchestration/index.js';
|
|
4
|
+
import { deliveryStream, IntegrationStreamKind } from '../../contracts/streams.js';
|
|
5
|
+
import { createDeliveryEventData } from '../contracts/event-factory.js';
|
|
6
|
+
import { DeliveryEventType, selectDeliveryEvent } from '../contracts/events.js';
|
|
7
|
+
import { DeliveryIntentKind, DeliveryResultKind, DeliveryState } from '../contracts/vocabulary.js';
|
|
8
|
+
export async function reconcileMergedDeliveries(input) {
|
|
9
|
+
for (const entry of await input.projections.list(IntegrationStreamKind.Delivery)) {
|
|
10
|
+
await confirmMergedDelivery(entry.value, input.journal, input.orchestration, input.pullRequests);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Reconcile durable merged evidence only after the exact intent's wait exists. */
|
|
14
|
+
export async function confirmMergedDelivery(intent, journal, orchestration, pullRequests) {
|
|
15
|
+
if (intent.payload.kind !== DeliveryIntentKind.PrMerge ||
|
|
16
|
+
!('revision' in intent.payload) ||
|
|
17
|
+
(intent.state !== DeliveryState.Pending && intent.state !== DeliveryState.Ambiguous))
|
|
18
|
+
return;
|
|
19
|
+
const instance = await orchestration.get(workflowInstanceId(intent.workflowInstanceId));
|
|
20
|
+
if (!isMatchingWait(instance, intent))
|
|
21
|
+
return;
|
|
22
|
+
const selected = selectPrimaryPullRequest(await pullRequests.authorityInput(instance.workItemId), instance.workItemId);
|
|
23
|
+
if (selected?.pullRequest.resourceId !== intent.resourceId ||
|
|
24
|
+
selected.pullRequest.state !== PullRequestState.Merged ||
|
|
25
|
+
selected.pullRequest.headRevision !== intent.payload.revision)
|
|
26
|
+
return;
|
|
27
|
+
const evidence = (await pullRequests.factsFor(intent.resourceId)).find((fact) => fact.event.eventType === ActivityEventType.PrStateChanged &&
|
|
28
|
+
fact.event.payload.state === PullRequestState.Merged);
|
|
29
|
+
if (evidence === undefined)
|
|
30
|
+
return;
|
|
31
|
+
const stream = deliveryStream(intent.intentEventId);
|
|
32
|
+
const facts = await journal.readStream(stream);
|
|
33
|
+
if (facts.some((fact) => {
|
|
34
|
+
const delivery = selectDeliveryEvent(fact);
|
|
35
|
+
return (delivery?.event.eventType === DeliveryEventType.Failed ||
|
|
36
|
+
delivery?.event.eventType === DeliveryEventType.Confirmed ||
|
|
37
|
+
(delivery?.event.eventType === DeliveryEventType.Reconciled &&
|
|
38
|
+
delivery.event.payload.result === DeliveryResultKind.Confirmed));
|
|
39
|
+
}))
|
|
40
|
+
return;
|
|
41
|
+
await journal.appendToStream(stream, facts.length, [
|
|
42
|
+
createDeliveryEventData({
|
|
43
|
+
eventId: `${intent.intentEventId}:merged-evidence`,
|
|
44
|
+
eventType: DeliveryEventType.Reconciled,
|
|
45
|
+
occurredAt: evidence.event.occurredAt,
|
|
46
|
+
correlationId: evidence.event.correlationId,
|
|
47
|
+
causationId: evidence.event.eventId,
|
|
48
|
+
actor: { kind: EventActorKind.System, id: 'delivery-outcome-reactor' },
|
|
49
|
+
source: { kind: EventSourceKind.Internal, id: IntegrationStreamKind.Delivery },
|
|
50
|
+
payload: {
|
|
51
|
+
intentEventId: intent.intentEventId,
|
|
52
|
+
intentGlobalPosition: intent.globalPosition,
|
|
53
|
+
workflowInstanceId: intent.workflowInstanceId,
|
|
54
|
+
activationId: intent.activationId,
|
|
55
|
+
occurrenceOrdinal: intent.occurrenceOrdinal + 1,
|
|
56
|
+
result: DeliveryResultKind.Confirmed,
|
|
57
|
+
externalId: selected.resource.resource.externalKey.key,
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
function isMatchingWait(instance, intent) {
|
|
63
|
+
return (instance?.pendingActivation?.activationId === intent.activationId &&
|
|
64
|
+
instance.pendingActivation.status === ActivityActivationStatus.Waiting &&
|
|
65
|
+
instance.waitingFor?.signalKind === 'delivery-result' &&
|
|
66
|
+
instance.waitingFor.intentEventId === intent.intentEventId);
|
|
67
|
+
}
|
|
@@ -7,12 +7,19 @@ export declare class DurableFakeDeliveryProvider implements ExternalDeliveryAdap
|
|
|
7
7
|
deliveryCalls: number;
|
|
8
8
|
private ambiguous;
|
|
9
9
|
private crashAfterEffect;
|
|
10
|
+
private deferEffect;
|
|
10
11
|
constructor(options?: DurableFakeDeliveryProviderOptions);
|
|
11
12
|
private readonly effectsFile;
|
|
12
13
|
crashAfterNextEffect(): void;
|
|
14
|
+
deferNextDelivery(): void;
|
|
13
15
|
deliver(intent: DeliveryIntentView): Promise<{
|
|
16
|
+
kind: "ambiguous";
|
|
17
|
+
reconciliationKey: EventId;
|
|
18
|
+
externalId?: never;
|
|
19
|
+
} | {
|
|
14
20
|
kind: "confirmed";
|
|
15
21
|
externalId: string;
|
|
22
|
+
reconciliationKey?: never;
|
|
16
23
|
}>;
|
|
17
24
|
rememberAmbiguous(intentEventId: EventId, reconciliationKey: string): void;
|
|
18
25
|
reconcile(_intent: DeliveryIntentView, reconciliationKey: string): Promise<{
|
|
@@ -5,6 +5,7 @@ export class DurableFakeDeliveryProvider {
|
|
|
5
5
|
deliveryCalls = 0;
|
|
6
6
|
ambiguous = new Map();
|
|
7
7
|
crashAfterEffect = false;
|
|
8
|
+
deferEffect = false;
|
|
8
9
|
constructor(options = {}) {
|
|
9
10
|
this.effects = new Map(Object.entries(options.effects ?? {}));
|
|
10
11
|
this.effectsFile = options.effectsFile;
|
|
@@ -13,8 +14,16 @@ export class DurableFakeDeliveryProvider {
|
|
|
13
14
|
crashAfterNextEffect() {
|
|
14
15
|
this.crashAfterEffect = true;
|
|
15
16
|
}
|
|
17
|
+
deferNextDelivery() {
|
|
18
|
+
this.deferEffect = true;
|
|
19
|
+
}
|
|
16
20
|
async deliver(intent) {
|
|
17
21
|
this.deliveryCalls += 1;
|
|
22
|
+
if (this.deferEffect) {
|
|
23
|
+
this.deferEffect = false;
|
|
24
|
+
this.rememberAmbiguous(intent.intentEventId, intent.intentEventId);
|
|
25
|
+
return { kind: DeliveryResultKind.Ambiguous, reconciliationKey: intent.intentEventId };
|
|
26
|
+
}
|
|
18
27
|
const existing = this.effects.get(intent.intentEventId);
|
|
19
28
|
if (existing !== undefined)
|
|
20
29
|
return { kind: DeliveryResultKind.Confirmed, externalId: existing };
|
|
@@ -3,4 +3,4 @@ import type { DeliveryIntentView } from '../../delivery/contracts/views.js';
|
|
|
3
3
|
export declare function createGitHubDelivery(deliver: (intent: DeliveryIntentView, idempotencyKey: string) => Promise<string>, reconcileIssue?: (intent: DeliveryIntentView) => Promise<string | null>, precondition?: (intent: DeliveryIntentView) => Promise<{
|
|
4
4
|
readonly allowed: boolean;
|
|
5
5
|
readonly reason?: string;
|
|
6
|
-
}>): ExternalDeliveryAdapter;
|
|
6
|
+
}>, mergedTarget?: (intent: DeliveryIntentView) => Promise<string | null>): ExternalDeliveryAdapter;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { BuiltInActivityName } from '../../../activities/index.js';
|
|
2
2
|
import { DeliveryResultKind } from '../../delivery/contracts/vocabulary.js';
|
|
3
3
|
const GitHubDeliveryFailureCode = 'github-error';
|
|
4
|
-
export function createGitHubDelivery(deliver, reconcileIssue, precondition) {
|
|
4
|
+
export function createGitHubDelivery(deliver, reconcileIssue, precondition, mergedTarget) {
|
|
5
|
+
async function confirmedMerge(intent) {
|
|
6
|
+
if (intent.kind !== BuiltInActivityName.PullRequestMerge)
|
|
7
|
+
return null;
|
|
8
|
+
const externalId = await mergedTarget?.(intent);
|
|
9
|
+
return externalId == null ? null : { kind: DeliveryResultKind.Confirmed, externalId };
|
|
10
|
+
}
|
|
5
11
|
return {
|
|
6
12
|
async deliver(intent) {
|
|
7
13
|
try {
|
|
14
|
+
const merged = await confirmedMerge(intent);
|
|
15
|
+
if (merged !== null)
|
|
16
|
+
return merged;
|
|
8
17
|
if (intent.kind === BuiltInActivityName.PullRequestMerge &&
|
|
9
18
|
'autoMerge' in intent.payload &&
|
|
10
19
|
intent.payload.autoMerge) {
|
|
@@ -18,6 +27,14 @@ export function createGitHubDelivery(deliver, reconcileIssue, precondition) {
|
|
|
18
27
|
};
|
|
19
28
|
}
|
|
20
29
|
catch (error) {
|
|
30
|
+
try {
|
|
31
|
+
const merged = await confirmedMerge(intent);
|
|
32
|
+
if (merged !== null)
|
|
33
|
+
return merged;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Unavailable evidence cannot turn a failed attempt into success.
|
|
37
|
+
}
|
|
21
38
|
return {
|
|
22
39
|
kind: DeliveryResultKind.Failed,
|
|
23
40
|
code: GitHubDeliveryFailureCode,
|
|
@@ -26,6 +43,14 @@ export function createGitHubDelivery(deliver, reconcileIssue, precondition) {
|
|
|
26
43
|
}
|
|
27
44
|
},
|
|
28
45
|
async reconcile(intent) {
|
|
46
|
+
if (intent.kind === BuiltInActivityName.PullRequestMerge) {
|
|
47
|
+
try {
|
|
48
|
+
return (await confirmedMerge(intent)) ?? { kind: DeliveryResultKind.Unknown };
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { kind: DeliveryResultKind.Unknown };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
29
54
|
if (intent.kind !== BuiltInActivityName.IssueComplete || reconcileIssue === undefined)
|
|
30
55
|
return { kind: DeliveryResultKind.Unknown };
|
|
31
56
|
try {
|
|
@@ -142,6 +142,18 @@ export const gitHubProviderDefinition = {
|
|
|
142
142
|
catch {
|
|
143
143
|
return { allowed: false, reason: 'lookup-unavailable' };
|
|
144
144
|
}
|
|
145
|
+
}, async (intent) => {
|
|
146
|
+
if (intent.payload.kind !== BuiltInActivityName.PullRequestMerge ||
|
|
147
|
+
!('revision' in intent.payload))
|
|
148
|
+
return null;
|
|
149
|
+
const resource = await services.resources.get(resourceId(intent.resourceId));
|
|
150
|
+
if (resource === null)
|
|
151
|
+
return null;
|
|
152
|
+
const parsed = parsePullRequestKey(resource.externalKey.key);
|
|
153
|
+
if (parsed === null)
|
|
154
|
+
return null;
|
|
155
|
+
const pr = await client.getPullRequest(parsed.owner, parsed.repo, parsed.number);
|
|
156
|
+
return pr.merged && pr.head.sha === intent.payload.revision ? String(pr.id) : null;
|
|
145
157
|
}),
|
|
146
158
|
verifyArtifact: async (kind, externalKey, context) => {
|
|
147
159
|
if (kind !== resourceKind('pull-request'))
|
|
@@ -17,6 +17,7 @@ export * from './contracts/provider.js';
|
|
|
17
17
|
export * from './contracts/reply-routing.js';
|
|
18
18
|
export * from './contracts/streams.js';
|
|
19
19
|
export * from './delivery/application/delivery-outcome-reactor.js';
|
|
20
|
+
export * from './delivery/application/merged-delivery-evidence.js';
|
|
20
21
|
export * from './delivery/application/delivery-projector.js';
|
|
21
22
|
export * from './delivery/application/delivery-service.js';
|
|
22
23
|
export * from './delivery/contracts/commands.js';
|
|
@@ -17,6 +17,7 @@ export * from './contracts/provider.js';
|
|
|
17
17
|
export * from './contracts/reply-routing.js';
|
|
18
18
|
export * from './contracts/streams.js';
|
|
19
19
|
export * from './delivery/application/delivery-outcome-reactor.js';
|
|
20
|
+
export * from './delivery/application/merged-delivery-evidence.js';
|
|
20
21
|
export * from './delivery/application/delivery-projector.js';
|
|
21
22
|
export * from './delivery/application/delivery-service.js';
|
|
22
23
|
export * from './delivery/contracts/commands.js';
|
|
@@ -89,6 +89,11 @@ export declare const outcomeRouteConfigSchema: z.ZodObject<{
|
|
|
89
89
|
}, z.core.$strict>>;
|
|
90
90
|
retry: z.ZodOptional<z.ZodObject<{
|
|
91
91
|
max: z.ZodNumber;
|
|
92
|
+
reasons: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
93
|
+
"checks-pending": "checks-pending";
|
|
94
|
+
"checks-could-not-be-read": "checks-could-not-be-read";
|
|
95
|
+
}>>>;
|
|
96
|
+
delaysMs: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
92
97
|
}, z.core.$strict>>;
|
|
93
98
|
await: z.ZodOptional<z.ZodObject<{
|
|
94
99
|
signal: z.ZodString;
|
|
@@ -152,6 +157,11 @@ export declare const stageConfigSchema: z.ZodObject<{
|
|
|
152
157
|
}, z.core.$strict>>;
|
|
153
158
|
retry: z.ZodOptional<z.ZodObject<{
|
|
154
159
|
max: z.ZodNumber;
|
|
160
|
+
reasons: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
161
|
+
"checks-pending": "checks-pending";
|
|
162
|
+
"checks-could-not-be-read": "checks-could-not-be-read";
|
|
163
|
+
}>>>;
|
|
164
|
+
delaysMs: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
155
165
|
}, z.core.$strict>>;
|
|
156
166
|
await: z.ZodOptional<z.ZodObject<{
|
|
157
167
|
signal: z.ZodString;
|
|
@@ -259,6 +269,11 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
|
|
|
259
269
|
}, z.core.$strict>>;
|
|
260
270
|
retry: z.ZodOptional<z.ZodObject<{
|
|
261
271
|
max: z.ZodNumber;
|
|
272
|
+
reasons: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
273
|
+
"checks-pending": "checks-pending";
|
|
274
|
+
"checks-could-not-be-read": "checks-could-not-be-read";
|
|
275
|
+
}>>>;
|
|
276
|
+
delaysMs: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
262
277
|
}, z.core.$strict>>;
|
|
263
278
|
await: z.ZodOptional<z.ZodObject<{
|
|
264
279
|
signal: z.ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ApprovalAuthorityKind, ConversationSurfaceCapability, WorkflowStatus, } from './vocabulary.js';
|
|
3
|
-
import { ActivityEventType, PullRequestCheckState, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
|
|
3
|
+
import { ActivityEventType, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
|
|
4
4
|
import { WorkspaceMode } from '../../execution/index.js';
|
|
5
5
|
import { MatchMode } from '../../kernel/index.js';
|
|
6
6
|
const identifier = z.string().trim().min(1);
|
|
@@ -106,7 +106,20 @@ export const outcomeRouteConfigSchema = z
|
|
|
106
106
|
activities: z.array(followOnActivityConfigSchema).readonly().optional(),
|
|
107
107
|
then: identifier,
|
|
108
108
|
repeat: bound.optional(),
|
|
109
|
-
retry:
|
|
109
|
+
retry: z
|
|
110
|
+
.object({
|
|
111
|
+
max: z.number().int().positive(),
|
|
112
|
+
reasons: z
|
|
113
|
+
.array(z.enum([PullRequestDenialCode.ChecksUnavailable, PullRequestDenialCode.ChecksPending]))
|
|
114
|
+
.min(1)
|
|
115
|
+
.optional(),
|
|
116
|
+
delaysMs: z.array(z.number().int().positive()).min(1).optional(),
|
|
117
|
+
})
|
|
118
|
+
.strict()
|
|
119
|
+
.refine((value) => value.delaysMs === undefined || value.delaysMs.length === value.max, {
|
|
120
|
+
message: 'retry.delaysMs must contain one delay per retry',
|
|
121
|
+
})
|
|
122
|
+
.optional(),
|
|
110
123
|
await: awaitConfigSchema.optional(),
|
|
111
124
|
watchGates: z.array(watchGateConfigSchema).optional(),
|
|
112
125
|
resourceTransitions: z.array(resourceTransitionConfigSchema).min(1).optional(),
|
|
@@ -52,6 +52,7 @@ export declare const waitingOutcomeSchema: z.ZodPipe<z.ZodObject<{
|
|
|
52
52
|
};
|
|
53
53
|
}>>;
|
|
54
54
|
export declare const activityRequestedSchema: z.ZodObject<{
|
|
55
|
+
notBefore: z.ZodOptional<z.ZodISODateTime>;
|
|
55
56
|
activationId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivationId, string>>;
|
|
56
57
|
ordinal: z.ZodNumber;
|
|
57
58
|
activity: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivityName, string>>;
|
|
@@ -71,6 +71,7 @@ const executionSchema = z
|
|
|
71
71
|
.strict();
|
|
72
72
|
export const activityRequestedSchema = z
|
|
73
73
|
.object({
|
|
74
|
+
notBefore: z.iso.datetime().optional(),
|
|
74
75
|
activationId: brandedStringSchema(activationId),
|
|
75
76
|
ordinal: z.number().int().positive(),
|
|
76
77
|
activity: brandedStringSchema(activityName),
|
|
@@ -174,6 +174,7 @@ export interface GroupBudgetExhaustedPayload extends ChildCoordinationMetadata {
|
|
|
174
174
|
readonly workflowName?: WorkflowName;
|
|
175
175
|
}
|
|
176
176
|
export interface ActivityRequestedPayload {
|
|
177
|
+
readonly notBefore?: string;
|
|
177
178
|
readonly activationId: ActivationId;
|
|
178
179
|
readonly ordinal: number;
|
|
179
180
|
readonly activity: ActivityName;
|
|
@@ -4,6 +4,7 @@ import type { ApprovalAuthority, CompiledResourceTransition, StageConfig, Transi
|
|
|
4
4
|
import type { OrchestrationGroupId, SignalName, StageName, WorkflowInstanceId, WorkflowName } from './identifiers.js';
|
|
5
5
|
import type { ActivityActivationStatus, WorkflowStatus } from './vocabulary.js';
|
|
6
6
|
export interface ActivityActivationView {
|
|
7
|
+
readonly notBefore?: string;
|
|
7
8
|
readonly activationId: ActivationId;
|
|
8
9
|
readonly ordinal: number;
|
|
9
10
|
readonly activity: ActivityName;
|
|
@@ -5,6 +5,13 @@ import { activation, nextOrdinal, stateDraft } from './decision-events.js';
|
|
|
5
5
|
export function mayRetry(route, state, outcome) {
|
|
6
6
|
if (route.retry === undefined || requiresReconciliation(outcome))
|
|
7
7
|
return false;
|
|
8
|
+
if (route.retry.reasons !== undefined) {
|
|
9
|
+
const data = outcome.data;
|
|
10
|
+
if (typeof data !== 'object' || data === null || !('reason' in data))
|
|
11
|
+
return false;
|
|
12
|
+
if (!route.retry.reasons.some((reason) => reason === data.reason))
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
8
15
|
const retryKey = `${state.currentStage}:${outcome.kind}`;
|
|
9
16
|
return (state.retryCounts[retryKey] ?? 0) < route.retry.max;
|
|
10
17
|
}
|
|
@@ -12,12 +19,18 @@ export function requestRetry(events, definition, state, input) {
|
|
|
12
19
|
const retryKey = `${state.currentStage}:${input.outcome.kind}`;
|
|
13
20
|
const count = (state.retryCounts[retryKey] ?? 0) + 1;
|
|
14
21
|
const stage = definition.stages[stageName(state.currentStage)];
|
|
22
|
+
const delay = stage.on[input.outcome.kind]?.retry?.delaysMs?.[count - 1];
|
|
15
23
|
events.push(stateDraft(state, input, { eventType: OrchestrationEventType.RetryCounted, payload: { retryKey, count } }, events.length + 1), stateDraft(state, input, {
|
|
16
24
|
eventType: OrchestrationEventType.ActivityRequested,
|
|
17
|
-
payload:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
payload: {
|
|
26
|
+
...(delay === undefined
|
|
27
|
+
? {}
|
|
28
|
+
: { notBefore: new Date(Date.parse(input.occurredAt) + delay).toISOString() }),
|
|
29
|
+
...activation(state.workflowInstanceId, nextOrdinal(state), stage.activity, stage.with, {
|
|
30
|
+
execution: stage.execution,
|
|
31
|
+
stage: stageName(state.currentStage),
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
21
34
|
}, events.length + 2));
|
|
22
35
|
}
|
|
23
36
|
function requiresReconciliation(outcome) {
|
|
@@ -203,6 +203,7 @@ function applyActivityRequested(state, payload) {
|
|
|
203
203
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.ActivityRequested];
|
|
204
204
|
delete state.waitingFor;
|
|
205
205
|
state.pendingActivation = {
|
|
206
|
+
...(payload.notBefore === undefined ? {} : { notBefore: payload.notBefore }),
|
|
206
207
|
activationId: payload.activationId,
|
|
207
208
|
ordinal: payload.ordinal,
|
|
208
209
|
activity: payload.activity,
|
|
@@ -31,7 +31,7 @@ export interface TriggerResponse {
|
|
|
31
31
|
readonly paused: boolean;
|
|
32
32
|
readonly pauseReason: string | null;
|
|
33
33
|
readonly nextOccurrence: string | null;
|
|
34
|
-
readonly pending: readonly (TriggerView['coalesced'][string] & {
|
|
34
|
+
readonly pending: readonly (Omit<TriggerView['coalesced'][string], 'manualRequests' | 'automaticRequests'> & {
|
|
35
35
|
readonly activeWorkItemId: string | null;
|
|
36
36
|
})[];
|
|
37
37
|
readonly latestSkip: TriggerSkipDiagnostic | null;
|