fix: clean up assistant transient sessions

This commit is contained in:
ajnart committed 2026-08-20 14:50:00 +02:00
1 parent 80b90802e5
commit d79c748c4d
2 files changed
+27 -5

No files matched your search

@@ -3331,8 +3331,20 @@ export const AssistantPanel = ({
onReasoningChange, onReasoningChange,
}: AssistantPanelProps) => { }: AssistantPanelProps) => {
const t = useScopedI18n("common.assistant"); const t = useScopedI18n("common.assistant");
const aui = useAui();
const previousFocusRef = useRef<HTMLElement | null>(null); const previousFocusRef = useRef<HTMLElement | null>(null);
const panelRef = useRef<HTMLDialogElement>(null); const panelRef = useRef<HTMLDialogElement>(null);
const stopVoiceActivityWithoutSurface = () => {
if (hasVisibleWidget) return;
const composer = aui.composer();
if (composer.getState().dictation !== undefined) composer.stopDictation();
const thread = aui.thread();
if (thread.getState().speech !== undefined) thread.stopSpeaking();
};
const minimize = () => {
stopVoiceActivityWithoutSurface();
onClose();
};
useWindowEvent("keydown", (event) => { useWindowEvent("keydown", (event) => {
if ( if (
@@ -3344,7 +3356,7 @@ export const AssistantPanel = ({
) )
return; return;
event.preventDefault(); event.preventDefault();
onClose(); minimize();
}); });
useEffect(() => { useEffect(() => {
if (!opened) { if (!opened) {
@@ -3394,8 +3406,9 @@ export const AssistantPanel = ({
onModelChange={onModelChange} onModelChange={onModelChange}
onReasoningChange={onReasoningChange} onReasoningChange={onReasoningChange}
autoFocusComposer autoFocusComposer
onMinimize={onClose} onMinimize={minimize}
onDismiss={() => { onDismiss={() => {
stopVoiceActivityWithoutSurface();
onDismissActivity(); onDismissActivity();
onClose(); onClose();
}} }}
@@ -42,6 +42,7 @@ class AssistantSurfaceComposerRuntimeCore extends INTERNAL.DefaultThreadComposer
} }
public dispose() { public dispose() {
if (this.dictation !== undefined) this.stopDictation();
composerConnectionDisposers.get(this)?.(); composerConnectionDisposers.get(this)?.();
composerConnectionDisposers.delete(this); composerConnectionDisposers.delete(this);
} }
@@ -294,18 +295,22 @@ export const createAssistantSurfaceRuntime = (runtime: AssistantRuntime): Assist
subscribe(callback) { subscribe(callback) {
let activeCore = sharedBinding.getState(); let activeCore = sharedBinding.getState();
let activeConversationId = getConversationId(); let activeConversationId = getConversationId();
let activeComposer = getComposer(activeConversationId, activeCore);
retainConversation(activeConversationId); retainConversation(activeConversationId);
let unsubscribeComposer = getComposer(activeConversationId, activeCore).subscribe(callback); let unsubscribeComposer = activeComposer.subscribe(callback);
const handleSharedUpdate = () => { const handleSharedUpdate = () => {
const nextCore = sharedBinding.getState(); const nextCore = sharedBinding.getState();
const nextConversationId = getConversationId(); const nextConversationId = getConversationId();
if (nextCore !== activeCore || nextConversationId !== activeConversationId) { if (nextCore !== activeCore || nextConversationId !== activeConversationId) {
if (activeComposer.dictation !== undefined) activeComposer.stopDictation();
if (activeCore.speech !== undefined) activeCore.stopSpeaking();
unsubscribeComposer(); unsubscribeComposer();
releaseConversation(activeConversationId); releaseConversation(activeConversationId);
activeCore = nextCore; activeCore = nextCore;
activeConversationId = nextConversationId; activeConversationId = nextConversationId;
retainConversation(activeConversationId); retainConversation(activeConversationId);
unsubscribeComposer = getComposer(activeConversationId, activeCore).subscribe(callback); activeComposer = getComposer(activeConversationId, activeCore);
unsubscribeComposer = activeComposer.subscribe(callback);
} }
callback(); callback();
}; };
@@ -360,6 +365,10 @@ export const createAssistantSurfaceRuntime = (runtime: AssistantRuntime): Assist
registerModelContextProvider: () => () => {}, registerModelContextProvider: () => () => {},
dispose() { dispose() {
activeConversationCounts.clear(); activeConversationCounts.clear();
const threadCores = new Set(Array.from(surfaceCoreByConversation.values(), (entry) => entry.source));
for (const threadCore of threadCores) {
if (threadCore.speech !== undefined) threadCore.stopSpeaking();
}
for (const [conversationId, entry] of composerByConversation) disposeComposer(conversationId, entry); for (const [conversationId, entry] of composerByConversation) disposeComposer(conversationId, entry);
}, },
}; };
@@ -509,7 +518,6 @@ export const AssistantComposerSurfaceBoundary = ({ children, surfaceId }: PropsW
}} }}
onPasteCapture={handlePasteCapture} onPasteCapture={handlePasteCapture}
> >
<AssistantComposerSurfaceEvents />
{children} {children}
</div> </div>
</AssistantComposerSurfaceContext.Provider> </AssistantComposerSurfaceContext.Provider>
@@ -588,6 +596,7 @@ export const AssistantComposerRuntimeProvider = ({ children }: PropsWithChildren
return ( return (
<AssistantRuntimeProvider aui={parentAui} runtime={surfaceRuntime}> <AssistantRuntimeProvider aui={parentAui} runtime={surfaceRuntime}>
<AssistantComposerSurfaceEvents />
{children} {children}
</AssistantRuntimeProvider> </AssistantRuntimeProvider>
); );