Report each new Kavita chapter only once (stop repeated new-book notifications) - #16
Merged
Merged
Conversation
komf decides a Kavita chapter is new when its volume got a CoverUpdate and the chapter was created after lastScan, which is set when Kavita sends ScanProgress "started". Kavita (0.9.1.4) sends "started" only from ScanSeries; ScanLibrary sends "ended" alone. So after library scans — scheduled, or the folder watcher picking up new files — lastScan trails by hours or days, and every later scan end re-reports each chapter created since then whose volume got a CoverUpdate in between. CoverUpdates are frequent: a reset's forced cover refresh sends one for every volume of the series, and new files and cover uploads send more. The result is repeated "new book" notifications and repeated auto-identification for books that were not new: one comic issue was announced five times in seven minutes, and whole series (every volume) again after being reset. Keep the createdUtc filter as it is — using the scan start (008c672, upstream Snd-R#306) is what lets a cover that arrives after its scan ended still count — and additionally remember which chapters were already reported, skipping them. The set is in memory and capped: lastScan restarts at "now" when komf starts, so older chapters never qualify again after a restart. Claiming happens under the existing lock, so concurrent scan ends cannot report the same chapter twice. Checked by replaying hub events into the real handler with a fixed clock against a mock Kavita — library scans without "started", a reset cover refresh, a single-series scan, and the late-cover case from Snd-R#306. Master reported five of six chapters twice; this reports each once, and the late cover is still picked up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stops komf from reporting the same Kavita books as "new" over and over. That was sending repeated Discord notifications and re-running auto-identify for books that weren't new.
What was happening
In
discord, Power Rangers Green V2026 #2 was announced 5 times in 7 minutes (6:55, 6:57, 7:00, 7:01, 7:02 PM). Phantom Busters v01–v03 and The Great Cleric v01–v16 were re-announced in full with no new files.Cause
komf treats a Kavita chapter as new when its volume got a
CoverUpdateand it was created afterlastScan.lastScanis the time of Kavita's lastScanProgressstarted event.Kavita (checked on 0.9.1.4) only sends started from
ScanSeries.ScanLibrarysends onlyended. So after library scans (scheduled, or the folder watcher picking up new files),lastScangoes stale. Every later scan end then re-reports each chapter created since then whose volume got aCoverUpdate. Those are frequent: a reset's forced cover refresh sends one for every volume of the series, which is how entire series came back.Using the scan start came from upstream Snd-R#306 (
008c672). It fixed a real bug, Snd-R#275: covers often arrive after their scan has ended, and the old end-time cutoff dropped those chapters. So reverting it isn't the answer.Fix
Keep the time check as it is, and also remember which chapters were already reported, skipping them.
lastScanrestarts at "now" when komf starts, so older chapters can't qualify again after a restart.Verified
Kavita hub events were replayed into the real
KavitaEventHandlerwith a fixed clock against a mock Kavita, counting the "new book" reports:On master, the repeats only happen after library scans (no
started), which confirms the cause.Build status
✅ Full build passed at
657443a: https://github.com/ThoughtzThruKeyz/komf/actions/runs/36372620029. Image pushed asghcr.io/thoughtzthrukeyz/komf:fix-kavita-duplicate-new-books;:latestis untouched until this merges.Independent of #15. The repo has no test sources, so the replay harness isn't committed.
🤖 Generated with Claude Code