Skip to content

fix(react-core): stop useInterrupt re-renders on agent updates - #6969

Merged
lukasmoschitz merged 1 commit into
CopilotKit:mainfrom
deepshekhardas:fix/6934-use-interrupt-no-rerender
Sep 10, 2026
Merged

lukasmoschitz merged 1 commit into
CopilotKit:mainfrom
deepshekhardas:fix/6934-use-interrupt-no-rerender

Conversation

@deepshekhardas

@deepshekhardas deepshekhardas commented Sep 9, 2026 •

Copy link
Copy Markdown

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

  • Bug Fixes
    • Improved interrupt handling by preventing unnecessary re-renders when unrelated agent updates occur.
    • Interrupt-related behavior now remains stable when chat rendering is disabled.

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.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 0459b637-e08b-44ee-bee6-97a5dd488bca

📥 Commits

Reviewing files that changed from the base of the PR and between ad6d42a and e2887b4.

📒 Files selected for processing (2)
  • packages/react-core/src/v2/hooks/__tests__/use-interrupt.test.tsx
  • packages/react-core/src/v2/hooks/use-interrupt.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Interrupt render control

Layer / File(s) Summary
Disable agent updates
packages/react-core/src/v2/hooks/use-interrupt.tsx, packages/react-core/src/v2/hooks/__tests__/use-interrupt.test.tsx
useInterrupt passes updates: [] to useAgent. The test verifies that the hook opts out of agent update re-renders.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e2887

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing useInterrupt from re-rendering when agent updates occur.
Linked Issues check ✅ Passed The changes satisfy issue #6934. useInterrupt now passes updates: [] to useAgent, which prevents re-renders from agent events while preserving the direct agent subscription. The regression test verifi…
Out of Scope Changes check ✅ Passed All changes are directly related to issue #6934. The implementation update and regression test address useInterrupt re-render behavior without unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lukasmoschitz lukasmoschitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown
@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@6969

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@6969

@copilotkit/angular

pnpm add https://pkg.pr.new/@copilotkit/angular@6969

@copilotkit/channels

pnpm add https://pkg.pr.new/@copilotkit/channels@6969

@copilotkit/channels-core

pnpm add https://pkg.pr.new/@copilotkit/channels-core@6969

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/@copilotkit/channels-discord@6969

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/@copilotkit/channels-intelligence@6969

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/@copilotkit/channels-slack@6969

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/@copilotkit/channels-teams@6969

@copilotkit/channels-telegram

pnpm add https://pkg.pr.new/@copilotkit/channels-telegram@6969

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/@copilotkit/channels-ui@6969

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/@copilotkit/channels-whatsapp@6969

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@6969

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@6969

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@6969

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@6969

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@6969

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@6969

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@6969

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@6969

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@6969

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@6969

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@6969

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@6969

@copilotkit/web-components

pnpm add https://pkg.pr.new/@copilotkit/web-components@6969

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@6969

commit: e2887b4

@lukasmoschitz
lukasmoschitz merged commit 35c1e80 into CopilotKit:main Sep 10, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: useInterrupt causes re-renders

2 participants