01 · Before and afterThe pattern
// before: commit the highest sequence any handler touched
cursor = Math.max(cursor, record.seq);
// after: commit only up to the oldest record still waiting for a consumer
pending.add(record.seq); // when buffered
pending.delete(record.seq); // when consumed
const safe = pending.size ? Math.min(...pending) - 1 : highestSeen;
saveCursor(safe);02 · Run it on your appThe check
If your worker crashes right now, can a message that arrived but was not yet processed be skipped on restart?
If the honest answer is no or not sure, this is worth a look before it reaches production.