Skip to content

Commit a34ad4b

Browse files
committed
fix(session-delivery): propagate non-ENOENT retry persistence failures
drainQueuedEntry swallowed a non-ENOENT error from failSessionDelivery as a clean "failed", so the retry metadata (retryCount/lastAttemptAt) never advanced and the entry was re-driven without progressing toward the max-retries terminal move. Re-throw non-ENOENT to match the sibling moveSessionDeliveryToFailed paths; ENOENT still maps to already-gone.
1 parent 527f8f0 commit a34ad4b

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎src/infra/session-delivery-queue-recovery.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ async function drainQueuedEntry(opts: {
114114
if (getErrnoCode(failErr) === "ENOENT") {
115115
return "already-gone";
116116
}
117-
return "failed";
117+
// A non-ENOENT persistence failure here means the retry metadata
118+
// (retryCount/lastAttemptAt) never advanced, so swallowing it as "failed"
119+
// re-drives the same entry forever without progressing toward the
120+
// max-retries terminal move. Surface it like the sibling moveToFailed
121+
// paths below, which also re-throw non-ENOENT.
122+
throw failErr;
118123
}
119124
}
120125
}

‎src/infra/session-delivery-queue.recovery.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ import {
1111
recoverPendingSessionDeliveries,
1212
} from "./session-delivery-queue.js";
1313

14+
// Lets one test force `failSessionDelivery` to reject with a non-ENOENT error
15+
// (e.g. a disk/IO failure) while the rest of the suite uses the real impl.
16+
const { failState } = vi.hoisted(() => ({
17+
failState: { override: null as null | (() => Promise<never>) },
18+
}));
19+
20+
vi.mock("./session-delivery-queue-storage.js", async (importActual) => {
21+
const actual = await importActual<typeof import("./session-delivery-queue-storage.js")>();
22+
return {
23+
...actual,
24+
failSessionDelivery: (id: string, error: string, stateDir?: string) =>
25+
failState.override ? failState.override() : actual.failSessionDelivery(id, error, stateDir),
26+
};
27+
});
28+
1429
describe("session-delivery queue recovery", () => {
1530
it("replays and acks pending entries on recovery", async () => {
1631
await withTempDir({ prefix: "openclaw-session-delivery-" }, async (tempDir) => {
@@ -231,4 +246,42 @@ describe("session-delivery queue recovery", () => {
231246

232247
vi.useRealTimers();
233248
});
249+
250+
it("propagates a non-ENOENT failure-state persistence error instead of swallowing it", async () => {
251+
await withTempDir({ prefix: "openclaw-session-delivery-" }, async (tempDir) => {
252+
await enqueueSessionDelivery(
253+
{
254+
kind: "systemEvent",
255+
sessionKey: "agent:main:main",
256+
text: "retry persistence fails",
257+
},
258+
tempDir,
259+
);
260+
261+
// Delivery fails (enter the retry path), then the failure-state write
262+
// itself fails with a non-ENOENT IO error. That must surface, not be
263+
// swallowed as a clean "failed" (which would leave retryCount/lastAttemptAt
264+
// unadvanced and re-drive the same entry forever).
265+
const deliver = vi.fn(async () => {
266+
throw new Error("send failed");
267+
});
268+
failState.override = () =>
269+
Promise.reject(Object.assign(new Error("no space left on device"), { code: "ENOSPC" }));
270+
271+
try {
272+
await expect(
273+
recoverPendingSessionDeliveries({
274+
deliver,
275+
stateDir: tempDir,
276+
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
277+
}),
278+
).rejects.toThrow(/no space left on device/);
279+
} finally {
280+
failState.override = null;
281+
}
282+
283+
// The entry is left pending (not lost) for a later recovery cycle.
284+
expect(await loadPendingSessionDeliveries(tempDir)).toHaveLength(1);
285+
});
286+
});
234287
});

0 commit comments

Comments
 (0)