fix(coding-runtime): close Pi extension lifecycle races
This commit is contained in:
@@ -798,6 +798,13 @@ export class PiConversationRuntime implements CodingConversationRuntime {
|
||||
|
||||
async recover(conversationId: string): Promise<ConversationRuntimeState> {
|
||||
await this.waitForProjection(conversationId);
|
||||
const before = this.snapshot(conversationId);
|
||||
const generation = this.pool.getState(conversationId)?.generation;
|
||||
if (before.run.runId && generation) {
|
||||
await this.interactions.cancelRun(conversationId, before.run.runId, true);
|
||||
this.extensionUi.endRun(conversationId, before.run.runId);
|
||||
await this.extensionHost?.clearRun(conversationId, generation, before.run.runId);
|
||||
}
|
||||
const state = await this.pool.recover(conversationId);
|
||||
await this.requestHydration(conversationId, state, false);
|
||||
this.settleRecoveredRun(conversationId);
|
||||
@@ -1003,8 +1010,12 @@ export class PiConversationRuntime implements CodingConversationRuntime {
|
||||
this.replaceWorkerGeneration(event.conversationId, event.state, true);
|
||||
this.resetProjector(event.conversationId);
|
||||
const runId = this.states.get(event.conversationId)?.snapshot.run.runId;
|
||||
if (runId) this.extensionUi.replaceGeneration(event.conversationId, event.generation, runId);
|
||||
if (this.extensionHost && runId) {
|
||||
const activeRun = this.pool.getActiveRun(event.conversationId);
|
||||
const continuesActiveRun = Boolean(runId && activeRun?.runId === runId);
|
||||
if (runId && continuesActiveRun) {
|
||||
this.extensionUi.replaceGeneration(event.conversationId, event.generation, runId);
|
||||
}
|
||||
if (this.extensionHost && runId && continuesActiveRun) {
|
||||
void this.extensionHost.bindRun(event.conversationId, event.generation, runId).catch((error) => {
|
||||
this.recordProjectionFailure(event.conversationId, event.generation, error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user