feat(spreadsheet-analysis): fail-fast size guard on analyze_spreadsheet downloads#397
Merged
Merged
Conversation
…et downloads Adds 25 MB hard-fail and 10 MB soft-warning thresholds (env-tunable via ANALYZE_MAX_FILE_SIZE_BYTES / ANALYZE_WARN_FILE_SIZE_BYTES). The check runs before _download_file using the size_bytes already on file_info, so oversize files never hit S3 GetObject or base64. A logger.warning fires at module load when the thresholds are misconfigured (warn >= max). Soft warning is attached to both success and error responses for files in the 10-25 MB range. Docstring updated with the new safety limit. Closes #258 (items 1+2). Streaming (item 3) tracked separately.
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
Closes #258 (items 1+2). Streaming download/upload (item 3) tracked separately.
Adds a pre-download file size guard to
analyze_spreadsheet. Previously, arbitrarily large files could be downloaded and base64-encoded into memory — a 100 MB XLSX becomes ~133 MB in-memory after inflation. This change stops that before any S3 or Code Interpreter call is made.Changes
analyze_tool.pyANALYZE_MAX_FILE_SIZE_BYTES, default 25 MB): files above this are rejected immediately with an actionable error message before_download_fileis called. No S3 GetObject, no Code Interpreter start.ANALYZE_WARN_FILE_SIZE_BYTES, default 10 MB): files in the 10–25 MB range proceed but attach a slow-analysis warning to both success and error responses.logger.warningfires at module load if the thresholds are misconfigured (warn >= max).size_bytesalready present on thefile_infodict fromlist_spreadsheets— zero extra AWS calls.test_size_guard.py(new file, 8 tests)size_bytesdoes not block (regression guard for legacy records)monkeypatch.setattrwork correctlyTest results