mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 17:11:04 -07:00
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com> Co-authored-by: Sandy Tao <sandytao520@icloud.com>
This commit is contained in:
@@ -923,21 +923,36 @@ export class CoreToolScheduler {
|
||||
this._cancelAllQueuedCalls();
|
||||
}
|
||||
|
||||
// If we are already finalizing, another concurrent call to
|
||||
// checkAndNotifyCompletion will just return. The ongoing finalized loop
|
||||
// will pick up any new tools added to completedToolCallsForBatch.
|
||||
if (this.isFinalizingToolCalls) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's nothing to report and we weren't cancelled, we can stop.
|
||||
// But if we were cancelled, we must proceed to potentially start the next queued request.
|
||||
if (this.completedToolCallsForBatch.length === 0 && !signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.onAllToolCallsComplete) {
|
||||
this.isFinalizingToolCalls = true;
|
||||
// Use the batch array, not the (now empty) active array.
|
||||
await this.onAllToolCallsComplete(this.completedToolCallsForBatch);
|
||||
this.completedToolCallsForBatch = []; // Clear after reporting.
|
||||
this.isFinalizingToolCalls = true;
|
||||
try {
|
||||
// We use a while loop here to ensure that if new tools are added to the
|
||||
// batch (e.g., via cancellation) while we are awaiting
|
||||
// onAllToolCallsComplete, they are also reported before we finish.
|
||||
while (this.completedToolCallsForBatch.length > 0) {
|
||||
const batchToReport = [...this.completedToolCallsForBatch];
|
||||
this.completedToolCallsForBatch = [];
|
||||
if (this.onAllToolCallsComplete) {
|
||||
await this.onAllToolCallsComplete(batchToReport);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.isFinalizingToolCalls = false;
|
||||
this.isCancelling = false;
|
||||
this.notifyToolCallsUpdate();
|
||||
}
|
||||
this.isCancelling = false;
|
||||
this.notifyToolCallsUpdate();
|
||||
|
||||
// After completion of the entire batch, process the next item in the main request queue.
|
||||
if (this.requestQueue.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user