mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-15 16:14:43 +00:00
fix(ui): sync toolStreamRef on tool.result to prevent stale overwrite
tool.result updated React state via functional update but didn't sync toolStreamRef.current. When the next tool.call arrived and set state to toolStreamRef.current (direct value), it overwrote completed statuses with stale "calling" phase — causing tool cards to stay stuck at "Running..." forever.
This commit is contained in:
1 parent
56dd8b5885
commit
e06b44179c
1 file changed
+13
-11
@@ -144,18 +144,20 @@ export function useChatMessages(sessionKey: string, agentId: string) {
|
||||
}
|
||||
case "tool.result": {
|
||||
const isError = event.payload?.is_error;
|
||||
setToolStream((prev) =>
|
||||
prev.map((t) =>
|
||||
t.toolCallId === event.payload?.id
|
||||
? {
|
||||
...t,
|
||||
phase: isError ? "error" : "completed",
|
||||
errorContent: isError ? event.payload?.content : undefined,
|
||||
updatedAt: Date.now(),
|
||||
}
|
||||
: t,
|
||||
),
|
||||
const resultId = event.payload?.id;
|
||||
const now = Date.now();
|
||||
// Update ref first so subsequent tool.call events don't overwrite with stale data.
|
||||
toolStreamRef.current = toolStreamRef.current.map((t) =>
|
||||
t.toolCallId === resultId
|
||||
? {
|
||||
...t,
|
||||
phase: isError ? ("error" as const) : ("completed" as const),
|
||||
errorContent: isError ? event.payload?.content : undefined,
|
||||
updatedAt: now,
|
||||
}
|
||||
: t,
|
||||
);
|
||||
setToolStream(toolStreamRef.current);
|
||||
break;
|
||||
}
|
||||
case "run.completed": {
|
||||
|
||||
Reference in new issue
Block a user