fix(pi): prove packaged workers end to end
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -207,6 +207,7 @@ interface WorkerRecord {
|
||||
generationResources: Record<PiGenerationResourceKind, Map<string, () => void>>;
|
||||
rebuildFlight?: Promise<WorkerRecord>;
|
||||
acceptedPromptCount: number;
|
||||
coldStart: boolean;
|
||||
processLease: PiProcessLease | null;
|
||||
processStopFlight?: Promise<void>;
|
||||
reconfigureAfterSettled: boolean;
|
||||
@@ -281,7 +282,15 @@ export class PiWorkerPool {
|
||||
revision,
|
||||
})
|
||||
.then(async ({ opened: { worker, session }, lease }) => {
|
||||
const record = this.createRecord(conversation, worker, session, generation, revision, lease);
|
||||
const record = this.createRecord(
|
||||
conversation,
|
||||
worker,
|
||||
session,
|
||||
generation,
|
||||
revision,
|
||||
lease,
|
||||
true,
|
||||
);
|
||||
this.workers.set(conversation.conversationId, record);
|
||||
this.notifyReclaimableWorker();
|
||||
const state = this.publicState(record);
|
||||
@@ -336,6 +345,7 @@ export class PiWorkerPool {
|
||||
generation,
|
||||
revision,
|
||||
lease,
|
||||
true,
|
||||
);
|
||||
this.workers.set(conversation.conversationId, record);
|
||||
this.notifyReclaimableWorker();
|
||||
@@ -536,8 +546,8 @@ export class PiWorkerPool {
|
||||
this.launchTopLevel(record, pending);
|
||||
return { accepted };
|
||||
}
|
||||
this.waitingRuns.push(pending);
|
||||
pending.queuedAt = this.now();
|
||||
this.waitingRuns.push(pending);
|
||||
record.state = 'queued';
|
||||
this.notifyReclaimableWorker();
|
||||
return { queuePosition: this.waitingRuns.length, accepted };
|
||||
@@ -619,7 +629,7 @@ export class PiWorkerPool {
|
||||
this.activeRuns.set(run.conversationId, {
|
||||
runId: run.runId,
|
||||
generation: record.generation,
|
||||
cold: record.acceptedPromptCount === 0,
|
||||
cold: record.coldStart && record.acceptedPromptCount === 0,
|
||||
});
|
||||
void this.acceptTopLevel(record, run);
|
||||
}
|
||||
@@ -632,12 +642,16 @@ export class PiWorkerPool {
|
||||
const active = this.activeRuns.get(run.conversationId);
|
||||
if (!active) throw new Error('Top-level run was cancelled before acceptance');
|
||||
active.generation = current.generation;
|
||||
active.cold = current.coldStart && current.acceptedPromptCount === 0;
|
||||
current.state = 'running';
|
||||
this.revisions.beginRun(current.revisionWorkerId);
|
||||
beganRun = true;
|
||||
if (run.queuedAt !== undefined) {
|
||||
this.recordMilestone(current, run, 'worker.queue_wait', this.now() - run.queuedAt);
|
||||
}
|
||||
this.recordMilestone(
|
||||
current,
|
||||
run,
|
||||
'worker.queue_wait',
|
||||
run.queuedAt === undefined ? 0 : this.now() - run.queuedAt,
|
||||
);
|
||||
const acceptedAt = this.now();
|
||||
const response = await current.worker.request(run.command);
|
||||
if (run.command.type === 'prompt') {
|
||||
@@ -792,6 +806,7 @@ export class PiWorkerPool {
|
||||
generation,
|
||||
revision,
|
||||
lease,
|
||||
false,
|
||||
);
|
||||
replacement.state = record.state === 'spawning' && this.activeRuns.has(conversationId)
|
||||
? 'running'
|
||||
@@ -822,6 +837,7 @@ export class PiWorkerPool {
|
||||
generation: number,
|
||||
revision: PiManagedInputRevision,
|
||||
processLease: PiProcessLease,
|
||||
coldStart: boolean,
|
||||
): WorkerRecord {
|
||||
const revisionWorkerId = `${conversation.conversationId}:${generation}`;
|
||||
this.revisions.registerWorker(revisionWorkerId, revision);
|
||||
@@ -841,6 +857,7 @@ export class PiWorkerPool {
|
||||
child: new Map(),
|
||||
},
|
||||
acceptedPromptCount: 0,
|
||||
coldStart,
|
||||
processLease,
|
||||
reconfigureAfterSettled: false,
|
||||
};
|
||||
@@ -1058,7 +1075,7 @@ export class PiWorkerPool {
|
||||
run: Pick<PendingTopLevelRun, 'runId'>,
|
||||
milestone: 'worker.queue_wait' | 'prompt.accepted' | 'agent.settled',
|
||||
durationMs: number,
|
||||
cold = record.acceptedPromptCount === 0,
|
||||
cold = record.coldStart && record.acceptedPromptCount === 0,
|
||||
): void {
|
||||
if (!this.onTelemetry) return;
|
||||
this.onTelemetry(createPiRuntimeTelemetryEvent({
|
||||
|
||||
@@ -208,6 +208,16 @@ export class PiWorkerProcess {
|
||||
return this.generationValue;
|
||||
}
|
||||
|
||||
get processId(): number | undefined {
|
||||
return this.child?.pid;
|
||||
}
|
||||
|
||||
get isRunning(): boolean {
|
||||
return this.child !== null
|
||||
&& this.child.exitCode === null
|
||||
&& this.child.signalCode === null;
|
||||
}
|
||||
|
||||
get pendingCommandCount(): number {
|
||||
return this.rpc?.pendingCount ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user