fix(desktop): keep session load on its replay fast path when stopped (#13190)

This commit is contained in:
jaias92
2026-10-30 08:51:05 +00:00
committed by GitHub
parent 0aeb4077a9
commit 090dedb762
4 changed files with 59 additions and 1 deletions
@@ -220,6 +220,35 @@ describe('acpChatSessionController.stop', () => {
);
expect(acpCancelPrompt).toHaveBeenCalledWith(SESSION_ID);
});
it('leaves the chat state alone when stopping during a session load', () => {
vi.mocked(acpChatSessionStore.getSnapshot).mockReturnValue({
...snapshotWithActivePrompt(null),
chatState: ChatState.LoadingConversation,
});
acpChatSessionController.stop(SESSION_ID);
expect(acpChatSessionActions.setChatState).not.toHaveBeenCalled();
expect(acpChatSessionActions.startPromptCancellation).not.toHaveBeenCalled();
expect(acpCancelPrompt).not.toHaveBeenCalled();
});
it('cancels a leftover prompt attempt when stopping during a session load', () => {
vi.mocked(acpChatSessionStore.getSnapshot).mockReturnValue({
...snapshotWithActivePrompt('attempt-1'),
chatState: ChatState.LoadingConversation,
});
acpChatSessionController.stop(SESSION_ID);
expect(acpChatSessionActions.startPromptCancellation).toHaveBeenCalledWith(
SESSION_ID,
'attempt-1'
);
expect(acpCancelPrompt).toHaveBeenCalledWith(SESSION_ID);
expect(acpChatSessionActions.setChatState).not.toHaveBeenCalled();
});
});
describe('acpChatSessionController.submitMessage', () => {
@@ -542,6 +542,28 @@ describe('acpChatSessionStore', () => {
expect(finishedSnapshot.messages[0].content).toEqual([{ type: 'text', text: 'Hello' }]);
});
it('keeps only the late notification when one arrives after a failed session load', () => {
const currentSessionId = sessionId('session-1');
acpChatSessionActions.startSessionLoad(currentSessionId);
acpChatSessionActions.applyAcpSessionNotification(
agentMessageChunkNotification(currentSessionId, 'message-1', 'Hello')
);
const failedSnapshot = acpChatSessionActions.failSessionLoad(currentSessionId, 'boom');
expect(failedSnapshot.sessionLoadError).toBe('boom');
expect(failedSnapshot.messages).toEqual([]);
const lateSnapshot = acpChatSessionActions.applyAcpSessionNotification(
agentMessageChunkNotification(currentSessionId, 'message-2', 'World')
);
expect(lateSnapshot.messages.map((item) => item.id)).toEqual(['message-2']);
expect(
acpChatSessionStore.getSnapshot(currentSessionId)?.messages.map((item) => item.id)
).toEqual(['message-2']);
});
it('applies permission requests as waiting action-required messages', () => {
const currentSessionId = sessionId('session-1');
+7 -1
View File
@@ -225,7 +225,8 @@ async function submitMessage(
}
function stop(sessionId: string): void {
const storedPromptAttemptId = acpChatSessionStore.getSnapshot(sessionId)?.activePromptAttemptId;
const snapshot = acpChatSessionStore.getSnapshot(sessionId);
const storedPromptAttemptId = snapshot?.activePromptAttemptId;
const hasStoredAcpPrompt = storedPromptAttemptId !== null && storedPromptAttemptId !== undefined;
if (hasStoredAcpPrompt) {
@@ -238,6 +239,11 @@ function stop(sessionId: string): void {
return;
}
// A session load has nothing to cancel; ending it here would leave the replay fast path.
if (snapshot?.chatState === ChatState.LoadingConversation) {
return;
}
acpChatSessionActions.setChatState(sessionId, ChatState.Idle);
}
+1
View File
@@ -237,6 +237,7 @@ function createAcpChatSessionStoreInternal(): AcpChatSessionStoreInternal {
sessionLoadError
) => {
const entry = getOrCreateEntry(sessionId);
resetReplayState(entry);
entry.sessionLoadError = sessionLoadError;
entry.progressMessage = undefined;
entry.chatState = ChatState.Idle;