fix(pi): settle delayed compact ownership

This commit is contained in:
2026-08-26 09:41:25 +08:00
parent f5e6a04c7d
commit 9f05e2d7e1
12 changed files with 334 additions and 25 deletions

View File

@@ -1398,6 +1398,41 @@ export class PiConversationRuntime implements CodingConversationRuntime {
});
return;
}
if (event.type === 'top-level.settled') {
void this.enqueueProjection(event.conversationId, async () => {
const snapshot = this.states.get(event.conversationId)?.snapshot;
const current = snapshot?.run;
if (!snapshot
|| snapshot.cursor.workerGeneration !== event.generation
|| current?.runId !== event.runId
|| runIsTerminal(current.status)) return;
this.emit(event.conversationId, {
op: 'run.state',
run: {
status: 'idle',
runId: event.runId,
settledAt: this.now(),
terminalReason: 'completed',
},
}, event.runId);
this.extensionUi.endRun(event.conversationId, event.runId);
try {
await Promise.allSettled([
this.interactions.cancelRun(event.conversationId, event.runId, true),
this.extensionHost?.clearRun(
event.conversationId,
event.generation,
event.runId,
),
]);
} finally {
this.releaseRunBackgroundLease(event.conversationId, event.runId);
}
}).catch((error) => {
this.recordProjectionFailure(event.conversationId, event.generation, error);
});
return;
}
if (event.type === 'top-level.failed') {
void this.enqueueProjection(event.conversationId, async () => {
await this.failRun(
@@ -1525,8 +1560,11 @@ export class PiConversationRuntime implements CodingConversationRuntime {
const current = this.states.get(conversationId)?.snapshot?.run;
const snapshotGeneration = this.states.get(conversationId)?.snapshot?.cursor.workerGeneration;
if (current?.runId !== runId
|| runIsTerminal(current.status)
|| (generation !== undefined && snapshotGeneration !== generation)) return;
if (runIsTerminal(current.status)) {
if (releaseBackgroundLease) this.releaseRunBackgroundLease(conversationId, runId);
return;
}
const publicError = runtimeFailure(error);
this.emit(conversationId, {
op: 'run.state',