sim
sim copied to clipboard
improvement(logs): fixed logs for parallel and loop execution flow
Summary
Loop/Parallel Block level errors captured.
Type of Change
- [x] Other: UX Improvement
Testing
Tested with @Sg312
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
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) andMAX_PARALLEL_BRANCHES(20) to prevent excessive resource usage - Extracted utility functions (
validateMaxCount,resolveArrayInput,addSubflowErrorLog) tosubflow-utils.tsfor 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
validationErrorfield toLoopScopeandParallelScopefor 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.tswhere empty arrays could result inscope.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
@greptile