fix(router): rmi snapshot image on PR merge so it isn't leaked to disk#1231
Merged
zbigniewsobiecki merged 1 commit intodevfrom Apr 29, 2026
Merged
fix(router): rmi snapshot image on PR merge so it isn't leaked to disk#1231zbigniewsobiecki merged 1 commit intodevfrom
zbigniewsobiecki merged 1 commit intodevfrom
Conversation
`pr-merged` previously called `invalidateSnapshot(projectId, workItemId)` (registry-only). The image lingered in Docker storage, and the periodic 5-minute cleanup loop iterates registry entries only — so the now-orphaned image was leaked permanently, freed only by `docker image prune -af` or host disk pressure. This is a primary contributor to the 2026-04-29 disk- fill incident on prod. Fix: split into two pieces. - `invalidateSnapshot(projectId, workItemId)` now RETURNS the removed metadata (or undefined) so any caller can `docker rmi` the underlying image. Removing the registry entry without the image is the leak; the return shape forces callers to think about the image. - New helper `invalidateAndRemoveSnapshot(projectId, workItemId)` in `snapshot-cleanup.ts` chains `invalidateSnapshot` + the existing `removeSnapshotImage` (which gracefully handles 404 / 409 + Sentry- captures unexpected docker errors). `pr-merged.ts` calls this helper as fire-and-forget (`void ... .catch(logger.warn)`) — preserves the non-blocking property of the original call site. `removeSnapshotImage` is now exported (was module-private) so the new helper can reuse it without duplicating the docker rmi block. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
pr-mergedpreviously calledinvalidateSnapshot(projectId, workItemId)— a registry-only operation. The Docker image lingered in storage, and the periodic 5-minute cleanup loop iterates registry entries only — so the now-orphaned image was leaked permanently, freed only bydocker image prune -afor host disk pressure.This is a primary contributor to the 2026-04-29 prod disk-fill incident that put Redis into MISCONF write-block.
Fix
invalidateSnapshot(projectId, workItemId)now RETURNS the removed metadata (orundefined). Callers candocker rmithe underlying image; removing the registry entry without the image is the leak.invalidateAndRemoveSnapshot(projectId, workItemId)insnapshot-cleanup.tschainsinvalidateSnapshot+ the existingremoveSnapshotImage(which gracefully handles 404 / 409 and Sentry-captures unexpected docker errors).pr-merged.tscalls the new helper as fire-and-forget (void … .catch(logger.warn)) — preserves the non-blocking property of the original call site.removeSnapshotImageis now exported so the new helper reuses it without duplicating the rmi block.Test plan
tests/unit/router/snapshot-manager.test.ts— pinsinvalidateSnapshotreturning metadata when an entry exists /undefinedwhen not.tests/unit/router/snapshot-cleanup.test.ts— pinsinvalidateAndRemoveSnapshotcallingdocker.getImage().remove()on the registered image, no-op when nothing is registered, swallows 404 / 409.tests/unit/triggers/pr-merged.test.ts— mock target moved fromsnapshot-manager.invalidateSnapshottosnapshot-cleanup.invalidateAndRemoveSnapshot; existing assertions verify the helper is called with the right args on merged PRs and not on closed-but-not-merged or work-item-less PRs.npm run typecheckclean.npm run lintclean.🤖 Generated with Claude Code