fix: clear stale active job after reconnect

This commit is contained in:
Benjamin Lu
2026-03-13 11:54:47 -07:00
parent 422db2baa2
commit ea691eaea3
3 changed files with 53 additions and 2 deletions

View File

@@ -491,6 +491,45 @@ describe('useExecutionStore - clearTrackedJob', () => {
expect(store.initializingJobIds).toEqual(new Set(['job-2']))
expect(store._executingNodeProgress).toBeNull()
})
it('clears a stale active job when a different prompt completes', () => {
const terminalJobState = {
value: 3,
max: 10,
state: 'running' as const,
node_id: 'node-2',
prompt_id: 'job-2'
}
store.activeJobId = 'job-1'
store.queuedJobs = {
'job-1': { nodes: {} },
'job-2': { nodes: {} }
}
store.nodeProgressStates = {
'node-2': terminalJobState
}
store.nodeProgressStatesByJob = {
'job-1': {},
'job-2': { 'node-2': terminalJobState }
}
store.initializingJobIds = new Set(['job-1', 'job-2'])
store.bindExecutionEvents()
const handler = apiEventHandlers.get('execution_success')
if (!handler) throw new Error('execution_success handler not bound')
handler(
new CustomEvent('execution_success', {
detail: { prompt_id: 'job-2' }
})
)
expect(store.activeJobId).toBeNull()
expect(store.queuedJobs).toEqual({})
expect(store.nodeProgressStates).toEqual({})
expect(store.nodeProgressStatesByJob).toEqual({})
expect(store.initializingJobIds).toEqual(new Set())
})
})
describe('useExecutionErrorStore - Node Error Lookups', () => {

View File

@@ -544,10 +544,22 @@ export const useExecutionStore = defineStore('execution', () => {
return
}
removeTrackedJobState(jobId, {
const normalizedJobId = String(jobId)
const staleActiveJobId =
activeJobId.value && activeJobId.value !== normalizedJobId
? activeJobId.value
: null
removeTrackedJobState(normalizedJobId, {
clearAllNodeProgressStates: true,
clearPromptError: true
})
if (staleActiveJobId) {
removeTrackedJobState(staleActiveJobId, {
clearPromptError: true
})
}
}
/**

View File

@@ -585,7 +585,7 @@ export const useQueueStore = defineStore('queue', () => {
const activeJobId = executionStore.activeJobId
const missedTerminalExecution =
activeJobId !== null &&
!activeJobIds.has(String(activeJobId)) &&
!activeJobIds.has(activeJobId) &&
nextHistoryTasks.some((task) => task.jobId === activeJobId)
if (missedTerminalExecution) {