Skip to content
Open
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 @@ -243,6 +243,16 @@ export class ChatService extends Disposable implements IChatService {
const model = this._sessionModels.get(sessionResource);
if (model) {
model.setCustomTitle(title);
} else {
let modelRef: IChatModelReference | undefined;
try {
modelRef = await this.getOrRestoreSession(sessionResource);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH doing this seems a bit silly to me, just restore the chat model to update the title and dispose it, futher down then updating the store.
@roblourens when reviving a chat model, do we take the title from the store? If so maybe we just need to fire onDidChange event without the need of creating the modelRef

Copy link
Member

Choose a reason for hiding this comment

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

I think the title is already in the index to avoid having to do this. I think the problem is just that when loading a model, we should take the title from the index and let it overwrite the one in the stored model.

Copy link
Member

Choose a reason for hiding this comment

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

And I believe the block below this (// Update the title in the file storage) can be in the else from if (model)

modelRef?.object.setCustomTitle(title);
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The else branch properly handles the case where the model is not currently in memory by restoring it, setting the title, and disposing the reference. However, if getOrRestoreSession returns undefined (line 512 shows this can happen when sessionData is not found), the code silently continues without any logging or error indication. Consider adding a log statement to trace when the session cannot be restored, which would help with debugging issues related to setting titles on non-existent sessions.

Suggested change
modelRef?.object.setCustomTitle(title);
if (modelRef) {
modelRef.object.setCustomTitle(title);
} else {
this.trace('setChatSessionTitle', `Could not restore session ${sessionResource.toString()} to set title`);
}

Copilot uses AI. Check for mistakes.
} catch (e) {
this.error('setChatSessionTitle', `Failed to restore session ${sessionResource} to set title: ${toErrorMessage(e)}`);
} finally {
modelRef?.dispose();
}
}

// Update the title in the file storage
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/model/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ export interface IChatModel extends IDisposable {
readonly initialLocation: ChatAgentLocation;
readonly title: string;
readonly hasCustomTitle: boolean;
setCustomTitle(title: string): void;
/** True whenever a request is currently running */
readonly requestInProgress: IObservable<boolean>;
/** Provides session information when a request needs user interaction to continue */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class MockChatModel extends Disposable implements IChatModel {
super.dispose();
}

setCustomTitle(title: string): void {
this.customTitle = title;
}
startEditingSession(isGlobalEditingSession?: boolean, transferFromSession?: IChatEditingSession): void { }
getRequests(): IChatRequestModel[] { return []; }
setCheckpoint(requestId: string | undefined): void { }
Expand Down
Loading