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
+1 -1
View File
@@ -29,7 +29,7 @@
"sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.26.0-nightly.20260114.bb6c57414"
},
"dependencies": {
"@agentclientprotocol/sdk": "^0.11.0",
"@agentclientprotocol/sdk": "^0.12.0",
"@google/gemini-cli-core": "file:../core",
"@google/genai": "1.30.0",
"@iarna/toml": "^2.2.5",
@@ -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 {
+3 -3
View File
@@ -114,10 +114,10 @@ export async function createContentGenerator(
): Promise<ContentGenerator> {
const generator = await (async () => {
if (gcConfig.fakeResponses) {
return new LoggingContentGenerator(
await FakeContentGenerator.fromFile(gcConfig.fakeResponses),
gcConfig,
const fakeGenerator = await FakeContentGenerator.fromFile(
gcConfig.fakeResponses,
);
return new LoggingContentGenerator(fakeGenerator, gcConfig);
}
const version = await getVersion();
const model = resolveModel(