@atolis-hq/wake 0.4.115 → 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.
Files changed (49) hide show
  1. package/dist/src/activities/contracts/activity.d.ts +2 -0
  2. package/dist/src/activities/contracts/event-schema.d.ts +77 -0
  3. package/dist/src/activities/contracts/event-schema.js +2 -0
  4. package/dist/src/activities/contracts/observed-streams.d.ts +9 -0
  5. package/dist/src/activities/contracts/observed-streams.js +9 -0
  6. package/dist/src/activities/index.d.ts +1 -0
  7. package/dist/src/activities/index.js +1 -0
  8. package/dist/src/activities/pr/activity-support.js +2 -0
  9. package/dist/src/activities/pr/application.js +21 -6
  10. package/dist/src/activities/pr/contracts.d.ts +3 -0
  11. package/dist/src/activities/pr/merge.js +5 -1
  12. package/dist/src/bootstrap/board-projection.d.ts +1 -0
  13. package/dist/src/bootstrap/board-projection.js +17 -2
  14. package/dist/src/bootstrap/integration-runtime.js +3 -1
  15. package/dist/src/bootstrap/surface-api-merge-policy.d.ts +1 -0
  16. package/dist/src/bootstrap/surface-cli-applications.js +13 -10
  17. package/dist/src/bootstrap/version.js +1 -1
  18. package/dist/src/execution/contracts/events.js +15 -3
  19. package/dist/src/orchestration/application/observed-state-reactor.d.ts +4 -0
  20. package/dist/src/orchestration/application/observed-state-reactor.js +23 -0
  21. package/dist/src/orchestration/application/observed-state-retry.d.ts +5 -0
  22. package/dist/src/orchestration/application/observed-state-retry.js +102 -0
  23. package/dist/src/orchestration/application/orchestration-service.d.ts +2 -0
  24. package/dist/src/orchestration/application/orchestration-service.js +4 -0
  25. package/dist/src/orchestration/contracts/activity-outcome.js +6 -1
  26. package/dist/src/orchestration/contracts/event-decoder.d.ts +14 -0
  27. package/dist/src/orchestration/contracts/event-decoder.js +17 -1
  28. package/dist/src/orchestration/contracts/event-factory.js +2 -0
  29. package/dist/src/orchestration/contracts/events.d.ts +11 -1
  30. package/dist/src/orchestration/contracts/events.js +1 -0
  31. package/dist/src/orchestration/contracts/observed-retry-description.d.ts +2 -0
  32. package/dist/src/orchestration/contracts/observed-retry-description.js +7 -0
  33. package/dist/src/orchestration/contracts/views.d.ts +9 -1
  34. package/dist/src/orchestration/domain/interpreter.js +16 -1
  35. package/dist/src/orchestration/domain/transition.d.ts +1 -0
  36. package/dist/src/orchestration/domain/transition.js +8 -1
  37. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  38. package/dist/src/orchestration/domain/workflow-instance-events.js +7 -0
  39. package/dist/src/orchestration/index.d.ts +2 -0
  40. package/dist/src/orchestration/index.js +2 -0
  41. package/dist/src/surfaces/api/contracts/board.d.ts +1 -0
  42. package/dist/src/surfaces/api/contracts/orchestration.d.ts +1 -0
  43. package/dist/src/surfaces/api/presenters/orchestration.js +10 -1
  44. package/dist/src/surfaces/cli/commands/audit.d.ts +2 -0
  45. package/dist/src/surfaces/cli/commands/audit.js +27 -2
  46. package/dist/src/surfaces/cli/main.d.ts +2 -0
  47. package/dist/src/surfaces/web-assets/assets/{index-BsP1QXQ3.js → index-KZEn2twL.js} +2 -2
  48. package/dist/src/surfaces/web-assets/index.html +1 -1
  49. package/package.json +1 -1
@@ -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({ kind: z.string().min(1), data: z.unknown().optional() })
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,2 @@
1
+ import type { ObservedStream } from '../../activities/index.js';
2
+ export declare function observedRetryDescription(observed: readonly ObservedStream[], exhausted?: boolean): string;
@@ -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
+ }
@@ -8,6 +8,7 @@ interface TransitionInput {
8
8
  readonly causationId: string;
9
9
  }
10
10
  interface DecisionContext {
11
+ readonly outcome?: ActivityOutcome;
11
12
  readonly occurredAt: string;
12
13
  readonly causationId: string;
13
14
  }
@@ -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: { signalKind: target.signal },
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>>;
@@ -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 (await journal.readAll(0))
5
- .filter((event) => event.stream.id === workItemId)
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;