Repository navigation
fix(react-core): wait for the user on humanInTheLoop provider tools - #6851
Conversation
|
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 (4)
🚧 Files skipped from review as they are similar to previous changes (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe React provider keeps human-in-the-loop tool calls pending until ChangesReact provider HITL lifecycle
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The provider now waits for human responses, handles aborts, and preserves wildcard tool names. No concrete merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
@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: |
|
Size Change: +1.45 kB (+0.09%) Total Size: 1.65 MB 📦 View Changed
ℹ️ View Unchanged
|
2acc641 to
28531fc
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
The `humanInTheLoop` prop on `CopilotKitProvider` registered a handler that warned and resolved `undefined` the moment the agent invoked it, and it registered the renderer unwrapped, so the render never received a working `respond`. A tool declared that way jumped straight to Complete over dead controls while the agent was told the tool had succeeded. The placeholder is unchanged since the first v2 provider commit (a2ef51a), so this documented prop has never waited on the user. It fails the same way on both transports. Match the `useHumanInTheLoop` semantics: park the tool call until the render calls `respond`, expose `respond` only while the status is Executing, and reject with 'Human-in-the-loop interaction aborted' when the run is aborted so core records an explicit error tool result (#5554). Pending interactions are keyed by tool call id, and a wildcard registration keeps the invoked tool's name rather than "*". Two existing unit tests asserted the placeholder behavior (the console warning and render identity). They now assert the waiting contract and that the wrapper renders the caller's component. Mirrors the Vue fix in #6527. Related: #4953 (the provider-prop half of that report) and #4955. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
28531fc to
2031643
Compare
Summary
A human-in-the-loop tool declared through the
humanInTheLoopprop on<CopilotKitProvider>never waited for the user. The handler resolvedundefinedthe moment the agent invoked it, and the renderer was registered unwrapped, so it never received a workingrespond. The card appeared once atCompleteover dead controls while the agent was told the tool had succeeded.This is not a regression. The placeholder handler is unchanged since the first v2 provider commit (
a2ef51aaf3, #2794), so this documented prop has never waited. The reference page describes it as self-sufficient: "Declarative human-in-the-loop tool definitions. Each becomes both a tool handler and a tool call renderer." TheuseHumanInTheLoophook path is unaffected and has always worked.Changes
packages/react-core/src/v2/providers/CopilotKitProvider.tsx, matchinguseHumanInTheLoop:respond, keyed by tool call id so one call of a tool cannot resolve anotherrespondlive only while the status isExecutingHuman-in-the-loop interaction abortedon abort, so core records an explicit error tool result rather than an empty success (Bug: renderAndWaitForResponse silently completes on user abandonment — no timeout, no error propagation to agent #5554)"*") registration instead of overwriting it with"*"Two existing unit tests asserted the placeholder behavior (the
console.warn, and render identity). They now assert the waiting contract and that the wrapper renders the caller's component.Testing
New:
CopilotKitProvider.hitl.e2e.test.tsx(4 tests). These mount the real pipeline —CopilotChat-> tool calls view -> the provider's registered renderer — rather than calling the renderer directly, so a mismatch between the key the handler parks under and the tool call id the pipeline supplies cannot pass.All four fail on
mainfor the right reason (Unable to find an element by: [data-testid="hitl-respond"]— the respond button never appears), and pass with the change.Each mechanism was mutation-checked separately:
respondfailSuite, types, format
oxfmtapplied to every changed file. The fullreact-corerun also has 7 failures acrossCopilotChatView.pinToSend.test.tsxanduse-pin-to-send.test.tsx(ResizeObserver is not a constructor). Those are pre-existing: I removed this change from the working tree and ran those two files on cleanmain, and they fail identically.Live, in
examples/v2/react/demoagainst a real agent and a rebuilt distcomplete,respondundefined, console warned, agent said "Please pick a time slot in the scheduler UI to confirm" over disabled buttonsexecutingwith live buttons for 17s, then "Booked a call with Sam about the Waterfall project meeting for Tue 14:00"useHumanInTheLoophook, multi-route RESTinProgress->executing->completewith the chosen slot reaching the agentCredit
@Tushar-Khandelwal-2004 diagnosed this path and implemented the parking handler and the abort semantics first, in #4955. That PR predates the wildcard-name work and the current
main, and its review asks were still open, so this lands the same fix rebased onmainwith the wildcard branch and pipeline-level tests added. #4955 is now closed in favor of this PR, with the credit staying with them.Related
useHumanInTheLoopsilently fails under the default multi-route transport (CopilotKitProvider) #4953 — the reporter hit the hook path, which does not reproduce onmain; this is the confirmed provider-prop half of that reportAngular already implements this path (
addHumanInTheLoop->#hitl.onResult), so React was the last framework missing it.Summary by CodeRabbit
New Features
Bug Fixes