fix: Gracefully handle missing speech profiles bucket#6223
fix: Gracefully handle missing speech profiles bucket#6223neooriginal wants to merge 2 commits intoBasedHardware:mainfrom
Conversation
Make BUCKET_SPEECH_PROFILES handling robust: trim the env var and treat empty value as unset. Introduce _get_speech_profiles_bucket(required=False) that returns a bucket, warns once when the bucket is not configured, and optionally raises if an operation requires the bucket. Update all speech-profile related functions to use the helper and either no-op/return safe defaults when the bucket is absent or raise for required uploads. Also add early checks for download/delete helpers to avoid calling storage APIs when configuration is missing. This prevents crashes and noisy repeated warnings when speech profile storage is not configured.
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of speech profile storage operations by centralizing access to the speech profiles GCS bucket and handling missing bucket configuration more gracefully across read/write/delete paths.
Changes:
- Parse
BUCKET_SPEECH_PROFILESmore robustly (treat empty/whitespace-only values as unset). - Add
_get_speech_profiles_bucket()helper to centralize bucket resolution + one-time warning + optional hard failure. - Update speech-profile-related functions to early-return (or raise) when the bucket is not configured.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
Greptile SummaryThis PR improves robustness for deployments where Key changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Speech profile function called] --> B{_get_speech_profiles_bucket}
B -->|bucket configured| C[Return storage_client.bucket obj]
B -->|not configured + required=False| D[Log one-time warning\nReturn None]
B -->|not configured + required=True| E[Log one-time warning\nRaise RuntimeError]
C --> F[Proceed with GCS operation]
D --> G{Function type}
G -->|get_user_has_speech_profile| H[return False]
G -->|get_profile_audio_if_exists| I[return None]
G -->|get_additional_profile_recordings| J[return empty list]
G -->|delete_* functions| K[return early / no-op]
E --> L[Caller receives RuntimeError\n→ HTTP 500]
M[download_speech_profile_bytes] --> N{speech_profiles_bucket set?}
N -->|No| O[raise BlobNotFound ⚠️\nSame type as 'blob missing']
N -->|Yes| P[download_blob_bytes]
O --> Q[Migration catches NotFound\n→ marks for Firestore deletion ⚠️]
Reviews (1): Last reviewed commit: "Merge branch 'BasedHardware:main' into m..." | Re-trigger Greptile |
Fully tested e2e
This pull request improves the robustness and error handling of all speech profile storage operations in
backend/utils/other/storage.py. It introduces a helper function to safely access the speech profiles bucket, adds warnings and explicit error messages when the bucket is not configured, and ensures that all relevant functions gracefully handle missing configuration instead of failing unexpectedly.Speech profile bucket access and error handling:
_get_speech_profiles_buckethelper function to centralize logic for accessing thespeech_profiles_bucket, including warning logging and raising errors when required. All speech profile functions now use this helper to prevent failures when the bucket is not configured.upload_profile_audio,get_user_has_speech_profile,get_profile_audio_if_exists, etc.) to use_get_speech_profiles_bucketand handle missing bucket configuration gracefully by returning early or raising informative exceptions. [1] [2] [3] [4] [5] [6] [7] [8]download_speech_profile_bytesand safe return indelete_speech_profile_blobif the speech profiles bucket is not configured, improving clarity and preventing silent failures. [1] [2]Environment variable handling:
BUCKET_SPEECH_PROFILESenvironment variable to correctly handle empty or whitespace-only values, ensuring the configuration is robust against misconfiguration.