@@ -26,7 +26,7 @@ import { DeferredPromise, disposableTimeout, IntervalTimer, SequencerByKey, Thro
2626import { CancellationToken } from '../../../util/vs/base/common/cancellation' ;
2727import { isCancellationError } from '../../../util/vs/base/common/errors' ;
2828import { Emitter , Event } from '../../../util/vs/base/common/event' ;
29- import { Disposable , DisposableStore , IDisposable , IReference , toDisposable } from '../../../util/vs/base/common/lifecycle' ;
29+ import { Disposable , DisposableStore , IDisposable , IReference } from '../../../util/vs/base/common/lifecycle' ;
3030import { relative } from '../../../util/vs/base/common/path' ;
3131import { basename , dirname , extUri , isEqual } from '../../../util/vs/base/common/resources' ;
3232import { URI } from '../../../util/vs/base/common/uri' ;
@@ -156,6 +156,11 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
156156 // There's an issue in core (about holding onto ref of the Chat Model).
157157 // As a temporary solution, return the same untitled session id back to core until the session is completed.
158158 public readonly untitledSessionIdMapping = new Map < string , string > ( ) ;
159+ /**
160+ * Until the untitled session is properly swappped with the new session, we should keep track of this mapping.
161+ * When VS Code asks for the session, always return the old untitled session Uri.
162+ */
163+ public readonly sdkToUntitledUriMapping = new Map < string , Uri > ( ) ;
159164 private readonly _onDidChangeChatSessionItems = this . _register ( new Emitter < void > ( ) ) ;
160165 public readonly onDidChangeChatSessionItems : Event < void > = this . _onDidChangeChatSessionItems . event ;
161166
@@ -236,7 +241,7 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
236241 }
237242
238243 public async toChatSessionItem ( session : ICopilotCLISessionItem ) : Promise < vscode . ChatSessionItem > {
239- const resource = SessionIdForCLI . getResource ( this . untitledSessionIdMapping . get ( session . id ) ?? session . id ) ;
244+ const resource = this . sdkToUntitledUriMapping . get ( session . id ) ?? SessionIdForCLI . getResource ( this . untitledSessionIdMapping . get ( session . id ) ?? session . id ) ;
240245 const worktreeProperties = await this . worktreeManager . getWorktreeProperties ( session . id ) ;
241246 const workingDirectory = worktreeProperties ?. worktreePath ? vscode . Uri . file ( worktreeProperties . worktreePath )
242247 : session . workingDirectory ;
@@ -1359,9 +1364,6 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
13591364 sdkSessionId = session . object . sessionId ;
13601365 const modeInstructions = this . createModeInstructions ( request ) ;
13611366 this . chatSessionMetadataStore . updateRequestDetails ( sessionId , [ { vscodeRequestId : request . id , agentId : agent ?. name ?? '' , modeInstructions } ] ) . catch ( ex => this . logService . error ( ex , 'Failed to update request details' ) ) ;
1362- if ( isUntitled ) {
1363- disposables . add ( toDisposable ( ( ) => this . sessionItemProvider . untitledSessionIdMapping . delete ( session . object . sessionId ) ) ) ;
1364- }
13651367
13661368 // Lock the repo option with more accurate information.
13671369 // Previously we just updated it with details of the folder.
@@ -1421,7 +1423,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
14211423 _sessionBranch . delete ( id ) ;
14221424 _sessionIsolation . delete ( id ) ;
14231425 this . sessionItemProvider . untitledSessionIdMapping . delete ( id ) ;
1424- this . sessionItemProvider . untitledSessionIdMapping . delete ( session . object . sessionId ) ;
1426+ this . sessionItemProvider . sdkToUntitledUriMapping . delete ( session . object . sessionId ) ;
14251427 this . folderRepositoryManager . deleteNewSessionFolder ( id ) ;
14261428 this . sessionItemProvider . swap ( chatSessionContext . chatSessionItem , { resource : SessionIdForCLI . getResource ( session . object . sessionId ) , label : request . prompt } ) ;
14271429 }
@@ -1721,6 +1723,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
17211723 this . logService . info ( `Using Copilot CLI session: ${ session . object . sessionId } (isNewSession: ${ isNewSession } , isolationEnabled: ${ isIsolationEnabled ( workspaceInfo ) } , workingDirectory: ${ workingDirectory } , worktreePath: ${ worktreeProperties ?. worktreePath } )` ) ;
17221724 if ( isNewSession ) {
17231725 this . sessionItemProvider . untitledSessionIdMapping . set ( id , session . object . sessionId ) ;
1726+ this . sessionItemProvider . sdkToUntitledUriMapping . set ( session . object . sessionId , resource ) ;
17241727 if ( worktreeProperties ) {
17251728 void this . copilotCLIWorktreeManagerService . setWorktreeProperties ( session . object . sessionId , worktreeProperties ) ;
17261729 }
0 commit comments