Fix progress tracking synchronization issues

- Pre-generate sessionId on client side before API call to avoid race conditions
- Add small delays in progress tracker to ensure EventSource connection is established
- Improve logging and error handling in progress streaming
- Add connection confirmation messages in EventSource stream
- Fix TypeScript interface to include sessionId in AnalysisProgress

This should resolve the lag between actual analysis progress and progress bar display.
This commit is contained in:
mindesbunister
2025-07-17 12:10:47 +02:00
parent 7e8f033bb2
commit 0399103f8a
4 changed files with 45 additions and 13 deletions

View File

@@ -36,7 +36,12 @@ class ProgressTracker extends EventEmitter {
}
this.sessions.set(sessionId, progress)
this.emit(`progress:${sessionId}`, progress)
// Small delay to ensure EventSource connection is established before emitting
setTimeout(() => {
this.emit(`progress:${sessionId}`, progress)
}, 100)
return progress
}
@@ -77,7 +82,11 @@ class ProgressTracker extends EventEmitter {
this.sessions.set(sessionId, updatedProgress)
console.log(`🔍 Emitting progress event for ${sessionId}, currentStep: ${updatedProgress.currentStep}`)
this.emit(`progress:${sessionId}`, updatedProgress)
// Small delay to ensure proper event ordering and prevent race conditions
setTimeout(() => {
this.emit(`progress:${sessionId}`, updatedProgress)
}, 50)
}
updateTimeframeProgress(sessionId: string, current: number, total: number, currentTimeframe?: string): void {