fix(patch): cherry-pick eda47f5 to release/v0.24.0-preview.2-pr-16557 [CONFLICTS] (#16577)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
This commit is contained in:
gemini-cli-robot
2026-01-13 22:04:14 -08:00
committed by GitHub
parent df72e3af3d
commit 4b2701195a

View File

@@ -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) {