Repository navigation
fix(classes): defer superseded image cleanup until after commit with retry recovery - #213
Merged
Merged
Conversation
theosiemensrhodes
marked this pull request as draft
November 23, 2026 06:30
theosiemensrhodes
force-pushed
the
fix/neuron-n10-image-cleanup
branch
2 times, most recently
from
November 25, 2026 06:28
ccf3187 to
e6c3a74
Compare
theosiemensrhodes
force-pushed
the
fix/neuron-n10-image-cleanup
branch
from
November 25, 2026 06:35
e6c3a74 to
1424fb3
Compare
theosiemensrhodes
marked this pull request as ready for review
November 26, 2026 02:09
Signed-off-by: Theo Siemens-Rhodes <112789743+theosiemensrhodes@users.noreply.github.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.
Problem
ClassService.updateClasspreviously calledimageService.deleteImage(oldImageKey)inside the Postgres transaction before later schedule/recurrence validation and writes, and triggered deletion whenever bothoriginalClass.imageanddbClassUpdate.imagewere truthy (including same-key updates). If later validation failed and rolled back, the database restored the image key while the MinIO object was already gone; errors during deletion were swallowed with no retry recovery, and clearing an image tonullor deleting a class did not clean up superseded objects.Change
jobs.delete-image) inside the Postgres transaction viaJobService.run(..., { transaction: tx })inClassService.updateClassandClassService.deleteClass, locking thecourserow (FOR UPDATE) and only enqueueing whenoriginalClass.imageis non-empty and differs from the committedupdatedImage(preserving unchanged/same-key updates and handlingnullclears and class deletions).jobs.delete-imagewith exponential backoff retries (retryLimit: 8,retryDelay: 60,retryBackoff: true); before callingimageService.deleteImage, the handler validates the payload type/non-blankness without mutating the key and verifies in a single PostgresEXISTSquery that neithercourse.imagenoruser.imagestill references the exact stored key.ImageServicebucket initialization (ensureBucketReady) so transient MinIO startup failures clear the cached promise and recover on retry, and apply the bucket read policy idempotently so partial failures betweenmakeBucketandsetBucketPolicyalso heal on retry.TermService.deleteTermand bucket-wide orphan sweeping (jobs.cleanup-orphaned-images) are intentionally out of scope for this PR.Verification
pnpm exec prettier --checkon all 6 touched files: passedSKIP_ENV_VALIDATION=1 pnpm exec next typegen && pnpm typecheck: passed (0errors)pnpm vitest run src/test/integration/class-service.test.ts src/test/unit/against a disposable database (neuron_test_n10_image_cleanup, dropped after run): 9/9 test files, 77/77 tests passed (including an end-to-endClassService-> realJobService/pg-boss->deleteImageJobcommit & rollback test andImageServicebucket-readiness recovery tests).eslintcurrently fails repo-wide onmaindue to a pre-existingeslint-config-next/@eslint/eslintrcflat-config circular JSON error.