π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(heterogeneous-agents): classify host-cancelled ACP exits as interrupted (#20482)
AmAzing-e35e12bdf969
diff --git a/apps/cli/src/commands/hetero.test.ts b/apps/cli/src/commands/hetero.test.tsindex 874c1e72307..97f71419290 100644--- a/apps/cli/src/commands/hetero.test.ts+++ b/apps/cli/src/commands/hetero.test.ts@@ -104,6 +104,11 @@ describe('hetero exec command', () => {let stdoutSpy: ReturnType<typeof vi.spyOn>;beforeEach(() => {+ // The suite may run inside a dispatched `lh hetero exec` (e.g. on a+ // connected device), which sets this env for real β clear it so tests+ // decide the process-group mode explicitly instead of inheriting the+ // ambient wrapper's.+ vi.stubEnv(HETERO_EXEC_INHERIT_PROCESS_GROUP_ENV, '');// Stub `process.exit` so the test runner doesn't tear down β but THROW a// sentinel rather than return, mirroring `process.exit`'s `never` return// type in production. Without throwing, the command's code after an@@ -373,6 +378,55 @@ describe('hetero exec command', () => {await command;});+ // The same inherited-group SIGINT that kills `devin acp` must also notify the+ // session transport: without `interrupt` the ACP session classifies the+ // signal death as a transport crash and emits a terminal error card.+ it('notifies session transports through interrupt() inside an inherited wrapper group', async () => {+ vi.stubEnv(HETERO_EXEC_INHERIT_PROCESS_GROUP_ENV, '1');+ let sigintHandler: (() => void) | undefined;+ vi.spyOn(process, 'on').mockImplementation(((event: string, listener: () => void) => {+ if (event === 'SIGINT') sigintHandler = listener;+ return process;+ }) as typeof process.on);++ let resolveExit:+ ((result: { code: number | null; signal: NodeJS.Signals | null }) => void) | undefined;+ const stderr = new PassThrough();+ setImmediate(() => stderr.end());+ const interrupt = vi.fn();+ const kill = vi.fn();+ mockSpawnAgent.mockResolvedValue({+ events: {+ [Symbol.asyncIterator]: () => ({+ next: async () => ({ done: true, value: undefined }),+ }),+ },+ exit: new Promise((resolve) => {+ resolveExit = resolve;+ }),+ interrupt,+ kill,+ pid: 12_345,+ stderr,+ });++ const command = runCmd(['hetero', 'exec', '--type', 'devin', '--prompt', 'hi']);+ await vi.waitFor(() => {+ expect(sigintHandler).toBeDefined();+ });++ sigintHandler?.();+ // The signal may land before the async spawn binds `handle`; either way the+ // remembered cancellation is replayed through `interrupt` once it binds.+ await vi.waitFor(() => {+ expect(interrupt).toHaveBeenCalledWith('SIGINT');+ });+ expect(kill).not.toHaveBeenCalled();++ resolveExit?.({ code: null, signal: 'SIGINT' });+ await command;+ });+it('binds cancellation while the async Pi factory is still awaiting startup and escalates a second SIGINT', async () => {const signalHandlers = new Map<string, () => void>();vi.spyOn(process, 'on').mockImplementation(((event: string, listener: () => void) => {@@ -1126,8 +1180,11 @@ describe('hetero exec command', () => {for (let i = 0; i < 20 && !sigintHandler; i += 1) await Promise.resolve();sigintHandler?.();- await Promise.resolve();- expect(kill).toHaveBeenCalledWith('SIGINT');+ // The signal can land before the async spawn binds `handle`; the remembered+ // cancellation is then replayed through `handle.kill` once it binds.+ await vi.waitFor(() => {+ expect(kill).toHaveBeenCalledWith('SIGINT');+ });expect(mockHeteroFinishMutate).not.toHaveBeenCalled();resolveFirstEvent?.({diff --git a/apps/cli/src/commands/hetero.ts b/apps/cli/src/commands/hetero.tsindex 31082766db4..189faa99239 100644--- a/apps/cli/src/commands/hetero.ts+++ b/apps/cli/src/commands/hetero.ts@@ -825,7 +825,16 @@ const exec = async (options: ExecOptions): Promise<void> => {};const applyCancellation = (signal: NodeJS.Signals) => {cancellationSignal = signal;- if (!ownsSignalDelivery()) return;+ if (!ownsSignalDelivery()) {+ // The process group already delivered the OS signal, so a second one+ // would be a duplicate β but session transports (ACP, RPC) carry a+ // protocol-level cancel the signal cannot express. Notify it so the+ // session classifies the agent's resulting exit as host-driven+ // cancellation rather than reporting a transport crash.+ if (startupControl) cancelStartup(startupControl, signal);+ else handle?.interrupt?.(signal);+ return;+ }signalAgent(signal);};const onSigint = () => {@@ -863,12 +872,17 @@ const exec = async (options: ExecOptions): Promise<void> => {try {handle = await spawnAgentOrRuntime(spawnOpts, dumpAttempt?.writeStdout, (control) => {startupControl = control;- if (cancellationSignal && ownsSignalDelivery()) {- cancelStartup(control, cancellationSignal);- }+ // `control.cancel` is protocol-level (session abort), not an OS signal+ // β replay any cancellation received before the control bound, even+ // when the process group already delivered the signal itself.+ if (cancellationSignal) cancelStartup(control, cancellationSignal);});- if (cancellationSignal && !startupControl && ownsSignalDelivery()) {- handle.kill(cancellationSignal);+ if (cancellationSignal && !startupControl) {+ // Same split as `applyCancellation`: when the wrapper does not own+ // signal delivery the process group already signaled the agent, but+ // session transports still need the protocol-level cancel.+ if (ownsSignalDelivery()) handle.kill(cancellationSignal);+ else handle.interrupt?.(cancellationSignal);}} catch (err) {try {diff --git a/packages/heterogeneous-agents/src/rpc/piRpcAgentHandle.ts b/packages/heterogeneous-agents/src/rpc/piRpcAgentHandle.tsindex 8fe4fb8a10e..7762473c835 100644--- a/packages/heterogeneous-agents/src/rpc/piRpcAgentHandle.ts+++ b/packages/heterogeneous-agents/src/rpc/piRpcAgentHandle.ts@@ -38,6 +38,8 @@ export interface PiRpcStartupControl {export interface PiRpcAgentHandle {events: AsyncIterable<AgentStreamEvent>;exit: Promise<{ code: number | null; signal: NodeJS.Signals | null }>;+ /** Protocol-level cancel (RPC abort/close) β safe alongside an OS signal the process group already delivered. */+ interrupt: (signal?: NodeJS.Signals) => void;kill: (signal?: NodeJS.Signals) => void;pid: number | undefined;readonly sessionId: string | undefined;@@ -187,14 +189,17 @@ export const createPiRpcAgentHandle = async (: { code: 1, signal: null as NodeJS.Signals | null };});+ const signalSession = (signal?: NodeJS.Signals) => {+ void cancel(signal ?? 'SIGINT').catch(() => {+ /* legacy synchronous handle contract is best-effort */+ });+ };+return {events: queue,exit,- kill: (signal) => {- void cancel(signal ?? 'SIGINT').catch(() => {- /* legacy synchronous handle contract is best-effort */- });- },+ interrupt: signalSession,+ kill: signalSession,pid: session.pid,get sessionId() {return nativeSessionId;diff --git a/packages/heterogeneous-agents/src/spawn/acpAgentSession.ts b/packages/heterogeneous-agents/src/spawn/acpAgentSession.tsindex 05b4593d695..56cc1b2ab57 100644--- a/packages/heterogeneous-agents/src/spawn/acpAgentSession.ts+++ b/packages/heterogeneous-agents/src/spawn/acpAgentSession.ts@@ -99,6 +99,7 @@ export abstract class AcpAgentSession<private readonly cancelGraceMs: number;private readonly transport: HeterogeneousAgentRuntimeStatus['transport'];+ private cancelRequested = false;private cancelTimer?: ReturnType<typeof setTimeout>;private hostClosed = false;private lastStatus?: HeterogeneousAgentRuntimeStatus['state'];@@ -158,6 +159,15 @@ export abstract class AcpAgentSession<this.emitStatus('idle');} catch (cause) {if (this.hostClosed) return;+ if (this.cancelRequested) {+ // A host-driven cancel can kill the transport before session/cancel+ // settles the prompt (e.g. a process-group signal racing the RPC).+ // That death is the cancellation itself, not a crash β report the+ // interrupted terminal, never a transport error.+ await this.onRunCancelled?.();+ await this.emitEvents(await this.pipeline.flush());+ return;+ }const error = cause instanceof Error ? cause : new Error(String(cause));await this.onRunFailure?.(error);this.emitStatus('error');@@ -175,6 +185,7 @@ export abstract class AcpAgentSession<* `cancelled` stop reason. Force-closes after the grace period.*/interrupt(): void {+ this.cancelRequested = true;const sessionId = this.acpSessionId;if (!sessionId) {this.close();@@ -185,9 +196,10 @@ export abstract class AcpAgentSession<this.cancelTimer.unref?.();}- /** Host-forced shutdown: suppresses further events and kills the child. */- close(signal: NodeJS.Signals = 'SIGTERM'): void {+ /** Host-forced shutdown. Pass null if the host already signalled the child. */+ close(signal: NodeJS.Signals | null = 'SIGTERM'): void {if (this.hostClosed) return;+ this.cancelRequested = true;this.hostClosed = true;this.onHostClose?.();this.client.close(signal);@@ -278,6 +290,13 @@ export abstract class AcpAgentSession</** Emit synthetic terminal events for a failed run before the error is rethrown. */protected onRunFailure?(error: Error): Promise<void>;+ /**+ * Emit the cancelled-turn terminal when a host interrupt killed the transport+ * mid-prompt β the same shape the settled `stopReason: 'cancelled'` path+ * produces, so downstream consumers cannot tell the two apart.+ */+ protected onRunCancelled?(): Promise<void>;+/** Extra cleanup when the host force-closes the session. */protected onHostClose?(): void;}diff --git a/packages/heterogeneous-agents/src/spawn/acpStdioClient.ts b/packages/heterogeneous-agents/src/spawn/acpStdioClient.tsindex 80d8f07688d..b5c34a1a344 100644--- a/packages/heterogeneous-agents/src/spawn/acpStdioClient.ts+++ b/packages/heterogeneous-agents/src/spawn/acpStdioClient.ts@@ -177,12 +177,13 @@ export class AcpStdioClient {if (this.fatalError) throw this.fatalError;}- close(signal: NodeJS.Signals = 'SIGTERM'): void {+ /** Pass null when the host already delivered the terminating OS signal. */+ close(signal: NodeJS.Signals | null = 'SIGTERM'): void {if (this.closed) return;this.closed = true;this.stdoutBuffer = '';this.rejectPendingRequests(new Error('ACP stdio client closed by host'));- this.shutdownProcess(signal);+ if (signal !== null) this.shutdownProcess(signal);}private consumeStdout(chunk: Buffer): void {diff --git a/packages/heterogeneous-agents/src/spawn/cursorAcpSession.ts b/packages/heterogeneous-agents/src/spawn/cursorAcpSession.tsindex 421fcd46341..bf3de22d357 100644--- a/packages/heterogeneous-agents/src/spawn/cursorAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/cursorAcpSession.ts@@ -212,6 +212,10 @@ export class CursorAcpSession extends AcpAgentSession<await this.emitEvents(await this.pipeline.flush());}+ protected async onRunCancelled(): Promise<void> {+ await this.pushToPipeline({ stopReason: 'cancelled', type: 'cursor_prompt_completed' });+ }+protected async handleAgentMessage(message: AcpRpcMessage): Promise<void> {if (!this.acceptUpdates || message.method !== 'session/update') return;const params = isRecord(message.params) ? message.params : undefined;diff --git a/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts b/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.tsindex 6ed3ae19b45..912fbcac018 100644--- a/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts+++ b/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts@@ -37,6 +37,7 @@ const createAcpProcess = ({initializeResult,loadError,permissionRequest = false,+ promptAutoComplete = true,}: {configOptions?: Record<string, unknown>[];configOptionsByModel?: Record<string, Record<string, unknown>[]>;@@ -44,6 +45,7 @@ const createAcpProcess = ({initializeResult?: Record<string, unknown>;loadError?: { code: number; data?: unknown; message: string };permissionRequest?: boolean;+ promptAutoComplete?: boolean;} = {}) => {const child = new EventEmitter() as ChildProcess;const stdout = new PassThrough();@@ -217,7 +219,7 @@ const createAcpProcess = ({},},});- } else {+ } else if (promptAutoComplete) {send({ id: message.id, result: { stopReason: 'end_turn' } });}return;@@ -748,4 +750,30 @@ describe('DevinAcpSession', () => {expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(false);});++ it('reports a host-interrupted run as interrupted, not a transport error', async () => {+ const fake = createAcpProcess({ promptAutoComplete: false });+ spawnMock.mockReturnValue(fake.child);+ vi.spyOn(process, 'kill').mockImplementation(() => true);+ const events: AgentStreamEvent[] = [];+ const options = createSessionOptions({ onEvents: (batch) => events.push(...batch) });+ const session = new DevinAcpSession(options);+ const run = session.run();+ await vi.waitFor(() => {+ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(true);+ });++ session.interrupt();+ fake.child.emit('close', null, 'SIGINT');+ await run;++ expect(fake.requests.some(({ method }) => method === 'session/cancel')).toBe(true);+ expect(events.some(({ type }) => type === 'error')).toBe(false);+ expect(events).toContainEqual(+ expect.objectContaining({+ data: expect.objectContaining({ reason: 'interrupted', stopReason: 'cancelled' }),+ type: 'agent_runtime_end',+ }),+ );+ });});diff --git a/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts b/packages/heterogeneous-agents/src/spawn/devinAcpSession.tsindex c01865c75b1..a93b50926f1 100644--- a/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts@@ -237,6 +237,11 @@ export class DevinAcpSession extends AcpAgentSession<await this.emitEvents(await this.pipeline.flush());}+ protected async onRunCancelled(): Promise<void> {+ this.options.askUserBridge?.cancelAll('session_ended');+ await this.pushToPipeline({ stopReason: 'cancelled', type: 'devin_prompt_completed' });+ }+protected async handleAgentMessage(message: AcpRpcMessage): Promise<void> {if (!this.acceptUpdates || message.method !== 'session/update') return;const params = isRecord(message.params) ? message.params : undefined;diff --git a/packages/heterogeneous-agents/src/spawn/droidAcpSession.ts b/packages/heterogeneous-agents/src/spawn/droidAcpSession.tsindex a4a3d1b210f..4f723c72992 100644--- a/packages/heterogeneous-agents/src/spawn/droidAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/droidAcpSession.ts@@ -349,6 +349,11 @@ export class DroidAcpSession extends AcpAgentSession<await this.emitEvents(await this.pipeline.flush());}+ protected async onRunCancelled(): Promise<void> {+ this.options.askUserBridge?.cancelAll('session_ended');+ await this.pushToPipeline({ stopReason: 'cancelled', type: 'droid_prompt_completed' });+ }+protected onHostClose(): void {this.options.askUserBridge?.cancelAll('session_ended');this.modelDiscovery?.close();diff --git a/packages/heterogeneous-agents/src/spawn/grokAcpSession.ts b/packages/heterogeneous-agents/src/spawn/grokAcpSession.tsindex b80884cb129..a878036894f 100644--- a/packages/heterogeneous-agents/src/spawn/grokAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/grokAcpSession.ts@@ -190,6 +190,12 @@ export class GrokAcpSession extends AcpAgentSession<AcpInitializeResult, GrokAcp};}+ protected async onRunCancelled(): Promise<void> {+ // Same shape a cancelled `session/prompt` response carries β the adapter+ // turns it into the `reason: 'cancelled'` agent_runtime_end terminal.+ await this.pushToPipeline({ result: { stopReason: 'cancelled' } });+ }+protected async handleAgentMessage(message: AcpRpcMessage): Promise<void> {if (isAcpReplayMessage(message)) return;await this.pushToPipeline(message);diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.test.tsindex 041fd779fb7..1f816cced20 100644--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts@@ -794,6 +794,106 @@ describe('spawnAgent', () => {}});+ it('reports a host-interrupted Devin ACP run as interrupted, not a transport error', async () => {+ const fake = createFakeAcpProc({ promptAutoComplete: false, sessionId: 'devin-session-1' });+ nextFakeProc = fake.proc;+ const processKill = vi.spyOn(process, 'kill').mockImplementation(() => true);++ try {+ const { spawnAgent } = await import('./spawnAgent');+ const handle = await spawnAgent({+ agentType: 'devin',+ operationId: 'op-devin-interrupt',+ prompt: 'keep running',+ });+ await vi.waitFor(() => {+ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(true);+ });++ // The wrapper delivers the protocol-level cancel through `interrupt` when+ // the OS signal already reached the agent through a shared process group.+ expect(handle.interrupt).toBeTypeOf('function');+ handle.interrupt?.('SIGINT');+ fake.proc.emit('close', null, 'SIGINT');++ const events: any[] = [];+ for await (const event of handle.events) events.push(event);++ await expect(handle.exit).resolves.toEqual({ code: null, signal: 'SIGINT' });+ expect(events.some(({ type }) => type === 'error')).toBe(false);+ expect(events).toContainEqual(+ expect.objectContaining({+ data: expect.objectContaining({ reason: 'interrupted' }),+ type: 'agent_runtime_end',+ }),+ );+ } finally {+ processKill.mockRestore();+ }+ });++ it.each(['starting', 'running'] as const)(+ 'does not resend an inherited-group SIGTERM while ACP is %s',+ async (phase) => {+ const fake = createFakeAcpProc({ promptAutoComplete: false });+ nextFakeProc = fake.proc;+ const processKill = vi.spyOn(process, 'kill').mockImplementation(() => true);++ try {+ const { spawnAgent } = await import('./spawnAgent');+ const handle = await spawnAgent({+ agentType: 'devin',+ detached: false,+ operationId: 'op-devin-sigterm',+ prompt: 'keep running',+ });+ if (phase === 'running') {+ await vi.waitFor(() => {+ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(true);+ });+ }++ handle.interrupt?.('SIGTERM');+ const events = [];+ for await (const event of handle.events) events.push(event);++ await expect(handle.exit).resolves.toEqual({ code: null, signal: 'SIGTERM' });+ expect(events.some(({ type }) => type === 'error')).toBe(false);+ expect(fake.proc.kill).not.toHaveBeenCalled();+ expect(processKill).not.toHaveBeenCalled();+ if (phase === 'starting') {+ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(false);+ }+ } finally {+ processKill.mockRestore();+ }+ },+ );++ it.each(['SIGTERM', 'SIGKILL'] as const)(+ 'still delivers an owned %s to an inherited-group ACP child',+ async (signal) => {+ const fake = createFakeAcpProc({ promptAutoComplete: false });+ nextFakeProc = fake.proc;+ const { spawnAgent } = await import('./spawnAgent');+ const handle = await spawnAgent({+ agentType: 'devin',+ detached: false,+ operationId: 'op-devin-owned-signal',+ prompt: 'keep running',+ });+ await vi.waitFor(() => {+ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(true);+ });++ if (signal === 'SIGKILL') handle.interrupt?.(signal);+ else handle.kill(signal);++ await expect(handle.exit).resolves.toEqual({ code: null, signal });+ expect(fake.proc.kill).toHaveBeenCalledExactlyOnceWith(signal);+ },+ );+it('allows the official canonical trae-cli command to run through ACP', async () => {const fake = createFakeAcpProc();nextFakeProc = fake.proc;diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.tsindex 5309ccc4aaa..68bba83cd11 100644--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts@@ -106,6 +106,15 @@ export interface SpawnAgentHandle {* care about ordering.*/exit: Promise<{ code: number | null; signal: NodeJS.Signals | null }>;+ /**+ * Notify a session transport of host-initiated cancellation at the protocol+ * level (ACP `session/cancel`, RPC abort). Present only on session+ * transports β absent on one-shot CLI spawns where `kill` is the only+ * cancel channel. ACP SIGTERM closes the session without resending the+ * already-delivered signal; SIGINT retains protocol cancellation and its+ * grace timeout. SIGKILL remains a host-requested force-kill escalation.+ */+ interrupt?: (signal?: NodeJS.Signals) => void;/*** Send a signal to the child. A dedicated Unix process group is signaled as* a tree; inherited-group children receive a direct signal because their@@ -461,10 +470,10 @@ const createAcpSpawnBridge = () => {};const attach = (session: {- close: (signal?: NodeJS.Signals) => void;+ close: (signal?: NodeJS.Signals | null) => void;interrupt: () => void;run: () => Promise<void>;- }): Pick<SpawnAgentHandle, 'exit' | 'kill'> => {+ }): Pick<SpawnAgentHandle, 'exit' | 'interrupt' | 'kill'> => {const exit: SpawnAgentHandle['exit'] = session.run().then(() => getHostExit() ?? { code: 0, signal: null })@@ -488,14 +497,21 @@ const createAcpSpawnBridge = () => {if (signal === 'SIGINT') session.interrupt();else session.close(signal);};- return { exit, kill };+ const interrupt = (signal: NodeJS.Signals = 'SIGINT'): void => {+ hostSignal = signal;+ // SIGTERM already reached the child through the inherited process group.+ // Close pending RPCs without interrupting the child's shutdown again.+ if (signal === 'SIGTERM') session.close(null);+ else kill(signal);+ };+ return { exit, interrupt, kill };};return { attach, events, onEvents, onStderr, stderr };};interface AcpSpawnSession {- close: (signal?: NodeJS.Signals) => void;+ close: (signal?: NodeJS.Signals | null) => void;interrupt: () => void;pid?: number;run: () => Promise<void>;@@ -507,11 +523,12 @@ const createAcpSpawnHandle = (session: AcpSpawnSession,getSessionId: () => string | undefined = () => session.sessionId,): SpawnAgentHandle => {- const { exit, kill } = bridge.attach(session);+ const { exit, interrupt, kill } = bridge.attach(session);return {events: bridge.events,exit,+ interrupt,kill,get pid() {return session.pid;@@ -603,11 +620,12 @@ const spawnDroidAcpAgent = async (resumeSessionId: options.resumeSessionId,sessionId: options.operationId,});- const { exit, kill } = bridge.attach(session);+ const { exit, interrupt, kill } = bridge.attach(session);return {events: bridge.events,exit,+ interrupt,kill,get pid() {return session.pid;diff --git a/packages/heterogeneous-agents/src/spawn/traeAcpSession.ts b/packages/heterogeneous-agents/src/spawn/traeAcpSession.tsindex 36265a2f4ff..6648c885e2c 100644--- a/packages/heterogeneous-agents/src/spawn/traeAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/traeAcpSession.ts@@ -344,6 +344,10 @@ export class TraeAcpSession extends AcpAgentSession<await this.emitEvents(await this.pipeline.flush());}+ protected async onRunCancelled(): Promise<void> {+ await this.pushToPipeline({ stopReason: 'cancelled', type: 'trae_prompt_completed' });+ }+protected onHostClose(): void {this.modelDiscovery?.close();}