@atolis-hq/wake 0.4.114 → 0.4.116
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/activity.d.ts +2 -0
- package/dist/src/activities/contracts/event-schema.d.ts +77 -0
- package/dist/src/activities/contracts/event-schema.js +2 -0
- package/dist/src/activities/contracts/observed-streams.d.ts +9 -0
- package/dist/src/activities/contracts/observed-streams.js +9 -0
- package/dist/src/activities/index.d.ts +1 -0
- package/dist/src/activities/index.js +1 -0
- package/dist/src/activities/pr/activity-support.js +2 -0
- package/dist/src/activities/pr/application.js +21 -6
- package/dist/src/activities/pr/contracts.d.ts +3 -0
- package/dist/src/activities/pr/merge.js +5 -1
- package/dist/src/bootstrap/board-projection.d.ts +1 -0
- package/dist/src/bootstrap/board-projection.js +17 -2
- package/dist/src/bootstrap/external-ref.d.ts +1 -0
- package/dist/src/bootstrap/external-ref.js +14 -3
- package/dist/src/bootstrap/integration-runtime.js +3 -1
- package/dist/src/bootstrap/surface-api-applications.js +3 -1
- package/dist/src/bootstrap/surface-api-merge-policy.d.ts +1 -0
- package/dist/src/bootstrap/surface-cli-applications.js +13 -10
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/contracts/events.js +15 -3
- package/dist/src/orchestration/application/observed-state-reactor.d.ts +4 -0
- package/dist/src/orchestration/application/observed-state-reactor.js +23 -0
- package/dist/src/orchestration/application/observed-state-retry.d.ts +5 -0
- package/dist/src/orchestration/application/observed-state-retry.js +102 -0
- package/dist/src/orchestration/application/orchestration-service.d.ts +2 -0
- package/dist/src/orchestration/application/orchestration-service.js +4 -0
- package/dist/src/orchestration/contracts/activity-outcome.js +6 -1
- package/dist/src/orchestration/contracts/event-decoder.d.ts +14 -0
- package/dist/src/orchestration/contracts/event-decoder.js +17 -1
- package/dist/src/orchestration/contracts/event-factory.js +2 -0
- package/dist/src/orchestration/contracts/events.d.ts +11 -1
- package/dist/src/orchestration/contracts/events.js +1 -0
- package/dist/src/orchestration/contracts/observed-retry-description.d.ts +2 -0
- package/dist/src/orchestration/contracts/observed-retry-description.js +7 -0
- package/dist/src/orchestration/contracts/views.d.ts +9 -1
- package/dist/src/orchestration/domain/interpreter.js +16 -1
- package/dist/src/orchestration/domain/transition.d.ts +1 -0
- package/dist/src/orchestration/domain/transition.js +8 -1
- package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +7 -0
- package/dist/src/orchestration/index.d.ts +2 -0
- package/dist/src/orchestration/index.js +2 -0
- package/dist/src/surfaces/api/contracts/board.d.ts +2 -0
- package/dist/src/surfaces/api/contracts/orchestration.d.ts +1 -0
- package/dist/src/surfaces/api/presenters/orchestration.js +10 -1
- package/dist/src/surfaces/cli/commands/audit.d.ts +2 -0
- package/dist/src/surfaces/cli/commands/audit.js +27 -2
- package/dist/src/surfaces/cli/main.d.ts +2 -0
- package/dist/src/surfaces/web-assets/assets/index-KZEn2twL.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-BDXgDwPe.js +0 -1192
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
2
|
+
import { OrchestrationEventType } from '../contracts/events.js';
|
|
3
|
+
import { signalName } from '../contracts/identifiers.js';
|
|
4
|
+
import { WorkflowStatus } from '../contracts/vocabulary.js';
|
|
5
|
+
import { activation, nextOrdinal, stateDraft } from '../domain/decision-events.js';
|
|
6
|
+
import { reactorCommandContext } from './reactor-command-context.js';
|
|
7
|
+
/** Catch up from the read snapshot, including facts arriving before the wait was recorded. */
|
|
8
|
+
export async function retryObservedState(repository, journal, gate, trigger) {
|
|
9
|
+
for (const { view } of await repository.list()) {
|
|
10
|
+
if (view?.waitingFor?.observed === undefined)
|
|
11
|
+
continue;
|
|
12
|
+
await gate.run(view.workflowInstanceId, async () => {
|
|
13
|
+
const loaded = await repository.loadRequired(view.workflowInstanceId);
|
|
14
|
+
const state = loaded.view;
|
|
15
|
+
if (!eligible(state))
|
|
16
|
+
return state;
|
|
17
|
+
const advanced = await advancingEvent(journal, state);
|
|
18
|
+
if (advanced === undefined)
|
|
19
|
+
return state;
|
|
20
|
+
await repository.append(state.workflowInstanceId, loaded.sequence, retryEvents(state, advanced, trigger));
|
|
21
|
+
return (await repository.loadRequired(state.workflowInstanceId)).view;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return (await repository.list()).some(({ view }) => view !== null && eligible(view));
|
|
25
|
+
}
|
|
26
|
+
function eligible(state) {
|
|
27
|
+
return (state.status === WorkflowStatus.Waiting &&
|
|
28
|
+
state.pendingActivation !== undefined &&
|
|
29
|
+
state.lastOutcome?.kind === ActivityOutcomeKind.Blocked &&
|
|
30
|
+
state.waitingFor?.signalKind === signalName(ActivityOutcomeKind.Blocked) &&
|
|
31
|
+
state.waitingFor.observed !== undefined &&
|
|
32
|
+
!(state.observedRetry?.activationId === state.pendingActivation.activationId &&
|
|
33
|
+
state.observedRetry.exhausted));
|
|
34
|
+
}
|
|
35
|
+
async function advancingEvent(journal, state) {
|
|
36
|
+
const snapshots = await Promise.all(state.waitingFor.observed.map(async (observation) => ({
|
|
37
|
+
observation,
|
|
38
|
+
events: await journal.readStream(observation.stream),
|
|
39
|
+
})));
|
|
40
|
+
const consumed = retryChain(state)?.observed;
|
|
41
|
+
for (const { observation, events } of snapshots) {
|
|
42
|
+
const cursor = consumed?.find(({ stream }) => stream.kind === observation.stream.kind && stream.id === observation.stream.id);
|
|
43
|
+
const version = Math.max(observation.version, cursor?.version ?? 0);
|
|
44
|
+
// An activity's own decision/audit writes do not invalidate its read set.
|
|
45
|
+
const advanced = events.find((event) => {
|
|
46
|
+
const cause = event.event.causationId;
|
|
47
|
+
return event.sequence > version && cause !== state.pendingActivation.activationId;
|
|
48
|
+
});
|
|
49
|
+
if (advanced !== undefined)
|
|
50
|
+
return {
|
|
51
|
+
event: advanced,
|
|
52
|
+
observed: snapshots.map(({ observation: read, events: facts }) => ({
|
|
53
|
+
stream: read.stream,
|
|
54
|
+
version: facts.length,
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
function retryEvents(state, advanced, trigger) {
|
|
61
|
+
const pending = state.pendingActivation;
|
|
62
|
+
const chain = retryChain(state);
|
|
63
|
+
const context = reactorCommandContext(advanced.event, `observed-state-retry:${pending.activationId}`, 'observed-state-reactor');
|
|
64
|
+
const input = { occurredAt: trigger.event.occurredAt, causationId: context.commandId };
|
|
65
|
+
const count = chain?.count ?? 0;
|
|
66
|
+
const exhausted = count >= 5;
|
|
67
|
+
const next = nextActivation(state, pending);
|
|
68
|
+
const events = [
|
|
69
|
+
stateDraft(state, input, {
|
|
70
|
+
eventType: OrchestrationEventType.ObservedStateRetryRecorded,
|
|
71
|
+
payload: {
|
|
72
|
+
rootActivationId: chain?.rootActivationId ?? pending.activationId,
|
|
73
|
+
activationId: exhausted ? pending.activationId : next.activationId,
|
|
74
|
+
triggerEventId: advanced.event.event.eventId,
|
|
75
|
+
observed: advanced.observed,
|
|
76
|
+
count: exhausted ? count : count + 1,
|
|
77
|
+
exhausted,
|
|
78
|
+
},
|
|
79
|
+
}, 1),
|
|
80
|
+
];
|
|
81
|
+
if (!exhausted)
|
|
82
|
+
events.push(stateDraft(state, input, {
|
|
83
|
+
eventType: OrchestrationEventType.ActivityRequested,
|
|
84
|
+
payload: next,
|
|
85
|
+
}, 2));
|
|
86
|
+
return events;
|
|
87
|
+
}
|
|
88
|
+
function retryChain(state) {
|
|
89
|
+
return state.observedRetry?.activationId === state.pendingActivation?.activationId
|
|
90
|
+
? state.observedRetry
|
|
91
|
+
: undefined;
|
|
92
|
+
}
|
|
93
|
+
function nextActivation(state, pending) {
|
|
94
|
+
return activation(state.workflowInstanceId, nextOrdinal(state), pending.activity, pending.input, {
|
|
95
|
+
execution: pending.execution,
|
|
96
|
+
...(pending.stage === undefined ? {} : { stage: pending.stage }),
|
|
97
|
+
...(pending.followOnIndex === undefined ? {} : { followOnIndex: pending.followOnIndex }),
|
|
98
|
+
...(pending.supplemental === undefined ? {} : { supplemental: pending.supplemental }),
|
|
99
|
+
...(pending.sessionPolicy === undefined ? {} : { sessionPolicy: pending.sessionPolicy }),
|
|
100
|
+
...(pending.watchDriven === undefined ? {} : { watchDriven: pending.watchDriven }),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { DelegationArtifacts, DelegationAuthority, DelegationMessages, Dele
|
|
|
2
2
|
import type { DelegationAttentionReply, DelegationCaller, DelegationSubmission } from '../contracts/delegation.js';
|
|
3
3
|
import type { DeliveryIntegration } from '../contracts/delivery-ports.js';
|
|
4
4
|
import type { DeliveryCandidateCommand, DeliveryMaintenanceCommand, DeliveryQaCommand, DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
5
|
+
import { retryObservedState } from './observed-state-retry.js';
|
|
5
6
|
import type { ResourceTransitionEvidence } from './resource-transition-evidence.js';
|
|
6
7
|
import type { CommandContext, EventJournal, ProjectionStore } from '@atolis-hq/eventing';
|
|
7
8
|
import { type ActivationId, type ActivityOutcome, type ParentActionRequest } from '../../activities/index.js';
|
|
@@ -724,6 +725,7 @@ export declare class OrchestrationService {
|
|
|
724
725
|
extendBlockedGroupBudget(workflowInstanceId: WorkflowInstanceId, authority: {
|
|
725
726
|
readonly kind: string;
|
|
726
727
|
}, context: CommandContext): Promise<import("../contracts/views.js").GroupBudgetExhaustedView | WorkflowInstanceView>;
|
|
728
|
+
retryObservedState(event: Parameters<typeof retryObservedState>[3]): Promise<boolean>;
|
|
727
729
|
get(id: WorkflowInstanceId): Promise<WorkflowInstanceView | null>;
|
|
728
730
|
getPrimaryWorkflowInstanceId(workItemId: WorkItemId): Promise<string | undefined>;
|
|
729
731
|
listPendingActivations(workItemId?: string): Promise<import("./pending-activations.js").PendingActivationEntry[]>;
|
|
@@ -5,6 +5,7 @@ import { DelegationCommands } from './delegation-commands.js';
|
|
|
5
5
|
import { DelegationGate } from './delegation-gate.js';
|
|
6
6
|
import { DeliveryCoordinator } from './delivery-coordinator.js';
|
|
7
7
|
import { expireTimedOutWaits } from './expire-timed-out-waits.js';
|
|
8
|
+
import { retryObservedState } from './observed-state-retry.js';
|
|
8
9
|
import { recoverPolicyBlockedMerges } from './policy-blocked-merge-recovery.js';
|
|
9
10
|
import { WorkStatus, } from '../../work/index.js';
|
|
10
11
|
import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
|
|
@@ -385,6 +386,9 @@ export class OrchestrationService {
|
|
|
385
386
|
requestId: toWorkflowInstanceId(exhausted.requestId),
|
|
386
387
|
}, { ...context, commandId: `${context.commandId}:dispatch` });
|
|
387
388
|
}
|
|
389
|
+
retryObservedState(event) {
|
|
390
|
+
return retryObservedState(this.repository, this.journal, this.delegationGate, event);
|
|
391
|
+
}
|
|
388
392
|
get(id) {
|
|
389
393
|
return this.advanceWorkflow.get(id);
|
|
390
394
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { ActivityOutcomeKind, } from '../../activities/index.js';
|
|
1
|
+
import { ActivityOutcomeKind, observedStreamsSchema, } from '../../activities/index.js';
|
|
2
2
|
import { signalName } from './identifiers.js';
|
|
3
3
|
export function orchestrationActivityOutcome(outcome) {
|
|
4
|
+
if (outcome.observed !== undefined) {
|
|
5
|
+
if (outcome.kind !== ActivityOutcomeKind.Blocked)
|
|
6
|
+
throw new Error('Only blocked outcomes may observe streams');
|
|
7
|
+
observedStreamsSchema.parse(outcome.observed);
|
|
8
|
+
}
|
|
4
9
|
if (outcome.kind !== ActivityOutcomeKind.Waiting)
|
|
5
10
|
return outcome;
|
|
6
11
|
if (typeof outcome.data !== 'object' || outcome.data === null)
|
|
@@ -37,6 +37,13 @@ export declare const childMetadataSchema: z.ZodObject<{
|
|
|
37
37
|
export declare const outcomeSchema: z.ZodObject<{
|
|
38
38
|
kind: z.ZodString;
|
|
39
39
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
40
|
+
observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
41
|
+
stream: z.ZodObject<{
|
|
42
|
+
kind: z.ZodString;
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
version: z.ZodNumber;
|
|
46
|
+
}, z.core.$strict>>>;
|
|
40
47
|
}, z.core.$strict>;
|
|
41
48
|
export declare const waitingOutcomeSchema: z.ZodPipe<z.ZodObject<{
|
|
42
49
|
kind: z.ZodLiteral<"waiting">;
|
|
@@ -73,6 +80,13 @@ export declare const activityRequestedSchema: z.ZodObject<{
|
|
|
73
80
|
}, z.core.$strict>;
|
|
74
81
|
export declare const expectationSchema: z.ZodObject<{
|
|
75
82
|
signalKind: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identifiers.js").SignalName, string>>;
|
|
83
|
+
observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
84
|
+
stream: z.ZodObject<{
|
|
85
|
+
kind: z.ZodString;
|
|
86
|
+
id: z.ZodString;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
version: z.ZodNumber;
|
|
89
|
+
}, z.core.$strict>>>;
|
|
76
90
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
77
91
|
waitStartedAt: z.ZodOptional<z.ZodString>;
|
|
78
92
|
suppressWatchDispatch: z.ZodOptional<z.ZodLiteral<true>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observedStreamsSchema } from '../../activities/index.js';
|
|
1
2
|
/* eslint-disable max-lines */
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { delegationAttentionRequestSchema, delegationAttentionResolvedSchema, delegationAttentionResponseSchema, delegationInputsSchema, delegationJoinSchema, delegationReservationSchema, delegationResultSchema, delegationWaitSchema, } from './delegation.js';
|
|
@@ -50,7 +51,11 @@ export const childMetadataShape = {
|
|
|
50
51
|
};
|
|
51
52
|
export const childMetadataSchema = z.object(childMetadataShape).strict();
|
|
52
53
|
export const outcomeSchema = z
|
|
53
|
-
.object({
|
|
54
|
+
.object({
|
|
55
|
+
kind: z.string().min(1),
|
|
56
|
+
data: z.unknown().optional(),
|
|
57
|
+
observed: observedStreamsSchema.optional(),
|
|
58
|
+
})
|
|
54
59
|
.strict();
|
|
55
60
|
export const waitingOutcomeSchema = z
|
|
56
61
|
.object({
|
|
@@ -131,6 +136,7 @@ const resourceTransitionSchema = z
|
|
|
131
136
|
export const expectationSchema = z
|
|
132
137
|
.object({
|
|
133
138
|
signalKind: brandedStringSchema(signalName),
|
|
139
|
+
observed: observedStreamsSchema.optional(),
|
|
134
140
|
timeoutMs: z.number().int().positive().optional(),
|
|
135
141
|
waitStartedAt: z.string().datetime().optional(),
|
|
136
142
|
suppressWatchDispatch: z.literal(true).optional(),
|
|
@@ -301,6 +307,16 @@ const eventSchemas = {
|
|
|
301
307
|
outcome: waitingOutcomeSchema,
|
|
302
308
|
})
|
|
303
309
|
.strict()),
|
|
310
|
+
[OrchestrationEventType.ObservedStateRetryRecorded]: workflowEnvelope(OrchestrationEventType.ObservedStateRetryRecorded, z
|
|
311
|
+
.object({
|
|
312
|
+
observed: observedStreamsSchema.optional(),
|
|
313
|
+
rootActivationId: z.string().min(1),
|
|
314
|
+
activationId: z.string().min(1),
|
|
315
|
+
triggerEventId: z.string().min(1),
|
|
316
|
+
count: z.number().int().min(0).max(5),
|
|
317
|
+
exhausted: z.boolean(),
|
|
318
|
+
})
|
|
319
|
+
.strict()),
|
|
304
320
|
[OrchestrationEventType.SignalWaitStarted]: workflowEnvelope(OrchestrationEventType.SignalWaitStarted, expectationSchema),
|
|
305
321
|
[OrchestrationEventType.SignalDeferred]: workflowEnvelope(OrchestrationEventType.SignalDeferred, z
|
|
306
322
|
.object({
|
|
@@ -54,6 +54,8 @@ export function createOrchestrationEventData(input) {
|
|
|
54
54
|
return createEventData(input);
|
|
55
55
|
case OrchestrationEventType.ActivityWaiting:
|
|
56
56
|
return createEventData(input);
|
|
57
|
+
case OrchestrationEventType.ObservedStateRetryRecorded:
|
|
58
|
+
return createEventData(input);
|
|
57
59
|
case OrchestrationEventType.SignalWaitStarted:
|
|
58
60
|
return createEventData(input);
|
|
59
61
|
case OrchestrationEventType.SignalDeferred:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventDataUnion, EventUnion } from '@atolis-hq/eventing';
|
|
2
|
-
import type { ActivationId, ActivityName, ActivityOutcome, ActivityOutcomeKind } from '../../activities/index.js';
|
|
2
|
+
import type { ActivationId, ActivityName, ActivityOutcome, ActivityOutcomeKind, ObservedStream } from '../../activities/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
4
|
import type { OrchestrationWaitingActivityOutcome } from './activity-outcome.js';
|
|
5
5
|
import type { ApprovalAuthority, CompiledResourceTransition, CompiledWorkflow, StageConfig, TransitionTarget } from './config.js';
|
|
@@ -34,6 +34,7 @@ export declare const OrchestrationEventType: {
|
|
|
34
34
|
readonly ActivityExecutionFailed: "orchestration.activity-execution-failed";
|
|
35
35
|
readonly ActivityRetriedForRunnerQuota: "orchestration.activity-retried-for-runner-quota";
|
|
36
36
|
readonly ActivityWaiting: "orchestration.activity-waiting";
|
|
37
|
+
readonly ObservedStateRetryRecorded: "orchestration.observed-state-retry-recorded";
|
|
37
38
|
readonly SignalWaitStarted: "orchestration.signal-wait-started";
|
|
38
39
|
readonly SignalAccepted: "orchestration.signal-accepted";
|
|
39
40
|
readonly SignalDeferred: "orchestration.signal-deferred";
|
|
@@ -154,6 +155,14 @@ export interface OrchestrationEventPayloads {
|
|
|
154
155
|
readonly activationId: ActivationId;
|
|
155
156
|
readonly outcome: OrchestrationWaitingActivityOutcome;
|
|
156
157
|
};
|
|
158
|
+
readonly [OrchestrationEventType.ObservedStateRetryRecorded]: {
|
|
159
|
+
readonly observed?: readonly ObservedStream[] | undefined;
|
|
160
|
+
readonly rootActivationId: string;
|
|
161
|
+
readonly activationId: string;
|
|
162
|
+
readonly triggerEventId: string;
|
|
163
|
+
readonly count: number;
|
|
164
|
+
readonly exhausted: boolean;
|
|
165
|
+
};
|
|
157
166
|
readonly [OrchestrationEventType.SignalWaitStarted]: SignalExpectation;
|
|
158
167
|
readonly [OrchestrationEventType.SignalAccepted]: OrchestrationSignal;
|
|
159
168
|
readonly [OrchestrationEventType.SupplementalActivityQueued]: {
|
|
@@ -265,6 +274,7 @@ export interface ActivityRequestedPayload {
|
|
|
265
274
|
}
|
|
266
275
|
export interface SignalExpectation {
|
|
267
276
|
readonly signalKind: SignalName;
|
|
277
|
+
readonly observed?: readonly ObservedStream[] | undefined;
|
|
268
278
|
/** Present only for an explicit workflow await with a configured deadline. */
|
|
269
279
|
readonly timeoutMs?: number | undefined;
|
|
270
280
|
/** The control-plane time recorded by the durable wait-start event. */
|
|
@@ -26,6 +26,7 @@ export const OrchestrationEventType = {
|
|
|
26
26
|
ActivityExecutionFailed: 'orchestration.activity-execution-failed',
|
|
27
27
|
ActivityRetriedForRunnerQuota: 'orchestration.activity-retried-for-runner-quota',
|
|
28
28
|
ActivityWaiting: 'orchestration.activity-waiting',
|
|
29
|
+
ObservedStateRetryRecorded: 'orchestration.observed-state-retry-recorded',
|
|
29
30
|
SignalWaitStarted: 'orchestration.signal-wait-started',
|
|
30
31
|
SignalAccepted: 'orchestration.signal-accepted',
|
|
31
32
|
SignalDeferred: 'orchestration.signal-deferred',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WorkStreamKind } from '../../work/index.js';
|
|
2
|
+
export function observedRetryDescription(observed, exhausted = false) {
|
|
3
|
+
if (exhausted)
|
|
4
|
+
return 'blocked, observed-state retries exhausted (5 retries)';
|
|
5
|
+
const streams = observed.map(({ stream }) => `${stream.kind === WorkStreamKind.WorkItem ? 'work' : stream.kind}:${stream.id}`);
|
|
6
|
+
return `blocked, will retry when ${streams.join(', ')} change`;
|
|
7
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActivationId, ActivityName, ActivityOutcome } from '../../activities/index.js';
|
|
1
|
+
import type { ActivationId, ActivityName, ActivityOutcome, ObservedStream } from '../../activities/index.js';
|
|
2
2
|
import type { WorkItemId } from '../../work/index.js';
|
|
3
3
|
import type { ApprovalAuthority, CompiledResourceTransition, StageConfig, TransitionTarget } from './config.js';
|
|
4
4
|
import type { OrchestrationGroupId, SignalName, StageName, WorkflowInstanceId, WorkflowName } from './identifiers.js';
|
|
@@ -19,6 +19,7 @@ export interface ActivityActivationView {
|
|
|
19
19
|
}
|
|
20
20
|
export interface SignalExpectationView {
|
|
21
21
|
readonly signalKind: SignalName;
|
|
22
|
+
readonly observed?: readonly ObservedStream[] | undefined;
|
|
22
23
|
readonly timeoutMs?: number;
|
|
23
24
|
readonly waitStartedAt?: string;
|
|
24
25
|
readonly suppressWatchDispatch?: true;
|
|
@@ -74,6 +75,13 @@ export interface WorkflowInstanceView {
|
|
|
74
75
|
readonly repeatCounts: Readonly<Record<string, number>>;
|
|
75
76
|
readonly retryCounts: Readonly<Record<string, number>>;
|
|
76
77
|
readonly waitingFor?: SignalExpectationView;
|
|
78
|
+
readonly observedRetry?: {
|
|
79
|
+
readonly observed?: readonly ObservedStream[] | undefined;
|
|
80
|
+
readonly rootActivationId: string;
|
|
81
|
+
readonly activationId: string;
|
|
82
|
+
readonly count: number;
|
|
83
|
+
readonly exhausted: boolean;
|
|
84
|
+
};
|
|
77
85
|
readonly supplementalQueue: readonly SupplementalActivityView[];
|
|
78
86
|
readonly acceptedSignalIds: readonly string[];
|
|
79
87
|
readonly operatorRetryCommandIds: readonly string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
2
2
|
import { OrchestrationEventType, } from '../contracts/events.js';
|
|
3
|
-
import { stageName } from '../contracts/identifiers.js';
|
|
3
|
+
import { signalName, stageName } from '../contracts/identifiers.js';
|
|
4
4
|
import { acceptOutcomeDraft, isPendingOutcome, requestFollowOn, } from './activation-policy.js';
|
|
5
5
|
import { stateDraft } from './decision-events.js';
|
|
6
6
|
import { mayRetry, requestRetry } from './retry-policy.js';
|
|
@@ -24,6 +24,16 @@ export function acceptActivityOutcome(definition, state, input) {
|
|
|
24
24
|
return { kind: 'append', events };
|
|
25
25
|
}
|
|
26
26
|
const route = definition.stages[stageName(state.currentStage)]?.on[input.outcome.kind];
|
|
27
|
+
if (hasObservedBlockWithoutRoute(route, input.outcome)) {
|
|
28
|
+
events.push(stateDraft(state, input, {
|
|
29
|
+
eventType: OrchestrationEventType.SignalWaitStarted,
|
|
30
|
+
payload: {
|
|
31
|
+
signalKind: signalName(ActivityOutcomeKind.Blocked),
|
|
32
|
+
observed: input.outcome.observed,
|
|
33
|
+
},
|
|
34
|
+
}, 2));
|
|
35
|
+
return { kind: 'append', events };
|
|
36
|
+
}
|
|
27
37
|
if (route === undefined) {
|
|
28
38
|
// The outcome still durably happened even though this stage never
|
|
29
39
|
// declared how to route it — recording it (not just blocking) is what
|
|
@@ -51,3 +61,8 @@ export function acceptActivityOutcome(definition, state, input) {
|
|
|
51
61
|
finishRoute(events, definition, state, input, route);
|
|
52
62
|
return { kind: 'append', events };
|
|
53
63
|
}
|
|
64
|
+
function hasObservedBlockWithoutRoute(route, outcome) {
|
|
65
|
+
return (route === undefined &&
|
|
66
|
+
outcome.kind === ActivityOutcomeKind.Blocked &&
|
|
67
|
+
outcome.observed !== undefined);
|
|
68
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
1
2
|
import { OrchestrationEventType, ResourceTransitionSignal, WatchGateVerdictSignal, } from '../contracts/events.js';
|
|
2
3
|
import { ApprovalAuthorityKind, TransitionTargetKind } from '../contracts/vocabulary.js';
|
|
3
4
|
import { activation, nextOrdinal, stateDraft } from './decision-events.js';
|
|
@@ -83,7 +84,13 @@ export function resumeToTarget(events, definition, state, input, target, watchDr
|
|
|
83
84
|
if (target.kind === TransitionTargetKind.AwaitSignal) {
|
|
84
85
|
events.push(stateDraft(state, input, {
|
|
85
86
|
eventType: OrchestrationEventType.SignalWaitStarted,
|
|
86
|
-
payload: {
|
|
87
|
+
payload: {
|
|
88
|
+
signalKind: target.signal,
|
|
89
|
+
...(input.outcome?.kind === ActivityOutcomeKind.Blocked &&
|
|
90
|
+
input.outcome.observed !== undefined
|
|
91
|
+
? { observed: input.outcome.observed }
|
|
92
|
+
: {}),
|
|
93
|
+
},
|
|
87
94
|
}, events.length + 1));
|
|
88
95
|
return;
|
|
89
96
|
}
|
|
@@ -33,6 +33,7 @@ export type MutableWorkflowInstance = {
|
|
|
33
33
|
repeatCounts: Record<string, number>;
|
|
34
34
|
retryCounts: Record<string, number>;
|
|
35
35
|
waitingFor?: WorkflowInstanceView['waitingFor'];
|
|
36
|
+
observedRetry?: WorkflowInstanceView['observedRetry'];
|
|
36
37
|
supplementalQueue: Array<WorkflowInstanceView['supplementalQueue'][number]>;
|
|
37
38
|
acceptedSignalIds: string[];
|
|
38
39
|
operatorRetryCommandIds: string[];
|
|
@@ -112,6 +112,8 @@ function isLifecycleFact(event) {
|
|
|
112
112
|
case OrchestrationEventType.RetryCounted:
|
|
113
113
|
case OrchestrationEventType.InstanceCompleted:
|
|
114
114
|
case OrchestrationEventType.InstanceBlocked:
|
|
115
|
+
case OrchestrationEventType.ObservedStateRetryRecorded:
|
|
116
|
+
return true;
|
|
115
117
|
case OrchestrationEventType.OperatorRetryRequested:
|
|
116
118
|
case OrchestrationEventType.InstanceSuperseded:
|
|
117
119
|
return true;
|
|
@@ -144,6 +146,9 @@ function applyLifecycleFact(state, event) {
|
|
|
144
146
|
else
|
|
145
147
|
state.deliveryGateBlock = event.payload.deliveryGate;
|
|
146
148
|
return;
|
|
149
|
+
case OrchestrationEventType.ObservedStateRetryRecorded:
|
|
150
|
+
state.observedRetry = event.payload;
|
|
151
|
+
return;
|
|
147
152
|
case OrchestrationEventType.OperatorRetryRequested:
|
|
148
153
|
state.operatorRetryCommandIds.push(event.payload.commandId);
|
|
149
154
|
return;
|
|
@@ -247,6 +252,7 @@ function applySignalWaitStarted(state, event) {
|
|
|
247
252
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.SignalWaitStarted];
|
|
248
253
|
state.waitingFor = {
|
|
249
254
|
signalKind: event.payload.signalKind,
|
|
255
|
+
...(event.payload.observed === undefined ? {} : { observed: event.payload.observed }),
|
|
250
256
|
...(event.payload.timeoutMs === undefined ? {} : { timeoutMs: event.payload.timeoutMs }),
|
|
251
257
|
...(event.payload.waitStartedAt === undefined
|
|
252
258
|
? {}
|
|
@@ -316,6 +322,7 @@ export function immutableWorkflowInstanceView(state) {
|
|
|
316
322
|
? {}
|
|
317
323
|
: { deliveryGateBlock: state.deliveryGateBlock }),
|
|
318
324
|
currentStage: state.currentStage,
|
|
325
|
+
...(state.observedRetry === undefined ? {} : { observedRetry: state.observedRetry }),
|
|
319
326
|
repeatCounts: state.repeatCounts,
|
|
320
327
|
retryCounts: state.retryCounts,
|
|
321
328
|
supplementalQueue: state.supplementalQueue,
|
|
@@ -8,6 +8,7 @@ export * from './application/pull-request-transition-evidence.js';
|
|
|
8
8
|
export { isPolicyBlockedMergeWait } from './application/policy-blocked-merge-recovery.js';
|
|
9
9
|
export * from './application/resource-transition-evidence.js';
|
|
10
10
|
export * from './application/resource-transition-matching.js';
|
|
11
|
+
export * from './application/observed-state-reactor.js';
|
|
11
12
|
export * from './application/resource-transition-reactor.js';
|
|
12
13
|
export * from './application/signal-reactor.js';
|
|
13
14
|
export * from './application/watch-reactor.js';
|
|
@@ -23,6 +24,7 @@ export * from './contracts/events.js';
|
|
|
23
24
|
export * from './contracts/event-factory.js';
|
|
24
25
|
export * from './contracts/identifiers.js';
|
|
25
26
|
export * from './contracts/streams.js';
|
|
27
|
+
export * from './contracts/observed-retry-description.js';
|
|
26
28
|
export * from './contracts/views.js';
|
|
27
29
|
export * from './contracts/vocabulary.js';
|
|
28
30
|
export * from './domain/compiler.js';
|
|
@@ -8,6 +8,7 @@ export * from './application/pull-request-transition-evidence.js';
|
|
|
8
8
|
export { isPolicyBlockedMergeWait } from './application/policy-blocked-merge-recovery.js';
|
|
9
9
|
export * from './application/resource-transition-evidence.js';
|
|
10
10
|
export * from './application/resource-transition-matching.js';
|
|
11
|
+
export * from './application/observed-state-reactor.js';
|
|
11
12
|
export * from './application/resource-transition-reactor.js';
|
|
12
13
|
export * from './application/signal-reactor.js';
|
|
13
14
|
export * from './application/watch-reactor.js';
|
|
@@ -23,6 +24,7 @@ export * from './contracts/events.js';
|
|
|
23
24
|
export * from './contracts/event-factory.js';
|
|
24
25
|
export * from './contracts/identifiers.js';
|
|
25
26
|
export * from './contracts/streams.js';
|
|
27
|
+
export * from './contracts/observed-retry-description.js';
|
|
26
28
|
export * from './contracts/views.js';
|
|
27
29
|
export * from './contracts/vocabulary.js';
|
|
28
30
|
export * from './domain/compiler.js';
|
|
@@ -32,6 +32,7 @@ export interface BoardCardResponse {
|
|
|
32
32
|
readonly stage?: string;
|
|
33
33
|
/** Why the primary workflow is blocked, when it requires operator intervention. */
|
|
34
34
|
readonly blockReason?: string;
|
|
35
|
+
readonly retryCondition?: string;
|
|
35
36
|
readonly dwellSince: string;
|
|
36
37
|
readonly runCount: number;
|
|
37
38
|
readonly activeRuns?: Readonly<Record<string, BoardCardActiveRun>>;
|
|
@@ -46,6 +47,7 @@ export interface BoardCardResponse {
|
|
|
46
47
|
readonly totalCostUsd: number;
|
|
47
48
|
readonly totalDurationMs: number;
|
|
48
49
|
readonly externalRef?: string;
|
|
50
|
+
readonly repository?: string;
|
|
49
51
|
}
|
|
50
52
|
export interface BoardResponse {
|
|
51
53
|
readonly conditionCounts: Partial<Record<BoardCardCondition, number>>;
|
|
@@ -8,6 +8,7 @@ export interface WorkflowInstanceResponse {
|
|
|
8
8
|
readonly currentStage: string;
|
|
9
9
|
/** Why a blocked workflow requires operator intervention. */
|
|
10
10
|
readonly blockReason?: string;
|
|
11
|
+
readonly retryCondition?: string;
|
|
11
12
|
readonly retryEligible?: boolean;
|
|
12
13
|
readonly extendEligible?: boolean;
|
|
13
14
|
readonly mergePolicyBlock?: MergePolicyBlockResponse;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, WorkflowStatus, } from '../../../orchestration/index.js';
|
|
1
|
+
import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, observedRetryDescription, WorkflowStatus, } from '../../../orchestration/index.js';
|
|
2
2
|
import { toWorkItemKey } from '../contracts/work.js';
|
|
3
3
|
export function presentWorkflowInstance(value) {
|
|
4
4
|
return {
|
|
@@ -11,6 +11,7 @@ export function presentWorkflowInstance(value) {
|
|
|
11
11
|
: { parentWorkflowInstanceId: value.parentWorkflowInstanceId }),
|
|
12
12
|
status: value.status,
|
|
13
13
|
currentStage: value.currentStage,
|
|
14
|
+
...observedRetryCondition(value),
|
|
14
15
|
...(value.status === WorkflowStatus.Blocked && value.blockReason !== undefined
|
|
15
16
|
? { blockReason: value.blockReason }
|
|
16
17
|
: {}),
|
|
@@ -21,3 +22,11 @@ export function presentWorkflowInstance(value) {
|
|
|
21
22
|
: { waitingFor: { signalKind: value.waitingFor.signalKind } }),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
function observedRetryCondition(value) {
|
|
26
|
+
if (value.status !== WorkflowStatus.Waiting || value.waitingFor?.observed === undefined)
|
|
27
|
+
return {};
|
|
28
|
+
return {
|
|
29
|
+
retryCondition: observedRetryDescription(value.waitingFor.observed, value.observedRetry?.activationId === value.pendingActivation?.activationId &&
|
|
30
|
+
value.observedRetry?.exhausted),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -7,6 +7,7 @@ export interface AuditWork {
|
|
|
7
7
|
}
|
|
8
8
|
export interface AuditFact {
|
|
9
9
|
readonly event: EventEnvelope['event'] & Omit<EventEnvelope, 'event'>;
|
|
10
|
+
readonly retryCondition?: string;
|
|
10
11
|
readonly causalLinks: {
|
|
11
12
|
readonly causationId: string;
|
|
12
13
|
readonly correlationId: string;
|
|
@@ -14,3 +15,4 @@ export interface AuditFact {
|
|
|
14
15
|
}
|
|
15
16
|
/** Reads canonical journal facts, not a projection, so it remains useful during rebuilds. */
|
|
16
17
|
export declare function audit(journal: AuditJournal, work: AuditWork, workItemId: string): Promise<readonly AuditFact[]>;
|
|
18
|
+
export declare function auditFacts(journal: AuditJournal, workItemId: string): Promise<readonly AuditFact[]>;
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import { OrchestrationEventType, isWorkflowInstanceStream, observedRetryDescription, selectWorkflowOrchestrationEvent, } from '../../../orchestration/index.js';
|
|
2
|
+
import { WorkStreamKind } from '../../../work/index.js';
|
|
1
3
|
/** Reads canonical journal facts, not a projection, so it remains useful during rebuilds. */
|
|
2
4
|
export async function audit(journal, work, workItemId) {
|
|
3
5
|
await work.get(workItemId);
|
|
4
|
-
return (
|
|
5
|
-
|
|
6
|
+
return auditFacts(journal, workItemId);
|
|
7
|
+
}
|
|
8
|
+
export async function auditFacts(journal, workItemId) {
|
|
9
|
+
const events = await journal.readAll(0);
|
|
10
|
+
const workflowStreams = new Set(events.flatMap((event) => {
|
|
11
|
+
const fact = selectWorkflowOrchestrationEvent(event);
|
|
12
|
+
return fact?.event.eventType === OrchestrationEventType.InstanceStarted &&
|
|
13
|
+
fact.event.payload.workItemId === workItemId
|
|
14
|
+
? [fact.stream.id]
|
|
15
|
+
: [];
|
|
16
|
+
}));
|
|
17
|
+
return events
|
|
18
|
+
.filter((event) => (event.stream.kind === WorkStreamKind.WorkItem && event.stream.id === workItemId) ||
|
|
19
|
+
(isWorkflowInstanceStream(event.stream) && workflowStreams.has(event.stream.id)))
|
|
6
20
|
.map((event) => ({
|
|
21
|
+
...retryDescription(event),
|
|
7
22
|
event: {
|
|
8
23
|
...event.event,
|
|
9
24
|
stream: event.stream,
|
|
@@ -17,3 +32,13 @@ export async function audit(journal, work, workItemId) {
|
|
|
17
32
|
},
|
|
18
33
|
}));
|
|
19
34
|
}
|
|
35
|
+
function retryDescription(event) {
|
|
36
|
+
const fact = selectWorkflowOrchestrationEvent(event);
|
|
37
|
+
if (fact?.event.eventType === OrchestrationEventType.SignalWaitStarted &&
|
|
38
|
+
fact.event.payload.observed !== undefined)
|
|
39
|
+
return { retryCondition: observedRetryDescription(fact.event.payload.observed) };
|
|
40
|
+
if (fact?.event.eventType === OrchestrationEventType.ObservedStateRetryRecorded &&
|
|
41
|
+
fact.event.payload.exhausted)
|
|
42
|
+
return { retryCondition: observedRetryDescription([], true) };
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
@@ -52,6 +52,8 @@ export type WakeCommand = ({
|
|
|
52
52
|
readonly arguments: readonly string[];
|
|
53
53
|
};
|
|
54
54
|
export interface AuditRecord {
|
|
55
|
+
readonly payload?: unknown;
|
|
56
|
+
readonly retryCondition?: string;
|
|
55
57
|
readonly eventId: string;
|
|
56
58
|
readonly eventType: string;
|
|
57
59
|
readonly occurredAt: string;
|