Public Workspace Storage Calculation Fix
Fixed/Implemented in version: 0.230.082
Issue Description
Public workspaces were showing 0 bytes for storage sizes despite having documents, while group workspaces correctly calculated storage sizes from Azure Storage blobs.
Root Cause Analysis
After fixing the field name issue (public_workspace_id vs workspace_id) in version 0.230.081, document counts were working correctly but storage calculations had several issues:
Problems Identified:
- Incorrect folder prefix: Public workspaces used
public/{workspace_id}/but actual Azure Storage structure uses{workspace_id}/ - Inadequate fallback logic: Public workspaces had basic fallback, but groups had sophisticated file-type based estimation
- Inconsistent error handling: Public workspaces lacked the robust error handling that groups had
- Missing debug logging: Insufficient debugging information for storage calculation issues
Technical Solution
Files Modified:
route_backend_control_center.py: Updated public workspace storage calculation logic
Changes Implemented:
Fixed Folder Prefix
# Before (incorrect) workspace_folder_prefix = f"public/{workspace_id}/" # After (matches actual storage structure) workspace_folder_prefix = f"{workspace_id}/"Enhanced Fallback Logic
# Before: Simple sum query SELECT VALUE SUM(c.storage_account_size) FROM c # After: File-type based estimation (matching groups) SELECT c.file_name, c.number_of_pages FROM c # Then estimate based on file type: # - PDF: ~500KB per page # - Word: ~300KB per page # - PowerPoint: ~800KB per page # - Other: ~400KB per pageImproved Error Handling
# Before: Basic error logging debug_print(f"Error calculating storage...") # After: Robust error handling with fallback except Exception as storage_e: debug_print(f"❌ Storage calculation failed...") enhanced['activity']['document_metrics']['storage_account_size'] = 0 enhanced['storage_size'] = 0Enhanced Debug Logging
- Added blob enumeration logging
- Fallback estimation progress logging
- Consistent debug markers matching group patterns
Impact Assessment
Before Fix:
- ❌ Public workspace storage always showed 0 B
- ❌ No fallback when Azure Storage client unavailable
- ❌ Poor error handling caused calculation failures
- ❌ Minimal debug information for troubleshooting
After Fix:
- ✅ Public workspaces calculate actual storage sizes from Azure Storage
- ✅ Intelligent fallback estimation when storage client unavailable
- ✅ Robust error handling prevents crashes
- ✅ Comprehensive debug logging for troubleshooting
Technical Details
Storage Container Structure:
public-documents container:
├── {workspace-id-1}/
│ ├── document1.pdf
│ └── document2.docx
├── {workspace-id-2}/
│ └── document3.pptx
└── {workspace-id-3}/
├── document4.txt
└── document5.pdf
Calculation Logic:
- Primary: Enumerate blobs in
{workspace_id}/folder, sum actual blob sizes - Fallback: Query document metadata, estimate sizes based on file type and page count
- Error: Set storage size to 0 to prevent display issues
File Size Estimations:
- PDF files: 500KB × number_of_pages
- Word documents: 300KB × number_of_pages
- PowerPoint: 800KB × number_of_pages
- Other files: 400KB × number_of_pages
Testing and Validation
Test Coverage:
- Storage client retrieval and blob enumeration
- Folder prefix correction validation
- Fallback estimation logic verification
- Error handling robustness testing
- Container usage consistency checking
Validation Results:
- ✅ Folder prefix matches actual Azure Storage structure
- ✅ Fallback logic identical to proven group implementation
- ✅ Error handling prevents crashes and provides graceful degradation
- ✅ Debug logging enables effective troubleshooting
Expected Behavior Changes
Control Center Display:
Before:
HR | Total Docs: 2 | AI Search: 880 KB | Storage: 0 B
IT | Total Docs: 1 | AI Search: 160 KB | Storage: 0 B
Service Desk| Total Docs: 4 | AI Search: 1.41 MB| Storage: 0 B
After:
HR | Total Docs: 2 | AI Search: 880 KB | Storage: 1.2 MB
IT | Total Docs: 1 | AI Search: 160 KB | Storage: 450 KB
Service Desk| Total Docs: 4 | AI Search: 1.41 MB| Storage: 2.8 MB
Debug Output:
Enhanced logging provides clear insight into storage calculation:
💾 [PUBLIC WORKSPACE STORAGE DEBUG] Looking for blobs with prefix: dfbd222c-1aea-44c3-b1ac-6d9b7742682c/
💾 [PUBLIC WORKSPACE STORAGE DEBUG] Found 4 blobs, total size: 2847362 bytes
💾 [PUBLIC WORKSPACE STORAGE DEBUG] Fallback estimation complete: 2400000 bytes
Related Issues
This fix completes the public workspace metrics consistency work started in version 0.230.080-081:
- 0.230.080: Implemented caching consistency
- 0.230.081: Fixed field name consistency (
public_workspace_id) - 0.230.082: Fixed storage calculation consistency
Public workspaces now have complete feature parity with group workspaces for document metrics calculation and caching.