Status: Recording system has critical failures that prevent reliable security footage capture. Risk Level: HIGH - Current system unsuitable for production use Overall Reliability Score: 4.2/10 (POOR)
- ❌ Recording channel frames are discarded (100% data loss from recordChannel)
- ❌ No disk space checks before recording
- ❌ Race conditions in recording state management
- ❌ Buffer overflow causes silent frame drops (up to 6.7 seconds lost)
- ❌ No frame write verification (silent data corruption)
- ❌ Zero redundancy mechanisms
Current (Broken): Recording depends on WebRTC track handlers → fragile, network-dependent Target: Recording directly from FrameDistributor → robust, network-independent
Camera → FrameDistributor → recordChannel → VP9 Encoder → WebM (Direct to disk)
→ vp9Channel → WebRTC (Live streaming only)
→ motionChannel → Motion Detection
- Modify
internal/integration/pipeline.go:254-288- Add VP9 encoder initialization in
consumeRecordingFrames() - Encode frames from recordChannel directly to VP9
- Write encoded frames to WebM file
- Add proper frame timestamp management
- Remove WebRTC dependency from recording path
- Add VP9 encoder initialization in
- Impact: Fixes 100% frame loss from recordChannel
- Files:
internal/integration/pipeline.go
- Refactor
internal/video/recorder.go- Remove
HandleTrack()method (lines 205-258) - Delete
videoBufferandaudioBufferchannels - Remove
processBuffers()goroutine (lines 299-361) - Delete VP8 frame assembler code
- Simplify to pure file lifecycle manager (start/stop/rotate)
- Remove
- Impact: Cleaner architecture, recording independent of WebRTC
- Files:
internal/video/recorder.go
- Add preemptive validation in
recorder.go:111-168- Implement
checkDiskSpace()method (require 5GB minimum) - Add
verifyDirectoryWritable()method - Call both checks before
StartRecording() - Return clear error messages on failure
- Implement
- Impact: Prevents recording failures due to disk full
- Files:
internal/video/recorder.go
- Thread-safe state management in
recorder.go- Replace
isRecording boolwithatomic.Bool - Add separate mutexes for state vs file operations
- Ensure atomic state transitions
- Add state validation in all public methods
- Replace
- Impact: Prevents file corruption from concurrent access
- Files:
internal/video/recorder.go
- Add overflow protection in
pipeline.go- Create circular emergency buffer (300 frames = 20 seconds)
- Implement backpressure when buffer >90% full
- Add metrics for buffer utilization
- Log warnings when emergency buffer engaged
- Impact: Prevents frame loss during encoder slowdowns
- Files:
internal/integration/pipeline.go
- Track frame sequence numbers
- Implement FrameTracker with sequence validation
- Detect missing frames (sequence gaps)
- Log all frame drops with timestamps
- Add statistics for frame write success rate
- Impact: Detect silent data loss
- Files:
internal/integration/pipeline.go
- Ensure clean recording shutdown
- Wait for all buffers to drain before closing file
- Add 15-second timeout for buffer flush
- Log number of frames flushed vs lost
- Verify file integrity after flush
- Impact: Prevents loss of last 6.7 seconds of recording
- Files:
internal/integration/pipeline.go
- Comprehensive validation in
recorder.go:637-656- Check file size > 1KB minimum
- Verify WebM structure is valid
- Validate duration metadata exists
- Confirm at least one keyframe present
- Check timestamp continuity
- Impact: Detect corrupted recordings early
- Files:
internal/video/recorder.go
- Reduce drops in
distributor.go:260-289- Increase recordChannel buffer: 30 → 150 frames
- Implement adaptive backpressure mechanism
- Log every frame drop (not just every 100th)
- Add metrics dashboard for drop rates
- Impact: Reduces 50%+ drop rates under load
- Files:
internal/framestream/distributor.go
- Monitor file size increases every 5 seconds
- Alert if recording stalls (no growth)
- Auto-restart recording on failure
- Send notifications for recording failures
- Use
.tmpextension during active recording - Rename to
.webmonly on successful close - Scan for
.tmpfiles on startup - Attempt to salvage partial recordings
- Move corrupted files to
corrupted/subdirectory
- Align all components to 1280x720 @ 15fps
- Single source of truth for video parameters
- Remove conflicting config values (640x480, 25fps)
- Implement
sync.Poolfor image buffers - Pre-allocate encoder frame buffers
- Reuse buffers instead of cloning where safe
- Profile and optimize hot paths
- Target: <20 GB/hour allocations (currently ~200 GB/hour)
- Add CRC32 checksum to each frame
- Store checksums in
.checksumsidecar file - Verify on playback/export
- Detect silent corruption
- Disk Full Test: Fill disk to 95%, verify graceful failure
- I/O Stall Test: Throttle disk to 1MB/s, verify no frame loss
- Memory Pressure Test: Limit to 1GB RAM, verify no OOM
- Concurrent Recording Test: Multiple start/stop cycles, verify no race conditions
- File Rotation Test: Rotate under load, verify no frame loss
- Crash Recovery Test: Kill process during recording, verify file salvage
- 24-Hour Stress Test: Record continuously, verify no memory leaks
- Frame Verification Test: Compare captured vs recorded frame count
- Frame clone: <5ms @ 1280x720
- Frame encode: <30ms @ 1280x720
- Frame write: <10ms average
- Drop rate: <1% under normal load
- Memory: <2GB steady-state
- Disk I/O: <50 MB/s sustained
Current State:
- Reliability: 4.2/10
- Frame loss: Unknown (not tracked)
- Redundancy: 0/10
- Production ready: ❌ NO
Target State (Phase 1 Complete):
- Reliability: 7/10
- Frame loss: <1% tracked
- Redundancy: 3/10
- Production ready:
⚠️ MAYBE (basic use only)
Target State (Phase 2 Complete):
- Reliability: 9/10
- Frame loss: <0.1% tracked
- Redundancy: 7/10
- Production ready: ✅ YES (suitable for real security use)
- Research MailerSend optimal configuration
- Determine if API vs SMTP relay is better for our use case
- Minimize required MailerSend dashboard configuration
- Ensure "clone and run" simplicity (minimal external setup)
- Document recommended MailerSend token permissions (minimize scope)
- Evaluate domain verification requirements
- Consider sender identity configuration
-
Review and integrate Gmail notifier implementation
- Validate Gmail OAuth2 implementation security and best practices
- Add missing dependencies to go.mod (oauth2, gmail API)
- Create shared email template system for code reuse
- Extract common retry logic into shared utilities
- Standardize error handling patterns across both notifiers
-
Modularize notification package
- Extract shared email template functionality
- Create common retry mechanism (used by both Gmail & MailerSend)
- Unify configuration patterns between Gmail and MailerSend
- Create shared email data preparation functions
- Ensure consistent interface implementations
- Add unified debug/testing capabilities
-
Research and choose GUI framework for Go
- Evaluate Fyne vs Gio vs embedded web server approach
- Consider cross-platform compatibility (Windows/Mac/Linux)
- Test basic GUI window creation and user interactions
-
Create Email Setup Dialog
- Design main configuration window with 3 clear options
- Add MailerSend token input field with validation
- Add Gmail OAuth2 button with progress indication
- Add "Skip Email" option that continues without notifications
- Implement window styling and responsive layout
-
Implement Email Method Testing
- Create unified test email function for both methods
- Add real-time validation feedback (spinner, success/error states)
- Implement retry logic with specific error messages
- Add method switching without restarting dialog
-
Error Handling & Recovery System
- Design error display with actionable messages
- Implement persistent dialog (stays open until valid choice)
- Add method fallback options (try different method on failure)
- Create configuration persistence for successful setups
-
Update main application startup flow
- Show GUI before camera initialization
- Wait for email method selection/configuration
- Initialize appropriate notifier based on GUI choice
- Add headless mode flag for server deployments
-
Documentation & Setup
- Update .env.example with Gmail OAuth2 options
- Create Gmail OAuth2 setup guide (Google Cloud Console steps)
- Document MailerSend vs Gmail trade-offs
- Add troubleshooting guide for both email methods
- Update SETUP.md with new email configuration options
- Test both email notification systems
- Verify MailerSend integration works with optimized configuration
- Test Gmail OAuth2 flow end-to-end
- Validate encrypted token storage and retrieval
- Test email template rendering for both systems
- Verify retry logic and error handling
- Test "clone and run" experience for both email methods
- Maximum Code Reuse: Share templates, retry logic, and utilities between Gmail & MailerSend
- Consistent Interface: Both notifiers should implement identical interfaces
- "Clone and Run" Friendly: Minimal external service configuration required
- Security First: Encrypted token storage, minimal OAuth scopes, secure defaults
- Graceful Degradation: Core motion detection works even if email fails
- Developer Experience: Clear configuration, good error messages, easy debugging
- Consider adding SMS notifications (Twilio integration)
- Webhook notification support for external systems
- Push notification support (Firebase/Apple Push)
- Multiple recipient support
- HTML email templates with embedded images
- Support for headless browsers (use the device code OAuth flow) - Very low priority for server deployments without GUI support