Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,10 @@ export class SessionsManagementService extends Disposable implements ISessionsMa
}

private onDidReplaceSession(from: ISession, to: ISession): void {
// Rewrite the id in the visibility model so the same grid slot is
// reused for the replaced session.
const wasActive = this._visibility.activeSession.get()?.sessionId === from.sessionId;
this._visibility.replaceId(from.sessionId, to.sessionId);

if (wasActive) {
this.setActiveSession(to, /* force */ true);
} else {
this._visibility.refresh();
}
// Rewrite the visible wrapper so consumers of the active session observe
// the committed session object. This matters even when the provider keeps
// the same session id for the untitled -> committed transition.
this._visibility.updateSession(from, to);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandy081 @benibenj Not sure whether the changes are correct
Tagging you as this reverts the chagnes you have made
I"m not confident of this new change not breaking anything else,

@lszomoru tagging you as you might have a better fix/ideas

// Always fire the change event so the SessionsList refreshes even when
// the user navigated to a different session while the new one was
// being created (which is how duplicate rows appeared in the list).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,38 @@ suite('SessionsManagementService', () => {
await restorePromise;
assert.deepStrictEqual(agentSessionsService.observed.map(uri => uri.toString()), [targetSession.resource.toString()]);
});

test('same-id replacement updates the active session wrapper', async () => {
const replacementEmitter = disposables.add(new Emitter<{ readonly from: ISession; readonly to: ISession }>());
const fromSession = stubSession({ sessionId: 'same', providerId: 'test', title: constObservable('Untitled') });
const toSession = stubSession({ sessionId: 'same', providerId: 'test', title: constObservable('Committed') });
const provider = new class extends TestSessionsProvider {
override readonly onDidReplaceSession = replacementEmitter.event;
constructor() { super(fromSession); }
};

const instantiationService = disposables.add(new TestInstantiationService());
const chatWidgetService = new TestChatWidgetService();
const agentSessionsService = new TestAgentSessionsService();

instantiationService.stub(IStorageService, disposables.add(new InMemoryStorageService()));
instantiationService.stub(ILogService, new NullLogService());
instantiationService.stub(IContextKeyService, disposables.add(new MockContextKeyService()));
instantiationService.stub(ISessionsProvidersService, new TestSessionsProvidersService([provider]));
instantiationService.stub(IUriIdentityService, { extUri: extUriBiasedIgnorePathCase });
instantiationService.stub(IChatWidgetService, chatWidgetService);
instantiationService.stub(IAgentSessionsService, agentSessionsService);
instantiationService.stub(IProgressService, new TestProgressService());

const service = disposables.add(instantiationService.createInstance(SessionsManagementService));

await service.openSession(fromSession.resource);
assert.strictEqual(service.activeSession.get()?.title.get(), 'Untitled');

replacementEmitter.fire({ from: fromSession, to: toSession });

assert.strictEqual(service.activeSession.get()?.title.get(), 'Committed');
assert.strictEqual(service.visibleSessions.get()[0]?.title.get(), 'Committed');
});
});

Loading