Tool Confirmation Bug Fix
Note: For complete tool confirmation documentation, see Tool Confirmation System
Bug Description
When using the refactored EmissaryRefactored component, tool confirmation was failing with the error:
No user message found to resend with confirmed tools
The bug manifested as:
- User clicks “Confirm Tools” button
- Tools are confirmed (logged to console)
- Error message appears: “No user message found to resend with confirmed tools”
- Tool confirmation state is cleared
- No API call is made
- User sees no response despite clicking confirm
Root Cause
The ToolConfirmationContext was not properly accessing messages from the MessageStreamingContext.
Specific Issue: In ToolConfirmationContext.tsx line 140:
const messages = messageContext?.messages || [];
The messageContext prop was undefined because:
ToolConfirmationContextimporteduseMessageStreamingbut didn’t use it- It relied on a
messageContextprop that wasn’t being passed correctly in the refactored context hierarchy - This resulted in an empty messages array being passed to
getLastUserMessage() getLastUserMessage([])returnednull- The error was triggered and tool confirmation failed
Solution
Modified ToolConfirmationContext.tsx to properly use the MessageStreamingContext:
Changes Made:
- Added context usage (line 63):
const messageStreamingContext = useMessageStreaming(); - Fixed message access (line 140): ```typescript // Before: const messages = messageContext?.messages || [];
// After: const messages = messageStreamingContext?.messages || messageContext?.messages || [];
3. **Updated dependencies** (line 206):
```typescript
}, [state.confirmedTools, messageStreamingContext, messageContext, clearConfirmation, setProcessingConfirmation]);
How the Fix Works
ToolConfirmationContextnow directly accesses theMessageStreamingContextviauseMessageStreaming()- Messages are retrieved from the active context:
messageStreamingContext?.messages - Falls back to the prop-based approach for backwards compatibility:
messageContext?.messages getLastUserMessage()receives the actual messages array instead of empty array- Last user message is found successfully
- Tool confirmation proceeds with the API call
- User sees the expected response
Testing
The fix was verified to:
- ✅ Properly access messages from
MessageStreamingContext - ✅ Allow
getLastUserMessage()to find user messages - ✅ Enable successful tool confirmation flow
- ✅ Maintain backwards compatibility with prop-based message passing
- ✅ Pass TypeScript compilation
- ✅ Pass build process
Impact
This fix resolves the tool confirmation failure in the refactored EmissaryRefactored component, allowing users to:
- Successfully confirm tool configurations
- See API responses after tool confirmation
- Use the refactored app without encountering this blocking error
The fix maintains backward compatibility and doesn’t break existing functionality.