fix(pi): strengthen final release proof
This commit is contained in:
@@ -230,7 +230,12 @@ export class PiWorkerPool {
|
||||
private readonly prepareFlights = new Map<string, Promise<PiWorkerPoolState>>();
|
||||
private readonly rebuildFlights = new Set<Promise<WorkerRecord>>();
|
||||
private readonly waitingRuns: PendingTopLevelRun[] = [];
|
||||
private readonly activeRuns = new Map<string, { runId: string; generation: number }>();
|
||||
private readonly activeRuns = new Map<string, {
|
||||
runId: string;
|
||||
generation: number;
|
||||
cold: boolean;
|
||||
acceptedAt?: number;
|
||||
}>();
|
||||
private readonly generations = new Map<string, number>();
|
||||
private readonly listeners = new Set<(event: PiWorkerPoolEvent) => void>();
|
||||
private readonly reclaimWaiters = new Set<() => void>();
|
||||
@@ -614,6 +619,7 @@ export class PiWorkerPool {
|
||||
this.activeRuns.set(run.conversationId, {
|
||||
runId: run.runId,
|
||||
generation: record.generation,
|
||||
cold: record.acceptedPromptCount === 0,
|
||||
});
|
||||
void this.acceptTopLevel(record, run);
|
||||
}
|
||||
@@ -635,7 +641,15 @@ export class PiWorkerPool {
|
||||
const acceptedAt = this.now();
|
||||
const response = await current.worker.request(run.command);
|
||||
if (run.command.type === 'prompt') {
|
||||
this.recordMilestone(current, run, 'prompt.accepted', this.now() - acceptedAt);
|
||||
const acceptedFinishedAt = this.now();
|
||||
active.acceptedAt = acceptedFinishedAt;
|
||||
this.recordMilestone(
|
||||
current,
|
||||
run,
|
||||
'prompt.accepted',
|
||||
acceptedFinishedAt - acceptedAt,
|
||||
active.cold,
|
||||
);
|
||||
current.acceptedPromptCount += 1;
|
||||
}
|
||||
run.resolve(response);
|
||||
@@ -661,6 +675,15 @@ export class PiWorkerPool {
|
||||
const conversationId = record.conversation.conversationId;
|
||||
const active = this.activeRuns.get(conversationId);
|
||||
if (!active || active.generation !== record.generation) return;
|
||||
if (active.acceptedAt !== undefined) {
|
||||
this.recordMilestone(
|
||||
record,
|
||||
{ runId: active.runId },
|
||||
'agent.settled',
|
||||
this.now() - active.acceptedAt,
|
||||
active.cold,
|
||||
);
|
||||
}
|
||||
this.activeRuns.delete(conversationId);
|
||||
this.runningCount -= 1;
|
||||
record.state = 'idle';
|
||||
@@ -1032,9 +1055,10 @@ export class PiWorkerPool {
|
||||
|
||||
private recordMilestone(
|
||||
record: WorkerRecord,
|
||||
run: PendingTopLevelRun,
|
||||
milestone: 'worker.queue_wait' | 'prompt.accepted',
|
||||
run: Pick<PendingTopLevelRun, 'runId'>,
|
||||
milestone: 'worker.queue_wait' | 'prompt.accepted' | 'agent.settled',
|
||||
durationMs: number,
|
||||
cold = record.acceptedPromptCount === 0,
|
||||
): void {
|
||||
if (!this.onTelemetry) return;
|
||||
this.onTelemetry(createPiRuntimeTelemetryEvent({
|
||||
@@ -1042,7 +1066,7 @@ export class PiWorkerPool {
|
||||
conversationId: record.conversation.conversationId,
|
||||
workerGeneration: record.generation,
|
||||
runId: run.runId,
|
||||
cold: record.acceptedPromptCount === 0,
|
||||
cold,
|
||||
durationMs,
|
||||
at: this.now(),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user