Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Sep 27, 2025

Summary

  • Block references (e.g., <function1.result>) are now validated against accessible blocks before resolution - only references to connected/accessible blocks are highlighted in blue and resolved
  • Inaccessible references remain as literal strings instead of throwing validation errors, following the principle that only highlighted references get resolved
  • Removed validation errors from serializer and updated tests to match the new behavior where unconnected block references are left as-is rather than causing failures

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

Manually + Test suite

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 Sep 27, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Oct 1, 2025 0:21am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 1, 2025 0:21am

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.

Greptile Overview

Summary

This PR consolidates and improves the variable resolution system across the workflow platform. The changes introduce consistent block name normalization using a centralized normalizeBlockName() function, which converts block names to lowercase and removes spaces for reliable matching.

Key improvements include:

  • Enhanced Reference Detection: Updated extractReferencePrefixes() and isLikelyReferenceSegment() functions with better validation logic to accurately identify variable references while avoiding false positives from comparison operators and HTML-like content

  • Consolidated Resolution Logic: The InputResolver class has been significantly refactored to use pre-calculated accessible block maps for better performance, with improved handling of loop and parallel block references

  • UI Consistency: All input components now use the new useAccessibleReferencePrefixes hook, ensuring consistent variable reference highlighting and validation across the interface

  • Optimized Performance: The serializer now pre-computes accessible block relationships, reducing runtime complexity during variable resolution

  • Improved Error Handling: Better validation and error messages when blocks are not found or not accessible

The changes maintain backward compatibility while significantly improving the reliability and performance of variable resolution throughout the platform. The consolidated approach ensures all components use the same normalization and validation logic, reducing inconsistencies and potential bugs.

Confidence Score: 4/5

  • This PR is safe to merge with careful testing of variable resolution functionality
  • Score reflects comprehensive refactoring of a critical system component with good code quality and architectural improvements, but requires thorough testing due to the scope of changes affecting variable resolution across the entire platform
  • The core resolver (apps/sim/executor/resolver/resolver.ts) needs the most attention due to its complexity and critical role in variable resolution

Important Files Changed

File Analysis

Filename        Score        Overview
apps/sim/lib/workflows/references.ts 5/5 Enhanced variable reference detection with improved validation and block name normalization for consistent resolution across workflow components
apps/sim/executor/resolver/resolver.ts 4/5 Major refactoring to consolidate variable resolution logic with improved accessibility checks, block name normalization, and enhanced loop/parallel reference handling
apps/sim/serializer/index.ts 5/5 Added comprehensive accessible block calculation and improved workflow validation with consistent block name normalization throughout serialization
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes.ts 5/5 New React hook that provides consistent accessible reference prefix calculation for UI components using the same logic as the resolver
apps/sim/components/ui/formatted-text.tsx 5/5 Enhanced text formatting component with improved block name normalization for consistent syntax highlighting of variable references
apps/sim/components/ui/tag-dropdown.tsx 5/5 Updated dropdown component to use consistent block name normalization for better variable reference suggestions

Sequence Diagram

sequenceDiagram
    participant UI as UI Components
    participant Hook as useAccessibleReferencePrefixes
    participant Refs as references.ts
    participant Resolver as InputResolver
    participant Serializer as Serializer
    participant BlockCalc as BlockPathCalculator

    Note over UI,BlockCalc: Variable Resolution Flow

    UI->>Hook: Request accessible prefixes for blockId
    Hook->>BlockCalc: findAllPathNodes(edges, blockId)
    BlockCalc-->>Hook: ancestorIds[]
    Hook->>Hook: Add starter, loop, parallel blocks
    Hook->>Refs: normalizeBlockName() for each block
    Hook-->>UI: Set<string> accessible prefixes

    UI->>UI: User types variable reference <blockname.property>
    UI->>Refs: extractReferencePrefixes(inputText)
    Refs->>Refs: isLikelyReferenceSegment() validation
    Refs->>Refs: normalizeBlockName() on prefix
    Refs-->>UI: Array<{raw, prefix}> references

    Note over Resolver: During Execution

    Resolver->>Resolver: resolveInputs(block, context)
    Resolver->>Resolver: processStringValue() for each input
    Resolver->>Resolver: resolveVariableReferences() - handle <variable.name>
    Resolver->>Resolver: resolveBlockReferences() - handle <block.property>
    
    Resolver->>Resolver: validateBlockReference(blockRef, currentBlockId)
    Resolver->>Resolver: getAccessibleBlocks() using pre-calculated map
    Resolver->>Refs: normalizeBlockName() for comparison
    
    alt Block reference found and accessible
        Resolver->>Resolver: Resolve to actual value
    else Block not accessible
        Resolver-->>Resolver: Return validation error
    end

    Note over Serializer: During Serialization

    Serializer->>Serializer: serializeWorkflow()
    Serializer->>BlockCalc: computeAccessibleBlockIds()
    Serializer->>Refs: normalizeBlockName() for consistency
    Serializer-->>Resolver: accessibleBlocksMap for optimization
Loading

13 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs October 1, 2025 00:18 Inactive
@icecrasher321 icecrasher321 merged commit 0bf2bce into staging Oct 1, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/variable-resolution branch October 30, 2025 06:22
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