@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
@@ -3,6 +3,7 @@ import type { Brand } from '../../kernel/index.js';
3
3
  import type { ResourceCapability, ResourceView } from '../../resources/index.js';
4
4
  import type { WorkItemId } from '../../work/index.js';
5
5
  import type { ActivationId, ActivityName } from './identifiers.js';
6
+ import type { ObservedStream } from './observed-streams.js';
6
7
  import type { ActivityExecutionKind, ActivityOutcomeKind, ActivityResourceCardinality, ActivityResourceRole, ActivityRunnerTransportStatus, ActivityWorkspaceMode, ExternalExecutionKind } from './vocabulary.js';
7
8
  export interface ResourceRequirement {
8
9
  readonly capability: ResourceCapability;
@@ -25,6 +26,7 @@ export interface ActivityInvocation<Input = unknown> {
25
26
  }
26
27
  export interface ActivityOutcome<Kind extends string = string, Data = unknown> {
27
28
  readonly kind: Kind;
29
+ readonly observed?: readonly ObservedStream[] | undefined;
28
30
  readonly data?: Data;
29
31
  }
30
32
  export interface WaitingActivityOutcome extends ActivityOutcome<typeof ActivityOutcomeKind.Waiting, {
@@ -37,6 +37,13 @@ export declare const requestedOutcomeSchema: z.ZodObject<{
37
37
  }, z.core.$strict>;
38
38
  export declare const deniedOutcomeSchema: z.ZodObject<{
39
39
  kind: z.ZodLiteral<"blocked">;
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
  data: z.ZodObject<{
41
48
  reason: z.ZodEnum<{
42
49
  closed: "closed";
@@ -1279,6 +1286,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
1279
1286
  decisionKind: z.ZodLiteral<"denied">;
1280
1287
  outcome: z.ZodObject<{
1281
1288
  kind: z.ZodLiteral<"blocked">;
1289
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
1290
+ stream: z.ZodObject<{
1291
+ kind: z.ZodString;
1292
+ id: z.ZodString;
1293
+ }, z.core.$strict>;
1294
+ version: z.ZodNumber;
1295
+ }, z.core.$strict>>>;
1282
1296
  data: z.ZodObject<{
1283
1297
  reason: z.ZodEnum<{
1284
1298
  closed: "closed";
@@ -1534,6 +1548,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
1534
1548
  decisionKind: z.ZodLiteral<"denied">;
1535
1549
  outcome: z.ZodObject<{
1536
1550
  kind: z.ZodLiteral<"blocked">;
1551
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
1552
+ stream: z.ZodObject<{
1553
+ kind: z.ZodString;
1554
+ id: z.ZodString;
1555
+ }, z.core.$strict>;
1556
+ version: z.ZodNumber;
1557
+ }, z.core.$strict>>>;
1537
1558
  data: z.ZodObject<{
1538
1559
  reason: z.ZodEnum<{
1539
1560
  closed: "closed";
@@ -1681,6 +1702,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
1681
1702
  filesChanged?: number | undefined;
1682
1703
  } | undefined;
1683
1704
  };
1705
+ observed?: {
1706
+ stream: {
1707
+ kind: string;
1708
+ id: string;
1709
+ };
1710
+ version: number;
1711
+ }[] | undefined;
1684
1712
  };
1685
1713
  }, {
1686
1714
  action: "approve";
@@ -1699,6 +1727,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
1699
1727
  filesChanged?: number | undefined;
1700
1728
  } | undefined;
1701
1729
  };
1730
+ observed?: {
1731
+ stream: {
1732
+ kind: string;
1733
+ id: string;
1734
+ };
1735
+ version: number;
1736
+ }[] | undefined;
1702
1737
  };
1703
1738
  fact: {
1704
1739
  eventId: import("@atolis-hq/eventing").EventId;
@@ -1842,6 +1877,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
1842
1877
  decisionKind: z.ZodLiteral<"denied">;
1843
1878
  outcome: z.ZodObject<{
1844
1879
  kind: z.ZodLiteral<"blocked">;
1880
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
1881
+ stream: z.ZodObject<{
1882
+ kind: z.ZodString;
1883
+ id: z.ZodString;
1884
+ }, z.core.$strict>;
1885
+ version: z.ZodNumber;
1886
+ }, z.core.$strict>>>;
1845
1887
  data: z.ZodObject<{
1846
1888
  reason: z.ZodEnum<{
1847
1889
  closed: "closed";
@@ -2107,6 +2149,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2107
2149
  decisionKind: z.ZodLiteral<"denied">;
2108
2150
  outcome: z.ZodObject<{
2109
2151
  kind: z.ZodLiteral<"blocked">;
2152
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
2153
+ stream: z.ZodObject<{
2154
+ kind: z.ZodString;
2155
+ id: z.ZodString;
2156
+ }, z.core.$strict>;
2157
+ version: z.ZodNumber;
2158
+ }, z.core.$strict>>>;
2110
2159
  data: z.ZodObject<{
2111
2160
  reason: z.ZodEnum<{
2112
2161
  closed: "closed";
@@ -2254,6 +2303,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2254
2303
  filesChanged?: number | undefined;
2255
2304
  } | undefined;
2256
2305
  };
2306
+ observed?: {
2307
+ stream: {
2308
+ kind: string;
2309
+ id: string;
2310
+ };
2311
+ version: number;
2312
+ }[] | undefined;
2257
2313
  };
2258
2314
  }, {
2259
2315
  action: "merge";
@@ -2272,6 +2328,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2272
2328
  filesChanged?: number | undefined;
2273
2329
  } | undefined;
2274
2330
  };
2331
+ observed?: {
2332
+ stream: {
2333
+ kind: string;
2334
+ id: string;
2335
+ };
2336
+ version: number;
2337
+ }[] | undefined;
2275
2338
  };
2276
2339
  fact: {
2277
2340
  eventId: import("@atolis-hq/eventing").EventId;
@@ -2955,6 +3018,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2955
3018
  decisionKind: z.ZodLiteral<"denied">;
2956
3019
  outcome: z.ZodObject<{
2957
3020
  kind: z.ZodLiteral<"blocked">;
3021
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
3022
+ stream: z.ZodObject<{
3023
+ kind: z.ZodString;
3024
+ id: z.ZodString;
3025
+ }, z.core.$strict>;
3026
+ version: z.ZodNumber;
3027
+ }, z.core.$strict>>>;
2958
3028
  data: z.ZodObject<{
2959
3029
  reason: z.ZodEnum<{
2960
3030
  closed: "closed";
@@ -3146,6 +3216,13 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
3146
3216
  decisionKind: z.ZodLiteral<"denied">;
3147
3217
  outcome: z.ZodObject<{
3148
3218
  kind: z.ZodLiteral<"blocked">;
3219
+ observed: z.ZodOptional<z.ZodArray<z.ZodObject<{
3220
+ stream: z.ZodObject<{
3221
+ kind: z.ZodString;
3222
+ id: z.ZodString;
3223
+ }, z.core.$strict>;
3224
+ version: z.ZodNumber;
3225
+ }, z.core.$strict>>>;
3149
3226
  data: z.ZodObject<{
3150
3227
  reason: z.ZodEnum<{
3151
3228
  closed: "closed";
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { pullRequestCheckEvidenceSchema } from '../pr/check-evidence.js';
3
3
  import { mergePolicyDetailsSchema } from '../pr/merge-policy-denial.js';
4
4
  import { parentActionContextSchema } from '../pr/parent-scope.js';
5
+ import { observedStreamsSchema } from './observed-streams.js';
5
6
  import { eventDataSchema, eventEnvelopeSchema } from '@atolis-hq/eventing';
6
7
  import { brandedStringSchema } from '../../kernel/index.js';
7
8
  import { ResourceStreamKind, resourceId } from '../../resources/index.js';
@@ -124,6 +125,7 @@ export const requestedOutcomeSchema = z
124
125
  export const deniedOutcomeSchema = z
125
126
  .object({
126
127
  kind: z.literal(ActivityOutcomeKind.Blocked),
128
+ observed: observedStreamsSchema.optional(),
127
129
  data: z
128
130
  .object({
129
131
  reason: denialCodeSchema,
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ export declare const observedStreamsSchema: z.ZodArray<z.ZodObject<{
3
+ stream: z.ZodObject<{
4
+ kind: z.ZodString;
5
+ id: z.ZodString;
6
+ }, z.core.$strict>;
7
+ version: z.ZodNumber;
8
+ }, z.core.$strict>>;
9
+ export type ObservedStream = z.infer<typeof observedStreamsSchema>[number];
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ export const observedStreamsSchema = z
3
+ .array(z
4
+ .object({
5
+ stream: z.object({ kind: z.string().min(1), id: z.string().min(1) }).strict(),
6
+ version: z.number().int().nonnegative(),
7
+ })
8
+ .strict())
9
+ .min(1);
@@ -3,6 +3,7 @@ export * from './agent/agent-activity.js';
3
3
  export * from './agent/agent-result.js';
4
4
  export * from './issue/complete.js';
5
5
  export * from './contracts/activity.js';
6
+ export * from './contracts/observed-streams.js';
6
7
  export * from './contracts/config.js';
7
8
  export * from './contracts/events.js';
8
9
  export { createActivityEventData, type ActivityEventDataInput } from './contracts/event-factory.js';
@@ -3,6 +3,7 @@ export * from './agent/agent-activity.js';
3
3
  export * from './agent/agent-result.js';
4
4
  export * from './issue/complete.js';
5
5
  export * from './contracts/activity.js';
6
+ export * from './contracts/observed-streams.js';
6
7
  export * from './contracts/config.js';
7
8
  export * from './contracts/events.js';
8
9
  export { createActivityEventData } from './contracts/event-factory.js';
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { observedStreamsSchema } from '../contracts/observed-streams.js';
2
3
  import { ActivityFailureCode, ActivityOutcomeKind, ActivityResourceRole, IntentAppendStatus, } from '../contracts/vocabulary.js';
3
4
  import { mergePolicyDetailsSchema } from './merge-policy-denial.js';
4
5
  import { PullRequestDenialCode } from './vocabulary.js';
@@ -34,6 +35,7 @@ export const pullRequestOutcomeSchema = z.union([
34
35
  z
35
36
  .object({
36
37
  kind: z.literal(ActivityOutcomeKind.Blocked),
38
+ observed: observedStreamsSchema.optional(),
37
39
  data: z
38
40
  .object({
39
41
  resourceId: z.string().optional(),
@@ -152,22 +152,37 @@ class JournalPullRequestService {
152
152
  return view.headRevision === revision ? null : PullRequestDenialCode.StaleApproval;
153
153
  }
154
154
  async authorityInput(workItemId) {
155
+ // Capture before reading views so a concurrent append remains visible to catch-up.
156
+ const workStream = workItemStream(workItemId);
157
+ const workVersion = (await this.journal.readStream(workStream)).length;
155
158
  const correlations = await this.resources.correlationsForWork(workItemId);
159
+ const snapshots = await Promise.all(correlations.map(async ({ resourceId }) => {
160
+ const stream = resourceStream(resourceId);
161
+ return { resourceId, stream, events: await this.journal.readStream(stream) };
162
+ }));
163
+ const observed = [
164
+ { stream: workStream, version: workVersion },
165
+ ...snapshots.map(({ stream, events }) => ({ stream, version: events.length })),
166
+ ];
167
+ const eventsByResource = new Map(snapshots.map(({ resourceId, events }) => [resourceId, events]));
156
168
  const entries = await Promise.all(correlations.map(async ({ resourceId }) => this.resourceEntry(resourceId)));
157
169
  const resources = entries.filter(isPresent);
158
- const pullRequests = (await Promise.all(resources.map(({ resource }) => this.get(resource.resourceId)))).filter(isPresent);
159
- const acceptedSignals = (await Promise.all(resources.map(({ resource }) => this.acceptedSignals(resource.resourceId)))).flat();
170
+ const pullRequests = resources
171
+ .map(({ resource }) => eventsByResource
172
+ .get(resource.resourceId)
173
+ .reduce((view, event) => pullRequestProjection.project(view, event), pullRequestProjection.initial(resource.resourceId)))
174
+ .filter(isPresent);
175
+ const acceptedSignals = resources.flatMap(({ resource }) => eventsByResource
176
+ .get(resource.resourceId)
177
+ .reduce((view, event) => acceptedReviewSignalProjection.project(view, event), acceptedReviewSignalProjection.initial(resource.resourceId)));
160
178
  return {
179
+ observed,
161
180
  work: await this.work.get(workItemId),
162
181
  resources,
163
182
  pullRequests,
164
183
  acceptedSignals,
165
184
  };
166
185
  }
167
- async acceptedSignals(resourceId) {
168
- const events = await this.journal.readStream(resourceStream(resourceId));
169
- return events.reduce((view, event) => acceptedReviewSignalProjection.project(view, event), acceptedReviewSignalProjection.initial(resourceId));
170
- }
171
186
  async resourceEntry(resourceId) {
172
187
  const resource = await this.resources.get(resourceId);
173
188
  if (resource === null)
@@ -1,5 +1,6 @@
1
1
  import type { ResourceCorrelationView, ResourceId, ResourceView } from '../../resources/index.js';
2
2
  import type { WorkItemId, WorkItemView } from '../../work/index.js';
3
+ import type { ObservedStream } from '../contracts/observed-streams.js';
3
4
  import type { ActivityFailureCode, ActivityOutcomeKind, ActivityResourceRole } from '../contracts/vocabulary.js';
4
5
  import type { ReviewActorKind, ReviewerAuthorizationEvidence } from '../review/contracts.js';
5
6
  import type { PullRequestCheckEvidence } from './check-evidence.js';
@@ -104,6 +105,7 @@ export type PullRequestActivityOutcome = {
104
105
  };
105
106
  } | {
106
107
  readonly kind: typeof ActivityOutcomeKind.Blocked;
108
+ readonly observed?: readonly ObservedStream[] | undefined;
107
109
  readonly data: {
108
110
  readonly reason: PullRequestDenialCode;
109
111
  readonly resourceId?: string | undefined;
@@ -138,6 +140,7 @@ export interface AcceptedReviewSignalView {
138
140
  readonly trusted: boolean;
139
141
  }
140
142
  export interface PullRequestAuthorityInput {
143
+ readonly observed?: readonly ObservedStream[] | undefined;
141
144
  readonly work: WorkItemView | null;
142
145
  readonly resources: readonly PullRequestResourceView[];
143
146
  readonly pullRequests: readonly PullRequestView[];
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { ActivityOutcomeKind } from '../contracts/vocabulary.js';
3
3
  import { readMergePolicyDenial } from './merge-policy-denial.js';
4
- import { MergeMethod } from './vocabulary.js';
4
+ import { MergeMethod, PullRequestDenialCode } from './vocabulary.js';
5
5
  import { BuiltInResourceCapability, resourceStream, } from '../../resources/index.js';
6
6
  import { workItemStream } from '../../work/index.js';
7
7
  import { ActivityEventType } from '../contracts/events.js';
@@ -72,6 +72,10 @@ async function denyByAuthority({ journal, appender }, invocation, authority, res
72
72
  decisionKind: 'denied',
73
73
  outcome: {
74
74
  kind: ActivityOutcomeKind.Blocked,
75
+ ...(decision.reason === PullRequestDenialCode.MissingResource &&
76
+ authority.observed !== undefined
77
+ ? { observed: authority.observed }
78
+ : {}),
75
79
  data: {
76
80
  reason: decision.reason,
77
81
  ...(policyDenial === null
@@ -32,6 +32,7 @@ interface StoredCard {
32
32
  readonly workflowName?: string;
33
33
  readonly stage?: string;
34
34
  readonly blockReason?: string;
35
+ readonly retryCondition?: string;
35
36
  readonly dwellSince: string;
36
37
  readonly runCount: number;
37
38
  /** Set on delegated children; present only for work created after delegation existed. */
@@ -1,6 +1,6 @@
1
1
  import { ActivityOutcomeKind } from '../activities/index.js';
2
2
  import { agentTokenUsage, ExecutionEventType, RunStatus, selectRunExecutionEvent, } from '../execution/index.js';
3
- import { isApprovalAwaitingSignalKind, OrchestrationEventType, orchestrationStatusTransitions, selectWorkflowOrchestrationEvent, WorkflowStatus, } from '../orchestration/index.js';
3
+ import { isApprovalAwaitingSignalKind, observedRetryDescription, OrchestrationEventType, orchestrationStatusTransitions, selectWorkflowOrchestrationEvent, WorkflowStatus, } from '../orchestration/index.js';
4
4
  import { toWorkItemKey } from '../surfaces/index.js';
5
5
  import { selectWorkEvent, WorkEventType } from '../work/index.js';
6
6
  const conditionShape = {
@@ -193,6 +193,18 @@ function projectWorkflowUpdate(view, event, occurredAt) {
193
193
  // the board instead of silently sitting at whatever condition it had
194
194
  // before — this is exactly the class of gap that let the card sit in
195
195
  // Ready while GitHub's own label already said working.
196
+ if (event.event.eventType === OrchestrationEventType.ObservedStateRetryRecorded &&
197
+ event.event.payload.exhausted)
198
+ return {
199
+ ...view,
200
+ cards: {
201
+ ...view.cards,
202
+ [workId]: {
203
+ ...card,
204
+ retryCondition: observedRetryDescription([], true),
205
+ },
206
+ },
207
+ };
196
208
  const status = orchestrationStatusTransitions[event.event.eventType];
197
209
  if (status === undefined)
198
210
  return view;
@@ -205,6 +217,9 @@ function projectWorkflowUpdate(view, event, occurredAt) {
205
217
  [workId]: {
206
218
  ...withCondition,
207
219
  ...awaitingApprovalField(event.event.payload.signalKind),
220
+ ...(event.event.payload.observed === undefined
221
+ ? {}
222
+ : { retryCondition: observedRetryDescription(event.event.payload.observed) }),
208
223
  },
209
224
  },
210
225
  };
@@ -258,7 +273,7 @@ function awaitingApprovalField(signalKind) {
258
273
  return isApprovalAwaitingSignalKind(signalKind) ? { awaitingApproval: true } : {};
259
274
  }
260
275
  function withoutBlockReason(card) {
261
- const { blockReason: _blockReason, ...withoutReason } = card;
276
+ const { blockReason: _blockReason, retryCondition: _retryCondition, ...withoutReason } = card;
262
277
  return withoutReason;
263
278
  }
264
279
  const runTerminalEventTypes = new Set([
@@ -6,7 +6,7 @@ import { ControlEventType, ControlStreamKind, TriggerService, createDurableRunne
6
6
  import { ConversationOriginKind, workItemIdForConversation } from '../conversations/index.js';
7
7
  import { ExecutionStreamKind, NoEligibleRunnerError, RunRepository, createRuntimeMemoryProfile, decodeActivationExecutionEvent, isActiveRunStatus, isRunStream, runId, } from '../execution/index.js';
8
8
  import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, ProviderRegistry, deliveryProjectionDefinitions, fakeProviderDefinition, publishConversationCommandFeedback, reconcileMergedDeliveries, } from '../integrations/index.js';
9
- import { compileWorkflowSelectors, createConversationCommandReactor, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, createWatchReconciler, isWorkflowInstanceStream, selectWorkflow, workflowInstanceId, workflowName, } from '../orchestration/index.js';
9
+ import { compileWorkflowSelectors, createConversationCommandReactor, createObservedStateReactor, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, createWatchReconciler, isWorkflowInstanceStream, selectWorkflow, workflowInstanceId, workflowName, } from '../orchestration/index.js';
10
10
  import { BuiltInResourceCapability, resourceId, } from '../resources/index.js';
11
11
  import { isWorkItemStream, workItemId } from '../work/index.js';
12
12
  import { decodeCanonicalEvent } from './canonical-events.js';
@@ -190,6 +190,7 @@ export async function composeIntegrationRuntime(input) {
190
190
  },
191
191
  ],
192
192
  });
193
+ const observedState = createObservedStateReactor(input.orchestration);
193
194
  const resourceTransitions = createResourceTransitionReactor(input.orchestration, resourceTransitionEvidence);
194
195
  const recoverMergedWaits = () => input.orchestration.recoverPolicyBlockedMerges(resourceTransitionEvidence, {
195
196
  commandId: input.ids.next('command'),
@@ -290,6 +291,7 @@ export async function composeIntegrationRuntime(input) {
290
291
  ...triggerReactors,
291
292
  watch.processor,
292
293
  resourceTransitions.processor,
294
+ observedState,
293
295
  artifacts.processor,
294
296
  outcomes.processor,
295
297
  agentRunPublications.processor,
@@ -11,6 +11,7 @@ export declare function presentPrimaryWorkflow(root: CompositionRoot, workflow:
11
11
  status: string;
12
12
  currentStage: string;
13
13
  blockReason?: string;
14
+ retryCondition?: string;
14
15
  retryEligible?: boolean;
15
16
  extendEligible?: boolean;
16
17
  waitingFor?: {
@@ -10,9 +10,10 @@ import { FileArtifactMcpSessionStore } from '../artifacts/index.js';
10
10
  import { IntakeHost, ResidentHost, TickHost, } from '../control-plane/index.js';
11
11
  import { ExecutionFailureCode, RunStatus, isActiveRunStatus, loadPromptTemplate, } from '../execution/index.js';
12
12
  import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
13
+ import { OrchestrationEventType } from '../orchestration/index.js';
13
14
  import { ResourceCorrelationRole, resourceId } from '../resources/index.js';
14
- import { DockerProcessError, WakeOperationalCommand, createApiDispatcher, createLoggedDockerCli, createPackagedAssetSource, createPairingGrant, createProcessLogSink, createSandboxDockerPort, createSurfaceHttpServer, describeSandboxStartupFailure, drainProcessOutput, loadOrCreateCredentials, promoteSandboxImage, redeemPairingGrant, replaceAccessKey, runDoctor, runSandbox, runSandboxEntrypoint, runSandboxSetup, runSelfUpdateLatestLoop, runTargetSmoke, runWakeReadCommand, serveMcpOverStdio, verifyResidentStart, waitForActiveRuns, waitForever, } from '../surfaces/index.js';
15
- import { WorkStreamKind, workItemId } from '../work/index.js';
15
+ import { DockerProcessError, WakeOperationalCommand, auditFacts, createApiDispatcher, createLoggedDockerCli, createPackagedAssetSource, createPairingGrant, createProcessLogSink, createSandboxDockerPort, createSurfaceHttpServer, describeSandboxStartupFailure, drainProcessOutput, loadOrCreateCredentials, promoteSandboxImage, redeemPairingGrant, replaceAccessKey, runDoctor, runSandbox, runSandboxEntrypoint, runSandboxSetup, runSelfUpdateLatestLoop, runTargetSmoke, runWakeReadCommand, serveMcpOverStdio, verifyResidentStart, waitForActiveRuns, waitForever, } from '../surfaces/index.js';
16
+ import { workItemId } from '../work/index.js';
16
17
  import { createArtifactMcpServerForSession } from './artifact-mcp.js';
17
18
  import { createDiagnosticRoot } from './composition-root.js';
18
19
  import { loadConfig } from './config/load-config.js';
@@ -1046,15 +1047,17 @@ function runInteractive(command, arguments_) {
1046
1047
  function createAuditApplication(root) {
1047
1048
  return {
1048
1049
  async read(id) {
1049
- return (await root.journal.readAll(0))
1050
- .filter((event) => event.stream.kind === WorkStreamKind.WorkItem && event.stream.id === id)
1051
- .map((event) => ({
1052
- eventId: event.event.eventId,
1053
- eventType: event.event.eventType,
1054
- occurredAt: event.event.occurredAt,
1050
+ return (await auditFacts(root.journal, id)).map(({ event, retryCondition }) => ({
1051
+ eventId: event.eventId,
1052
+ eventType: event.eventType,
1053
+ occurredAt: event.occurredAt,
1055
1054
  stream: `${event.stream.kind}:${event.stream.id}`,
1056
- causationId: event.event.causationId,
1057
- correlationId: event.event.correlationId,
1055
+ ...(event.eventType === OrchestrationEventType.ObservedStateRetryRecorded
1056
+ ? { payload: event.payload }
1057
+ : {}),
1058
+ ...(retryCondition === undefined ? {} : { retryCondition }),
1059
+ causationId: event.causationId,
1060
+ correlationId: event.correlationId,
1058
1061
  }));
1059
1062
  },
1060
1063
  };
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
124
124
  return `g${headHash.slice(0, 7)}`;
125
125
  return '0.1.0-dev';
126
126
  }
127
- export const wakeVersion = "v0.4.115";
127
+ export const wakeVersion = "v0.4.116";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -1,6 +1,6 @@
1
1
  import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
2
2
  import { z } from 'zod';
3
- import { activationId, activityName, activityOrchestrationGroupId, activityWorkflowInstanceId, ExternalExecutionKind, } from '../../activities/index.js';
3
+ import { activationId, activityName, activityOrchestrationGroupId, activityWorkflowInstanceId, ExternalExecutionKind, observedStreamsSchema, } from '../../activities/index.js';
4
4
  import { brandedStringSchema, offsetIsoTimestampSchema } from '../../kernel/index.js';
5
5
  import { preparedCandidateSchema } from './candidate.js';
6
6
  import { changeOutputWorkspaceSchema } from './change-output.js';
@@ -175,7 +175,13 @@ const runEventSchema = eventEnvelopeSchema.extend({
175
175
  .string()
176
176
  .regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i)
177
177
  .optional(),
178
- outcome: z.object({ kind: z.string().min(1), data: z.unknown().optional() }).strict(),
178
+ outcome: z
179
+ .object({
180
+ kind: z.string().min(1),
181
+ data: z.unknown().optional(),
182
+ observed: observedStreamsSchema.optional(),
183
+ })
184
+ .strict(),
179
185
  finishedAt: offsetIsoTimestampSchema,
180
186
  })
181
187
  .strict(),
@@ -237,7 +243,13 @@ const runEventSchema = eventEnvelopeSchema.extend({
237
243
  payload: z
238
244
  .object({
239
245
  result: runnerResultPayloadSchema,
240
- outcome: z.object({ kind: z.string().min(1), data: z.unknown().optional() }).strict(),
246
+ outcome: z
247
+ .object({
248
+ kind: z.string().min(1),
249
+ data: z.unknown().optional(),
250
+ observed: observedStreamsSchema.optional(),
251
+ })
252
+ .strict(),
241
253
  finishedAt: offsetIsoTimestampSchema,
242
254
  })
243
255
  .strict(),
@@ -0,0 +1,4 @@
1
+ import { type EventEnvelope } from '@atolis-hq/eventing';
2
+ export declare function createObservedStateReactor(orchestration: {
3
+ retryObservedState(event: EventEnvelope): Promise<boolean>;
4
+ }): import("@atolis-hq/eventing").EventProcessor;
@@ -0,0 +1,23 @@
1
+ import { defineEventProcessor, EventProcessorCategory, EventProcessorReplayPolicy, } from '@atolis-hq/eventing';
2
+ import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
3
+ import { OrchestrationEventType } from '../contracts/events.js';
4
+ export function createObservedStateReactor(orchestration) {
5
+ // Bootstrap once from durable state; an observed wait-start re-arms a dormant reactor.
6
+ let active = true;
7
+ return defineEventProcessor({
8
+ consumer: 'reactor:orchestration.observed-state',
9
+ name: 'observed-state',
10
+ owner: 'orchestration',
11
+ category: EventProcessorCategory.Reactor,
12
+ replayPolicy: EventProcessorReplayPolicy.Idempotent,
13
+ batchSize: 100,
14
+ select: (event) => event,
15
+ async handle(event) {
16
+ const fact = selectOrchestrationEvent(event);
17
+ const startsWait = fact?.event.eventType === OrchestrationEventType.SignalWaitStarted &&
18
+ fact.event.payload.observed !== undefined;
19
+ if (active || startsWait)
20
+ active = await orchestration.retryObservedState(event);
21
+ },
22
+ });
23
+ }
@@ -0,0 +1,5 @@
1
+ import type { EventEnvelope, EventJournal } from '@atolis-hq/eventing';
2
+ import type { DelegationGate } from './delegation-gate.js';
3
+ import type { OrchestrationRepository } from './orchestration-repository.js';
4
+ /** Catch up from the read snapshot, including facts arriving before the wait was recorded. */
5
+ export declare function retryObservedState(repository: OrchestrationRepository, journal: EventJournal, gate: DelegationGate, trigger: EventEnvelope): Promise<boolean>;
@@ -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
+ }