Skip to content

Commit 69983f8

Browse files
committed
fix: retain ingress recovery after settlement failure
1 parent 1079ccf commit 69983f8

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎src/channels/message/ingress-drain.debounce-failure.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,62 @@ describe("channel ingress drain debounce failures", () => {
8484
drain.dispose();
8585
});
8686
});
87+
88+
it("keeps watchdog recovery after retry settlement fails", async () => {
89+
vi.useFakeTimers();
90+
await withTempState(async (stateDir) => {
91+
let clock = 10_000;
92+
const queue = createTestIngressQueue(stateDir, { now: () => clock });
93+
await queue.enqueue(
94+
"debounced-settlement-failure",
95+
{ text: "retry me" },
96+
{ laneKey: "shared", receivedAt: clock },
97+
);
98+
queue.release = async () => {
99+
throw new Error("persistent release failure");
100+
};
101+
102+
const sessionError = new Error("Session changed while starting work. Retry.");
103+
const debouncer = createInboundDebouncer<{ lifecycle: ChannelIngressDispatchLifecycle }>({
104+
debounceMs: 0,
105+
buildKey: () => "shared",
106+
onFlush: (entries, createFlush) =>
107+
createFlush({
108+
lifecycle: entries[0]?.lifecycle,
109+
dispatch: async () => {
110+
throw sessionError;
111+
},
112+
}),
113+
onError: () => undefined,
114+
});
115+
const drain = createChannelIngressDrain<Payload>({
116+
queue,
117+
now: () => clock,
118+
adoptionStallTimeoutMs: 200_000,
119+
dispatchClaimedEvent: async (_event, lifecycle) => {
120+
await debouncer.enqueue({ lifecycle });
121+
return { kind: "deferred" };
122+
},
123+
});
124+
125+
expect(await drain.drainOnce()).toEqual({ started: 1 });
126+
await vi.advanceTimersByTimeAsync(127_000);
127+
clock += 127_000;
128+
await drain.waitForIdle();
129+
130+
expect((await queue.listClaims()).map((claim) => claim.id)).toEqual([
131+
"debounced-settlement-failure",
132+
]);
133+
expect(drain.activeLaneKeys().has("shared")).toBe(true);
134+
135+
clock += 73_000;
136+
await vi.advanceTimersByTimeAsync(73_000);
137+
expect(await queue.listClaims()).toEqual([]);
138+
expect(await queue.listFailed?.({ limit: "all" })).toMatchObject([
139+
{ id: "debounced-settlement-failure", reason: "handler-timeout" },
140+
]);
141+
expect(drain.activeLaneKeys().has("shared")).toBe(false);
142+
drain.dispose();
143+
});
144+
});
87145
});

‎src/channels/message/ingress-drain.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ export function createChannelIngressDrain<
523523
if (state.guillotined || state.superseded) {
524524
return;
525525
}
526-
clearStallTimer(state);
526+
// Keep recovery armed until disposition commits; removeActive clears it after success.
527527
await state.settleOnce(async () => {
528528
await applyFailureDisposition(state.claim, error);
529529
});

0 commit comments

Comments
 (0)