fix(pi): keep active runs alive during background sleep
This commit is contained in:
@@ -635,21 +635,27 @@ export class PiWorkerPool {
|
||||
return this.publicState(await record.rebuildFlight);
|
||||
}
|
||||
|
||||
async dispose(conversationId: string): Promise<void> {
|
||||
async dispose(
|
||||
conversationId: string,
|
||||
reason: PiWorkerStopReason,
|
||||
canStop: () => boolean = () => true,
|
||||
): Promise<boolean> {
|
||||
const pendingPrepare = this.prepareFlights.get(conversationId);
|
||||
if (pendingPrepare) await pendingPrepare.catch(() => undefined);
|
||||
let record = this.workers.get(conversationId);
|
||||
if (!record) return;
|
||||
if (!record) return false;
|
||||
if (record.rebuildFlight) {
|
||||
record = await record.rebuildFlight.catch(() => record as WorkerRecord);
|
||||
}
|
||||
if (!canStop()) return false;
|
||||
this.cancelConversationRuns(conversationId, new Error('Conversation worker was disposed'));
|
||||
record.unsubscribeEvent();
|
||||
record.unsubscribeInvalidation();
|
||||
this.cancelGenerationResources(record);
|
||||
this.revisions.removeWorker(record.revisionWorkerId);
|
||||
if (this.workers.get(conversationId) === record) this.workers.delete(conversationId);
|
||||
await this.ensureStoppedAndReleased(record, 'dispose');
|
||||
await this.ensureStoppedAndReleased(record, reason);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async performShutdown(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user