fix(pi): converge worker failures and thinking state

This commit is contained in:
2026-08-25 11:45:14 +08:00
parent 274187e3cf
commit 61817b161f
28 changed files with 2019 additions and 118 deletions

View File

@@ -26,7 +26,12 @@ import type {
PiSubagentChildResult,
} from './subagent';
import { PiSubagentChildError } from './subagent';
import { PiWorkerProcess, type PiWorkerProcessOptions, type PiWorkerStopResult } from './worker-process';
import {
PiWorkerProcess,
type PiWorkerProcessOptions,
type PiWorkerStopReason,
type PiWorkerStopResult,
} from './worker-process';
import type { PiProcessError } from './process-errors';
import type { PiManagedExtensionHost } from './extension-host';
@@ -41,7 +46,7 @@ export interface PiSubagentProcessAdapter {
): Promise<PiRpcResponse<T>>;
subscribe(listener: (event: PiRpcEvent) => void): () => void;
subscribeInvalidation(listener: (error: PiProcessError) => void): () => void;
stop(): Promise<PiWorkerStopResult>;
stop(reason: PiWorkerStopReason): Promise<PiWorkerStopResult>;
}
export interface PiManagedSubagentChildOpenerOptions {
@@ -134,11 +139,11 @@ class ManagedPiSubagentChild implements PiSubagentChild {
}
}
async stop(): Promise<void> {
async stop(reason: PiWorkerStopReason): Promise<void> {
if (this.stopped) return;
this.stopped = true;
try {
await this.process.stop();
await this.process.stop(reason);
} finally {
await this.disposeExtension();
}
@@ -214,6 +219,8 @@ export function createPiManagedSubagentChildOpener(
],
env: { ...credential.env, ...extension.env },
sensitiveValues: [...credential.sensitiveValues, ...extension.sensitiveValues],
conversationId: input.conversationId,
workerGeneration: input.workerGeneration,
});
try {
await process.start();
@@ -221,7 +228,7 @@ export function createPiManagedSubagentChildOpener(
if (!ready.success) throw new PiSubagentChildError('SUBAGENT_CHILD_START_FAILED');
return new ManagedPiSubagentChild(input.taskId, process, extension.dispose);
} catch (error) {
await process.stop().catch(() => undefined);
await process.stop('subagent_open_failure').catch(() => undefined);
await extension.dispose();
throw error;
}