The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): keep coalescing workers alive when processors throw (#32178)
luke committed
Nov 15, 2026 at 08:02 UTC
2045004096340f58cd72b31708f5aec7e63f29d0
2 files changed
+29
-3
packages/shared/src/KeyedCoalescingWorker.test.ts
+25
@@ -179,4 +179,29 @@ describe("makeKeyedCoalescingWorker", () => {
179
expect(processed).toEqual(["terminal-1:first", "terminal-2:quiet", "terminal-1:second"]);
180
}),
181
);
182
+ it.effect(
183
+ "keeps processing and releases the key when a processor throws before returning an effect",
184
+ () =>
185
+ Effect.scoped(
186
+ Effect.gen(function* () {
187
+ const processed: string[] = [];
188
+ const worker = yield* makeKeyedCoalescingWorker<string, string, never, never>({
189
+ merge: (_current, next) => next,
190
+ process: (key, value) => {
191
+ if (value === "broken") throw new Error("processor construction failed");
192
+ return Effect.sync(() => {
193
+ processed.push(`${key}:${value}`);
194
+ });
195
+ },
196
+ });
197
+ yield* worker.enqueue("first", "broken");
198
+ yield* worker.enqueue("second", "healthy");
199
+ yield* worker.drainKey("first");
200
+ yield* worker.drainKey("second");
201
+ yield* worker.enqueue("first", "recovered");
202
+ yield* worker.drainKey("first");
203
+ expect(processed).toEqual(["second:healthy", "first:recovered"]);
204
+ }),
205
+ ),
206
+ );
207
});
packages/shared/src/KeyedCoalescingWorker.ts
+4
-3
@@ -70,9 +70,10 @@ export const makeKeyedCoalescingWorker = Effect.fn(
70
Effect.flatMap((item) =>
71
item === null
72
? Effect.void
73
- : options
74
- .process(item.key, item.value)
75
- .pipe(Effect.ignoreCause, Effect.ensuring(completeKey(item.key))),
73
+ : Effect.suspend(() => options.process(item.key, item.value)).pipe(
74
+ Effect.ignoreCause,
75
+ Effect.ensuring(completeKey(item.key)),
76
+ ),
77
),
78
Effect.forever,
79
Effect.forkScoped,