Skip to content

fix(media): stop promising downloads for skipped chats and half-described documents - #478

Merged
GeiserX merged 2 commits into
mainfrom
ai/skip-reason-residue
Sep 24, 2026
Merged

GeiserX merged 2 commits into
mainfrom
ai/skip-reason-residue

Conversation

@GeiserX

@GeiserX GeiserX commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Some media rows still read "Will download on next backup" and count as pending, even though no run will ever fetch them. There are two cases. A document with a file name but no stored MIME type (or the reverse) matched neither the download filter nor the "filtered" mark. A row in a chat listed in SKIP_MEDIA_CHAT_IDS is never fetched, but nothing marked it either. A third problem: a file already on disk could keep a stale "oversize" reason.

Fix

  • _document_mime_condition wraps mime_type and file_name in COALESCE(..., '') in the arms that compare them. When one column was NULL, the OR evaluated to NULL instead of true or false. It now matches what Config.document_mime_allowed does with a missing value. The arm that keeps a row with both columns NULL is unchanged.
  • reconcile_media_skip_reasons takes skip_media_chat_ids. Rows in those chats are marked filtered, and the clear step leaves them alone, so a second pass changes nothing. Removing a chat from the setting clears the mark on the next pass. The retry drain passes config.skip_media_chat_ids.
  • The two clear UPDATEs now also reach downloaded = 1 rows, and a row on disk counts as one whose reason no longer holds. The over-size writer leaves downloaded as it was, so a file fetched by an earlier run with a higher cap could sit on disk marked "oversize". The two mark UPDATEs still touch only downloaded = 0.
  • The four maintenance scripts that build a Config call config.log_summary() again. They printed that summary before 8.14.0.
  • Tests cover each of these. They also cover the review's other assertions: the type and MIME filters together, the guard that keeps an existing reason, the gallery never listing a skipped row, and a no-download session keeping the reason text.

What it deletes / overwrites / forgets

  • Deletes: nothing. No file or row is removed.
  • Overwrites: media.skip_reason only, which is derived state that every run re-derives from the settings. Rows in skipped chats go from NULL to filtered. A downloaded row loses a stale oversize or filtered.
  • Forgets: nothing. Once a chat is removed from SKIP_MEDIA_CHAT_IDS, its rows go back to pending.

For review

  • A downloaded row loses its reason even when its file is over the current cap. The brief was only to drop downloaded = 0 from the clears. That alone would not clear the realistic case, a file fetched under a higher cap, because the clear also required the file to be under the cap. The test seeds that exact row.
  • I did not change the template for no-download sessions. _strip_original_media_paths keeps skip_reason, so a skipped row still shows its reason, and the tests pin that. A downloaded file seen in a no-download session still reads "Will download on next backup" because the strip blanks every path. That behaviour predates 8.14.0. Giving it its own message would be a separate UI change.
  • The review asked for a test of the reconcile guard (a filtered row over the cap keeps filtered and all counts are zero). test_a_filtered_row_over_the_cap_keeps_its_reason already asserts exactly that, so I proved it can fail with a mutant instead of adding a duplicate.

…ibed documents

Rows in SKIP_MEDIA_CHAT_IDS chats and document rows with only one of mime_type/file_name read as pending forever. Reconcile now marks them filtered, clears stale reasons from files already on disk, and the maintenance scripts log the config summary again.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: GeiserX/Telegram-Archive/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 330d281e-5d19-4d20-98f5-58968922ecc4

📥 Commits

Reviewing files that changed from the base of the PR and between ae0fbc0 and 4bdd4b9.

📒 Files selected for processing (7)
  • scripts/deduplicate_media.py
  • scripts/detect_albums.py
  • scripts/fix_media_sizes.py
  • scripts/update_media_sizes.py
  • src/db/adapter.py
  • src/telegram_backup.py
  • tests/test_media_skip_reason.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.98%. Comparing base (ae0fbc0) to head (4bdd4b9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #478      +/-   ##
==========================================
+ Coverage   94.96%   94.98%   +0.01%     
==========================================
  Files          29       29              
  Lines       12318    12340      +22     
==========================================
+ Hits        11698    11721      +23     
+ Misses        620      619       -1     
Files with missing lines Coverage Δ
src/db/adapter.py 96.25% <100.00%> (+0.02%) ⬆️
src/telegram_backup.py 95.02% <ø> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@GeiserX
GeiserX merged commit 8782a84 into main Sep 24, 2026
11 checks passed
@GeiserX
GeiserX deleted the ai/skip-reason-residue branch September 24, 2026 10:00
@GeiserX GeiserX mentioned this pull request Sep 24, 2026
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