Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Dec 5, 2025

Summary

Fix copilot function execute tool

Type of Change

  • Bug fix

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 5, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 5, 2025 11:18pm

@Sg312 Sg312 merged commit 656dfaf into staging Dec 5, 2025
5 checks passed
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 5, 2025

Greptile Overview

Greptile Summary

This PR fixes multiple issues with the copilot function execute tool by improving the tool call handling component. The main changes address race conditions in button interactions, unreliable backend notifications for skipped tools, inconsistent state naming, and poor UI feedback during tool execution.

The fix implements race condition prevention using React refs to prevent multiple simultaneous button clicks, adds retry logic for backend notifications when tools are skipped (preventing agent hangs), standardizes state naming from 'errored' to 'error', and provides immediate UI feedback when tools start executing. Additionally, it improves auto-allowed tool management for set_environment_variables and function_execute tools with proper clickable handlers.

This change integrates with the existing copilot architecture by enhancing the tool call component that manages user interactions with AI agent tools, ensuring reliable state synchronization between frontend and backend for integration tools that require server-side execution.

Important Files Changed

Filename Score Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx 4/5 Enhanced tool call handling with race condition prevention, improved error handling, and better UI feedback

Confidence score: 4/5

  • This PR addresses legitimate issues with race conditions and backend synchronization that could cause real problems in production
  • Score reflects well-structured improvements to critical user interaction flows, though the complexity of async state management requires careful review
  • Pay close attention to the race condition prevention logic and backend notification retry mechanism to ensure proper state synchronization

Sequence Diagram

sequenceDiagram
    participant User
    participant ToolCall as "ToolCall Component"
    participant CopilotStore as "Copilot Store"
    participant Backend as "Backend API"
    participant ClientTool as "Client Tool"

    User->>ToolCall: "Interacts with tool call UI"
    ToolCall->>CopilotStore: "Get tool call state"
    CopilotStore-->>ToolCall: "Return tool call data"
    
    alt Tool is expandable and pending
        ToolCall->>ToolCall: "Set expanded state to true"
    end
    
    User->>ToolCall: "Clicks Run/Allow button"
    ToolCall->>ToolCall: "Set processing state"
    
    alt Integration tool (server-side)
        ToolCall->>CopilotStore: "setToolCallState('executing')"
        ToolCall->>CopilotStore: "executeIntegrationTool(toolCallId)"
        CopilotStore->>Backend: "Execute integration tool"
        Backend-->>CopilotStore: "Tool execution result"
        alt Execution fails
            ToolCall->>Backend: "POST /api/copilot/tools/mark-complete (error)"
        end
    else Client tool
        ToolCall->>ClientTool: "handleAccept(editedParams)"
        ClientTool-->>ToolCall: "Tool execution result"
    end
    
    User->>ToolCall: "Clicks Always Allow button"
    ToolCall->>CopilotStore: "addAutoAllowedTool(toolName)"
    ToolCall->>ToolCall: "Execute tool (same as Run flow)"
    
    User->>ToolCall: "Clicks Skip button"
    alt Integration tool
        ToolCall->>CopilotStore: "setToolCallState('rejected')"
        ToolCall->>Backend: "POST /api/copilot/tools/mark-complete (skipped)"
    else Client tool
        ToolCall->>ClientTool: "handleReject()"
        ToolCall->>CopilotStore: "setToolCallState('rejected')"
    end
    
    User->>ToolCall: "Edits parameters"
    ToolCall->>ToolCall: "setEditedParams(newParams)"
    
    User->>ToolCall: "Clicks Move to Background"
    ToolCall->>ClientTool: "setState('background')"
    ToolCall->>ClientTool: "markToolComplete(200, message)"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

})
} catch {
// Last resort: log error if we can't notify backend
console.error('[handleRun] Failed to notify backend of tool error:', toolCall.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Using console.error violates the logging rules - should use logger.error instead

Suggested change
console.error('[handleRun] Failed to notify backend of tool error:', toolCall.id)
logger.error('[handleRun] Failed to notify backend of tool error:', toolCall.id)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx
Line: 321:321

Comment:
**style:** Using `console.error` violates the logging rules - should use logger.error instead

```suggestion
        logger.error('[handleRun] Failed to notify backend of tool error:', toolCall.id)
```

How can I resolve this? If you propose a fix, please make it concise.

}

if (!notified) {
console.error('[handleSkip] Failed to notify backend after 3 attempts:', toolCall.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Using console.error violates the logging rules - should use logger.error instead

Suggested change
console.error('[handleSkip] Failed to notify backend after 3 attempts:', toolCall.id)
logger.error('[handleSkip] Failed to notify backend after 3 attempts:', toolCall.id)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx
Line: 378:378

Comment:
**style:** Using `console.error` violates the logging rules - should use logger.error instead

```suggestion
      logger.error('[handleSkip] Failed to notify backend after 3 attempts:', toolCall.id)
```

How can I resolve this? If you propose a fix, please make it concise.

@waleedlatif1 waleedlatif1 deleted the fix/copilot-function-execute branch December 7, 2025 02:15
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.

2 participants