Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Need to include subflow node in calculations for layering and position.

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 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 6, 2025 0:26am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 5, 2025

Greptile Overview

Greptile Summary

This PR fixes subflow node positioning in autolayout by accounting for the internal depth of subflow containers (loop and parallel blocks). When edges originate from subflow end handles (loop-end-source, parallel-end-source), the layer calculation now adds the subflow's internal depth to properly space subsequent blocks.

Key Changes:

  • Added SUBFLOW_END_HANDLES set and isSubflowEndEdge() helper to identify edges from subflow ends
  • Modified assignLayers() to accept optional subflowDepths parameter and adjust layer calculation for subflow end edges
  • Introduced calculateSubflowDepths() function to compute internal layer depth for each subflow container
  • Updated both applyAutoLayout() and applyTargetedLayout() to calculate and pass subflow depths
  • Correctly passes subflowDepths only for root-level layouts (not inside containers) to avoid incorrect nesting calculations

The implementation correctly handles edge cases like empty subflows (depth=1) and uses depth - 1 in calculations to avoid double-counting since the base layer calculation already adds 1.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured with clear logic, proper edge case handling (empty subflows, missing depths), and correct mathematical calculations. The code follows existing patterns in the codebase and only adds functionality without breaking changes. The minor code duplication is a style issue, not a functional concern.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/lib/workflows/autolayout/core.ts 5/5 Added subflow depth calculation for proper layering when edges originate from subflow end handles (loop-end-source, parallel-end-source). The logic correctly adds internal depth minus 1 to account for subflow internal structure.
apps/sim/lib/workflows/autolayout/index.ts 5/5 Introduced calculateSubflowDepths function to compute internal layer depth for each subflow container. Function correctly handles empty subflows (depth=1) and calculates max layer depth for non-empty subflows.
apps/sim/lib/workflows/autolayout/targeted.ts 5/5 Duplicated calculateSubflowDepths function and integrated subflow depth handling into targeted layout. Correctly passes depths only for root-level layout (not inside containers).

Sequence Diagram

sequenceDiagram
    participant User
    participant applyAutoLayout
    participant calculateSubflowDepths
    participant assignLayers
    participant layoutBlocksCore
    participant layoutContainers

    User->>applyAutoLayout: Layout workflow blocks
    applyAutoLayout->>calculateSubflowDepths: Calculate depth of all subflows
    
    loop For each subflow container
        calculateSubflowDepths->>assignLayers: Get layers of child blocks
        assignLayers-->>calculateSubflowDepths: Return max layer
        calculateSubflowDepths->>calculateSubflowDepths: Store depth (maxLayer + 1)
    end
    
    calculateSubflowDepths-->>applyAutoLayout: Return subflowDepths map
    
    applyAutoLayout->>layoutBlocksCore: Layout root blocks + subflowDepths
    layoutBlocksCore->>assignLayers: Assign layers with subflow depths
    
    loop For each node with incoming edges
        assignLayers->>assignLayers: Check if edge has subflow end handle
        alt Edge from subflow end
            assignLayers->>assignLayers: Add subflow depth - 1 to layer calculation
        else Normal edge
            assignLayers->>assignLayers: Use standard layer calculation
        end
    end
    
    assignLayers-->>layoutBlocksCore: Return nodes with adjusted layers
    layoutBlocksCore-->>applyAutoLayout: Return positioned blocks
    
    applyAutoLayout->>layoutContainers: Layout blocks inside containers
    layoutContainers-->>applyAutoLayout: Update container dimensions
    
    applyAutoLayout-->>User: Return laid out blocks
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.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit a50edf8 into staging Dec 6, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/subflow-autolayout-extension 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