diff options
| author | Brandon Keiji <[email protected]> | 2025-05-22 10:02:45 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-22 03:02:45 -0700 |
| commit | fb1d13d600645e51db493644e63736e18872b0e4 (patch) | |
| tree | e897c9f6aeb2c98359dddc384ecdb476d62074e0 /packages/cli/src | |
| parent | a8bfdf2d5603e9e2fb01e12d6c5499662dccaa85 (diff) | |
fix: cancel parallel tool calls mid-execution (#489)
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.ts | 5 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useToolScheduler.ts | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index d3ecad95..80f6945c 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -395,7 +395,10 @@ export const useGeminiStream = ( }; const streamingState: StreamingState = - isResponding || toolCalls.some((t) => t.status === 'awaiting_approval') + isResponding || + toolCalls.some( + (t) => t.status === 'awaiting_approval' || t.status === 'executing', + ) ? StreamingState.Responding : StreamingState.Idle; diff --git a/packages/cli/src/ui/hooks/useToolScheduler.ts b/packages/cli/src/ui/hooks/useToolScheduler.ts index e14241b6..8bcc0ae9 100644 --- a/packages/cli/src/ui/hooks/useToolScheduler.ts +++ b/packages/cli/src/ui/hooks/useToolScheduler.ts @@ -185,12 +185,19 @@ export function useToolScheduler( useEffect(() => { // effect for executing scheduled tool calls if (toolCalls.every((t) => t.status === 'scheduled')) { + const signal = abortController.signal; toolCalls.forEach((c) => { const callId = c.request.callId; setToolCalls(setStatus(c.request.callId, 'executing')); c.tool - .execute(c.request.args, abortController.signal) + .execute(c.request.args, signal) .then((result) => { + if (signal.aborted) { + setToolCalls( + setStatus(callId, 'cancelled', 'Cancelled during execution'), + ); + return; + } const functionResponse: Part = { functionResponse: { name: c.request.name, |
