Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Jan 16, 2026

Summary

Fix copilot router block

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 11:49pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 16, 2026

Greptile Summary

This PR enhances the copilot router block validation to accept semantic handle formats in addition to internal UUID-based handles. The changes enable the copilot to use more readable handle formats like router-{blockId}-route-1 instead of router-{uuid}.

Key changes:

  • Added router_v2 case to handle validation with support for semantic handles (1-indexed route numbers and normalized titles)
  • Implemented conversion functions to transform internal UUID handles to semantic format in training data
  • Fixed notification filtering to only show workflow-specific notifications in diff controls

The implementation mirrors the existing condition block validation pattern and maintains backward compatibility by accepting both UUID and semantic formats.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows established patterns from condition block validation, maintains backward compatibility by accepting both handle formats, and includes proper error handling with descriptive messages. The notification filtering change is a straightforward improvement that uses existing store functionality.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts Added router_v2 validation case and validateRouterHandle function to accept semantic handles (router-{blockId}-route-N format) in addition to internal UUID handles
apps/sim/lib/workflows/sanitization/json-sanitizer.ts Added conversion functions to transform internal UUID-based handles to semantic format for both router and condition blocks in training data
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/diff-controls/diff-controls.tsx Filtered notifications to show only those relevant to the current workflow by checking workflowId field

Sequence Diagram

sequenceDiagram
    participant Copilot
    participant EditWorkflow
    participant Validation
    participant Sanitizer
    participant UI

    Note over Copilot,UI: Copilot Edit Flow with Semantic Handles
    
    Copilot->>EditWorkflow: edit_workflow with semantic handles<br/>(e.g., router-{blockId}-route-1)
    EditWorkflow->>Validation: validateSourceHandleForBlock
    
    alt Block type is router_v2
        Validation->>Validation: Check handle starts with "router-"
        Validation->>Validation: validateRouterHandle
        Validation->>Validation: Accept UUID format: router-{uuid}
        Validation->>Validation: Accept semantic format: router-{blockId}-route-N
        Validation->>Validation: Accept title format: router-{blockId}-{title}
        Validation-->>EditWorkflow: valid=true
    else Block type is condition
        Validation->>Validation: validateConditionHandle
        Validation-->>EditWorkflow: valid=true/false
    end
    
    EditWorkflow-->>Copilot: Edge created successfully
    
    Note over Sanitizer,UI: Sanitization for Training Data
    
    UI->>Sanitizer: sanitizeForCopilot(workflowState)
    Sanitizer->>Sanitizer: extractConnectionsForBlock
    
    loop For each edge
        Sanitizer->>Sanitizer: convertToSemanticHandle
        alt Router block
            Sanitizer->>Sanitizer: convertRouterHandleToSemantic<br/>(router-{uuid} → router-{blockId}-route-N)
        else Condition block
            Sanitizer->>Sanitizer: convertConditionHandleToSemantic<br/>(condition-{uuid} → condition-{blockId}-if)
        end
    end
    
    Sanitizer-->>UI: CopilotWorkflowState with semantic handles
Loading

@Sg312 Sg312 merged commit aa80116 into staging Jan 16, 2026
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/copilot-router 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