fix(react)+test: lock down PR #5 regressions and close three useChat gaps#7
Merged
Merged
Conversation
- send(): sync messagesRef before runStream so rapid synchronous sends both reach the outgoing request body - useState init: hydrate pendingDecisions from initialMessages so rehydrated paused tool calls render decision UI immediately - unmount: abort the in-flight fetch on cleanup to prevent leaked streams when the consumer unmounts mid-request Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds four regression tests that act as acceptance criteria for the fixes shipped in PR #5 and the companion useChat fixes in this branch. agent.test.ts: - injectDeferralResults() + prompt() places the synthetic toolResult adjacent to its assistant block (verifies the documented "user typed instead of deciding" recovery pattern produces provider-valid order). use-chat.test.ts: - initialMessages with a paused tool call hydrates pendingDecisions. - Two rapid synchronous send() calls both reach the outgoing body. - Unmount aborts the in-flight fetch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Follow-up to #5. Adds the regression tests originally drafted on
review/pr-5as permanent acceptance criteria, plus fixes threeuseChatgaps the review surfaced that weren't addressed in the merged PR.useChat fixes (
packages/react/src/use-chat.ts)send()sync ref: rapid synchronous sends now both reach the outgoing request body. Previously the second send read a stalemessagesRef.currentbecause the ref was only updated by auseEffect, not synchronously inside the callback.pendingDecisionshydration:initialMessagescontaining a paused tool call now populatespendingDecisionson mount. Previously the map was initialized empty and only filled via stream events, so rehydrated sessions couldn't render decision UI for prior pauses.useEffectnow aborts the in-flightAbortControllerwhen the hook unmounts. Previously an unmount mid-stream leaked the fetch.Regression tests
packages/agent/__tests__/agent.test.ts:injectDeferralResults()+prompt()places the synthetictoolResultadjacent to its assistant block (verifies the documented "user typed instead of deciding" recovery pattern produces provider-valid ordering).packages/react/__tests__/use-chat.test.ts: three tests covering the three fixes above.Together these lock down the four behaviors and document the recovery pattern via executable example.
Test plan
pnpm --filter @agentic-kit/agent test— 42/42 pass (incl. new injectDeferralResults adjacency test)pnpm --filter @agentic-kit/react test— 31/31 pass (incl. three new tests, which fail onmainand pass with the fixes here)pnpm --filter agentic-kit test— 17/17 pass🤖 Generated with Claude Code