Add trace logs around chat session opening#313853
Merged
Conversation
Adds tracing logs around openChat/openSession in SessionsManagementService, ChatWidgetService.openSession, ChatViewPane.loadSession, and MainThreadChatSessions._provideChatSessionContent to help diagnose chat session opening performance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Screenshot ChangesBase: Changed (1)blocks-ci screenshots changedReplace the contents of Updated blocks-ci-screenshots.md<!-- auto-generated by CI — do not edit manually -->
#### editor/codeEditor/CodeEditor/Dark

#### editor/codeEditor/CodeEditor/Light

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Dark

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Light

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Dark

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Light
 |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds trace-level timing logs to the chat session open pipeline to help diagnose slow session opening across the sessions UI, chat widget/view, and main thread session content provider.
Changes:
- Instrumented session open entry points in
SessionsManagementService(openChat,openSession) withstart/done total=...mstrace logs. - Added tracing to
ChatWidgetService.openSessionto distinguish reveal/view/editor paths and report end-to-end timing. - Added tracing around
ChatViewPane.loadSessionandMainThreadChatSessions._provideChatSessionContentto correlate timings across layers.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts | Adds trace timing logs to loadSession including cancellation/error phases. |
| src/vs/workbench/contrib/chat/browser/widget/chatWidgetService.ts | Adds trace timing logs to openSession and injects ILogService. |
| src/vs/workbench/api/browser/mainThreadChatSessions.ts | Adds trace timing logs to _provideChatSessionContent. |
| src/vs/sessions/services/sessions/browser/sessionsManagementService.ts | Switches to trace-level timing logs for openChat/openSession and tweaks warn message format. |
Copilot's findings
Comments suppressed due to low confidence (4)
src/vs/workbench/api/browser/mainThreadChatSessions.ts:943
_provideChatSessionContentlogsstartand logsdoneonly on the success path. Ifsession.initialize(...)throws (including cancellation), you end up with astartlog without adone, which makes timing correlation incomplete. Consider moving the finaldone total=...msinto afinallyblock and adding anerror=true/cancelled=truemarker when appropriate.
This issue also appears on line 898 of the same file.
private async _provideChatSessionContent(providerHandle: number, sessionResource: URI, token: CancellationToken): Promise<IChatSession> {
const t0 = Date.now();
this._logService.trace(`[MainThreadChatSessions] _provideChatSessionContent start handle=${providerHandle} uri=${sessionResource.toString()}`);
warnOnUntitledSessionResource(sessionResource, this._logService);
let session = this._activeSessions.get(sessionResource);
if (!session) {
session = new ObservableChatSession(
sessionResource,
providerHandle,
this._proxy,
this._logService,
this._dialogService
);
this._activeSessions.set(sessionResource, session);
const disposable = session.onWillDispose(() => {
this._activeSessions.delete(sessionResource);
this._sessionDisposables.get(sessionResource)?.dispose();
this._sessionDisposables.delete(sessionResource);
});
this._sessionDisposables.set(sessionResource, disposable);
}
try {
const initialSessionOptions = this._chatSessionsService.getSessionOptions(sessionResource);
await session.initialize(token, {
initialSessionOptions: initialSessionOptions ? [...initialSessionOptions].map(([optionId, value]) => ({ optionId, value: typeof value === 'string' ? value : value?.id })) : undefined,
});
if (session.options) {
for (const [_, handle] of this._sessionTypeToHandle) {
if (handle === providerHandle) {
for (const [optionId, value] of session.options) {
this._chatSessionsService.setSessionOption(sessionResource, optionId, value);
}
break;
}
}
}
this._logService.trace(`[MainThreadChatSessions] _provideChatSessionContent done total=${Date.now() - t0}ms handle=${providerHandle}`);
return session;
} catch (error) {
session.dispose();
this._logService.error(`Error providing chat session content for handle ${providerHandle} and resource ${sessionResource.toString()}:`, error);
throw error;
}
src/vs/workbench/api/browser/mainThreadChatSessions.ts:901
- These
tracelogs eagerly callsessionResource.toString()and build template strings even when Trace logging is disabled. Since this method can be called frequently, please guard the trace log construction withcanLog(this._logService.getLevel(), LogLevel.Trace)(or similar) so URI stringification and string building only occurs at Trace level.
private async _provideChatSessionContent(providerHandle: number, sessionResource: URI, token: CancellationToken): Promise<IChatSession> {
const t0 = Date.now();
this._logService.trace(`[MainThreadChatSessions] _provideChatSessionContent start handle=${providerHandle} uri=${sessionResource.toString()}`);
warnOnUntitledSessionResource(sessionResource, this._logService);
src/vs/workbench/contrib/chat/browser/widget/chatWidgetService.ts:112
- These
tracelogs build template strings and callsessionResource.toString()/Date.now()unconditionally, even when the log level is above Trace. Since this is on the session-opening hot path, please guard the log construction withcanLog(logService.getLevel(), LogLevel.Trace)(or agetLevel() === LogLevel.Tracecheck) so the additional overhead is avoided unless Trace logging is enabled.
const t0 = Date.now();
const targetKind = target === ChatViewPaneTarget ? 'view' : (typeof target === 'undefined' ? 'undefined' : 'editor');
this.logService.trace(`[ChatWidgetService] openSession start uri=${sessionResource.toString()} target=${targetKind}`);
src/vs/sessions/services/sessions/browser/sessionsManagementService.ts:250
- The new
openSessiontracing only logsdoneafterchatWidgetService.openSession(...)resolves. If that call throws, thestartlog will have no matchingdone. For consistent timing correlation, consider emitting thedone total=...msfrom afinallyblock with anerror=true/cancelled=trueattribute as appropriate.
async openSession(sessionResource: URI, options?: { preserveFocus?: boolean }): Promise<void> {
const t0 = Date.now();
const sessionData = this.getSession(sessionResource);
if (!sessionData) {
this.logService.warn(`[SessionsManagement] openSession: session not found uri=${sessionResource.toString()}`);
throw new Error(`Session with resource ${sessionResource.toString()} not found`);
}
this.logService.trace(`[SessionsManagement] openSession start uri=${sessionResource.toString()} provider=${sessionData.providerId}`);
this.isNewChatSessionContext.set(false);
this._isNewChatInSessionContext.set(false);
this.setActiveSession(sessionData);
// Open the active chat (which may have been restored to the last active chat)
const activeChat = this._activeSession.get()?.activeChat.get();
const openUri = activeChat?.resource ?? sessionData.resource;
await this.chatWidgetService.openSession(openUri, ChatViewPaneTarget, { preserveFocus: options?.preserveFocus });
this.logService.trace(`[SessionsManagement] openSession done total=${Date.now() - t0}ms`);
}
- Files reviewed: 4/4 changed files
- Comments generated: 4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…3556219+Copilot@users.noreply.github.com>
Keep simple success-path logging only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bhavyaus
approved these changes
May 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tracing logs to help diagnose chat session opening performance.
Instrumented call path:
SessionsManagementService.openChat/openSessionChatWidgetService.openSessionChatViewPane.loadSessionMainThreadChatSessions._provideChatSessionContentEach entry logs a
startanddone total=Xmsattracelevel so timings can be correlated end-to-end when investigating slow open scenarios.