3108
3109
private async _doResumeSession(sessionId: string): Promise<CopilotAgentSession> {
3110
>
this._logService.info(`[Copilot:${sessionId}] _resumeSession called — session not in memory, resuming...`);
copilotAgent.ts
3111
>
const client = await this._ensureClient();
3112
>
3113
>
const sessionUri = AgentSession.uri(this.id, sessionId);
3114
>
const storedMetadata = await this._readSessionMetadata(sessionUri);
3115
>
const sessionMetadata = await client.getSessionMetadata(sessionId).catch(err => {
3116
this._logService.warn(`[Copilot:${sessionId}] getSessionMetadata failed`, err);
3117
return undefined;
3119
>
const workingDirectory = storedMetadata.workingDirectory ?? (typeof sessionMetadata?.context?.workingDirectory === 'string' ? URI.file(sessionMetadata.context.workingDirectory) : undefined);
3120
>
if (!workingDirectory) {
3121
throw new Error(`workingDirectory is required to resume Copilot session '${sessionId}'`);
3122
}
3123
>
// A workspace-less chat's working directory is a stable per-session scratch dir
copilotAgent.ts
3124
>
// that may have been reaped (OS temp cleanup, reboot) while the session
3125
>
// persisted. Recreate it (mkdir -p) so shell/git/scratch ops don't fail.
3126
>
let resolvedWorkingDirectory = workingDirectory;
3127
>
if (storedMetadata.workspaceless) {
3128
await this._ensureWorkspacelessScratchDir(workingDirectory, sessionId);
3130
resolvedWorkingDirectory = await this._configurationService.resolveWorkingDirectoryForResume(sessionUri.toString(), workingDirectory);
3131
}
3132
>
// Anchor customization discovery to the working directory (the worktree for
copilotAgent.ts
3133
>
// worktree-isolated sessions), matching how the session was materialized.
3134
>
// Older sessions persisted `customizationDirectory` as the user-picked
3135
>
// folder; preferring the working directory corrects them on resume.
3136
>
const customizationDirectory = resolvedWorkingDirectory;
3137
>
// Always create an ActiveClient so the snapshot includes host +
3138
>
// session-discovered customizations, even when no client has
3139
>
// registered an active-client handle yet.
3140
>
const activeClient = this._getOrCreateActiveClient(sessionUri, customizationDirectory);
3141
>
activeClient.pluginController.reanchor(customizationDirectory);
3142
>
const snapshot = await activeClient.snapshot();
3143
>
3144
>
const shellManager = this._instantiationService.createInstance(ShellManager, sessionUri, resolvedWorkingDirectory);
3145
>
const resolvedAgentName = storedMetadata.agent ? this._resolveAgentName(snapshot, storedMetadata.agent) : undefined;
3146
>
if (storedMetadata.agent && !resolvedAgentName) {
3147
this._logService.info(`[Copilot:${sessionId}] Stored custom agent is not available in the current plugin snapshot; resuming without a custom agent`);
3148
}
3150
>
kind: 'resume',
3151
>
client,
3152
>
sessionId,
3153
>
workingDirectory: resolvedWorkingDirectory,
3154
>
resolvedAgentName,
3155
>
snapshot,
3156
>
activeClientToolSet: activeClient.toolSet,
3157
>
shellManager,
3158
>
githubToken: this._githubToken,
3159
>
workspaceless: storedMetadata.workspaceless,
3160
>
fallback: {
3161
>
model: storedMetadata.model,
3162
>
longContextWindow: this._longContextWindowFor(storedMetadata.model?.id),
3163
>
freeLongContext: this._isFreeLongContext(storedMetadata.model?.id),
3164
>
},
3165
>
};
3166
>
3167
>
const agentSession = this._createAgentSession(launchPlan, customizationDirectory, activeClient);
3168
>
try {
3169
>
await agentSession.initializeSession();
3170
this._registerInitializedSession(sessionId, agentSession);
3172
agentSession.dispose();
3173
throw err;