Skip to content

The agent that grows with you

fix(desktop): a superseded preview action only releases its own controller (#125408)

Brooklyn Nicholson6d42313deee6
diff --git a/apps/desktop/src/app/chat/right-rail/preview-typing-abort.ts b/apps/desktop/src/app/chat/right-rail/preview-typing-abort.ts
index 91e62f9b99c..8ba2f06c479 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-typing-abort.ts
+++ b/apps/desktop/src/app/chat/right-rail/preview-typing-abort.ts
@@ -37,7 +37,16 @@ export function abortPreviewTyping(requestId: string, reason = 'interrupted'): v
}
/** Drop the controller once the action has settled, so a late cancel is a no-op
- * rather than aborting a controller the next action might reuse. */
-export function releasePreviewTyping(requestId: string): void {
+ * rather than aborting a controller the next action might reuse. An action can
+ * be superseded by a same-id replay (`trackPreviewTyping` aborts the original
+ * and installs a replacement): release only the controller this action owns,
+ * identified by its signal — the original's `finally` must not delete the
+ * replay's entry, or a later cancel finds nothing and the replay keeps typing
+ * (#125408). */
+export function releasePreviewTyping(requestId: string, owner?: AbortSignal): void {
+ if (owner !== undefined && controllers.get(requestId)?.signal !== owner) {
+ return
+ }
+
controllers.delete(requestId)
}
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
index fffacbce5f8..765320d9ff4 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts
@@ -500,7 +500,7 @@ const previewAct: Handler = ({ deps, isActiveSession, request, sessionId }) => {
clearInterval(watch)
}
- releasePreviewTyping(request.id)
+ releasePreviewTyping(request.id, signal)
})
}