From f2f2ecf9d83224778e5fc38cfcc4a1edddf9f7d4 Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Tue, 27 May 2025 23:40:25 -0700 Subject: feat: Allow cancellation of in-progress Gemini requests and pre-execution checks - Implements cancellation for Gemini requests while they are actively being processed by the model. - Extends cancellation support to the logic within tools. This allows users to cancel operations during the phase where the system is determining if a tool execution requires user confirmation, which can include potentially long-running pre-flight checks or LLM-based corrections. - Underlying LLM calls for edit corrections (within and ) and next speaker checks can now also be cancelled. - Previously, cancellation of the main request was not possible until text started streaming, and pre-execution checks were not cancellable. - This change leverages the updated SDK's ability to accept an abort token and threads s throughout the request, tool execution, and pre-execution check lifecycle. Fixes https://github.com/google-gemini/gemini-cli/issues/531 --- packages/server/src/tools/write-file.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/server/src/tools/write-file.ts') diff --git a/packages/server/src/tools/write-file.ts b/packages/server/src/tools/write-file.ts index 60646cc2..2285c819 100644 --- a/packages/server/src/tools/write-file.ts +++ b/packages/server/src/tools/write-file.ts @@ -141,6 +141,7 @@ export class WriteFileTool extends BaseTool { */ async shouldConfirmExecute( params: WriteFileToolParams, + abortSignal: AbortSignal, ): Promise { if (this.config.getAlwaysSkipModificationConfirmation()) { return false; @@ -154,6 +155,7 @@ export class WriteFileTool extends BaseTool { const correctedContentResult = await this._getCorrectedFileContent( params.file_path, params.content, + abortSignal, ); if (correctedContentResult.error) { @@ -193,7 +195,7 @@ export class WriteFileTool extends BaseTool { async execute( params: WriteFileToolParams, - _signal: AbortSignal, + abortSignal: AbortSignal, ): Promise { const validationError = this.validateToolParams(params); if (validationError) { @@ -206,6 +208,7 @@ export class WriteFileTool extends BaseTool { const correctedContentResult = await this._getCorrectedFileContent( params.file_path, params.content, + abortSignal, ); if (correctedContentResult.error) { @@ -277,6 +280,7 @@ export class WriteFileTool extends BaseTool { private async _getCorrectedFileContent( filePath: string, proposedContent: string, + abortSignal: AbortSignal, ): Promise { let originalContent = ''; let fileExists = false; @@ -316,6 +320,7 @@ export class WriteFileTool extends BaseTool { file_path: filePath, }, this.client, + abortSignal, ); correctedContent = correctedParams.new_string; } else { @@ -323,6 +328,7 @@ export class WriteFileTool extends BaseTool { correctedContent = await ensureCorrectFileContent( proposedContent, this.client, + abortSignal, ); } return { originalContent, correctedContent, fileExists }; -- cgit v1.2.3