Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Dec 11, 2025

Summary

Fix variable resolution in parallel for each collection

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 Dec 11, 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 11, 2025 9:46pm

@Sg312 Sg312 changed the title Fix var resolution in parallel fix(parallel): variable resolution in collection Dec 11, 2025
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 11, 2025

Greptile Overview

Greptile Summary

Enables runtime resolution of dynamic distribution items in parallel blocks by mirroring the loop resolver pattern. Previously, parallel blocks could not resolve references like <previousBlock.items> as distribution items because resolution happened too late in the execution flow. This PR injects the VariableResolver into ParallelOrchestrator and resolves distribution items at scope initialization time (before block execution), storing them in scope.items. The ParallelResolver then reads from this resolved data, ensuring <parallel.currentItem> correctly accesses dynamically-provided items.

Key changes:

  • Injected VariableResolver into ParallelOrchestrator via setResolver() method
  • Added resolveDistributionItems() method that handles references using resolveSingleReference()
  • Moved parallel scope initialization to happen before block execution in NodeExecutionOrchestrator
  • Added items field to ParallelScope interface to cache resolved distribution items
  • Updated ParallelResolver to prioritize scope.items over static config data

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation correctly mirrors the established pattern from LoopOrchestrator and LoopResolver, maintaining architectural consistency. The changes are well-scoped, non-breaking (all new fields are optional), and solve a legitimate bug where dynamic references in parallel distribution items couldn't be resolved. The resolver injection pattern is clean, initialization timing is correct, and the fallback logic (scope.items ?? getDistributionItems()) ensures backward compatibility with static configurations.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/executor/variables/resolvers/parallel.ts 5/5 Enhanced to read resolved distribution items from parallel scope at runtime, mirroring loop resolver pattern
apps/sim/executor/orchestrators/parallel.ts 5/5 Added variable resolver injection and runtime item resolution using resolveSingleReference, stores items in parallel scope
apps/sim/executor/orchestrators/node.ts 5/5 Initializes parallel scope before block execution to ensure <parallel.currentItem> can be resolved during execution

Sequence Diagram

sequenceDiagram
    participant Executor as DAGExecutor
    participant ParallelOrch as ParallelOrchestrator
    participant NodeOrch as NodeExecutionOrchestrator
    participant Resolver as VariableResolver
    participant ParallelResolver as ParallelResolver
    participant BlockExec as BlockExecutor

    Executor->>Resolver: new VariableResolver()
    Executor->>ParallelOrch: new ParallelOrchestrator()
    Executor->>ParallelOrch: setResolver(resolver)
    Note over ParallelOrch: Resolver now available for runtime resolution

    NodeOrch->>NodeOrch: executeNode(ctx, nodeId)
    NodeOrch->>ParallelOrch: getParallelScope(ctx, parallelId)
    ParallelOrch-->>NodeOrch: undefined (not initialized)
    
    NodeOrch->>ParallelOrch: initializeParallelScope(ctx, parallelId, ...)
    ParallelOrch->>ParallelOrch: resolveDistributionItems(ctx, config)
    
    alt Distribution is reference
        ParallelOrch->>Resolver: resolveSingleReference(ctx, '', rawItems)
        Resolver-->>ParallelOrch: resolved array or object
    else Distribution is static data
        ParallelOrch->>ParallelOrch: return as-is or parse JSON
    end
    
    ParallelOrch->>ParallelOrch: Store items in scope.items
    ParallelOrch-->>NodeOrch: ParallelScope with items
    
    Note over NodeOrch: Scope initialized BEFORE execution

    NodeOrch->>BlockExec: execute(ctx, node, block)
    BlockExec->>Resolver: resolve reference
    Resolver->>ParallelResolver: resolve(reference, context)
    ParallelResolver->>ParallelResolver: Get parallelScope from ctx
    ParallelResolver->>ParallelResolver: items = scope.items ?? getDistributionItems()
    Note over ParallelResolver: Prioritizes runtime-resolved items from scope
    ParallelResolver->>ParallelResolver: return items[branchIndex]
    ParallelResolver-->>Resolver: currentItem value
    Resolver-->>BlockExec: resolved value
    BlockExec-->>NodeOrch: execution output
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.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Sg312 Sg312 merged commit c0bb854 into staging Dec 11, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/parallel-variable-resolution branch December 13, 2025 04:18
royceP2 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Dec 15, 2025
* Fix var resolution in parallel

* Fix parallel

* Clean logs

* FIx loop error port
arenadeveloper02 added a commit to arenadeveloper02/p2-sim that referenced this pull request Dec 15, 2025
fix(parallel): variable resolution in collection (simstudioai#2314)
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