Skip to content

Comments

fix(workflow-vars): duplicate, export/import copies#3224

Merged
icecrasher321 merged 1 commit intostagingfrom
fix/workflow-var-copies
Feb 15, 2026
Merged

fix(workflow-vars): duplicate, export/import copies#3224
icecrasher321 merged 1 commit intostagingfrom
fix/workflow-var-copies

Conversation

@icecrasher321
Copy link
Collaborator

Summary

  • Duplicate is not regenerating and mapping workflow variable ids accurately affecting variables block
  • Import/Export -- doesn't keep workflow variables.

Type of Change

  • Bug fix

Testing

Tested manually

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 Feb 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 14, 2026 11:56pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 14, 2026

Greptile Overview

Greptile Summary

Fixes two critical bugs in workflow variable handling: (1) during duplication, variable IDs are now correctly regenerated and remapped in variables-input subblocks, and (2) import/export now properly validates and preserves the Record<string, Variable> structure instead of incorrectly treating variables as an array.

Key Changes:

  • Added remapVariableIdsInSubBlocks() helper function to update variableId references in block subBlocks during workflow duplication
  • Changed import validation from Array.isArray(workflowData.variables) to proper object type checking
  • Updated ExportWorkflowState type definition to correctly reflect variables as a Record instead of Array
  • Variable ID mapping is now tracked and applied to all variables-input type subblocks in duplicated workflows

Confidence Score: 5/5

  • This PR is safe to merge with no significant risks
  • The changes are well-structured bug fixes that address specific, documented issues with workflow variable handling. The implementation correctly handles variable ID remapping during duplication and fixes the data type validation during import/export. The code follows defensive programming practices with proper type checks and maintains backward compatibility.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/workflows/persistence/duplicate.ts Adds helper function remapVariableIdsInSubBlocks and updates duplication logic to properly remap variable IDs in variables-input subblocks when duplicating workflows
apps/sim/lib/workflows/operations/import-export.ts Changed variables validation from Array.isArray to object type check to correctly handle the Record-based variables structure
apps/sim/lib/workflows/sanitization/json-sanitizer.ts Updated ExportWorkflowState type definition to correctly reflect variables as Record<string, Variable> instead of Array<Variable>

Flowchart

flowchart TD
    A[Duplicate Workflow Request] --> B[Generate New Workflow ID]
    B --> C[Create Variable ID Mapping]
    C --> D[Duplicate Variables with New IDs]
    D --> E[Process Blocks]
    E --> F{Block Has subBlocks?}
    F -->|Yes| G[Check for variables-input type]
    G --> H{Is variables-input?}
    H -->|Yes| I[Remap variableId references using varIdMapping]
    H -->|No| J[Keep subBlocks unchanged]
    I --> K[Insert Block with Updated subBlocks]
    J --> K
    F -->|No| K
    K --> L[Duplicate Edges & Subflows]
    L --> M[Return Duplicated Workflow]
    
    N[Export Workflow] --> O[Serialize Variables as Record]
    O --> P[Export to JSON]
    
    Q[Import Workflow] --> R{Variables is object?}
    R -->|Yes| S[Parse Variables]
    R -->|No| T[Set Variables to undefined]
    S --> U[Load Workflow]
    T --> U
Loading

Last reviewed commit: 6cb51f9

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.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit c44211a into staging Feb 15, 2026
19 of 20 checks passed
@icecrasher321 icecrasher321 deleted the fix/workflow-var-copies branch February 15, 2026 00:02
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.

1 participant