From 66eb3d2a988d44f4729a2c6c7588af095a161daa Mon Sep 17 00:00:00 2001 From: Sulthan Zaki Date: Mon, 27 Jul 2026 17:38:49 +0700 Subject: [PATCH] fix(userscript): don't let a failing in-flight write clobber a deferred entry Co-Authored-By: Claude Opus 5 --- userscript/manga-bookmark.user.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/userscript/manga-bookmark.user.js b/userscript/manga-bookmark.user.js index 5cae976..2e3107e 100644 --- a/userscript/manga-bookmark.user.js +++ b/userscript/manga-bookmark.user.js @@ -554,7 +554,15 @@ } ok = true; } catch (e) { - queueEnqueue(key, "put", withStatus, e); + // Same guard as the success path: a newer write is parked for this key, so + // classifying *this* failure would clobber its op or, on a 400, drop it + // outright. Its own drain reports its own outcome. The one thing that must + // still carry across is sendStatus — this flight may have been the archive + // replay, and losing its flag here would narrow the parked write into a + // silent un-archive. + const parked = inFlight.get(key) ? queueGet(key) : null; + if (parked) queueDefer(key, parked.op, withStatus); + else queueEnqueue(key, "put", withStatus, e); } finally { inFlight.delete(key); } @@ -576,7 +584,7 @@ if (!inFlight.get(key)) queueDrop(key); return true; } catch (e) { - queueEnqueue(key, "delete", false, e); + if (!inFlight.get(key)) queueEnqueue(key, "delete", false, e); // see pushBookmark return false; } finally { inFlight.delete(key);