Skip to content

Commit 6fc7614

Browse files
fix(ui): race condition with progress
There's a race condition where a canceled session may emit a progress event or two after it's been canceled, and the progress image isn't cleared out. To resolve this, the system slice tracks canceled session ids. When a progress event comes in, we check the cancellations and skip setting the progress if canceled.
1 parent 9c926f2 commit 6fc7614

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

invokeai/frontend/web/src/features/system/store/systemSlice.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const initialSystemState: SystemState = {
3131
shouldUseWatermarker: false,
3232
shouldEnableInformationalPopovers: false,
3333
status: 'DISCONNECTED',
34+
cancellations: [],
3435
};
3536

3637
export const systemSlice = createSlice({
@@ -88,6 +89,7 @@ export const systemSlice = createSlice({
8889
* Invocation Started
8990
*/
9091
builder.addCase(socketInvocationStarted, (state) => {
92+
state.cancellations = [];
9193
state.denoiseProgress = null;
9294
state.status = 'PROCESSING';
9395
});
@@ -105,6 +107,12 @@ export const systemSlice = createSlice({
105107
queue_batch_id: batch_id,
106108
} = action.payload.data;
107109

110+
if (state.cancellations.includes(session_id)) {
111+
// Do not update the progress if this session has been cancelled. This prevents a race condition where we get a
112+
// progress update after the session has been cancelled.
113+
return;
114+
}
115+
108116
state.denoiseProgress = {
109117
step,
110118
total_steps,
@@ -146,6 +154,7 @@ export const systemSlice = createSlice({
146154
if (['completed', 'canceled', 'failed'].includes(action.payload.data.queue_item.status)) {
147155
state.status = 'CONNECTED';
148156
state.denoiseProgress = null;
157+
state.cancellations.push(action.payload.data.queue_item.session_id);
149158
}
150159
});
151160
},
@@ -177,5 +186,5 @@ export const systemPersistConfig: PersistConfig<SystemState> = {
177186
name: systemSlice.name,
178187
initialState: initialSystemState,
179188
migrate: migrateSystemState,
180-
persistDenylist: ['isConnected', 'denoiseProgress', 'status'],
189+
persistDenylist: ['isConnected', 'denoiseProgress', 'status', 'cancellations'],
181190
};

invokeai/frontend/web/src/features/system/store/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ export interface SystemState {
5555
shouldUseWatermarker: boolean;
5656
status: SystemStatus;
5757
shouldEnableInformationalPopovers: boolean;
58+
cancellations: string[]
5859
}

0 commit comments

Comments
 (0)