Repository navigation
Feat/persist channel icons - #3
Conversation
Fetch each channel icon once and keep it for the life of the process and on disk under server.icon_cache_dir (default /data/icon-cache). Only successful fetches are stored; failures are retried on the next request. Icons are stored outside the IPA cache dir so the size-based eviction sweep cannot delete them. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Reviewer's GuideImplementationReplace expiring in-memory icon caching with permanent memory-and-disk caching, including cache reads, writes, and refresh behavior.
ConfigurationAdd the icon-cache directory setting and configure it in the example alongside the updated channel list.
DocumentationDocument the icon-cache configuration and its permanent caching and retry behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main.py" line_range="441" />
<code_context>
+ if not settings.icon_cache_dir:
+ return None
+ # Slugs are sanitised in settings to [A-Za-z0-9_-], so they are safe as filenames.
+ return Path(settings.icon_cache_dir) / f"{source_slug}.img"
+
+
</code_context>
<issue_to_address>
**Previous channel icon is served**
When a configuration change assigns an existing slug to a different channel, `_source_channel_icon` reads the memory or disk cache by `source.slug` without checking channel identity, so the replacement channel receives the previous channel’s icon indefinitely.
Key both memory and disk icon caches by a stable channel identity rather than the slug alone.
Also at `src/main.py:474-476`, `src/main.py:483`.
</issue_to_address>
### Comment 2
<location path="config.example.yml" line_range="32" />
<code_context>
+- blatants
+- eeveespotifyrevived
+- the_public_archive
+- ethModsGroup
+- compiledipas
+- ciesIPAs
</code_context>
<issue_to_address>
**Duplicate channel sources are published**
When a user starts from the example channel list, `_load_sources` creates a source for each duplicate channel entry and only deduplicates slugs, so the same Telegram channel appears as two sources with duplicate content.
Remove the duplicate channel entry from the example configuration or deduplicate sources by channel identity.
Also at `config.example.yml:24`, `config.example.yml:33`.
</issue_to_address>
### Comment 3
<location path="README.md" line_range="59" />
<code_context>
ipa_cache_global_workers: 8
ipa_cache_part_size: 8388608
ipa_cache_max_mb: 1024
+icon_cache_dir: /data/icon-cache
channels:
</code_context>
<issue_to_address>
**Documented cache path is ignored**
When a user follows either README configuration example to customize or disable icon storage, `load_settings` reads `server.icon_cache_dir`, but the examples place `icon_cache_dir` at the YAML root, so the custom path or empty value is ignored and the default directory is used.
Place `icon_cache_dir` under `server` in both README configuration examples.
Also at `README.md:100`.
</issue_to_address>
### Comment 4
<location path="src/main.py" line_range="465" />
<code_context>
+ temp_path.replace(path)
+ except OSError as exc:
+ logger.warning("Channel icon cache write failed for %s: %s", path.name, exc)
+ temp_path.unlink(missing_ok=True)
+
+
</code_context>
<issue_to_address>
**Cache write failure aborts icon request**
When writing the cache fails and removing the temporary file also fails, `_write_icon_cache` catches the initial filesystem error but lets `temp_path.unlink` raise another `OSError`, so the request fails instead of returning the fetched icon.
Guard or suppress errors from temporary-file cleanup in the write-error handler.
</issue_to_address>
### Comment 5
<location path="src/main.py" line_range="481" />
<code_context>
+ return from_disk
if not await telegram.is_authorized():
return None
icon = await telegram.download_channel_photo(source)
- cache["value"] = icon
- cache["expires_at"] = now + 86400
</code_context>
<issue_to_address>
**Concurrent requests fetch icons repeatedly**
When multiple requests for the same uncached source arrive before its first Telegram download finishes, `_source_channel_icon` lets each cache-missing request call `telegram.download_channel_photo`, so concurrent requests duplicate Telegram downloads and writes; callers can receive different bytes and a later write can replace the cached icon.
Coalesce concurrent misses for each source behind a shared in-flight download.
Also at `src/main.py:471`.
</issue_to_address>
### Comment 6
<location path="src/main.py" line_range="484" />
<code_context>
- cache["expires_at"] = now + 86400
+ if icon:
+ source_icon_caches[source.slug] = icon
+ _write_icon_cache(path, icon)
return icon
</code_context>
<issue_to_address>
**Icon cache can fill shared disk**
When many configured channels have their icons requested over time, `_write_icon_cache` stores successful icons without a size limit or eviction, so the cache can fill `/data`, which is also used for the Telegram session and IPA cache, and disrupt the service.
Bound the icon cache with a size limit and eviction policy.
</issue_to_address>
### Comment 7
<location path="src/main.py" line_range="482" />
<code_context>
icon = await telegram.download_channel_photo(source)
- cache["value"] = icon
- cache["expires_at"] = now + 86400
+ if icon:
+ source_icon_caches[source.slug] = icon
+ _write_icon_cache(path, icon)
</code_context>
<issue_to_address>
**Failed icon fetches retry on every request**
When a channel has no downloadable photo or Telegram keeps failing while clients request its icon, `_source_channel_icon()` records only truthy results, so a missing photo or failed Telegram download leaves no cache entry; each subsequent icon request repeats the upstream call, while `download_channel_photo()` suppresses download exceptions and the route returns the fallback icon.
Apply a bounded negative-cache or retry-backoff interval to failed icon fetches.
</issue_to_address>
### Comment 8
<location path="src/main.py" line_range="483-484" />
<code_context>
- cache["value"] = icon
- cache["expires_at"] = now + 86400
+ if icon:
+ source_icon_caches[source.slug] = icon
+ _write_icon_cache(path, icon)
return icon
</code_context>
<issue_to_address>
**Refresh stores an old channel icon**
When the config UI replaces a channel with another channel using the same slug while the old channel’s icon request is awaiting Telegram, the in-flight request retains its old `source`, but after `_runtime_refresh` replaces the global cache and settings, the request stores that old icon under the slug in the new cache and may write it to the new cache directory. A replacement channel reusing that slug is served the old channel’s icon.
Before caching a fetched icon, verify that the current source for the slug still has the same channel identity as the request’s source.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 8 findings to address first, and a successfully fetched icon is written to disk and then reused indefinitely, so a stale or incorrect icon can keep being served after a restart. Reverting stops the new code from using these files, but the cached files remain on disk and can be cleared to repair the issue.
Blocking findings: src/main.py:441, config.example.yml:32, README.md:59, src/main.py:465, src/main.py:481, and 3 more
| if not settings.icon_cache_dir: | ||
| return None | ||
| # Slugs are sanitised in settings to [A-Za-z0-9_-], so they are safe as filenames. | ||
| return Path(settings.icon_cache_dir) / f"{source_slug}.img" |
There was a problem hiding this comment.
🟡 Medium · Previous channel icon is served
When a configuration change assigns an existing slug to a different channel, _source_channel_icon reads the memory or disk cache by source.slug without checking channel identity, so the replacement channel receives the previous channel’s icon indefinitely.
Key both memory and disk icon caches by a stable channel identity rather than the slug alone.
Also at src/main.py:474-476, src/main.py:483.
Prompt for AI agents
In `src/main.py` at line 441:
**Previous channel icon is served**
When a configuration change assigns an existing slug to a different channel, `_source_channel_icon` reads the memory or disk cache by `source.slug` without checking channel identity, so the replacement channel receives the previous channel’s icon indefinitely.
Key both memory and disk icon caches by a stable channel identity rather than the slug alone.
Also at `src/main.py:474-476`, `src/main.py:483`.| - Sa1y0miii | ||
| - IAppsBestLibrary | ||
| - ASJTweaks | ||
| - ethModsGroup |
There was a problem hiding this comment.
🟡 Medium · Duplicate channel sources are published
When a user starts from the example channel list, _load_sources creates a source for each duplicate channel entry and only deduplicates slugs, so the same Telegram channel appears as two sources with duplicate content.
Remove the duplicate channel entry from the example configuration or deduplicate sources by channel identity.
Also at config.example.yml:24, config.example.yml:33.
Prompt for AI agents
In `config.example.yml` at line 32:
**Duplicate channel sources are published**
When a user starts from the example channel list, `_load_sources` creates a source for each duplicate channel entry and only deduplicates slugs, so the same Telegram channel appears as two sources with duplicate content.
Remove the duplicate channel entry from the example configuration or deduplicate sources by channel identity.
Also at `config.example.yml:24`, `config.example.yml:33`.| ipa_cache_global_workers: 8 | ||
| ipa_cache_part_size: 8388608 | ||
| ipa_cache_max_mb: 1024 | ||
| icon_cache_dir: /data/icon-cache |
There was a problem hiding this comment.
🟡 Medium · Documented cache path is ignored
When a user follows either README configuration example to customize or disable icon storage, load_settings reads server.icon_cache_dir, but the examples place icon_cache_dir at the YAML root, so the custom path or empty value is ignored and the default directory is used.
Place icon_cache_dir under server in both README configuration examples.
Also at README.md:100.
Prompt for AI agents
In `README.md` at line 59:
**Documented cache path is ignored**
When a user follows either README configuration example to customize or disable icon storage, `load_settings` reads `server.icon_cache_dir`, but the examples place `icon_cache_dir` at the YAML root, so the custom path or empty value is ignored and the default directory is used.
Place `icon_cache_dir` under `server` in both README configuration examples.
Also at `README.md:100`.| temp_path.replace(path) | ||
| except OSError as exc: | ||
| logger.warning("Channel icon cache write failed for %s: %s", path.name, exc) | ||
| temp_path.unlink(missing_ok=True) |
There was a problem hiding this comment.
🟡 Medium · Cache write failure aborts icon request
When writing the cache fails and removing the temporary file also fails, _write_icon_cache catches the initial filesystem error but lets temp_path.unlink raise another OSError, so the request fails instead of returning the fetched icon.
Guard or suppress errors from temporary-file cleanup in the write-error handler.
Prompt for AI agents
In `src/main.py` at line 465:
**Cache write failure aborts icon request**
When writing the cache fails and removing the temporary file also fails, `_write_icon_cache` catches the initial filesystem error but lets `temp_path.unlink` raise another `OSError`, so the request fails instead of returning the fetched icon.
Guard or suppress errors from temporary-file cleanup in the write-error handler.| return from_disk | ||
| if not await telegram.is_authorized(): | ||
| return None | ||
| icon = await telegram.download_channel_photo(source) |
There was a problem hiding this comment.
🟡 Medium · Concurrent requests fetch icons repeatedly
When multiple requests for the same uncached source arrive before its first Telegram download finishes, _source_channel_icon lets each cache-missing request call telegram.download_channel_photo, so concurrent requests duplicate Telegram downloads and writes; callers can receive different bytes and a later write can replace the cached icon.
Coalesce concurrent misses for each source behind a shared in-flight download.
Also at src/main.py:471.
Prompt for AI agents
In `src/main.py` at line 481:
**Concurrent requests fetch icons repeatedly**
When multiple requests for the same uncached source arrive before its first Telegram download finishes, `_source_channel_icon` lets each cache-missing request call `telegram.download_channel_photo`, so concurrent requests duplicate Telegram downloads and writes; callers can receive different bytes and a later write can replace the cached icon.
Coalesce concurrent misses for each source behind a shared in-flight download.
Also at `src/main.py:471`.| cache["expires_at"] = now + 86400 | ||
| if icon: | ||
| source_icon_caches[source.slug] = icon | ||
| _write_icon_cache(path, icon) |
There was a problem hiding this comment.
🟠 High · Icon cache can fill shared disk
When many configured channels have their icons requested over time, _write_icon_cache stores successful icons without a size limit or eviction, so the cache can fill /data, which is also used for the Telegram session and IPA cache, and disrupt the service.
Bound the icon cache with a size limit and eviction policy.
Prompt for AI agents
In `src/main.py` at line 484:
**Icon cache can fill shared disk**
When many configured channels have their icons requested over time, `_write_icon_cache` stores successful icons without a size limit or eviction, so the cache can fill `/data`, which is also used for the Telegram session and IPA cache, and disrupt the service.
Bound the icon cache with a size limit and eviction policy.| icon = await telegram.download_channel_photo(source) | ||
| cache["value"] = icon | ||
| cache["expires_at"] = now + 86400 | ||
| if icon: |
There was a problem hiding this comment.
🟡 Medium · Failed icon fetches retry on every request
When a channel has no downloadable photo or Telegram keeps failing while clients request its icon, _source_channel_icon() records only truthy results, so a missing photo or failed Telegram download leaves no cache entry; each subsequent icon request repeats the upstream call, while download_channel_photo() suppresses download exceptions and the route returns the fallback icon.
Apply a bounded negative-cache or retry-backoff interval to failed icon fetches.
Prompt for AI agents
In `src/main.py` at line 482:
**Failed icon fetches retry on every request**
When a channel has no downloadable photo or Telegram keeps failing while clients request its icon, `_source_channel_icon()` records only truthy results, so a missing photo or failed Telegram download leaves no cache entry; each subsequent icon request repeats the upstream call, while `download_channel_photo()` suppresses download exceptions and the route returns the fallback icon.
Apply a bounded negative-cache or retry-backoff interval to failed icon fetches.| source_icon_caches[source.slug] = icon | ||
| _write_icon_cache(path, icon) |
There was a problem hiding this comment.
🟡 Medium · Refresh stores an old channel icon
When the config UI replaces a channel with another channel using the same slug while the old channel’s icon request is awaiting Telegram, the in-flight request retains its old source, but after _runtime_refresh replaces the global cache and settings, the request stores that old icon under the slug in the new cache and may write it to the new cache directory. A replacement channel reusing that slug is served the old channel’s icon.
Before caching a fetched icon, verify that the current source for the slug still has the same channel identity as the request’s source.
Prompt for AI agents
In `src/main.py` at lines 483-484:
**Refresh stores an old channel icon**
When the config UI replaces a channel with another channel using the same slug while the old channel’s icon request is awaiting Telegram, the in-flight request retains its old `source`, but after `_runtime_refresh` replaces the global cache and settings, the request stores that old icon under the slug in the new cache and may write it to the new cache directory. A replacement channel reusing that slug is served the old channel’s icon.
Before caching a fetched icon, verify that the current source for the slug still has the same channel identity as the request’s source.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d1dd3749d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ipa_cache_global_workers: 8 | ||
| ipa_cache_part_size: 8388608 | ||
| ipa_cache_max_mb: 1024 | ||
| icon_cache_dir: /data/icon-cache |
There was a problem hiding this comment.
Nest the cache option under
server
When a user follows either README YAML snippet and changes icon_cache_dir to customize or disable storage, this root-level key is ignored: load_settings() reads only server.icon_cache_dir, so the app silently keeps using the default. Indent the option under server: in both snippets.
Useful? React with 👍 / 👎.
fix(icons): address PR #3 review findings
Closes #IssueNr
📑 Description
✅ Checks
ℹ Additional Information
Summary by Sourcery
Persist successfully fetched channel icons to configurable local storage and serve them from memory or disk on subsequent requests.
New Features:
Enhancements:
Documentation:
Chores: