Elffuss BraidHub

kikocis/continue public

Merge pull request #6649 from continuedev/pe/agent-cutoff-fix

fix: continue streaming even if no tool call states found
Changesetd22531502d6c125003967efe6f03d7f91bfd5e6ec640058efaeb8545794c6093
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-07-16 08:28 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-16 08:28 -07:00
Parents4aa90a5da6be, f960a00a2c65

Browse the files at this changeset

7 files changed

modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +0 −1
@@ -89,7 +89,6 @@
8989 <ArgsToggleIcon
9090 isShowing={showingArgs}
9191 setIsShowing={setShowingArgs}
92- toolCallId={toolCallState.toolCallId}
9392 />
9493 ) : null}
9594 </div>
deleted gui/src/pages/gui/ToolCallDiv/ToolCall.tsx +0 −66
@@ -1,66 +0,0 @@
1-import { Tool, ToolCallState } from "core";
2-import { useMemo, useState } from "react";
3-import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
4-import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
5-import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
6-
7-interface ToolCallDisplayProps {
8- children: React.ReactNode;
9- icon: React.ReactNode;
10- tool: Tool | undefined;
11- toolCallState: ToolCallState;
12- historyIndex: number;
13-}
14-
15-export function ToolCallDisplay({
16- tool,
17- toolCallState,
18- children,
19- icon,
20- historyIndex,
21-}: ToolCallDisplayProps) {
22- const [argsExpanded, setArgsExpanded] = useState(false);
23-
24- const args: [string, any][] = useMemo(() => {
25- return Object.entries(toolCallState.parsedArgs);
26- }, [toolCallState.parsedArgs]);
27-
28- return (
29- <>
30- <div className="flex flex-col justify-center p-4 pb-1">
31- <div className="mb-2 flex flex-col">
32- <div className="flex flex-row items-center justify-between gap-1.5">
33- <div className="flex min-w-0 flex-row items-center gap-2">
34- <div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold">
35- {icon}
36- </div>
37- {tool?.faviconUrl && (
38- <img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
39- )}
40- <ToolCallStatusMessage
41- tool={tool}
42- toolCallState={toolCallState}
43- />
44- </div>
45- <div className="flex flex-row items-center gap-1.5">
46- {!!toolCallState.output && (
47- <ToolTruncateHistoryIcon historyIndex={historyIndex} />
48- )}
49- {!!args.length ? (
50- <ArgsToggleIcon
51- isShowing={argsExpanded}
52- setIsShowing={setArgsExpanded}
53- toolCallId={toolCallState.toolCallId}
54- />
55- ) : null}
56- </div>
57- </div>
58- {argsExpanded && !!args.length && (
59- <ArgsItems args={args} isShowing={argsExpanded} />
60- )}
61- </div>
62- <div>{children}</div>
63- </div>
64- </>
65- );
66-}
modified gui/src/pages/gui/ToolCallDiv/ToolCallArgs.tsx +0 −2
@@ -4,13 +4,11 @@
44 interface ArgsToggleIconProps {
55 isShowing: boolean;
66 setIsShowing: (val: boolean) => void;
7- toolCallId: string;
87 }
98
109 export const ArgsToggleIcon = ({
1110 isShowing,
1211 setIsShowing,
13- toolCallId,
1412 }: ArgsToggleIconProps) => {
1513 return (
1614 <ToolbarButtonWithTooltip
added gui/src/pages/gui/ToolCallDiv/ToolCallDisplay.tsx +65 −0
@@ -0,0 +1,65 @@
1+import { Tool, ToolCallState } from "core";
2+import { useMemo, useState } from "react";
3+import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
4+import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
5+import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
6+
7+interface ToolCallDisplayProps {
8+ children: React.ReactNode;
9+ icon: React.ReactNode;
10+ tool: Tool | undefined;
11+ toolCallState: ToolCallState;
12+ historyIndex: number;
13+}
14+
15+export function ToolCallDisplay({
16+ tool,
17+ toolCallState,
18+ children,
19+ icon,
20+ historyIndex,
21+}: ToolCallDisplayProps) {
22+ const [argsExpanded, setArgsExpanded] = useState(false);
23+
24+ const args: [string, any][] = useMemo(() => {
25+ return Object.entries(toolCallState.parsedArgs);
26+ }, [toolCallState.parsedArgs]);
27+
28+ return (
29+ <>
30+ <div className="flex flex-col justify-center">
31+ <div className="mb-2 flex flex-col">
32+ <div className="flex flex-row items-center justify-between gap-1.5">
33+ <div className="flex min-w-0 flex-row items-center gap-2">
34+ <div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold">
35+ {icon}
36+ </div>
37+ {tool?.faviconUrl && (
38+ <img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
39+ )}
40+ <ToolCallStatusMessage
41+ tool={tool}
42+ toolCallState={toolCallState}
43+ />
44+ </div>
45+ <div className="flex flex-row items-center gap-1.5">
46+ {!!toolCallState.output && (
47+ <ToolTruncateHistoryIcon historyIndex={historyIndex} />
48+ )}
49+ {!!args.length ? (
50+ <ArgsToggleIcon
51+ isShowing={argsExpanded}
52+ setIsShowing={setArgsExpanded}
53+ />
54+ ) : null}
55+ </div>
56+ </div>
57+ {argsExpanded && !!args.length && (
58+ <ArgsItems args={args} isShowing={argsExpanded} />
59+ )}
60+ </div>
61+ <div>{children}</div>
62+ </div>
63+ </>
64+ );
65+}
modified gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx +1 −1
@@ -53,7 +53,7 @@
5353
5454 return (
5555 <div
56- className="text-description line-clamp-4 min-w-0 break-words"
56+ className="text-description line-clamp-4 min-w-0 break-all"
5757 data-testid="tool-call-title"
5858 >
5959 {`Continue ${intro} ${message}`}
modified gui/src/pages/gui/ToolCallDiv/index.tsx +2 −5
@@ -6,7 +6,7 @@
66 import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
77 import { GroupedToolCallHeader } from "./GroupedToolCallHeader";
88 import { SimpleToolCallUI } from "./SimpleToolCallUI";
9-import { ToolCallDisplay } from "./ToolCall";
9+import { ToolCallDisplay } from "./ToolCallDisplay";
1010 import { getStatusIcon, toolCallIcons } from "./utils";
1111
1212 interface ToolCallDivProps {
@@ -103,10 +103,7 @@
103103 }
104104
105105 return toolCallStates.map((toolCallState) => (
106- <div
107- className="border-border rounded-lg border p-3"
108- key={toolCallState.toolCallId}
109- >
106+ <div className="p-4 pb-1" key={toolCallState.toolCallId}>
110107 {renderToolCall(toolCallState)}
111108 </div>
112109 ));
modified gui/src/redux/thunks/streamResponseAfterToolCall.ts +21 −63
@@ -2,80 +2,32 @@
22 import { ChatMessage } from "core";
33 import { renderContextItems } from "core/util/messageContent";
44 import {
5+ ChatHistoryItemWithMessageId,
56 resetNextCodeBlockToApplyIndex,
67 streamUpdate,
78 } from "../slices/sessionSlice";
8-import { AppThunkDispatch, RootState, ThunkApiType } from "../store";
9+import { ThunkApiType } from "../store";
910 import { findToolCallById } from "../util";
1011 import { streamNormalInput } from "./streamNormalInput";
1112 import { streamThunkWrapper } from "./streamThunkWrapper";
1213
13-/**
14- * Finds the assistant message that contains the specified tool call.
15- */
16-function findAssistantMessageWithToolCall(
17- history: RootState["session"]["history"],
18- toolCallId: string,
19-) {
20- return history.find(
21- (item) =>
22- item.message.role === "assistant" &&
23- item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId),
24- );
25-}
26-
27-/**
28- * Checks if all parallel tool calls in an assistant message are complete.
29- */
30-function areAllToolCallsComplete(
31- toolCallStates: NonNullable<
32- ReturnType<typeof findAssistantMessageWithToolCall>
33- >["toolCallStates"],
34-): boolean {
35- if (!toolCallStates) return false;
36-
37- const completedToolCalls = toolCallStates.filter(
38- (tc) => tc.status === "done",
39- );
40-
41- return completedToolCalls.length === toolCallStates.length;
42-}
43-
4414 /**
4515 * Determines if we should continue streaming based on tool call completion status.
4616 */
47-function shouldContinueStreaming(
48- assistantMessage: ReturnType<typeof findAssistantMessageWithToolCall>,
17+function areAllToolsDoneStreaming(
18+ assistantMessage: ChatHistoryItemWithMessageId | undefined,
4919 ): boolean {
20+ // This might occur because of race conditions, if so, the tools are completed
5021 if (!assistantMessage?.toolCallStates) {
51- return false; // No assistant message found - don't stream
52- }
53-
54- const totalToolCalls = assistantMessage.toolCallStates.length;
55-
56- // Single tool call - always continue streaming
57- if (totalToolCalls === 1) {
5822 return true;
5923 }
6024
61- // Multiple tool calls - only continue if all are complete
62- return areAllToolCallsComplete(assistantMessage.toolCallStates);
63-}
25+ // Only continue if all tool calls are complete
26+ const completedToolCalls = assistantMessage.toolCallStates.filter(
27+ (tc) => tc.status === "done",
28+ );
6429
65-/**
66- * Creates and dispatches a tool message for the completed tool call.
67- */
68-function createAndDispatchToolMessage(
69- dispatch: AppThunkDispatch,
70- toolCallId: string,
71- toolOutput: any[],
72-): void {
73- const newMessage: ChatMessage = {
74- role: "tool",
75- content: renderContextItems(toolOutput),
76- toolCallId,
77- };
78- dispatch(streamUpdate([newMessage]));
30+ return completedToolCalls.length === assistantMessage.toolCallStates.length;
7931 }
8032
8133 export const streamResponseAfterToolCall = createAsyncThunk<
@@ -104,16 +56,22 @@
10456 await new Promise((resolve) => setTimeout(resolve, 0));
10557
10658 // Create and dispatch the tool message
107- createAndDispatchToolMessage(dispatch, toolCallId, toolOutput);
59+ const newMessage: ChatMessage = {
60+ role: "tool",
61+ content: renderContextItems(toolOutput),
62+ toolCallId,
63+ };
64+ dispatch(streamUpdate([newMessage]));
10865
10966 // Check if we should continue streaming based on tool call completion
11067 const history = getState().session.history;
111- const assistantMessage = findAssistantMessageWithToolCall(
112- history,
113- toolCallId,
68+ const assistantMessage = history.find(
69+ (item) =>
70+ item.message.role === "assistant" &&
71+ item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId),
11472 );
11573
116- if (shouldContinueStreaming(assistantMessage)) {
74+ if (areAllToolsDoneStreaming(assistantMessage)) {
11775 unwrapResult(await dispatch(streamNormalInput({})));
11876 }
11977 }),