@workflow/web-shared 5.0.4 → 5.0.6

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 (31) hide show
  1. package/dist/components/event-list-view.d.ts.map +1 -1
  2. package/dist/components/event-list-view.js +14 -4
  3. package/dist/components/sidebar/attribute-panel.d.ts.map +1 -1
  4. package/dist/components/sidebar/attribute-panel.js +9 -2
  5. package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
  6. package/dist/components/workflow-traces/trace-span-construction.js +8 -4
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -1
  10. package/dist/lib/duplicate-events.d.ts +6 -6
  11. package/dist/lib/duplicate-events.d.ts.map +1 -1
  12. package/dist/lib/duplicate-events.js +18 -18
  13. package/dist/lib/event-materialization.d.ts +3 -1
  14. package/dist/lib/event-materialization.d.ts.map +1 -1
  15. package/dist/lib/event-materialization.js +11 -4
  16. package/dist/lib/run-limit-guidance.d.ts +43 -0
  17. package/dist/lib/run-limit-guidance.d.ts.map +1 -0
  18. package/dist/lib/run-limit-guidance.js +72 -0
  19. package/package.json +4 -4
  20. package/src/components/event-list-view.test.ts +51 -0
  21. package/src/components/event-list-view.tsx +16 -3
  22. package/src/components/sidebar/attribute-panel.tsx +10 -1
  23. package/src/components/workflow-traces/trace-span-construction.test.ts +28 -0
  24. package/src/components/workflow-traces/trace-span-construction.ts +10 -3
  25. package/src/index.ts +7 -0
  26. package/src/lib/duplicate-events.test.ts +8 -11
  27. package/src/lib/duplicate-events.ts +18 -16
  28. package/src/lib/event-materialization.test.ts +19 -0
  29. package/src/lib/event-materialization.ts +11 -3
  30. package/src/lib/run-limit-guidance.test.ts +90 -0
  31. package/src/lib/run-limit-guidance.ts +111 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Guidance for runs that failed because they outgrew the default per-run
3
+ * event limit or replay budget. Pure (no React) so every observability UI
4
+ * (the self-hosted web UI and the Vercel dashboard) can share the decision
5
+ * and the copy while rendering it with its own components.
6
+ */
7
+ export type RunLimitGuidanceKind = 'max-events-exceeded' | 'replay-timeout';
8
+ export interface RunLimitGuidance {
9
+ kind: RunLimitGuidanceKind;
10
+ /** Short heading, e.g. for an alert title. */
11
+ title: string;
12
+ /** One or two sentences explaining what to do. Plain text. */
13
+ description: string;
14
+ /** The env var assignment to suggest, for rendering as code. */
15
+ envVar: string;
16
+ /** Docs page for the error code. */
17
+ docsUrl: string;
18
+ }
19
+ /**
20
+ * The run fields this guidance reads. Accepts both a hydrated run (where
21
+ * `hydrateResourceIO` lifts `workflowVm` / `snapshotThreshold` out of the
22
+ * stripped `executionContext`) and a raw run (with `executionContext`).
23
+ */
24
+ export interface RunLimitGuidanceInput {
25
+ status?: string;
26
+ errorCode?: string | null;
27
+ workflowVm?: unknown;
28
+ snapshotThreshold?: unknown;
29
+ executionContext?: unknown;
30
+ }
31
+ /**
32
+ * Whether the run was started on the QuickJS VM with snapshotting enabled,
33
+ * which exempts it from the default per-run event limit. Mirrors the World
34
+ * policy (`isEventLimitExemptRun` in `@workflow/world`).
35
+ */
36
+ export declare function isQuickJSSnapshotRun(run: RunLimitGuidanceInput): boolean;
37
+ /**
38
+ * Returns guidance to show for a failed run whose error code is
39
+ * `MAX_EVENTS_EXCEEDED` or `REPLAY_TIMEOUT` and that wasn't already running
40
+ * on the QuickJS VM with snapshotting. Returns `null` otherwise.
41
+ */
42
+ export declare function getRunLimitGuidance(run: RunLimitGuidanceInput | null | undefined): RunLimitGuidance | null;
43
+ //# sourceMappingURL=run-limit-guidance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-limit-guidance.d.ts","sourceRoot":"","sources":["../../src/lib/run-limit-guidance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAE5E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,oBAAoB,CAAC;IAC3B,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAgBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAQxE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,qBAAqB,GAAG,IAAI,GAAG,SAAS,GAC5C,gBAAgB,GAAG,IAAI,CAkCzB"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Guidance for runs that failed because they outgrew the default per-run
3
+ * event limit or replay budget. Pure (no React) so every observability UI
4
+ * (the self-hosted web UI and the Vercel dashboard) can share the decision
5
+ * and the copy while rendering it with its own components.
6
+ */
7
+ /** Error codes this guidance applies to (`RUN_ERROR_CODES` values). */
8
+ const MAX_EVENTS_EXCEEDED = 'MAX_EVENTS_EXCEEDED';
9
+ const REPLAY_TIMEOUT = 'REPLAY_TIMEOUT';
10
+ const DOCS_BASE_URL = 'https://workflow-sdk.dev/err';
11
+ function readVmPolicy(run) {
12
+ const ctx = run.executionContext && typeof run.executionContext === 'object'
13
+ ? run.executionContext
14
+ : undefined;
15
+ return {
16
+ workflowVm: run.workflowVm ?? ctx?.workflowVm,
17
+ snapshotThreshold: run.snapshotThreshold ?? ctx?.snapshotThreshold,
18
+ };
19
+ }
20
+ /**
21
+ * Whether the run was started on the QuickJS VM with snapshotting enabled,
22
+ * which exempts it from the default per-run event limit. Mirrors the World
23
+ * policy (`isEventLimitExemptRun` in `@workflow/world`).
24
+ */
25
+ export function isQuickJSSnapshotRun(run) {
26
+ const { workflowVm, snapshotThreshold } = readVmPolicy(run);
27
+ return (workflowVm === 'quickjs' &&
28
+ typeof snapshotThreshold === 'number' &&
29
+ Number.isSafeInteger(snapshotThreshold) &&
30
+ snapshotThreshold > 0);
31
+ }
32
+ /**
33
+ * Returns guidance to show for a failed run whose error code is
34
+ * `MAX_EVENTS_EXCEEDED` or `REPLAY_TIMEOUT` and that wasn't already running
35
+ * on the QuickJS VM with snapshotting. Returns `null` otherwise.
36
+ */
37
+ export function getRunLimitGuidance(run) {
38
+ if (!run || run.status !== 'failed')
39
+ return null;
40
+ const code = run.errorCode;
41
+ if (code !== MAX_EVENTS_EXCEEDED && code !== REPLAY_TIMEOUT)
42
+ return null;
43
+ // Already on the recommended configuration; switching wouldn't help.
44
+ if (isQuickJSSnapshotRun(run))
45
+ return null;
46
+ const { workflowVm } = readVmPolicy(run);
47
+ const onQuickJS = workflowVm === 'quickjs';
48
+ const remediation = onQuickJS
49
+ ? "This run used the QuickJS VM, but a snapshot threshold wasn't recorded when it started (snapshotting was disabled, or the run was started by an older SDK), so the default event limit applied. Set a positive WORKFLOW_SNAPSHOT_THRESHOLD in the environment that starts runs, or upgrade the workflow package, so new runs are exempt."
50
+ : 'Run long-running workflows on the QuickJS VM with snapshotting. Snapshotted runs resume without replaying the full event log and are exempt from the default per-run event limit. Set this in the environment that starts runs; only new runs are affected.';
51
+ if (code === MAX_EVENTS_EXCEEDED) {
52
+ return {
53
+ kind: 'max-events-exceeded',
54
+ title: 'This run reached the per-run event limit',
55
+ description: remediation,
56
+ envVar: onQuickJS
57
+ ? 'WORKFLOW_SNAPSHOT_THRESHOLD=1000'
58
+ : 'WORKFLOW_VM=quickjs',
59
+ docsUrl: `${DOCS_BASE_URL}/max-events-exceeded`,
60
+ };
61
+ }
62
+ return {
63
+ kind: 'replay-timeout',
64
+ title: 'This run exceeded the workflow replay time limit',
65
+ description: `Replay time grows with the size of the event log. ${remediation}`,
66
+ envVar: onQuickJS
67
+ ? 'WORKFLOW_SNAPSHOT_THRESHOLD=1000'
68
+ : 'WORKFLOW_VM=quickjs',
69
+ docsUrl: `${DOCS_BASE_URL}/replay-timeout`,
70
+ };
71
+ }
72
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVuLWxpbWl0LWd1aWRhbmNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2xpYi9ydW4tbGltaXQtZ3VpZGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7O0dBS0c7QUFFSCx1RUFBdUU7QUFDdkUsTUFBTSxtQkFBbUIsR0FBRyxxQkFBcUIsQ0FBQztBQUNsRCxNQUFNLGNBQWMsR0FBRyxnQkFBZ0IsQ0FBQztBQUV4QyxNQUFNLGFBQWEsR0FBRyw4QkFBOEIsQ0FBQztBQTZCckQsU0FBUyxZQUFZLENBQUMsR0FBMEI7SUFJOUMsTUFBTSxHQUFHLEdBQ1AsR0FBRyxDQUFDLGdCQUFnQixJQUFJLE9BQU8sR0FBRyxDQUFDLGdCQUFnQixLQUFLLFFBQVE7UUFDOUQsQ0FBQyxDQUFFLEdBQUcsQ0FBQyxnQkFBNEM7UUFDbkQsQ0FBQyxDQUFDLFNBQVMsQ0FBQztJQUNoQixPQUFPO1FBQ0wsVUFBVSxFQUFFLEdBQUcsQ0FBQyxVQUFVLElBQUksR0FBRyxFQUFFLFVBQVU7UUFDN0MsaUJBQWlCLEVBQUUsR0FBRyxDQUFDLGlCQUFpQixJQUFJLEdBQUcsRUFBRSxpQkFBaUI7S0FDbkUsQ0FBQztBQUNKLENBQUM7QUFFRDs7OztHQUlHO0FBQ0gsTUFBTSxVQUFVLG9CQUFvQixDQUFDLEdBQTBCO0lBQzdELE1BQU0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gb25seSBuZXcgcnVucyBhcmUgYWZmZWN0ZWQuJztcblxuICBpZiAoY29kZSA9PT0gTUFYX0VWRU5UU19FWENFRURFRCkge1xuICAgIHJldHVybiB7XG4gICAgICBraW5kOiAnbWF4LWV2ZW50cy1leGNlZWRlZCcsXG4gICAgICB0aXRsZTogJ1RoaXMgcnVuIHJlYWNoZWQgdGhlIHBlci1ydW4gZXZlbnQgbGltaXQnLFxuICAgICAgZGVzY3JpcHRpb246IHJlbWVkaWF0aW9uLFxuICAgICAgZW52VmFyOiBvblF1aWNrSlNcbiAgICAgICAgPyAnV09SS0ZMT1dfU05BUFNIT1RfVEhSRVNIT0xEPTEwMDAnXG4gICAgICAgIDogJ1dPUktGTE9XX1ZNPXF1aWNranMnLFxuICAgICAgZG9jc1VybDogYCR7RE9DU19CQVNFX1VSTH0vbWF4LWV2ZW50cy1leGNlZWRlZGAsXG4gICAgfTtcbiAgfVxuICByZXR1cm4ge1xuICAgIGtpbmQ6ICdyZXBsYXktdGltZW91dCcsXG4gICAgdGl0bGU6ICdUaGlzIHJ1biBleGNlZWRlZCB0aGUgd29ya2Zsb3cgcmVwbGF5IHRpbWUgbGltaXQnLFxuICAgIGRlc2NyaXB0aW9uOiBgUmVwbGF5IHRpbWUgZ3Jvd3Mgd2l0aCB0aGUgc2l6ZSBvZiB0aGUgZXZlbnQgbG9nLiAke3JlbWVkaWF0aW9ufWAsXG4gICAgZW52VmFyOiBvblF1aWNrSlNcbiAgICAgID8gJ1dPUktGTE9XX1NOQVBTSE9UX1RIUkVTSE9MRD0xMDAwJ1xuICAgICAgOiAnV09SS0ZMT1dfVk09cXVpY2tqcycsXG4gICAgZG9jc1VybDogYCR7RE9DU19CQVNFX1VSTH0vcmVwbGF5LXRpbWVvdXRgLFxuICB9O1xufVxuIl19
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workflow/web-shared",
3
3
  "description": "Shared components for Workflow Observability UI",
4
- "version": "5.0.4",
4
+ "version": "5.0.6",
5
5
  "private": false,
6
6
  "files": [
7
7
  "dist",
@@ -42,9 +42,9 @@
42
42
  "@radix-ui/react-tooltip": "1.2.8",
43
43
  "@tailwindcss/postcss": "4",
44
44
  "@tootallnate/zstd-wasm": "0.0.2",
45
- "@workflow/core": "5.2.1",
45
+ "@workflow/core": "5.2.3",
46
46
  "@workflow/utils": "5.0.2",
47
- "@workflow/world": "5.0.4",
47
+ "@workflow/world": "5.0.5",
48
48
  "class-variance-authority": "0.7.1",
49
49
  "clsx": "2.1.1",
50
50
  "date-fns": "4.1.0",
@@ -64,7 +64,7 @@
64
64
  "@types/node": "22.19.0",
65
65
  "@types/react": "19",
66
66
  "@types/react-dom": "19",
67
- "@workflow/errors": "5.0.4",
67
+ "@workflow/errors": "5.0.5",
68
68
  "@workflow/tsconfig": "5.0.0",
69
69
  "ai": "6.0.116",
70
70
  "typescript": "^6.0.3",
@@ -0,0 +1,51 @@
1
+ import type { Event } from '@workflow/world';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { buildNameMaps } from './event-list-view';
4
+
5
+ function event(
6
+ eventType: Event['eventType'],
7
+ correlationId: string,
8
+ eventData: Record<string, unknown>
9
+ ): Event {
10
+ return {
11
+ eventId: `evt_${eventType}_${correlationId}`,
12
+ runId: 'run_1',
13
+ eventType,
14
+ correlationId,
15
+ createdAt: new Date(0),
16
+ eventData,
17
+ } as unknown as Event;
18
+ }
19
+
20
+ describe('buildNameMaps', () => {
21
+ it('names a step whose creation is recorded on its step_started', () => {
22
+ const { correlationNameMap } = buildNameMaps(
23
+ [
24
+ event('step_started', 'step_a', {
25
+ stepName: 'step//src/billing.ts//fetchInvoices',
26
+ }),
27
+ ],
28
+ null
29
+ );
30
+
31
+ expect(correlationNameMap.get('step_a')).toBe('fetchInvoices');
32
+ });
33
+
34
+ it('prefers the step_created name in either list order', () => {
35
+ const created = event('step_created', 'step_a', {
36
+ stepName: 'step//src/billing.ts//fetchInvoices',
37
+ input: null,
38
+ });
39
+ const started = event('step_started', 'step_a', {
40
+ stepName: 'step//src/billing.ts//somethingElse',
41
+ });
42
+
43
+ for (const events of [
44
+ [created, started],
45
+ [started, created],
46
+ ]) {
47
+ const { correlationNameMap } = buildNameMaps(events, null);
48
+ expect(correlationNameMap.get('step_a')).toBe('fetchInvoices');
49
+ }
50
+ });
51
+ });
@@ -171,11 +171,24 @@ export function buildNameMaps(
171
171
  } {
172
172
  const correlationNameMap = new Map<string, string>();
173
173
 
174
- // Map step correlationId (= stepId) → parsed step name from step_created events
174
+ // Map step correlationId (= stepId) → parsed step name. Taken from
175
+ // step_created, or from step_started for a step whose creation the World
176
+ // recorded on its start alone (no step_created in the log).
175
177
  if (events) {
176
178
  for (const event of events) {
177
- if (event.eventType === 'step_created' && event.correlationId) {
178
- const stepName = event.eventData?.stepName ?? '';
179
+ if (
180
+ (event.eventType === 'step_created' ||
181
+ event.eventType === 'step_started') &&
182
+ event.correlationId
183
+ ) {
184
+ const stepName = event.eventData?.stepName;
185
+ if (typeof stepName !== 'string') continue;
186
+ if (
187
+ event.eventType === 'step_started' &&
188
+ correlationNameMap.has(event.correlationId)
189
+ ) {
190
+ continue;
191
+ }
179
192
  const parsed =
180
193
  parseStepName(String(stepName)) ??
181
194
  parseWorkflowName(String(stepName));
@@ -239,6 +239,7 @@ type AttributeKey =
239
239
  | 'resumeAt'
240
240
  | 'expiredAt'
241
241
  | 'workflowCoreVersion'
242
+ | 'workflowVm'
242
243
  | 'receivedCount'
243
244
  | 'lastReceivedAt'
244
245
  | 'disposedAt'
@@ -277,6 +278,7 @@ const attributeOrder: AttributeKey[] = [
277
278
  'computeInstanceId',
278
279
  'specVersion',
279
280
  'workflowCoreVersion',
281
+ 'workflowVm',
280
282
  'ownerId',
281
283
  'projectId',
282
284
  'environment',
@@ -335,6 +337,7 @@ const attributeDisplayNames: Partial<Record<AttributeKey, string>> = {
335
337
  computeInstanceId: 'Compute Instance ID',
336
338
  specVersion: 'Spec Version',
337
339
  workflowCoreVersion: '@workflow/core version',
340
+ workflowVm: 'Workflow VM',
338
341
  occurredAt: 'Occurred',
339
342
  createdAt: 'Created',
340
343
  startedAt: 'Started',
@@ -471,6 +474,9 @@ const attributeToDisplayFn: Record<
471
474
  computeInstanceId: opaqueIdOrNull,
472
475
  specVersion: (value: unknown) => String(value),
473
476
  workflowCoreVersion: (value: unknown) => String(value),
477
+ // Only present when the run's executionContext recorded an engine.
478
+ workflowVm: (value: unknown) =>
479
+ typeof value === 'string' && value.length > 0 ? value : null,
474
480
  // Tenancy (we don't show these)
475
481
  ownerId: (_value: unknown) => null,
476
482
  projectId: (_value: unknown) => null,
@@ -905,7 +911,7 @@ export const AttributePanel = ({
905
911
  /** Resource type of the selected span, used to show targeted loading skeletons. */
906
912
  resource?: string;
907
913
  }) => {
908
- // Extract workflowCoreVersion from executionContext for display
914
+ // Extract workflowCoreVersion / workflowVm from executionContext for display
909
915
  const displayData = useMemo(() => {
910
916
  const result = { ...data };
911
917
  const execCtx = data.executionContext as
@@ -914,6 +920,9 @@ export const AttributePanel = ({
914
920
  if (execCtx?.workflowCoreVersion) {
915
921
  result.workflowCoreVersion = execCtx.workflowCoreVersion;
916
922
  }
923
+ if (typeof execCtx?.workflowVm === 'string') {
924
+ result.workflowVm = execCtx.workflowVm;
925
+ }
917
926
  if (moduleSpecifier) {
918
927
  result.moduleSpecifier = moduleSpecifier;
919
928
  } else if (typeof data.stepName === 'string') {
@@ -141,4 +141,32 @@ describe('stepToSpan', () => {
141
141
 
142
142
  expect(span?.name).toBe('fetchInvoices');
143
143
  });
144
+
145
+ it('names and times a step whose creation is recorded on its step_started', () => {
146
+ const span = stepToSpan(
147
+ [
148
+ event({
149
+ eventType: 'step_started',
150
+ correlationId: 'step_1',
151
+ createdAt: date(1_000),
152
+ eventData: { stepName: 'step//src/billing.ts//fetchInvoices' },
153
+ }),
154
+ event({
155
+ eventType: 'step_completed',
156
+ correlationId: 'step_1',
157
+ createdAt: date(2_000),
158
+ eventData: { result: null },
159
+ }),
160
+ ],
161
+ date(2_000)
162
+ );
163
+
164
+ expect(span?.name).toBe('fetchInvoices');
165
+ expect(span?.attributes.data).toMatchObject({
166
+ stepName: 'step//src/billing.ts//fetchInvoices',
167
+ status: 'completed',
168
+ attempt: 1,
169
+ });
170
+ expect(otelTimeToMs(span!.startTime)).toBe(1_000);
171
+ });
144
172
  });
@@ -172,9 +172,13 @@ export const stepEventsToStepEntity = (
172
172
  (event) => event.eventType === 'step_created'
173
173
  );
174
174
 
175
- // V1 runs don't emit step_created events. Fall back to the earliest event
176
- // in the group so we can still build a step span.
175
+ // V1 runs don't emit step_created events, and a World may record an inline
176
+ // step's creation on its `step_started` alone. Fall back to the earliest
177
+ // event in the group so we can still build a step span.
177
178
  const anchorEvent = createdEvent ?? events[0];
179
+ const firstStartedEvent = events.find(
180
+ (event) => event.eventType === 'step_started'
181
+ );
178
182
  if (!anchorEvent) {
179
183
  return null;
180
184
  }
@@ -218,7 +222,10 @@ export const stepEventsToStepEntity = (
218
222
  return {
219
223
  stepId: anchorEvent.correlationId ?? '',
220
224
  runId: anchorEvent.runId,
221
- stepName: createdEvent?.eventData?.stepName ?? '',
225
+ stepName:
226
+ createdEvent?.eventData?.stepName ??
227
+ firstStartedEvent?.eventData?.stepName ??
228
+ '',
222
229
  status,
223
230
  attempt,
224
231
  createdAt: getEventTimestamp(anchorEvent) ?? anchorEvent.createdAt,
package/src/index.ts CHANGED
@@ -59,6 +59,13 @@ export {
59
59
  STREAM_REF_TYPE,
60
60
  truncateId,
61
61
  } from './lib/hydration';
62
+ export {
63
+ getRunLimitGuidance,
64
+ isQuickJSSnapshotRun,
65
+ type RunLimitGuidance,
66
+ type RunLimitGuidanceInput,
67
+ type RunLimitGuidanceKind,
68
+ } from './lib/run-limit-guidance';
62
69
  export {
63
70
  isSealedNoopEvent,
64
71
  SEALED_EVENT_MESSAGE,
@@ -80,17 +80,18 @@ describe('findDuplicateEventIds', () => {
80
80
  ).toEqual(new Set([createdAgain.eventId, startedAgain.eventId]));
81
81
  });
82
82
 
83
- it('leaves a class the log has not recorded for the entity yet', () => {
84
- // The step finished without a step_started in the log, so this one repeats
85
- // nothing. The runtime reports that as divergence rather than passing it
86
- // over, and the UI must not present it as a settled repeat.
83
+ it('reads past a start after the outcome even if it repeats nothing', () => {
84
+ // Terminal-inert: once the step's outcome is in the log, every later
85
+ // event for the step is read past, the same as the runtime does.
87
86
  const events = [
88
87
  event('step_created', { correlationId: 'step_a' }),
89
88
  event('step_completed', { correlationId: 'step_a' }),
90
89
  event('step_started', { correlationId: 'step_a' }),
91
90
  ];
92
91
 
93
- expect(findDuplicateEventIds(events, COMPLETE)).toEqual(new Set());
92
+ expect(findDuplicateEventIds(events, COMPLETE)).toEqual(
93
+ new Set([events[2].eventId])
94
+ );
94
95
  });
95
96
 
96
97
  it('treats completed and failed as one terminal class', () => {
@@ -266,11 +267,7 @@ describe('findDuplicateEventIds', () => {
266
267
  ).toEqual(new Set());
267
268
  });
268
269
 
269
- it('classifies nothing past the point the run diverged', () => {
270
- // The step finished without a step_started, so the runtime reports
271
- // divergence on the first trailing start and exits. The second start and
272
- // the wait's repeat after it went unread, and neither is a repeat the run
273
- // passed over. The wait's repeat before it still is.
270
+ it('reads past every event of an entity after it closed', () => {
274
271
  const events = [
275
272
  event('wait_created', { correlationId: 'wait_a' }),
276
273
  event('wait_completed', { correlationId: 'wait_a' }),
@@ -283,7 +280,7 @@ describe('findDuplicateEventIds', () => {
283
280
  ];
284
281
 
285
282
  expect(findDuplicateEventIds(events, COMPLETE)).toEqual(
286
- new Set([events[2].eventId])
283
+ new Set([2, 5, 6, 7].map((index) => events[index].eventId))
287
284
  );
288
285
  });
289
286
 
@@ -21,9 +21,9 @@ import {
21
21
  * registered callback has declined it, and a callback registered for a
22
22
  * still-open entity legitimately claims a repeat (each retry of a step writes
23
23
  * another `step_started`, and a live step consumer absorbs a second
24
- * `step_created`). So a repeat counts here only once a terminal event for the
24
+ * `step_created`). So an event counts here only once a terminal event for the
25
25
  * same entity sits earlier in the log, which is the point past which no
26
- * consumer remains.
26
+ * consumer remains, and from then on every event for that entity counts.
27
27
  */
28
28
 
29
29
  /** Classes with no entity to close first: the log records one per run. */
@@ -107,6 +107,15 @@ function foldDuplicates(ordered: readonly Event[]): Set<string> {
107
107
  const closedEntities = new Set<string>();
108
108
 
109
109
  for (const event of ordered) {
110
+ // Terminal-inert: once an entity's terminal event is in the log, its
111
+ // consumer is gone and every later event under the same correlation id
112
+ // is read past, whatever its class (a start or a retry after the step's
113
+ // outcome included). This is the rule the runtime applies too.
114
+ if (event.correlationId && closedEntities.has(event.correlationId)) {
115
+ duplicates.add(event.eventId);
116
+ continue;
117
+ }
118
+
110
119
  // Shared with the runtime's own duplicate detection, deliberately: an
111
120
  // event it tracks under no class is one it never reads past, so naming it
112
121
  // here would grey out an event the run acted on.
@@ -116,26 +125,19 @@ function foldDuplicates(ordered: readonly Event[]): Set<string> {
116
125
  const { eventClass, entity } = classification;
117
126
  const classKey = `${eventClass}:${entity}`;
118
127
  const repeatsClass = seenClasses.has(classKey);
119
- const entityWasClosed = closedEntities.has(entity);
120
128
 
121
129
  if (TERMINAL_EVENT_CLASSES.has(eventClass)) {
122
130
  closedEntities.add(entity);
123
131
  }
124
132
 
125
133
  if (!repeatsClass) {
126
- // First of its class, but the entity already finished: no consumer is
127
- // left to take it and it repeats nothing, so the runtime reports
128
- // divergence here and exits. Everything past this point went unread, so
129
- // the fold stops with it rather than recording the class and presenting
130
- // a later event of it as a repeat the run passed over.
131
- if (entityWasClosed) break;
132
134
  seenClasses.add(classKey);
133
135
  continue;
134
136
  }
135
137
 
136
138
  // The entity is still open, so a consumer is registered for it and takes
137
139
  // this event: another attempt, not a repeat read past.
138
- if (entityWasClosed || SINGLETON_EVENT_CLASSES.has(eventClass)) {
140
+ if (SINGLETON_EVENT_CLASSES.has(eventClass)) {
139
141
  duplicates.add(event.eventId);
140
142
  }
141
143
  }
@@ -144,8 +146,9 @@ function foldDuplicates(ordered: readonly Event[]): Set<string> {
144
146
  }
145
147
 
146
148
  /**
147
- * The IDs of the events in `events` that repeat a class the log already
148
- * records for the same entity, after that entity finished.
149
+ * The IDs of the events in `events` the run reads past: every event recorded
150
+ * for an entity after that entity's terminal event, and a repeat of a class
151
+ * that records once per run.
149
152
  *
150
153
  * `isCompleteHistory` must be false whenever the caller holds a subset of the
151
154
  * run's log: one page of a paginated list, or the result of a search. Which
@@ -153,10 +156,9 @@ function foldDuplicates(ordered: readonly Event[]): Set<string> {
153
156
  * subset the earlier event may be missing, and the fold would report
154
157
  * the surviving one. Nothing is classified in that case.
155
158
  *
156
- * Two other things make the answer unknowable and yield the same empty result:
157
- * a log whose order cannot be recovered from the events (see
158
- * {@link hasKnowableLogOrder}), and everything past the point the run
159
- * diverged, since the run exited there and read no further.
159
+ * A log whose order cannot be recovered from the events (see
160
+ * {@link hasKnowableLogOrder}) also makes the answer unknowable and yields the
161
+ * same empty result.
160
162
  */
161
163
  export function findDuplicateEventIds(
162
164
  events: readonly Event[],
@@ -39,6 +39,25 @@ describe('materializeSteps', () => {
39
39
  expect(step.completedAt?.getTime()).toBe(BASE_TIME + 5000);
40
40
  });
41
41
 
42
+ it('materializes a step whose creation is recorded on its step_started', () => {
43
+ const started = event('step_started', { correlationId: 'step_a', at: 2 });
44
+ const events = [
45
+ { ...started, eventData: { stepName: 'doWork' } } as Event,
46
+ event('step_completed', { correlationId: 'step_a', at: 5 }),
47
+ ];
48
+
49
+ const [step] = materializeSteps(events);
50
+
51
+ expect(step).toMatchObject({
52
+ stepId: 'step_a',
53
+ stepName: 'doWork',
54
+ status: 'completed',
55
+ attempt: 1,
56
+ });
57
+ expect(step.createdAt.getTime()).toBe(BASE_TIME + 2000);
58
+ expect(step.startedAt?.getTime()).toBe(BASE_TIME + 2000);
59
+ });
60
+
42
61
  it('counts one attempt per start across retries', () => {
43
62
  const events = [
44
63
  event('step_created', { correlationId: 'step_a', at: 1 }),
@@ -105,7 +105,9 @@ function getEventTimestamp(event: Event | undefined): Date | undefined {
105
105
  * Group step_* events by correlationId and build Step-like entities.
106
106
  *
107
107
  * Handles partial event lists gracefully: a step may only have a
108
- * step_created event with no completion yet.
108
+ * step_created event with no completion yet. A step whose creation the World
109
+ * recorded on its first `step_started` (no `step_created` in the log) is
110
+ * anchored on that start instead.
109
111
  *
110
112
  * The derived status and timestamps come from the events the run acted on. A
111
113
  * repeat of a class the log already records is read past by every replay, so
@@ -127,7 +129,12 @@ export function materializeSteps(
127
129
  const steps: MaterializedStep[] = [];
128
130
 
129
131
  for (const [correlationId, stepEvents] of groups) {
130
- const created = stepEvents.find((e) => e.eventType === 'step_created');
132
+ // A World may record an inline step's creation on its `step_started`
133
+ // alone, with no `step_created` in the log. That start is then the step's
134
+ // creation event.
135
+ const created =
136
+ stepEvents.find((e) => e.eventType === 'step_created') ??
137
+ stepEvents.find((e) => e.eventType === 'step_started');
131
138
  if (!created) continue;
132
139
 
133
140
  let status: StepStatus = 'pending';
@@ -168,7 +175,8 @@ export function materializeSteps(
168
175
  stepId: correlationId,
169
176
  runId: created.runId,
170
177
  stepName:
171
- created.eventType === 'step_created'
178
+ created.eventType === 'step_created' ||
179
+ created.eventType === 'step_started'
172
180
  ? (created.eventData?.stepName ?? correlationId)
173
181
  : correlationId,
174
182
  status,
@@ -0,0 +1,90 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ getRunLimitGuidance,
4
+ isQuickJSSnapshotRun,
5
+ } from './run-limit-guidance';
6
+
7
+ const failed = (errorCode: string, extra: Record<string, unknown> = {}) => ({
8
+ status: 'failed',
9
+ errorCode,
10
+ ...extra,
11
+ });
12
+
13
+ describe('getRunLimitGuidance', () => {
14
+ it('returns null for missing, non-failed, and unrelated runs', () => {
15
+ expect(getRunLimitGuidance(undefined)).toBeNull();
16
+ expect(getRunLimitGuidance(null)).toBeNull();
17
+ expect(
18
+ getRunLimitGuidance({
19
+ status: 'running',
20
+ errorCode: 'MAX_EVENTS_EXCEEDED',
21
+ })
22
+ ).toBeNull();
23
+ expect(getRunLimitGuidance(failed('USER_ERROR'))).toBeNull();
24
+ expect(getRunLimitGuidance({ status: 'failed' })).toBeNull();
25
+ });
26
+
27
+ it('recommends WORKFLOW_VM=quickjs for node runs that hit the event limit', () => {
28
+ const guidance = getRunLimitGuidance(failed('MAX_EVENTS_EXCEEDED'));
29
+ expect(guidance).toMatchObject({
30
+ kind: 'max-events-exceeded',
31
+ envVar: 'WORKFLOW_VM=quickjs',
32
+ docsUrl: 'https://workflow-sdk.dev/err/max-events-exceeded',
33
+ });
34
+ expect(
35
+ getRunLimitGuidance(failed('MAX_EVENTS_EXCEEDED', { workflowVm: 'node' }))
36
+ ?.envVar
37
+ ).toBe('WORKFLOW_VM=quickjs');
38
+ });
39
+
40
+ it('recommends QuickJS for replay timeouts', () => {
41
+ expect(getRunLimitGuidance(failed('REPLAY_TIMEOUT'))).toMatchObject({
42
+ kind: 'replay-timeout',
43
+ envVar: 'WORKFLOW_VM=quickjs',
44
+ docsUrl: 'https://workflow-sdk.dev/err/replay-timeout',
45
+ });
46
+ });
47
+
48
+ it('suggests a snapshot threshold for QuickJS runs without one', () => {
49
+ for (const extra of [
50
+ { workflowVm: 'quickjs' },
51
+ { workflowVm: 'quickjs', snapshotThreshold: 0 },
52
+ ]) {
53
+ const guidance = getRunLimitGuidance(
54
+ failed('MAX_EVENTS_EXCEEDED', extra)
55
+ );
56
+ expect(guidance?.envVar).toBe('WORKFLOW_SNAPSHOT_THRESHOLD=1000');
57
+ expect(guidance?.description).toContain('QuickJS');
58
+ }
59
+ });
60
+
61
+ it('returns null for runs already on QuickJS with snapshotting', () => {
62
+ const hydrated = { workflowVm: 'quickjs', snapshotThreshold: 1000 };
63
+ expect(
64
+ getRunLimitGuidance(failed('MAX_EVENTS_EXCEEDED', hydrated))
65
+ ).toBeNull();
66
+ expect(getRunLimitGuidance(failed('REPLAY_TIMEOUT', hydrated))).toBeNull();
67
+ // Raw (unhydrated) runs carry the policy in executionContext.
68
+ expect(
69
+ getRunLimitGuidance(
70
+ failed('MAX_EVENTS_EXCEEDED', { executionContext: hydrated })
71
+ )
72
+ ).toBeNull();
73
+ });
74
+ });
75
+
76
+ describe('isQuickJSSnapshotRun', () => {
77
+ it('requires the QuickJS VM and a positive safe-integer threshold', () => {
78
+ expect(
79
+ isQuickJSSnapshotRun({ workflowVm: 'quickjs', snapshotThreshold: 1 })
80
+ ).toBe(true);
81
+ expect(isQuickJSSnapshotRun({ workflowVm: 'quickjs' })).toBe(false);
82
+ expect(
83
+ isQuickJSSnapshotRun({ workflowVm: 'quickjs', snapshotThreshold: 1.5 })
84
+ ).toBe(false);
85
+ expect(
86
+ isQuickJSSnapshotRun({ workflowVm: 'node', snapshotThreshold: 1000 })
87
+ ).toBe(false);
88
+ expect(isQuickJSSnapshotRun({})).toBe(false);
89
+ });
90
+ });