This commit addresses all identified bugs and issues in the training code path: ## Critical Fixes: - Add get_start_time() method to TrainingLogRepository and fix non-existent method call - Remove duplicate training.started event from API endpoint (trainer publishes the accurate one) - Add missing progress events for 80-100% range (85%, 92%, 94%) to eliminate progress "dead zone" ## High Priority Fixes: - Fix division by zero risk in time estimation with double-check and max() safety - Remove unreachable exception handler in training_operations.py - Simplify WebSocket token refresh logic to only reconnect on actual user session changes ## Medium Priority Fixes: - Fix auto-start training effect with useRef to prevent duplicate starts - Add HTTP polling debounce delay (5s) to prevent race conditions with WebSocket - Extract all magic numbers to centralized constants files: - Backend: services/training/app/core/training_constants.py - Frontend: frontend/src/constants/training.ts - Standardize error logging with exc_info=True on critical errors ## Code Quality Improvements: - All progress percentages now use named constants - All timeouts and intervals now use named constants - Improved code maintainability and readability - Better separation of concerns ## Files Changed: - Backend: training_service.py, trainer.py, training_events.py, progress_tracker.py - Backend: training_operations.py, training_log_repository.py, training_constants.py (new) - Frontend: training.ts (hooks), MLTrainingStep.tsx, training.ts (constants, new) All training progress events now properly flow from 0% to 100% with no gaps.
26 lines
954 B
TypeScript
26 lines
954 B
TypeScript
/**
|
|
* Training Progress Constants
|
|
* Centralized constants for training UI and behavior
|
|
*/
|
|
|
|
// Time Intervals (milliseconds)
|
|
export const TRAINING_SKIP_OPTION_DELAY_MS = 120000; // 2 minutes
|
|
export const TRAINING_COMPLETION_DELAY_MS = 2000; // 2 seconds
|
|
export const HTTP_POLLING_INTERVAL_MS = 5000; // 5 seconds
|
|
export const HTTP_POLLING_DEBOUNCE_MS = 5000; // 5 seconds
|
|
export const WEBSOCKET_HEARTBEAT_INTERVAL_MS = 30000; // 30 seconds
|
|
|
|
// WebSocket Configuration
|
|
export const WEBSOCKET_MAX_RECONNECT_ATTEMPTS = 3;
|
|
export const WEBSOCKET_RECONNECT_INITIAL_DELAY_MS = 1000; // 1 second
|
|
export const WEBSOCKET_RECONNECT_MAX_DELAY_MS = 10000; // 10 seconds
|
|
|
|
// Progress Milestones
|
|
export const PROGRESS_DATA_ANALYSIS = 20;
|
|
export const PROGRESS_TRAINING_RANGE_START = 20;
|
|
export const PROGRESS_TRAINING_RANGE_END = 80;
|
|
export const PROGRESS_COMPLETED = 100;
|
|
|
|
// Skip Timer Check Interval
|
|
export const SKIP_TIMER_CHECK_INTERVAL_MS = 5000; // 5 seconds
|