Repository navigation
fix(agents): stop useAgentChat's tool-result cleanup dispatching per chunk (#2217) - #2403
Merged
threepointone merged 2 commits intoSep 28, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 5fba64a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
threepointone
added this pull request to stack #2407
September 28, 2026 14:47
threepointone
marked this pull request as ready for review
September 28, 2026 14:50
threepointone
force-pushed
the
fix/2217-tool-result-cleanup
branch
from
September 28, 2026 15:46
a999c3f to
8114a60
Compare
Contributor
|
✅ agents import sizes: no significant changes ( |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
…chunk (#2217) The stale clientToolResults cleanup effect called setState on every message change and relied on the updater returning prev. During a stream React re-renders anyway and counts each passive-effect update toward its nested update limit, so long answers threw "Maximum update depth exceeded". Decide staleness from a ref mirror before dispatching. The resume-replay-burst ordering check now waits for the throttled render instead of sleeping 20ms; the spurious re-render used to flush it early. Co-authored-by: Konan <kixeyems0@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
threepointone
force-pushed
the
fix/2217-tool-result-cleanup
branch
from
September 28, 2026 16:54
8114a60 to
5fba64a
Compare
Merged
tombeckenham
added a commit
to tombeckenham/agents-tom
that referenced
this pull request
Oct 7, 2026
Brings react-agui.tsx level with the legacy hook in agents/chat/react, which received these through the upstream merge: - cloudflare#2344 the server snapshot heals a diverged observed assistant - cloudflare#2348 an observer skips replayed continuation frames it already applied - cloudflare#2361 onToolCall fires only after the stream ends - cloudflare#2378 onTurnEnd fires once per ended request - cloudflare#2383 turns settle across replay, resume and observers (held and recovering requests, the resume:false idle probe) - cloudflare#2496 streaming protection is released when the socket closes - cloudflare#2394 follow the socket when the agent name changes - cloudflare#2403 the tool-result cleanup no longer dispatches per chunk - cloudflare#2039 keep an optimistic send the reconnect transcript omits The last three had no failing test: their upstream tests are ported into react-tests (the address-change one against a fake of useAgent's pending socket, since this package has no test worker) and failed before the fix. restoreBufferedSends, MAX_REMEMBERED_ENDED_TURNS and isSocketAddressPending are exported from agents/chat/react so the two hooks share them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2217. This takes over the fix from the reporter's fork, with co-author credit to @Konan69.
Problem
useAgentChat's cleanup effect for staleclientToolResultscalledsetStateon every message change, and relied on the updater returningprevto make that a no-op. During a stream, React re-renders anyway and counts every update made in a passive effect toward its nested update limit. Long answers threw "Maximum update depth exceeded". I reproduced this with the reporter's test.Fix
A ref mirrors
clientToolResults. The effect checks the ref for stale keys before it dispatches anything. The updater still recomputes fromprevand returnsprevwhen nothing changed, so a race cannot drop a fresh result.Tests
tool-result-prune-updates.test.tsx, from the fork, fails with "Maximum update depth exceeded" without the fix.resume-replay-burst.test.tsxnow waits for the throttled render instead of sleeping 20 ms. The spurious re-render used to flush it early.