Repository navigation
fix(react-core): stop useInterrupt re-renders on agent updates - #6969
lukasmoschitz merged 1 commit into
Conversation
useInterrupt only needs the agent handle - interrupt events arrive via its own direct agent.subscribe(). But useAgent() with no update filter force-updates the consumer on every message/state/run-status change. Pass updates: [] so the re-render subscription is skipped entirely (use-agent early-returns when the list is empty) while the agent handle still resolves.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughChangesInterrupt render control
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~5 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to useInterrupt now avoids agent-update-driven component re-renders while preserving interrupt handling, with regression coverage for the update-subscription opt-out. No current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
lukasmoschitz
left a comment
There was a problem hiding this comment.
Verified this locally against current main. Two things beyond reading the diff:
I checked that updates: [] actually means "no updates" rather than falling through to the default — use-agent.tsx:219 uses ??, which doesn't fall back on an empty array, and the subscription effect at :373 returns before installing anything. Then I measured it with the real hook in the use-agent-throttle harness: with updates: [], five onMessagesChanged notifications produce zero extra renders, while the same harness with OnMessagesChanged re-renders as expected. Full react-core target is green (145 vitest files, 47 node tests).
Also removed your one-liner and confirmed your test fails without it — thanks for writing one that actually pins the change.
One note for anyone reading this later: the render callback receives agent, and it will no longer re-render on message/state changes. That's the point of the fix and matches what #6934 asked for, but an interrupt UI that displays live agent data would need its own useAgent.
Separately, and not for this PR: use-capabilities.tsx:20 has the same shape — useAgent({ agentId }) where only agent.capabilities is read. Worth checking whether it wants the same treatment, though capabilities may arrive asynchronously and rely on the re-render.
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
fix #6934
useInterrupt only needs the agent handle - interrupt events arrive via its own direct agent.subscribe(). But useAgent() with no update filter force-updates the consumer on every message/state/run-status change. Passing updates: [] skips the re-render subscription entirely (use-agent early-returns on an empty list) while the agent handle still resolves.
Includes a regression test asserting the hook opts out of agent updates.
Summary by CodeRabbit