From 7e258988e5d3b2032fc9d4db4f159e9a65fb2d48 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Tue, 10 Nov 2026 17:31:59 +0000 Subject: [PATCH] Read reports: a report that throws no longer wedges its room The per-room tail was chained with .then(run), so a rejected run skipped every later report for that room and left the cleanup as an unhandled rejection. Chain on both outcomes and clean up on both. A test reaches it with a presence failure plus a throwing logger and fails on the old chain. Co-Authored-By: Claude Sonnet 5.5 --- tests/persona-matrix-mouth.test.mjs | 18 ++++++++++++++++++ tools/persona-matrix-mouth.mjs | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/persona-matrix-mouth.test.mjs b/tests/persona-matrix-mouth.test.mjs index f08426e..1e33f64 100644 --- a/tests/persona-matrix-mouth.test.mjs +++ b/tests/persona-matrix-mouth.test.mjs @@ -1285,3 +1285,21 @@ test("chat_read round-trips and refuses a malformed tuple", () => { assert.throws(() => docs.parseRead(["eureka", "#r", "$e", -1]), /at_unix_ms/); assert.throws(() => docs.parseRead(["eureka", "#r", "$e"])); }); + +test("a read report that throws does not wedge the room: the next report still posts and nothing is left unhandled", async () => { + const hs = await fakeHomeserver({ sync: receiptScript }); + let boom = false; + const fetch = (url, init) => boom && String(url).includes("/presence/") ? Promise.reject(new Error("net")) : hs.fetch(url, init); + const mouth = await withMail(hs, { fetch, log: line => { if (boom && line.startsWith("presence not set")) throw new Error("logger down"); } }); // the presence failure and a throwing logger make run() reject + const unhandled = [], note = error => unhandled.push(String(error)); + process.on("unhandledRejection", note); + try { + boom = true; + await assert.rejects(reportRead(mouth, A, "$a1"), /logger down/); + boom = false; + assert.equal(await reportRead(mouth, A, "$a2"), null, "the room's next report is judged and posted"); + await new Promise(resolve => setTimeout(resolve, 50)); + } finally { process.off("unhandledRejection", note); } + assert.deepEqual(unhandled, [], "no rejection escapes the tail's cleanup"); + assert.equal(hs.receipts().length, 1); +}); diff --git a/tools/persona-matrix-mouth.mjs b/tools/persona-matrix-mouth.mjs index ad7f114..658c728 100644 --- a/tools/persona-matrix-mouth.mjs +++ b/tools/persona-matrix-mouth.mjs @@ -409,9 +409,9 @@ export function createMouth({ readThrough.set(known.roomId, { seq: known.seq, eventId }); return null; }; - const tail = (readTails.get(known.roomId) ?? Promise.resolve()).then(run); + const tail = (readTails.get(known.roomId) ?? Promise.resolve()).then(run, run); // a report that threw must not wedge the room's later ones readTails.set(known.roomId, tail); - tail.then(() => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); }); + tail.then(() => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); }, () => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); }); return tail; }