@swirls/looms 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 06942de: An in-process effect whose attempts keep being lost now fails instead of being re-attempted without limit. When a wake finds an attempt that an earlier wake started and never finished, because its process was lost or the wake failed, it still starts the next attempt, but only while attempts remain: up to the effect's `maxAttempts`, or three attempts when the effect has no retry policy. After that the effect fails with `attempt N was lost before it finished, and no attempts remain`. Attempts ended by a signal in the same wake, such as steering an agent, are not treated as lost.
8
+
3
9
  ## 0.13.1
4
10
 
5
11
  ### Patch Changes
@@ -24,252 +24,6 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
24
24
  readonly alreadyCompacted?: boolean | undefined;
25
25
  readonly consumedSteerMessageIds?: readonly string[] | undefined;
26
26
  }, AgentDefinitionsTag | LlmTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
27
- readonly type: "runtime.child.close.requested";
28
- readonly payload: {
29
- readonly policy: "terminate" | "wait";
30
- };
31
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
32
- readonly type: "runtime.child.settled";
33
- readonly payload: {
34
- readonly runId: string;
35
- readonly status: "cancelled" | "completed" | "failed";
36
- readonly output: Schema.Json;
37
- readonly error: string | null;
38
- };
39
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
40
- readonly type: "runtime.effect.ambiguous";
41
- readonly payload: {
42
- readonly effectId: string;
43
- readonly attempt: number;
44
- readonly error: string;
45
- };
46
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
47
- readonly type: "runtime.effect.attempt.started";
48
- readonly payload: {
49
- readonly effectId: string;
50
- readonly attempt: number;
51
- };
52
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
53
- readonly type: "runtime.effect.cancel.requested";
54
- readonly payload: {
55
- readonly effectId: string;
56
- readonly attempt: number;
57
- readonly deadlineAt: number | null;
58
- };
59
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
60
- readonly type: "runtime.effect.cancelled";
61
- readonly payload: {
62
- readonly effectId: string;
63
- readonly attempt: number;
64
- };
65
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
66
- readonly type: "runtime.effect.completed";
67
- readonly payload: {
68
- readonly effectId: string;
69
- readonly attempt: number;
70
- };
71
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
72
- readonly type: "runtime.effect.dispatch.deferred";
73
- readonly payload: {
74
- readonly effectId: string;
75
- readonly attempt: number;
76
- readonly retryAt: number;
77
- readonly error: string;
78
- readonly try: number;
79
- };
80
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
81
- readonly type: "runtime.effect.dispatched";
82
- readonly payload: {
83
- readonly effectId: string;
84
- readonly attempt: number;
85
- readonly deadlineAt: number | null;
86
- };
87
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
88
- readonly type: "runtime.effect.failed";
89
- readonly payload: {
90
- readonly effectId: string;
91
- readonly error: string;
92
- readonly nonRetryable?: boolean | undefined;
93
- readonly retryAfterMs?: number | undefined;
94
- };
95
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
96
- readonly type: "runtime.effect.heartbeat";
97
- readonly payload: {
98
- readonly effectId: string;
99
- readonly attempt: number;
100
- readonly heartbeatAt: number;
101
- readonly deadlineAt: number | null;
102
- readonly details?: Schema.Json | undefined;
103
- };
104
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
105
- readonly type: "runtime.effect.queued";
106
- readonly payload: {
107
- readonly effectId: string;
108
- readonly attempt: number;
109
- readonly deadlineAt: number | null;
110
- };
111
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
112
- readonly type: "runtime.effect.retry.scheduled";
113
- readonly payload: {
114
- readonly effectId: string;
115
- readonly attempt: number;
116
- readonly nextAttemptAt: number;
117
- readonly error: string;
118
- };
119
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
120
- readonly type: "runtime.effect.timed_out";
121
- readonly payload: {
122
- readonly effectId: string;
123
- readonly attempt: number;
124
- readonly timeout: string;
125
- };
126
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
127
- readonly type: "runtime.effect.worker.started";
128
- readonly payload: {
129
- readonly effectId: string;
130
- readonly attempt: number;
131
- readonly deadlineAt: number | null;
132
- };
133
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
134
- readonly type: "runtime.fork.elided";
135
- readonly payload: {
136
- readonly type: string;
137
- };
138
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
139
- readonly type: "runtime.run.cancelled";
140
- readonly payload: {
141
- readonly reason?: string | undefined;
142
- };
143
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
144
- readonly type: "runtime.run.completed";
145
- readonly payload: {
146
- readonly output: Schema.Json;
147
- readonly error: string | null;
148
- };
149
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
150
- readonly type: "runtime.run.forked";
151
- readonly payload: {
152
- readonly sourceRunId: string;
153
- readonly sourceSeq: number;
154
- };
155
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
156
- readonly type: "runtime.run.launched";
157
- readonly payload: {
158
- readonly runId: string;
159
- readonly kind: string;
160
- readonly definitionName: string;
161
- readonly definitionVersion: string;
162
- readonly effectId: string;
163
- readonly close: "terminate" | "wait";
164
- };
165
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
166
- readonly type: "runtime.run.started";
167
- readonly payload: {
168
- readonly rootThreadId?: string | undefined;
169
- readonly kind: string;
170
- readonly definitionName: string;
171
- readonly definitionVersion: string;
172
- readonly input: Schema.Json;
173
- readonly requestedThreadId?: string | null | undefined;
174
- readonly launchedBy?: {
175
- readonly runId: string;
176
- readonly threadId: string;
177
- readonly effectId: string;
178
- readonly causationId: string;
179
- readonly causationSeq: number;
180
- } | undefined;
181
- readonly attributes?: {
182
- readonly [x: string]: string;
183
- } | undefined;
184
- readonly trace?: {
185
- readonly traceparent: string;
186
- readonly tracestate?: string | undefined;
187
- } | undefined;
188
- };
189
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
190
- readonly type: "runtime.signal.received";
191
- readonly payload: {
192
- readonly signalType: string;
193
- };
194
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
195
- readonly type: "runtime.snapshot.taken";
196
- readonly payload: {
197
- readonly seq: number;
198
- readonly stateHash: string;
199
- readonly state?: Schema.Json | undefined;
200
- };
201
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
202
- readonly type: "runtime.thread.cancel.requested";
203
- readonly payload: {
204
- readonly threadId: string;
205
- };
206
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
207
- readonly type: "runtime.thread.cancelled";
208
- readonly payload: {
209
- readonly threadId: string;
210
- readonly reason?: string | undefined;
211
- readonly resumeSeq?: number | undefined;
212
- };
213
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
214
- readonly type: "runtime.thread.completed";
215
- readonly payload: {
216
- readonly threadId: string;
217
- readonly output: Schema.Json;
218
- };
219
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
220
- readonly type: "runtime.thread.failed";
221
- readonly payload: {
222
- readonly threadId: string;
223
- readonly error: string;
224
- };
225
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
226
- readonly type: "runtime.thread.started";
227
- readonly payload: {
228
- readonly threadId: string;
229
- readonly kind: string;
230
- readonly definitionName: string;
231
- readonly definitionVersion: string;
232
- readonly input: Schema.Json;
233
- readonly parentThreadId: string | null;
234
- };
235
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
236
- readonly type: "runtime.timer.fired";
237
- readonly payload: {
238
- readonly timerId: string;
239
- readonly waitId: string;
240
- };
241
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
242
- readonly type: "runtime.timer.set";
243
- readonly payload: {
244
- readonly timerId: string;
245
- readonly waitId: string;
246
- readonly wakeAt: number;
247
- };
248
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
249
- readonly type: "runtime.wait.registered";
250
- readonly payload: {
251
- readonly waitId: string;
252
- readonly threadId?: string | undefined;
253
- readonly on: {
254
- readonly type: string | readonly string[];
255
- readonly match?: Schema.Json | undefined;
256
- } | {
257
- readonly timerAt: number;
258
- };
259
- readonly tag?: Schema.Json | undefined;
260
- };
261
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
262
- readonly type: "runtime.wait.satisfied";
263
- readonly payload: {
264
- readonly waitId: string;
265
- readonly tag?: Schema.Json | undefined;
266
- readonly event: {
267
- readonly id: string;
268
- readonly type: string;
269
- readonly payload: Schema.Json;
270
- };
271
- };
272
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
273
27
  readonly type: "agent.context.compacted";
274
28
  readonly payload: {
275
29
  readonly turn: number;
@@ -517,19 +271,7 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
517
271
  readonly input: number;
518
272
  readonly output: number;
519
273
  };
520
- })>>;
521
- export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
522
- readonly turn: number;
523
- readonly definitionName?: string | undefined;
524
- readonly definitionVersion: string;
525
- readonly toolCall: {
526
- readonly id: string;
527
- readonly name: string;
528
- readonly arguments: Schema.Json;
529
- };
530
- readonly input?: Schema.Json | undefined;
531
- readonly depth?: number | undefined;
532
- }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
274
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
533
275
  readonly type: "runtime.child.close.requested";
534
276
  readonly payload: {
535
277
  readonly policy: "terminate" | "wait";
@@ -775,7 +517,19 @@ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").Loc
775
517
  readonly payload: Schema.Json;
776
518
  };
777
519
  };
778
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
520
+ })>>;
521
+ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
522
+ readonly turn: number;
523
+ readonly definitionName?: string | undefined;
524
+ readonly definitionVersion: string;
525
+ readonly toolCall: {
526
+ readonly id: string;
527
+ readonly name: string;
528
+ readonly arguments: Schema.Json;
529
+ };
530
+ readonly input?: Schema.Json | undefined;
531
+ readonly depth?: number | undefined;
532
+ }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
779
533
  readonly type: "agent.context.compacted";
780
534
  readonly payload: {
781
535
  readonly turn: number;
@@ -1023,5 +777,251 @@ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").Loc
1023
777
  readonly input: number;
1024
778
  readonly output: number;
1025
779
  };
780
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
781
+ readonly type: "runtime.child.close.requested";
782
+ readonly payload: {
783
+ readonly policy: "terminate" | "wait";
784
+ };
785
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
786
+ readonly type: "runtime.child.settled";
787
+ readonly payload: {
788
+ readonly runId: string;
789
+ readonly status: "cancelled" | "completed" | "failed";
790
+ readonly output: Schema.Json;
791
+ readonly error: string | null;
792
+ };
793
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
794
+ readonly type: "runtime.effect.ambiguous";
795
+ readonly payload: {
796
+ readonly effectId: string;
797
+ readonly attempt: number;
798
+ readonly error: string;
799
+ };
800
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
801
+ readonly type: "runtime.effect.attempt.started";
802
+ readonly payload: {
803
+ readonly effectId: string;
804
+ readonly attempt: number;
805
+ };
806
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
807
+ readonly type: "runtime.effect.cancel.requested";
808
+ readonly payload: {
809
+ readonly effectId: string;
810
+ readonly attempt: number;
811
+ readonly deadlineAt: number | null;
812
+ };
813
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
814
+ readonly type: "runtime.effect.cancelled";
815
+ readonly payload: {
816
+ readonly effectId: string;
817
+ readonly attempt: number;
818
+ };
819
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
820
+ readonly type: "runtime.effect.completed";
821
+ readonly payload: {
822
+ readonly effectId: string;
823
+ readonly attempt: number;
824
+ };
825
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
826
+ readonly type: "runtime.effect.dispatch.deferred";
827
+ readonly payload: {
828
+ readonly effectId: string;
829
+ readonly attempt: number;
830
+ readonly retryAt: number;
831
+ readonly error: string;
832
+ readonly try: number;
833
+ };
834
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
835
+ readonly type: "runtime.effect.dispatched";
836
+ readonly payload: {
837
+ readonly effectId: string;
838
+ readonly attempt: number;
839
+ readonly deadlineAt: number | null;
840
+ };
841
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
842
+ readonly type: "runtime.effect.failed";
843
+ readonly payload: {
844
+ readonly effectId: string;
845
+ readonly error: string;
846
+ readonly nonRetryable?: boolean | undefined;
847
+ readonly retryAfterMs?: number | undefined;
848
+ };
849
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
850
+ readonly type: "runtime.effect.heartbeat";
851
+ readonly payload: {
852
+ readonly effectId: string;
853
+ readonly attempt: number;
854
+ readonly heartbeatAt: number;
855
+ readonly deadlineAt: number | null;
856
+ readonly details?: Schema.Json | undefined;
857
+ };
858
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
859
+ readonly type: "runtime.effect.queued";
860
+ readonly payload: {
861
+ readonly effectId: string;
862
+ readonly attempt: number;
863
+ readonly deadlineAt: number | null;
864
+ };
865
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
866
+ readonly type: "runtime.effect.retry.scheduled";
867
+ readonly payload: {
868
+ readonly effectId: string;
869
+ readonly attempt: number;
870
+ readonly nextAttemptAt: number;
871
+ readonly error: string;
872
+ };
873
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
874
+ readonly type: "runtime.effect.timed_out";
875
+ readonly payload: {
876
+ readonly effectId: string;
877
+ readonly attempt: number;
878
+ readonly timeout: string;
879
+ };
880
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
881
+ readonly type: "runtime.effect.worker.started";
882
+ readonly payload: {
883
+ readonly effectId: string;
884
+ readonly attempt: number;
885
+ readonly deadlineAt: number | null;
886
+ };
887
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
888
+ readonly type: "runtime.fork.elided";
889
+ readonly payload: {
890
+ readonly type: string;
891
+ };
892
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
893
+ readonly type: "runtime.run.cancelled";
894
+ readonly payload: {
895
+ readonly reason?: string | undefined;
896
+ };
897
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
898
+ readonly type: "runtime.run.completed";
899
+ readonly payload: {
900
+ readonly output: Schema.Json;
901
+ readonly error: string | null;
902
+ };
903
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
904
+ readonly type: "runtime.run.forked";
905
+ readonly payload: {
906
+ readonly sourceRunId: string;
907
+ readonly sourceSeq: number;
908
+ };
909
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
910
+ readonly type: "runtime.run.launched";
911
+ readonly payload: {
912
+ readonly runId: string;
913
+ readonly kind: string;
914
+ readonly definitionName: string;
915
+ readonly definitionVersion: string;
916
+ readonly effectId: string;
917
+ readonly close: "terminate" | "wait";
918
+ };
919
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
920
+ readonly type: "runtime.run.started";
921
+ readonly payload: {
922
+ readonly rootThreadId?: string | undefined;
923
+ readonly kind: string;
924
+ readonly definitionName: string;
925
+ readonly definitionVersion: string;
926
+ readonly input: Schema.Json;
927
+ readonly requestedThreadId?: string | null | undefined;
928
+ readonly launchedBy?: {
929
+ readonly runId: string;
930
+ readonly threadId: string;
931
+ readonly effectId: string;
932
+ readonly causationId: string;
933
+ readonly causationSeq: number;
934
+ } | undefined;
935
+ readonly attributes?: {
936
+ readonly [x: string]: string;
937
+ } | undefined;
938
+ readonly trace?: {
939
+ readonly traceparent: string;
940
+ readonly tracestate?: string | undefined;
941
+ } | undefined;
942
+ };
943
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
944
+ readonly type: "runtime.signal.received";
945
+ readonly payload: {
946
+ readonly signalType: string;
947
+ };
948
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
949
+ readonly type: "runtime.snapshot.taken";
950
+ readonly payload: {
951
+ readonly seq: number;
952
+ readonly stateHash: string;
953
+ readonly state?: Schema.Json | undefined;
954
+ };
955
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
956
+ readonly type: "runtime.thread.cancel.requested";
957
+ readonly payload: {
958
+ readonly threadId: string;
959
+ };
960
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
961
+ readonly type: "runtime.thread.cancelled";
962
+ readonly payload: {
963
+ readonly threadId: string;
964
+ readonly reason?: string | undefined;
965
+ readonly resumeSeq?: number | undefined;
966
+ };
967
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
968
+ readonly type: "runtime.thread.completed";
969
+ readonly payload: {
970
+ readonly threadId: string;
971
+ readonly output: Schema.Json;
972
+ };
973
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
974
+ readonly type: "runtime.thread.failed";
975
+ readonly payload: {
976
+ readonly threadId: string;
977
+ readonly error: string;
978
+ };
979
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
980
+ readonly type: "runtime.thread.started";
981
+ readonly payload: {
982
+ readonly threadId: string;
983
+ readonly kind: string;
984
+ readonly definitionName: string;
985
+ readonly definitionVersion: string;
986
+ readonly input: Schema.Json;
987
+ readonly parentThreadId: string | null;
988
+ };
989
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
990
+ readonly type: "runtime.timer.fired";
991
+ readonly payload: {
992
+ readonly timerId: string;
993
+ readonly waitId: string;
994
+ };
995
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
996
+ readonly type: "runtime.timer.set";
997
+ readonly payload: {
998
+ readonly timerId: string;
999
+ readonly waitId: string;
1000
+ readonly wakeAt: number;
1001
+ };
1002
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1003
+ readonly type: "runtime.wait.registered";
1004
+ readonly payload: {
1005
+ readonly waitId: string;
1006
+ readonly threadId?: string | undefined;
1007
+ readonly on: {
1008
+ readonly type: string | readonly string[];
1009
+ readonly match?: Schema.Json | undefined;
1010
+ } | {
1011
+ readonly timerAt: number;
1012
+ };
1013
+ readonly tag?: Schema.Json | undefined;
1014
+ };
1015
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1016
+ readonly type: "runtime.wait.satisfied";
1017
+ readonly payload: {
1018
+ readonly waitId: string;
1019
+ readonly tag?: Schema.Json | undefined;
1020
+ readonly event: {
1021
+ readonly id: string;
1022
+ readonly type: string;
1023
+ readonly payload: Schema.Json;
1024
+ };
1025
+ };
1026
1026
  })>>;
1027
1027
  export declare function readToolCall(value: JsonValue): ToolCall | null;
@@ -1,15 +1,17 @@
1
1
  import { Clock, Deferred, Effect, Exit, Fiber, Option, Queue, } from 'effect';
2
- import { createEvent, deferredUntil, EventStoreTag, foldRun, isRunTerminal, } from '@swirls/looms/core';
2
+ import { createEvent, deferredUntil, EventStoreTag, foldRun, isPrimitiveEffect, isRunTerminal, } from '@swirls/looms/core';
3
3
  import { childCloseCancellations, notifyLaunchingParent } from './child-run.js';
4
4
  import { nextRuntimeDeadline, planDeadlineTransitions, planTerminalCancellationTransitions, } from './deadline-transition-planner.js';
5
5
  import { admitOrFailAttempt } from './effect-admission.js';
6
6
  import { DuplicateEffectDispatchError, MaxWakeIterationsError, RuntimeExecutionError, } from './errors.js';
7
- import { cascadedCancellations, groupOutstanding, stripSeq, synthesizedThreadFailed, waitSatisfiedEvents, } from './helpers.js';
7
+ import { cascadedCancellations, createEffectFailedEvent, groupOutstanding, stripSeq, synthesizedThreadFailed, waitSatisfiedEvents, } from './helpers.js';
8
8
  import { executeLocalEffects } from './local-effect-executor.js';
9
9
  import { notifyObserver } from './observer.js';
10
10
  import { requestWakeAgain, } from './run-execution-context.js';
11
11
  import { dispatchWorkerEffect, isWorkerEffect, planWorkerEffects } from './worker-effect-dispatch.js';
12
12
  const DEFAULT_LIVENESS_LEASE_MS = 30_000;
13
+ /** Attempts allowed for an effect with no retry policy when its attempts keep being lost. */
14
+ const DEFAULT_LOST_ATTEMPT_LIMIT = 3;
13
15
  function currentTimeMillis() {
14
16
  return Math.floor(performance.timeOrigin + performance.now());
15
17
  }
@@ -77,6 +79,9 @@ export function createWakeEngine(options) {
77
79
  executionContext.resolveWakeCompletion = resolveCompletion;
78
80
  executionContext.waking = true;
79
81
  let released = false;
82
+ // `effectId:attempt` of every attempt this wake started, across its passes. An attempt
83
+ // found running that is not here was started by a wake that never finished it.
84
+ const startedByThisWake = new Set();
80
85
  // When the liveness deadline is next due for renewal; `null` while this wake holds none.
81
86
  let livenessRenewAt = null;
82
87
  // In-process effects have no deadline of their own, so nothing would wake the run if this
@@ -319,11 +324,35 @@ export function createWakeEngine(options) {
319
324
  }
320
325
  return yield* new DuplicateEffectDispatchError(runId, item.effectId, item.threadId);
321
326
  }
327
+ // An attempt left running by a wake that is gone (its process was lost, or the wake
328
+ // failed) is re-attempted below. That counts against the effect's attempts, so an
329
+ // effect that takes its process down every time fails instead of repeating forever.
330
+ const exhausted = outstanding.flatMap((item) => {
331
+ const execution = state.effectExecutions[item.effectId];
332
+ if (execution?.status !== 'running' ||
333
+ isPrimitiveEffect(item.effect) ||
334
+ startedByThisWake.has(`${item.effectId}:${execution.attempt}`)) {
335
+ return [];
336
+ }
337
+ const limit = registry.effects.get(item.effect.type)?.retry?.maxAttempts ??
338
+ DEFAULT_LOST_ATTEMPT_LIMIT;
339
+ return execution.attempt >= limit
340
+ ? [
341
+ createEffectFailedEvent(runId, item, `attempt ${execution.attempt} was lost before it finished, and no attempts remain`),
342
+ ]
343
+ : [];
344
+ });
345
+ if (exhausted.length > 0) {
346
+ yield* foldProduced(exhausted);
347
+ continue;
348
+ }
322
349
  const due = outstanding.filter((item) => !dispatchedEffectIds.has(dispatchKeyFor(item)));
323
350
  if (due.length > 0) {
324
351
  const attempts = new Map(due.map((item) => [item.effectId, attemptFor(item)]));
325
352
  for (const item of due) {
326
- dispatchedEffectIds.add(`${item.effectId}:${attempts.get(item.effectId) ?? 1}`);
353
+ const key = `${item.effectId}:${attempts.get(item.effectId) ?? 1}`;
354
+ dispatchedEffectIds.add(key);
355
+ startedByThisWake.add(key);
327
356
  }
328
357
  const attemptEvents = due.map((item) => createEvent(runId, {
329
358
  type: 'runtime.effect.attempt.started',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/looms",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Pluggable event-sourced runtime for durable agents and workflows",
5
5
  "homepage": "https://github.com/ByteSliceHQ/looms#readme",
6
6
  "bugs": {