Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Jan 16, 2026

Summary

Fix copilot server bugs
Adds a few ux improvements (continue options, options outside thinking text, diff on new chat)

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 Jan 16, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 16, 2026 9:28pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 16, 2026

Greptile Summary

This PR fixes several copilot server bugs and adds UX improvements including continue options, cleaner option displays, and diff display on new chats.

Key Changes:

  • Mode handling: Fixed mode transformation logic where agent mode is now properly converted to build internally while maintaining agent for transport
  • Model selection: Corrected provider config to use selectedModel for non-Azure/Vertex providers instead of always using envModel
  • Array subblock normalization: Generalized ID normalization from inputFormat-only to all array subblocks (headers, params, variables, metrics, etc.) with UUID validation
  • Deployment tools: Enhanced deploy_chat and deploy_mcp to handle updates gracefully by fetching existing deployments and using PATCH instead of failing
  • Empty diff detection: Added logic to skip diff view when no meaningful changes are detected
  • Tool execution: Fixed duplicate execution in edit-workflow by moving hasExecuted check outside timeout wrapper
  • Checkpoint management: Improved checkpoint cleanup to clear all checkpoints and properly trigger callbacks
  • Continue options: Added support for <options> tags to show continue prompts after assistant responses
  • Thinking tag cleanup: Added stripThinkingTags to handle persisted messages with escaped tags

Confidence Score: 4/5

  • This PR is safe to merge with thorough testing of deployment flows
  • The changes fix real bugs and improve UX, but involve complex state management in the copilot store and mode transformation logic that should be carefully tested. The deployment tool enhancements (update vs create) add fallback logic that could have edge cases. No critical security issues or data loss risks detected.
  • Pay close attention to apps/sim/stores/panel/copilot/store.ts (complex refactoring) and deployment tools (deploy-chat.ts, deploy-mcp.ts) for proper update/create flow handling

Important Files Changed

Filename Overview
apps/sim/app/api/copilot/chat/route.ts Refactored model enums to use centralized constants, added mode transformation logic (agent -> build), and fixed provider config to use correct model variable
apps/sim/stores/panel/copilot/store.ts Major refactoring: extracted helper functions for streaming, added checkpoint persistence logic, fixed tool abort handling to clear subAgentStreaming flag, and added continue options support
apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts Fixed array subblock ID normalization by generalizing from inputFormat-only to handle all array types (headers, params, variables, metrics, etc.) with UUID validation and generation
apps/sim/lib/copilot/tools/client/workflow/edit-workflow.ts Fixed duplicate execution issue by moving hasExecuted check outside executeWithTimeout and removed redundant markToolComplete logic for skipped executions
apps/sim/stores/workflow-diff/store.ts Added empty diff detection to skip diff view when no changes detected, and integrated checkpoint saving after successful diff application
apps/sim/lib/copilot/tools/client/workflow/deploy-chat.ts Improved to fetch existing deployment and merge with new args, added update support via PATCH endpoint, and reduced required field validation by using existing deployment values as fallbacks
apps/sim/lib/copilot/tools/client/workflow/deploy-mcp.ts Enhanced to handle "already added" errors by automatically updating existing tools via PATCH endpoint instead of failing

Sequence Diagram

sequenceDiagram
    participant User
    participant CopilotUI as Copilot UI
    participant CopilotStore as Copilot Store
    participant ChatAPI as Chat API Route
    participant EditTool as Edit Workflow Tool
    participant DeployTool as Deploy Tools
    participant DiffStore as Workflow Diff Store
    participant StatusAPI as Status API

    User->>CopilotUI: Send message (mode: 'agent')
    CopilotUI->>CopilotStore: sendMessage()
    CopilotStore->>CopilotStore: Capture workflow snapshot
    CopilotStore->>ChatAPI: POST /api/copilot/chat (mode: 'agent')
    ChatAPI->>ChatAPI: Transform mode: 'agent' → 'build'
    ChatAPI->>ChatAPI: Use selectedModel for non-azure/vertex
    ChatAPI-->>CopilotStore: Stream response
    
    alt Workflow Edit Tool Called
        CopilotStore->>EditTool: execute()
        EditTool->>EditTool: Check hasExecuted (prevent duplicates)
        EditTool->>EditTool: Normalize array subblock IDs
        EditTool->>DiffStore: Apply workflow diff
        DiffStore->>DiffStore: Check if diff is empty
        alt Diff has changes
            DiffStore->>DiffStore: Apply diff optimistically
            DiffStore->>CopilotStore: saveMessageCheckpoint()
            CopilotStore->>CopilotStore: Persist workflow snapshot
        else No changes detected
            DiffStore->>DiffStore: Skip diff view
        end
        EditTool-->>CopilotStore: markToolComplete()
    end
    
    alt Deploy Chat Tool Called
        CopilotStore->>DeployTool: execute()
        DeployTool->>StatusAPI: GET /api/workflows/{id}/chat/status
        StatusAPI-->>DeployTool: Return existing deployment
        alt Has existing deployment
            DeployTool->>DeployTool: Merge args with existing values
            DeployTool->>DeployTool: PATCH /api/chat/manage/{id}
        else No existing deployment
            DeployTool->>DeployTool: POST /api/chat
        end
        DeployTool-->>CopilotStore: markToolComplete()
    end
    
    alt Deploy MCP Tool Called
        CopilotStore->>DeployTool: execute()
        DeployTool->>DeployTool: POST /api/mcp/workflow-servers/{id}/tools
        alt Already exists error
            DeployTool->>DeployTool: Fetch existing tool
            DeployTool->>DeployTool: PATCH /api/mcp/workflow-servers/{id}/tools/{toolId}
            DeployTool-->>CopilotStore: Return updated tool
        else Success
            DeployTool-->>CopilotStore: Return new tool
        end
    end
    
    CopilotStore->>CopilotStore: Abort all in-progress tools
    CopilotStore->>CopilotStore: Clear subAgentStreaming flags
    CopilotStore->>CopilotUI: Update message with continue options
    CopilotUI-->>User: Display response with options
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.

25 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@Sg312
Copy link
Contributor Author

Sg312 commented Jan 16, 2026

@greptile

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.

26 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@Sg312 Sg312 merged commit 8361931 into staging Jan 16, 2026
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/copilot-bugs branch January 17, 2026 00:08
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