Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/vs/sessions/services/sessions/browser/sessionNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ export class SessionsNavigation extends Disposable {
this._register(autorun(reader => {
const activeSession = this._sessionsManagementService.activeSession.read(reader);
const activeChat = activeSession?.activeChat.read(reader);
const sessionStatus = activeSession?.status.read(reader);
const chatStatus = activeChat?.status.read(reader);
if (this._navigating) {
return;
}
if (!activeSession || activeSession.status.read(reader) === SessionStatus.Untitled) {
if (!activeSession || sessionStatus === SessionStatus.Untitled) {
// User navigated to new-session view: if we have history, remember we're
// beyond the stack so Back can return to the last real session.
if (this._history.length > 0) {
Expand All @@ -91,7 +93,7 @@ export class SessionsNavigation extends Disposable {
}

// Skip untitled chats (new-chat-in-session that hasn't been submitted)
const chatResource = activeChat && activeChat.status.read(reader) !== SessionStatus.Untitled
const chatResource = activeChat && chatStatus !== SessionStatus.Untitled
? activeChat.resource
: undefined;

Expand Down Expand Up @@ -185,7 +187,12 @@ export class SessionsNavigation extends Disposable {
const session = this._sessionsManagementService.getSession(entry.sessionResource);
if (session) {
if (entry.chatResource) {
await this._sessionsManagementService.openChat(session, entry.chatResource);
const chatExists = session.chats.get().some(c => c.resource.toString() === entry.chatResource!.toString());
if (chatExists) {
await this._sessionsManagementService.openChat(session, entry.chatResource);
} else {
Comment thread
sandy081 marked this conversation as resolved.
await this._sessionsManagementService.openSession(entry.sessionResource);
}
Comment thread
sandy081 marked this conversation as resolved.
} else {
await this._sessionsManagementService.openSession(entry.sessionResource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,30 @@ suite('SessionsNavigation', () => {
store.setActiveSession(s1, chatUntitled);
assert.strictEqual(canGoBack(), false, 'untitled chat produces a session-only entry, no second entry');
});

test('goBack falls back to openSession when chat was deleted', async () => {
const chatA = stubChatWithId('a');
const chatB = stubChatWithId('b');
const chatsObs = observableValue<readonly IChat[]>('test.chats', [chatA, chatB]);
const s1: ISession = {
...stubSession('s1', SessionStatus.Completed, [chatA, chatB]),
chats: chatsObs,
};
const s2 = stubSession('s2');
store.addSession(s1);
store.addSession(s2);

// Record history: s1/chatA → s1/chatB → s2
store.setActiveSession(s1, chatA);
store.setActiveChat(chatB);
store.setActiveSession(s2);

// Remove chatB from the session
chatsObs.set([chatA], undefined);

// Go back — chatB is stale, should fall back to openSession(s1)
await nav.goBack();
assert.strictEqual(store.lastOpenedResource?.toString(), s1.resource.toString());
assert.strictEqual(store.lastOpenedChatResource, undefined, 'should not open a stale chat');
});
});
Loading