Skip to content

Conversation

@Pbonmars-20031006
Copy link
Contributor

@Pbonmars-20031006 Pbonmars-20031006 commented Dec 19, 2025

Summary

Loop/Parallel Block level errors captured.

Type of Change

  • Other: UX Improvement

Testing

Tested with @Sg312

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 19, 2025

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 20, 2025 9:02pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 19, 2025

Greptile Summary

This PR improves error handling and logging for loop and parallel execution blocks by capturing validation errors at the block level and propagating them to the console and dashboard.

Key Changes:

  • Added validation limits: MAX_FOREACH_ITEMS (1000) and MAX_PARALLEL_BRANCHES (20) to prevent excessive resource usage
  • Extracted utility functions (validateMaxCount, resolveArrayInput, addSubflowErrorLog) to subflow-utils.ts for consistent error handling across loop and parallel blocks
  • Enhanced loop orchestrator to validate forEach item resolution, collection size, and iteration counts with proper error logging
  • Enhanced parallel orchestrator to validate distribution resolution and branch counts with proper error logging
  • Added validationError field to LoopScope and ParallelScope for tracking validation failures
  • Updated trace spans to include loop/parallel blocks with errors for better visibility in logs
  • Added DAG-level validation to ensure loops and parallels have internal blocks and proper connections

Issues Found:

  • One potential logic issue in loop.ts where empty arrays could result in scope.item = undefined (line 134)

Confidence Score: 4/5

  • This PR is generally safe to merge with one minor edge case to address
  • The changes introduce comprehensive error handling and validation for loop and parallel blocks, which significantly improves observability and prevents resource exhaustion. The code follows good practices by extracting utility functions and adding proper error logging. However, there is one edge case with empty arrays in forEach loops that should be handled to prevent potential undefined access issues.
  • apps/sim/executor/orchestrators/loop.ts - address the empty array edge case on line 134

Important Files Changed

Filename Overview
apps/sim/executor/utils/subflow-utils.ts Added validateMaxCount, resolveArrayInput, and addSubflowErrorLog utility functions for error handling and validation
apps/sim/executor/dag/builder.ts Added validateSubflowStructure to validate loop/parallel internal structure at DAG build time
apps/sim/executor/orchestrators/loop.ts Added comprehensive error handling and validation for forEach, for, and doWhile loops with proper error logging
apps/sim/executor/orchestrators/parallel.ts Added error handling for parallel distribution resolution and branch count validation with proper error logging

Sequence Diagram

sequenceDiagram
    participant Executor as DAGExecutor
    participant LoopOrch as LoopOrchestrator
    participant ParallelOrch as ParallelOrchestrator
    participant Utils as SubflowUtils
    participant Logger as BlockLog/ContextExtensions

    Note over Executor: Execution Flow with Error Handling

    Executor->>LoopOrch: setContextExtensions()
    Executor->>ParallelOrch: setContextExtensions()
    
    alt Loop Initialization
        Executor->>LoopOrch: initializeLoopScope(ctx, loopId)
        LoopOrch->>LoopOrch: Get loop config
        
        alt ForEach Loop
            LoopOrch->>Utils: resolveArrayInput(items)
            Utils-->>LoopOrch: resolved items array
            LoopOrch->>Utils: validateMaxCount(items.length, MAX_FOREACH_ITEMS)
            alt Validation Fails
                Utils-->>LoopOrch: error message
                LoopOrch->>Utils: addSubflowErrorLog(ctx, loopId, error)
                Utils->>Logger: Create BlockLog with error
                Utils->>Logger: Call onBlockComplete with error
                LoopOrch->>LoopOrch: Set validationError in scope
                LoopOrch-->>Executor: Throw Error
            else Validation Passes
                Utils-->>LoopOrch: undefined (no error)
                LoopOrch->>LoopOrch: Set scope.items and scope.item
            end
        end
        
        alt For/DoWhile Loop
            LoopOrch->>Utils: validateMaxCount(iterations, MAX_LOOP_ITERATIONS)
            alt Validation Fails
                Utils-->>LoopOrch: error message
                LoopOrch->>Utils: addSubflowErrorLog(ctx, loopId, error)
                Utils->>Logger: Create BlockLog with error
                LoopOrch-->>Executor: Throw Error
            end
        end
    end
    
    alt Parallel Initialization
        Executor->>ParallelOrch: initializeParallelScope(ctx, parallelId)
        ParallelOrch->>ParallelOrch: Get parallel config
        ParallelOrch->>Utils: resolveArrayInput(distribution)
        
        alt Resolution Fails
            Utils-->>ParallelOrch: Throw error
            ParallelOrch->>Utils: addSubflowErrorLog(ctx, parallelId, error)
            Utils->>Logger: Create BlockLog with error
            ParallelOrch->>ParallelOrch: setErrorScope with validationError
            ParallelOrch-->>Executor: Throw Error
        end
        
        ParallelOrch->>Utils: validateMaxCount(branchCount, MAX_PARALLEL_BRANCHES)
        alt Validation Fails
            Utils-->>ParallelOrch: error message
            ParallelOrch->>Utils: addSubflowErrorLog(ctx, parallelId, error)
            Utils->>Logger: Create BlockLog with error
            ParallelOrch->>ParallelOrch: setErrorScope with validationError
            ParallelOrch-->>Executor: Throw Error
        end
    end
    
    Note over Logger: Errors now propagate to console and dashboard
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.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321
Copy link
Collaborator

@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.

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit c252e88 into staging Dec 23, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the imporvement/paralle-loop-log-fix branch December 23, 2025 08:28
waleedlatif1 pushed a commit that referenced this pull request Dec 23, 2025
…2468)

* fixed logs for parallel and loop execution flow

* Fix array check for collection

* fixed for empty loop and paralle blocks and showing input on dashboard

* extracted utility functions

* fixed the refrencing errors and making sure it propogates to the console

* fix parallel

* fix tests'

---------

Co-authored-by: priyanshu.solanki <priyanshu.solanki@saviynt.com>
Co-authored-by: Siddharth Ganesan <siddharthganesan@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
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.

5 participants