Skip to content

Commit 64b97ca

Browse files
samejrclaude
andcommitted
Clear AgentView HITL resolution buffer once parts reach terminal state
pendingResolutionsRef previously grew unbounded over the lifetime of the component — one entry per tool call, never removed. On chatty long-lived sessions that's a slow leak plus wasted JSON.stringify equality work on every `.out` chunk. Delete the buffered entry once the overlay has landed at a terminal output-available/error/denied state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c8f79ab commit 64b97ca

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

apps/webapp/app/components/runs/v3/agent/AgentView.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ function useAgentSessionMessages({
335335
res.output === undefined &&
336336
res.errorText === undefined
337337
) {
338-
return false; // already applied
338+
// Already applied. If the part has reached a terminal state, drop
339+
// the buffered resolution so the Map doesn't grow unbounded on
340+
// long-lived sessions with many tool calls.
341+
if (terminal) pendingResolutionsRef.current.delete(toolCallId);
342+
return false;
339343
}
340344
const next = parts.slice();
341345
next[idx] = {
@@ -346,6 +350,13 @@ function useAgentSessionMessages({
346350
state: nextState,
347351
};
348352
pendingRef.current.set(mid, { ...msg, parts: next } as UIMessage);
353+
// Drop the buffered entry once the part has landed at a terminal
354+
// state — no future `.out` chunk will need this resolution.
355+
const reachedTerminal =
356+
nextState === "output-available" ||
357+
nextState === "output-error" ||
358+
nextState === "output-denied";
359+
if (reachedTerminal) pendingResolutionsRef.current.delete(toolCallId);
349360
return true;
350361
}
351362
return false;

0 commit comments

Comments
 (0)