fix(prepare): verify cache size integrity against server Content-Length#608
Open
aniruddhaadak80 wants to merge 1 commit into
Open
fix(prepare): verify cache size integrity against server Content-Length#608aniruddhaadak80 wants to merge 1 commit into
aniruddhaadak80 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves shard download integrity by validating cached/downloaded parquet shard sizes against the remote Content-Length and redownloading when a mismatch is detected.
Changes:
- Add HEAD-based validation for existing cached shards using
Content-Length. - Verify streamed downloads match
Content-Lengthbefore replacing the final file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
58
to
+60
| filename = f"shard_{index:05d}.parquet" | ||
| filepath = os.path.join(DATA_DIR, filename) | ||
| url = f"{BASE_URL}/{filename}" |
Comment on lines
+63
to
+77
| try: | ||
| response = requests.head(url, timeout=10) | ||
| response.raise_for_status() | ||
| content_length = int(response.headers.get("Content-Length", 0)) | ||
| if content_length > 0: | ||
| local_size = os.path.getsize(filepath) | ||
| if local_size == content_length: | ||
| return True | ||
| else: | ||
| print(f" Cached {filename} is corrupted or incomplete ({local_size} vs expected {content_length} bytes). Redownloading...") | ||
| else: | ||
| return True | ||
| except Exception: | ||
| if os.path.getsize(filepath) > 0: | ||
| return True |
Comment on lines
+90
to
94
| if content_length > 0: | ||
| downloaded_size = os.path.getsize(temp_path) | ||
| if downloaded_size != content_length: | ||
| raise IOError(f"Truncated download: expected {content_length} bytes, got {downloaded_size} bytes") | ||
| os.rename(temp_path, filepath) |
Comment on lines
82
to
83
| response = requests.get(url, stream=True, timeout=30) | ||
| response.raise_for_status() |
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.
Performs size validation for cached dataset shards using HEAD requests to check server Content-Length, triggering redownloads if corrupted or incomplete. Also verifies downloaded size post-download (Fixes #215).