Skip to content

Keep reader history saves from landing out of order - #119

Draft
PoonHarpoon wants to merge 1 commit into
AppFuton:develfrom
PoonHarpoon:fix/history-save-order
Draft

PoonHarpoon wants to merge 1 commit into
AppFuton:develfrom
PoonHarpoon:fix/history-save-order

Conversation

@PoonHarpoon

@PoonHarpoon PoonHarpoon commented Oct 18, 2026 •

Copy link
Copy Markdown

I’m currently testing this on my own device, and it’s opened as a draft so others can test it too before it’s marked ready. This goes together with #118, which fixes one source of bad saves; this one stops a bad save from sticking.

Each reader progress save (crossing into a new chapter, leaving the reader, going idle) runs as its own background task. Its database transaction also rewrites the chapter list and updates tracking. So two saves made a few milliseconds apart can reach the database in either order, and an out-of-date position can overwrite the newer one that came right after it. It’s the same kind of problem as the progress recalculation fix in #111, but for the reader’s own saves.

This adds a small HistorySaveOrder that numbers each save at the moment it’s requested. Saves are then written one at a time, and any save older than one already written for that manga is skipped, so the newest position always wins. A save that fails doesn’t count, so an older one can still go through. A skipped stale save also no longer triggers smart download for an out-of-date chapter. History changes you make yourself, like mark as read, mark as current and progress recalculation, aren’t affected.

HistorySaveOrderTest covers out-of-order saves, normal ordering, separate manga, a failed save, and two saves running at once. The full unit test suite passes.

The PR compiles and runs, but the bug is so transient and hard to reproduce on demand I’m still testing it on my end to see if this finally fixes it.

Each reader progress save runs as its own coroutine, and its transaction
also rewrites chapters and updates tracking, so two saves requested
milliseconds apart could reach the database in either order. A stale
position (such as the one fixed in the previous commit) could then
overwrite the correction made right after it and stay in history.

Take a sequence number when a save is requested and skip writing any
save older than one already written for that manga, so the newest
request always wins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant