Fix batched thumbnail cache clearing - #9
Merged
Conversation
ewlarson
marked this pull request as ready for review
August 13, 2026 21:06
ewlarson
added a commit
that referenced
this pull request
Aug 21, 2026
Fix batched thumbnail cache clearing
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.
Summary
clear_thumbnail_cache.pyinside one async event loop.Production incident
A Kamal production run attempted to clear thumbnail caches for 13 UNR resources:
The first resource completed, but the second aborted with:
Root cause
main()calledasyncio.run(clear_thumbnail_for_resource(rid))once for every resource. Each call created and closed a new event loop, while the process-global SQLAlchemy async engine/pool retained asyncpg connections bound to the previous loop. Checking out one of those connections for the next resource triggered the cross-loop failure.Fix
The resource loop now lives in
clear_thumbnails_for_resources(), andmain()callsasyncio.run()once for the whole batch. Exceptions retain the resource-specific log message and continue to propagate as before.User impact
Multi-resource cache purge commands now process the full resource list rather than failing after the first ID. Single-resource behavior and CLI syntax are unchanged.
Validation
BTAA_SKIP_TEST_DB=1 python -m pytest backend/tests/scripts/test_clear_thumbnail_cache.py -q— 2 passedruff checkpassedruff format --checkpassedgit diff --checkpassedIssue tracking
A standalone issue could not be created because GitHub Issues are disabled for
ewlarson/ogm-api(GitHub API returned HTTP 410). This PR includes the complete issue write-up so the incident remains documented.