fix: await queued Pi worker suspension

This commit is contained in:
2026-08-23 14:07:00 +08:00
parent 1727b75f30
commit 30c8bfd4d8
3 changed files with 68 additions and 19 deletions

View File

@@ -657,10 +657,18 @@ export class PiWorkerPool {
}
private async ensureFresh(record: WorkerRecord): Promise<WorkerRecord> {
const current = this.workers.get(record.conversation.conversationId);
const conversationId = record.conversation.conversationId;
let current = this.workers.get(conversationId);
if (!current) throw new Error('Conversation worker is no longer available');
if (current !== record) return await this.ensureFresh(current);
if (record.rebuildFlight) return await record.rebuildFlight;
if (record.processStopFlight) {
await record.processStopFlight;
current = this.workers.get(conversationId);
if (!current) throw new Error('Conversation worker is no longer available');
if (current !== record) return await this.ensureFresh(current);
if (record.rebuildFlight) return await record.rebuildFlight;
}
if (!record.processLease) {
record.rebuildFlight = this.beginRebuild(record, this.revisions.current);
return await record.rebuildFlight;