fix(acp): run exit cleanup when stdin closes (#14953)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Allen Hutchison <adh@google.com>
Co-authored-by: Allen Hutchison <allen@hutchison.org>
This commit is contained in:
Adrian Cole
2026-01-15 06:02:44 +08:00
committed by GitHub
parent b14cf1dc30
commit 7e6817da5b
6 changed files with 133 additions and 9 deletions

View File

@@ -44,6 +44,7 @@ import { z } from 'zod';
import { randomUUID } from 'node:crypto';
import type { CliArgs } from '../config/config.js';
import { loadCliConfig } from '../config/config.js';
import { runExitCleanup } from '../utils/cleanup.js';
export async function runZedIntegration(
config: Config,
@@ -55,10 +56,15 @@ export async function runZedIntegration(
const stdin = Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>;
const stream = acp.ndJsonStream(stdout, stdin);
new acp.AgentSideConnection(
const connection = new acp.AgentSideConnection(
(connection) => new GeminiAgent(config, settings, argv, connection),
stream,
);
// SIGTERM/SIGINT handlers (in sdk.ts) don't fire when stdin closes.
// We must explicitly await the connection close to flush telemetry.
// Use finally() to ensure cleanup runs even on stream errors.
await connection.closed.finally(runExitCleanup);
}
export class GeminiAgent {