fix(pi): converge worker failures and thinking state
This commit is contained in:
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
|
||||
|
||||
import type { PublicUsage, SubagentDetailsV1 } from '../contracts';
|
||||
import { PiProcessBudget, type PiProcessLease } from './worker-pool';
|
||||
import type { PiWorkerStopReason } from './worker-process';
|
||||
|
||||
export type PiSubagentMode = SubagentDetailsV1['mode'];
|
||||
export type PiSubagentToolProfile = SubagentDetailsV1['tasks'][number]['toolProfile'];
|
||||
@@ -43,7 +44,7 @@ export interface PiSubagentChild {
|
||||
signal: AbortSignal,
|
||||
onProgress?: (summary: string) => void,
|
||||
): Promise<PiSubagentChildResult>;
|
||||
stop(): Promise<void>;
|
||||
stop(reason: PiWorkerStopReason): Promise<void>;
|
||||
}
|
||||
|
||||
export interface PiSubagentDispatchResult {
|
||||
@@ -368,6 +369,7 @@ export class PiSubagentScheduler {
|
||||
let releaseChild: (() => void) | undefined;
|
||||
let processLease: PiProcessLease | undefined;
|
||||
let child: PiSubagentChild | undefined;
|
||||
let stopReason: PiWorkerStopReason = 'subagent_complete';
|
||||
try {
|
||||
releaseChild = await this.childPermits.acquire(record.controller.signal);
|
||||
processLease = await this.acquireProcessLease(record.controller.signal);
|
||||
@@ -394,12 +396,13 @@ export class PiSubagentScheduler {
|
||||
} catch (error) {
|
||||
const aborted = record.controller.signal.aborted
|
||||
|| (error instanceof PiSubagentChildError && error.code === 'SUBAGENT_ABORTED');
|
||||
if (aborted) stopReason = 'subagent_abort';
|
||||
projected.status = aborted ? 'aborted' : 'error';
|
||||
projected.errorCode = publicErrorCode(error, aborted);
|
||||
} finally {
|
||||
if (child) {
|
||||
record.children.delete(child);
|
||||
await child.stop().catch(() => undefined);
|
||||
await child.stop(stopReason).catch(() => undefined);
|
||||
}
|
||||
processLease?.release();
|
||||
releaseChild?.();
|
||||
|
||||
Reference in New Issue
Block a user