fix(cli): allow sub-agent confirmation requests in UI while preventing background flicker (#20722)

This commit is contained in:
Abhi
2026-02-28 21:39:25 -05:00
committed by GitHub
parent 0063581e47
commit 703759cfae
2 changed files with 168 additions and 25 deletions

View File

@@ -115,11 +115,42 @@ export function useToolScheduler(
useEffect(() => {
const handler = (event: ToolCallsUpdateMessage) => {
// Only process updates for the root scheduler.
// Subagent internal tools should not be displayed in the main tool list.
if (event.schedulerId !== ROOT_SCHEDULER_ID) {
return;
}
const isRoot = event.schedulerId === ROOT_SCHEDULER_ID;
setToolCallsMap((prev) => {
const prevCalls = prev[event.schedulerId] ?? [];
const prevCallIds = new Set(prevCalls.map((tc) => tc.request.callId));
// For non-root schedulers, we only show tool calls that:
// 1. Are currently awaiting approval.
// 2. Were previously shown (e.g., they are now executing or completed).
// This prevents "thinking" tools (reads/searches) from flickering in the UI
// unless they specifically required user interaction.
const filteredToolCalls = isRoot
? event.toolCalls
: event.toolCalls.filter(
(tc) =>
tc.status === CoreToolCallStatus.AwaitingApproval ||
prevCallIds.has(tc.request.callId),
);
// If this is a subagent and we have no tools to show and weren't showing any,
// we can skip the update entirely to avoid unnecessary re-renders.
if (
!isRoot &&
filteredToolCalls.length === 0 &&
prevCalls.length === 0
) {
return prev;
}
const adapted = internalAdaptToolCalls(filteredToolCalls, prevCalls);
return {
...prev,
[event.schedulerId]: adapted,
};
});
// Update output timer for UI spinners (Side Effect)
const hasExecuting = event.toolCalls.some(
@@ -134,18 +165,6 @@ export function useToolScheduler(
if (hasExecuting) {
setLastToolOutputTime(Date.now());
}
setToolCallsMap((prev) => {
const adapted = internalAdaptToolCalls(
event.toolCalls,
prev[event.schedulerId] ?? [],
);
return {
...prev,
[event.schedulerId]: adapted,
};
});
};
messageBus.subscribe(MessageBusType.TOOL_CALLS_UPDATE, handler);