Retain ChatModel ref when it has confirmations (#278903)

This commit is contained in:
Rob Lourens
2025-11-21 18:31:46 -08:00
committed by GitHub
parent 4867ea3bbe
commit 3873b96a9c

View File

@@ -1707,23 +1707,25 @@ export class ChatModel extends Disposable implements IChatModel {
return request?.response?.isInProgress.read(r) ?? false;
});
this.requestNeedsInput = lastRequest.map((request, r) => {
return !!request?.response?.isPendingConfirmation.read(r);
});
// Retain a reference to itself when a request is in progress, so the ChatModel stays alive in the background
// only while running a request. TODO also keep it alive for 5min or so so we don't have to dispose/restore too often?
if (this.initialLocation === ChatAgentLocation.Chat && configurationService.getValue<boolean>('chat.localBackgroundSessions')) {
const selfRef = this._register(new MutableDisposable<IChatModelReference>());
this._register(autorun(r => {
const inProgress = this.requestInProgress.read(r);
if (inProgress && !selfRef.value) {
const isWaitingForConfirmation = this.requestNeedsInput.read(r);
const shouldStayAlive = inProgress || isWaitingForConfirmation;
if (shouldStayAlive && !selfRef.value) {
selfRef.value = chatService.getActiveSessionReference(this._sessionResource);
} else if (!inProgress && selfRef.value) {
} else if (!shouldStayAlive && selfRef.value) {
selfRef.clear();
}
}));
}
this.requestNeedsInput = lastRequest.map((request, r) => {
return !!request?.response?.isPendingConfirmation.read(r);
});
}
startEditingSession(isGlobalEditingSession?: boolean, transferFromSession?: IChatEditingSession): void {