diff --git a/containers/libreportal/frontend/js/components/task/task-event-bus.js b/containers/libreportal/frontend/js/components/task/task-event-bus.js index 3b75415..27c8fed 100755 --- a/containers/libreportal/frontend/js/components/task/task-event-bus.js +++ b/containers/libreportal/frontend/js/components/task/task-event-bus.js @@ -119,13 +119,28 @@ class TaskEventBus { timestamp: Date.now() }; + const isTerminal = task.status === 'completed' || task.status === 'failed' || task.status === 'cancelled'; + const wasTerminal = prevStatus === 'completed' || prevStatus === 'failed' || prevStatus === 'cancelled'; + + // Bootstrap silently. When this is the first time we've ever seen a task + // AND it's already in a terminal state, we have NO evidence it + // transitioned just now — it might have completed seconds or hours ago. + // The backend re-broadcasts the file's contents on any inode change (e.g. + // the periodic ownership/permission sweep stats every task file), so + // firing taskCompleted here would surface a "ghost" completion + // notification for a task the user already saw finish 28 minutes ago. + // Just record it in our map and move on. + if (isNew && isTerminal) { + return; + } + if (isNew) { window.dispatchEvent(new CustomEvent('taskCreated', { detail })); } - const isTerminal = task.status === 'completed' || task.status === 'failed' || task.status === 'cancelled'; - const wasTerminal = prevStatus === 'completed' || prevStatus === 'failed' || prevStatus === 'cancelled'; - + // Genuine transition to terminal: we had a prior non-terminal record and + // the current upsert flips that to terminal. This is what users expect + // to be notified about. if (isTerminal && !wasTerminal) { window.dispatchEvent(new CustomEvent('taskCompleted', { detail })); } else if (!isNew) {