Clean up storage probe files when validation fails#717
Open
M-Hassan-Raza wants to merge 1 commit intocodingjoe:mainfrom
Open
Clean up storage probe files when validation fails#717M-Hassan-Raza wants to merge 1 commit intocodingjoe:mainfrom
M-Hassan-Raza wants to merge 1 commit intocodingjoe:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Storage health check failure path so that probe files are best-effort deleted when validation fails after a successful write, avoiding residue on object storage backends.
Changes:
- Refactors the storage probe flow to
save → validate → (cleanup on validation failure) → delete. - Adds a
cleanup_file()helper that logs (but does not mask) cleanup failures. - Adds regression tests covering missing file after save, content mismatch, and cleanup failure behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
health_check/checks.py |
Adds best-effort cleanup when post-write validation fails, while preserving the original validation error. |
tests/test_checks.py |
Adds parameterized regression coverage ensuring saved probe files are deleted on validation failures and cleanup failures are only logged. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #717 +/- ##
=======================================
Coverage 99.74% 99.75%
=======================================
Files 13 13
Lines 792 800 +8
=======================================
+ Hits 790 798 +8
Misses 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
The storage health check writes a temp probe file, validates it, and then deletes it. Before this change, if the write succeeded but validation failed after that, the temp file could be left behind.
That is usually harmless on local disk, but it is not great behavior on object storage backends where failed probes can leave residue behind over time. This change makes the failed validation path do a best effort cleanup before returning the original error.
The normal success path stays the same. The check still verifies that the backend can actually delete the probe file when the check passes, so this does not loosen the contract, it just fixes the broken failure path.
I also added regression coverage for the cases where the saved file is missing after write, where the saved content does not match, and where cleanup itself fails. In the cleanup failure case we still keep the original validation error and only log the cleanup problem instead of masking it.
Tests run:
uv run pytest -q tests/test_checks.py
uv run pytest -q
uvx ruff check health_check/checks.py tests/test_checks.py
Results on my side:
uv run pytest -q tests/test_checks.py passed
uv run pytest -q -> 154 passed, 26 skipped
uvx ruff check health_check/checks.py tests/test_checks.py passed