fix: atomic audio save with error handling and filesystem health endpoint#263
fix: atomic audio save with error handling and filesystem health endpoint#263
Conversation
…tem health endpoint - save_audio() now writes to .tmp then os.replace() for atomic writes - /generate endpoint catches OSError with specific messages for ENOENT, EACCES, ENOSPC, and BrokenPipeError - New /health/filesystem endpoint checks directory existence, write permissions, and disk space - New DirectoryCheck and FilesystemHealthResponse models Cherry-picked and expanded from #178 (@Vaibhavee89)
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughA new filesystem health endpoint was added to monitor per-directory existence, writability, and disk usage. Audio saving was enhanced with atomic write operations and errno-specific error handling. Two new Pydantic models were introduced to structure filesystem health responses. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Endpoint as /health/filesystem
participant FileSystem as File System
Client->>Endpoint: GET /health/filesystem
rect rgba(100, 150, 200, 0.5)
Note over Endpoint,FileSystem: Directory Checks
Endpoint->>FileSystem: Check /data existence
Endpoint->>FileSystem: Check /outputs existence
Endpoint->>FileSystem: Check /temp existence
end
rect rgba(100, 150, 200, 0.5)
Note over Endpoint,FileSystem: Writability Tests
Endpoint->>FileSystem: Create temporary file in /data
Endpoint->>FileSystem: Delete temporary file
end
rect rgba(100, 150, 200, 0.5)
Note over Endpoint,FileSystem: Disk Usage Computation
Endpoint->>FileSystem: Query disk free space
Endpoint->>FileSystem: Compute /data directory usage
end
Endpoint->>Client: Return FilesystemHealthResponse (healthy status, disk metrics, per-directory checks)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
save_audio()— writes to.tmpthenos.replace()to prevent corrupted/partial WAV files on interrupted writes/generate— catchesBrokenPipeError,ENOENT(dir not found),EACCES(permission denied),ENOSPC(disk full) with clear user-facing messages/health/filesystemendpoint — probes directory existence & write permissions forgenerations,profiles, anddatadirs, reports disk free/total space, flags unhealthy if <500 MB freeCherry-picked and expanded from #178 (@Vaibhavee89).
Changes
backend/utils/audio.py— atomic write via temp file +os.replace(), cleanup on failurebackend/main.py— error handling aroundsave_audiocall, new/health/filesystemendpointbackend/models.py—DirectoryCheckandFilesystemHealthResponsepydantic modelsSummary by CodeRabbit
Release Notes
New Features
Bug Fixes