Skip to content

Report each new Kavita chapter only once (stop repeated new-book notifications) - #16

Merged
ThoughtzThruKeyz merged 1 commit into
masterfrom
fix/kavita-duplicate-new-books
Sep 28, 2026
Merged

ThoughtzThruKeyz merged 1 commit into
masterfrom
fix/kavita-duplicate-new-books

Conversation

@ThoughtzThruKeyz

@ThoughtzThruKeyz ThoughtzThruKeyz commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

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 CoverUpdate and it was created after lastScan. lastScan is the time of Kavita's last ScanProgress started event.

Kavita (checked on 0.9.1.4) only sends started from ScanSeries. ScanLibrary sends only ended. So after library scans (scheduled, or the folder watcher picking up new files), lastScan goes stale. Every later scan end then re-reports each chapter created since then whose volume got a CoverUpdate. 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.

  • In memory, capped at 20k: lastScan restarts at "now" when komf starts, so older chapters can't qualify again after a restart.
  • Race-free: claiming happens under the handler's existing lock, so concurrent scan ends can't report the same chapter twice.

Verified

Kavita hub events were replayed into the real KavitaEventHandler with a fixed clock against a mock Kavita, counting the "new book" reports:

chapter master this branch
Power Rangers #2 2× 1×
Phantom Busters v1–v3 (re-announced after a reset) 2× each 1×
Power Rangers #3 2× 1×
#4 whose cover arrives after its scan ended (Snd-R#306's case) 1× 1× (still caught)

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 as ghcr.io/thoughtzthrukeyz/komf:fix-kavita-duplicate-new-books; :latest is untouched until this merges.

Independent of #15. The repo has no test sources, so the replay harness isn't committed.

🤖 Generated with Claude Code

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>
@ThoughtzThruKeyz
ThoughtzThruKeyz merged commit 042515e into master Sep 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant