Skip to content

fix hitl bug after reconnect - #2900

Merged
mme merged 1 commit into
mainfrom
mme/connect-hitl-continue
Dec 22, 2025
Merged

mme merged 1 commit into
mainfrom
mme/connect-hitl-continue

Conversation

@mme

@mme mme commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

(Describe the changes introduced in this PR)

Related PRs and Issues

  • (Direct link to related PR or issue, if relevant)

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of human-in-the-loop interactions during reconnection scenarios
    • Enhanced tool execution state tracking to persist reliably across component remounts and thread reconnections
  • Tests

    • Added comprehensive end-to-end test coverage for reconnection edge cases and late-mounting scenarios

✏️ Tip: You can customize this high-level summary in your review settings.

@changesets-bot-copilotkit

Copy link
Copy Markdown

⏭️ Changeset Not Required

Latest commit: a7e790e

No changes in this PR affected the @copilitkit/* packages. Merging this PR will not cause a version bump for any packages.

Changeset is not required for this PR.

@vercel

vercel Bot commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Dec 19, 2025 5:12pm
examples-coagents-ai-travel-app Ready Ready Preview, Comment Dec 19, 2025 5:12pm
examples-coagents-research-canvas-ui Ready Ready Preview, Comment Dec 19, 2025 5:12pm
1 Skipped Deployment
Project Deployment Review Updated (UTC)
examples-coagents-ai-researcher-ui Ignored Ignored Dec 19, 2025 5:12pm

@coderabbitai

coderabbitai Bot commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds HITL thread reconnection support via MockReconnectableAgent for testing, migrates executing tool call state tracking from local hook state to CopilotKitProvider context, and extends e2e tests to validate reconnection behavior and state persistence across component remounts and lifecycle edge cases.

Changes

Cohort / File(s) Summary
Test Helpers & Mock Infrastructure
src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
Introduces MockReconnectableAgent class extending AbstractAgent with event storage and replay capabilities. Stores emitted events, replays them on connect() with async delay, and manages internal subject and storedEvents. Updates isRunning state based on RUN_STARTED, RUN_FINISHED, and RUN_ERROR events. Adds rxjs from and delay imports.
Provider-Level State Management
src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
Extends CopilotKitContextValue with executingToolCallIds: ReadonlySet<string> field. Adds provider-level effects to subscribe to onToolExecutionStart and onToolExecutionEnd events, updating the set accordingly. Initializes context with EMPTY_SET default and propagates executing tool call IDs to consumers.
Hook State Refactoring
src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
Removes local useState and useEffect tracking of executing tool calls. Refactors isExecuting to source from provider context via useCopilotKit() instead of local state. Retains useSyncExternalStore subscription and memoized rendering logic.
E2E Test Suite Enhancements
src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
Adds waitFor assertion in "Tool Executing State" test to ensure statusHistory contains ToolCallStatus.Complete, aligning with React re-render cycle timing.
HITL Reconnection E2E Tests
src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
Adds comprehensive test suite "HITL Thread Reconnection Bug" with multiple e2e test cases covering: reconnection with pending HITL, event replay via connect(), fresh run after reconnect, sequential HITL tool calls, late-mounting components, and state persistence across remounts. Introduces MockReconnectableAgent import and act from testing-library. Includes various HITL tool definitions and UI assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Agent as MockReconnectableAgent
    participant Provider as CopilotKitProvider
    participant Hook as use-render-tool-call
    
    Test->>Agent: Emit RUN_STARTED event
    Agent->>Agent: Store event, update isRunning=true
    Agent->>Provider: Propagate event
    Provider->>Provider: Subscribe to onToolExecutionStart
    Provider->>Provider: Update executingToolCallIds (add ID)
    
    Test->>Agent: Emit tool execution events
    Agent->>Agent: Store events
    Agent->>Provider: Propagate events
    
    Test->>Agent: Emit RUN_FINISHED event
    Agent->>Agent: Store event, update isRunning=false
    Agent->>Provider: Propagate event
    Provider->>Provider: Subscribe to onToolExecutionEnd
    Provider->>Provider: Update executingToolCallIds (remove ID)
    
    rect rgb(220, 240, 250)
        Note over Test,Agent: Reconnection scenario
        Test->>Agent: Call connect() (replay)
        Agent->>Agent: Retrieve storedEvents
        Agent->>Agent: Return Observable with delay(10)
        Agent->>Provider: Stream replayed events
    end
    
    Provider->>Hook: Provide executingToolCallIds via context
    Hook->>Hook: useCopilotKit() retrieves executingToolCallIds
    Hook->>Hook: Render based on isExecuting from context
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Areas requiring extra attention:

  • State synchronization boundaries: Verify that migrating executingToolCallIds from local hook state to provider context doesn't introduce race conditions during reconnection or rapid tool execution transitions. Cross-check effects in CopilotKitProvider and hook subscription logic in use-render-tool-call.tsx.
  • MockReconnectableAgent event replay semantics: Validate that the delay(10) per event and event storage mechanism accurately simulate reconnection scenarios. Confirm stored events are correctly ordered and not lost during state transitions.
  • E2E test coverage of edge cases: Review the new HITL reconnection test suite for consistency of status transitions (InProgress → Executing → Complete) across remounts and late-mounting scenarios. Verify provider-level state tracking persists correctly.
  • Context initialization and cleanup: Ensure EMPTY_SET default and provider effect cleanup (subscription disposal) prevent memory leaks and undefined state access.

Suggested labels

preview

Suggested reviewers

  • ataibarkai
  • ranst91
  • tylerslaton

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title refers to fixing a 'hitl bug after reconnect', which aligns with the actual changeset that adds MockReconnectableAgent, provider-level execution tracking, and HITL reconnection test cases.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mme/connect-hitl-continue

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 and usage tips.

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx (1)

964-1049: Consider test isolation for mutable outer variables.

The test uses mutable outer variables (showTool, setShowTool) that are assigned inside the component. While functional, this pattern can cause test isolation issues if tests run in parallel or if the component re-renders unexpectedly.

🔎 Alternative using React ref pattern

Consider using a ref or state pattern that's more explicit about the control flow:

-    let showTool = false;
-    let setShowTool: (show: boolean) => void;
+    const setShowToolRef = { current: (_: boolean) => {} };

     const ToggleableHITL: React.FC = () => {
       const [show, setShow] = useState(false);
-      showTool = show;
-      setShowTool = setShow;
+      setShowToolRef.current = setShow;
       // ...
     };

     // Later in test:
-    act(() => {
-      setShowTool(true);
-    });
+    act(() => {
+      setShowToolRef.current(true);
+    });
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb4f809 and a7e790e.

📒 Files selected for processing (5)
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx (2 hunks)
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx (1 hunks)
  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx (3 hunks)
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx (3 hunks)
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
src/v2.x/packages/react/**/*.{test,spec}.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/CLAUDE.md)

React components must be tested with @testing-library/react using Vitest with jsdom environment. Runtime code must use Node environment for testing.

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Import and use CopilotProvider from '@copilotkit/react-core' as the main provider component at the root of your React application
Use useCopilotChat hook from '@copilotkit/react-core' for implementing chat functionality
Use useCopilotAction hook from '@copilotkit/react-core' to define actions that agents can execute
Use useCopilotReadable hook from '@copilotkit/react-core' to expose application state to agents
Use CopilotChat component from '@copilotkit/react-ui' for implementing pre-built chat interface UI
Use CopilotPopup component from '@copilotkit/react-ui' for implementing popup chat interface
Use CopilotSidebar component from '@copilotkit/react-ui' for implementing sidebar chat interface
Use CopilotTextarea component from '@copilotkit/react-textarea' for implementing AI-enhanced textarea with auto-completion and suggestions

Always use the provided hooks and functions to modify suggestions state - never modify suggestions state directly

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
**/*.{tsx,jsx,html}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Use Tailwind CSS for styling UI components and maintain consistent styling across the application

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/quick-reference.mdc)

For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Test with missing API keys to ensure your app doesn't infinite loop on network errors

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
src/v2.x/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/20-typescript.auto.mdc)

src/v2.x/**/*.{ts,tsx}: Prefer type aliases over interface for data structures in TypeScript
Avoid any in TypeScript; use explicit generics or unknown where necessary
Files should be named in kebab-case.ts or kebab-case.tsx with a single export per file

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
src/v2.x/**/*.{spec,test}.{ts,tsx}

📄 CodeRabbit inference engine (src/v2.x/.cursor/rules/50-vitest.auto.mdc)

src/v2.x/**/*.{spec,test}.{ts,tsx}: Use the Arrange-Act-Assert pattern in tests
Import vi from 'vitest' for mocking functions (use vi.fn(), vi.spyOn(), etc.)

Files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
🧠 Learnings (26)
📓 Common learnings
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Test components with different agent configurations to ensure proper integration
📚 Learning: 2025-12-18T18:09:47.478Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/CLAUDE.md:0-0
Timestamp: 2025-12-18T18:09:47.478Z
Learning: Applies to src/v2.x/packages/react/**/*.{test,spec}.{ts,tsx} : React components must be tested with testing-library/react using Vitest with jsdom environment. Runtime code must use Node environment for testing.

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:53.444Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/50-vitest.auto.mdc:0-0
Timestamp: 2025-12-18T18:11:53.444Z
Learning: Applies to src/v2.x/**/*.{spec,test}.{ts,tsx} : Use the Arrange-Act-Assert pattern in tests

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:53.444Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/50-vitest.auto.mdc:0-0
Timestamp: 2025-12-18T18:11:53.444Z
Learning: Applies to src/v2.x/**/vitest.config.{js,mjs,ts} : Use Vitest for all testing; see `packages/react/vitest.config.mjs` and `packages/runtime/vitest.config.mjs` for examples

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/*.test.{ts,tsx} : Test with missing API keys to ensure your app doesn't infinite loop on network errors

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `useCopilotReadable` hook from 'copilotkit/react-core' to expose application state to agents

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to examples/e2e/**/*.{ts,tsx,js} : For running tests, use examples/e2e for end-to-end testing and configure Playwright with playwright.config.ts

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:58.438Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/packages/runtime/.cursor/rules/runtime.always.mdc:0-0
Timestamp: 2025-12-18T18:11:58.438Z
Learning: Applies to src/v2.x/packages/runtime/src/__tests__/**/*.{ts,tsx} : Vitest tests reside in `src/__tests__/` and use Node environment

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/hooks/use-copilot-chat.ts : In react-core use-copilot-chat.ts hook, implement and expose functions for suggestions control: suggestions getter, setSuggestions, generateSuggestions, resetSuggestions, and isLoadingSuggestions state

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:09:47.478Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/CLAUDE.md:0-0
Timestamp: 2025-12-18T18:09:47.478Z
Learning: Always verify UI changes with Playwright when available, especially when matching behavior between frameworks (React/Angular). Continue working on UI issues until they are fully resolved and verified with Playwright or other testing tools.

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:10:31.160Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/development-workflow.mdc:0-0
Timestamp: 2025-12-18T18:10:31.160Z
Learning: End-to-end testing uses Playwright with configuration at examples/e2e/playwright.config.ts and test results stored in examples/e2e/test-results/

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to {registry,src/v1.x/packages/react-ui}/**/*.{tsx,ts} : For customizing UI components, browse registry for reusable components, check docs/components/react for documentation, and use react-ui for pre-built components

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `useCopilotAction` hook from 'copilotkit/react-core' to define actions that agents can execute

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Applies to **/*.{tsx,ts,jsx,js} : For building a simple Copilot, start with copilot-chat-with-your-data example, use react-core package for basic integration, and add react-ui package for pre-built components

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `CopilotChat` component from 'copilotkit/react-ui' for implementing pre-built chat interface UI

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `useCopilotChat` hook from 'copilotkit/react-core' for implementing chat functionality

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:11:01.653Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-12-18T18:11:01.653Z
Learning: Frontend applications should follow the common pattern of Next.js app with CopilotProvider and CopilotChat components

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Use `CopilotPopup` component from 'copilotkit/react-ui' for implementing popup chat interface

Applied to files:

  • src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx
  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/hooks/use-copilot-chat.ts : Use React effect dependencies that include configuration to trigger suggestion generation when configuration becomes available

Applied to files:

  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/*.{ts,tsx} : Always use the provided hooks and functions to modify suggestions state - never modify suggestions state directly

Applied to files:

  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/context/copilot-context.tsx : In react-core copilot-context.tsx, store and manage the actual suggestions state as the provider/context

Applied to files:

  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Applies to **/*.{ts,tsx} : Import and use `CopilotProvider` from 'copilotkit/react-core' as the main provider component at the root of your React application

Applied to files:

  • src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx
  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:10:15.706Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/copilotkit-architecture.mdc:0-0
Timestamp: 2025-12-18T18:10:15.706Z
Learning: Core React components and hooks for CopilotKit should be located in the react-core package

Applied to files:

  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:11:20.345Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-12-18T18:11:20.345Z
Learning: Applies to **/{suggestions.ts,use-copilot-chat.ts} : Handle race conditions between component mounting and configuration registration by waiting for chatSuggestionConfiguration to be populated before generating initial suggestions

Applied to files:

  • src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx
📚 Learning: 2025-12-18T18:11:53.444Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: src/v2.x/.cursor/rules/50-vitest.auto.mdc:0-0
Timestamp: 2025-12-18T18:11:53.444Z
Learning: Applies to src/v2.x/**/*.{spec,test}.{ts,tsx} : Import `vi` from 'vitest' for mocking functions (use `vi.fn()`, `vi.spyOn()`, etc.)

Applied to files:

  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
📚 Learning: 2025-12-18T18:10:47.795Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-12-18T18:10:47.795Z
Learning: Test components with different agent configurations to ensure proper integration

Applied to files:

  • src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx
🧬 Code graph analysis (2)
src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx (1)
src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx (6)
  • MockReconnectableAgent (66-118)
  • renderWithCopilotKit (123-171)
  • testId (309-311)
  • runStartedEvent (176-178)
  • toolCallChunkEvent (266-284)
  • runFinishedEvent (183-185)
src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx (1)
src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx (1)
  • useCopilotKit (372-392)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
  • GitHub Check: mastra-agent-local
  • GitHub Check: build (coagents-routing, agent, python, local-deps)
  • GitHub Check: build (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: llama-index
  • GitHub Check: build (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: langgraph-python
  • GitHub Check: aws-strands
  • GitHub Check: build (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: build (coagents-routing, ui)
  • GitHub Check: a2a-middleware
  • GitHub Check: mastra
  • GitHub Check: build (next-openai, next-openai)
  • GitHub Check: crew-ai
  • GitHub Check: build (coagents-routing, agent, js, local-deps)
  • GitHub Check: pydantic-ai
  • GitHub Check: middleware-starter
  • GitHub Check: langgraph-typescript
  • GitHub Check: agno
  • GitHub Check: langgraph-fastapi
  • GitHub Check: build (coagents-research-canvas, ui)
  • GitHub Check: adk-middleware
  • GitHub Check: server-starter
  • GitHub Check: build (coagents-qa-text, ui)
  • GitHub Check: server-starter-all
  • GitHub Check: build (coagents-qa-native, ui)
  • GitHub Check: unit / v2.x (20.x)
  • GitHub Check: unit / v2.x (22.x)
  • GitHub Check: unit / v1.x (22.x)
  • GitHub Check: unit / v2.x (24.x)
  • GitHub Check: unit / v1.x (20.x)
  • GitHub Check: unit / v1.x (24.x)
🔇 Additional comments (17)
src/v2.x/packages/react/src/hooks/__tests__/use-frontend-tool.e2e.test.tsx (1)

1031-1048: LGTM! Async waiting aligns with provider-level state tracking.

The added waitFor assertion correctly accounts for the React re-render cycle when ToolCallStatus.Complete propagates through the provider context. The 3-second timeout is reasonable for test stability, and the subsequent order verification ensures the state machine transitions correctly (InProgress → Executing → Complete).

src/v2.x/packages/react/src/hooks/use-render-tool-call.tsx (4)

1-1: Clean import adjustment.

Correctly removed useState and useEffect since the local state tracking is now handled at the provider level.


104-104: Provider-level state access is correct.

Destructuring executingToolCallIds from useCopilotKit() aligns with the provider changes and ensures this hook receives the centralized execution state.


120-124: Excellent documentation of the design rationale.

This comment clearly explains why the execution state is tracked at the provider level rather than locally. This is valuable context for future maintainers understanding the HITL reconnection timing requirements.


153-166: Correct dependency array update.

The useCallback now correctly includes executingToolCallIds in its dependencies, ensuring the callback is recreated when the executing state changes. This is necessary for accurate isExecuting derivation.

src/v2.x/packages/react/src/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx (6)

2-2: Correct import addition.

The act import from @testing-library/react is needed for wrapping state updates in the new reconnection tests, ensuring React batches updates correctly.


12-12: Test utility import for reconnection scenarios.

MockReconnectableAgent is properly imported to support the new HITL reconnection test cases.


654-769: Well-documented reconnection test case.

This test clearly documents the timing challenge (events firing before child components mount) and verifies the fix works across unmount/remount cycles. The two-phase approach (initial render → unmount → remount with replay) effectively simulates a page reload scenario.


771-850: Good regression test for normal flow.

This test ensures the reconnection fix doesn't break the standard HITL flow (InProgress → Executing → Complete transitions during a fresh run). Important for preventing regressions.


852-962: Sequential HITL execution test is thorough.

Validates that HITL tools execute one at a time (second tool stays InProgress until first completes), which is the expected behavior for followUp: true tools. The test effectively covers the entire state machine for both tools.


1051-1142: Key test for provider-level state persistence.

This test directly validates the core fix: executingToolCallIds survives component remounts because it's tracked at the provider level. The key prop remount approach is a clean way to force component recreation while keeping the provider stable.

src/v2.x/packages/react/src/providers/CopilotKitProvider.tsx (4)

25-31: Good type extension with clear documentation.

The JSDoc comment explains why this is tracked at the provider level, which is crucial context for understanding the HITL reconnection fix.


33-39: Proper default value initialization.

Using a module-level EMPTY_SET constant avoids creating new Set instances on every render for the default context value. The ReadonlySet type correctly prevents mutation by consumers.


318-348: Correct subscription pattern with proper cleanup.

The implementation correctly:

  1. Uses functional state updates to avoid stale closure issues (prev => ...)
  2. Avoids unnecessary re-renders by checking prev.has() before creating new Sets
  3. Creates new Set instances for immutability
  4. Properly cleans up the subscription on unmount

The dependency on copilotkit in the effect ensures the subscription is recreated if the core instance changes.


358-368: Context value correctly exposes new state.

The executingToolCallIds is properly passed to the context provider, making it available to all child components via useCopilotKit().

src/v2.x/packages/react/src/__tests__/utils/test-helpers.tsx (2)

13-13: Correct rxjs imports for replay functionality.

The from and delay operators are needed for the connect() method's event replay behavior.


61-118: Well-designed test helper for reconnection scenarios.

The MockReconnectableAgent effectively simulates HITL reconnection by:

  1. Storing events during run() for later replay
  2. Replaying stored events with a 10ms delay in connect() to simulate async transport
  3. Providing reset() to reinitialize the subject between test phases

The comment on line 114-115 clearly explains the purpose of the delay. The implementation mirrors MockStepwiseAgent patterns for consistency.

One consideration: the 10ms delay is hardcoded. If tests become flaky, you might need to make this configurable, but it's fine for now.

Based on learnings, this test helper follows the pattern of testing with different agent configurations to ensure proper integration.

@github-actions

github-actions Bot commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

Preview environments destroyed for this pull request.

@github-actions

github-actions Bot commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ❌ Failed (View Run)

Commit: f2ee4cf

Duration: 1582.4s

Total Tests: 37

Pass Rate: 5.4%

Failed Tests: 35

❌ Failed Tests

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video
OpenAI (LGC Python) chromium ❌ FAILED Video
Anthropic (LGC Python) chromium ❌ FAILED Video
OpenAI (LGC JS) chromium ❌ FAILED Video
Anthropic (LGC JS) chromium ❌ FAILED Video

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ❌ FAILED Video, Video, Video, Video, Video, Video
Anthropic chromium ❌ FAILED Video, Video, Video, Video, Video, Video
LangChain (OpenAI) chromium ❌ FAILED Video, Video, Video, Video, Video, Video
Groq chromium ❌ FAILED Video, Video, Video, Video, Video, Video

This branch was successfully deployed

3 active deployments
Preview – docs — a7e790e9 Deployed Dec 19, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — a7e790e9 Deployed Dec 19, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — a7e790e9 Deployed Dec 19, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant