Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Oct 7, 2025

Summary

  • Collect child workflow spans and render correctly in logs sidepanel. Previously limited to top level workflow which made debugging child workflows hard.
  • Change rate limit / billing checks to be done against API key owner for deployed workflows

Type of Change

  • New feature

Testing

Tested manually with @aadamgough

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 Oct 7, 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 7, 2025 7:31pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 7, 2025 7:31pm

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 introduces comprehensive support for collecting and rendering nested child workflow spans in the logs sidepanel, addressing a significant debugging limitation where only top-level workflow spans were previously visible. The changes span across multiple execution paths (chat, scheduled workflows, webhooks, direct API calls) to ensure consistent trace span collection regardless of how workflows are triggered.

The implementation adds a new WorkflowTraceSpan type that extends the base TraceSpan with metadata for distinguishing child workflow spans. Key improvements include enhanced error handling that preserves execution results and trace spans even when child workflows fail, ensuring debugging information isn't lost during failures. The code introduces utility functions for normalizing error messages and extracting execution results from complex error structures that may contain nested workflow information.

A new WORKFLOW_INPUT block type is introduced alongside the deprecated WORKFLOW type, with a helper function isWorkflowBlockType() providing backwards compatibility during the transition. The chat execution workflow has been significantly simplified, removing complex output processing logic in favor of streamlined trace span collection.

The changes ensure that buildTraceSpans() is called consistently across all execution paths and that trace spans are properly passed to logging sessions in both success and error scenarios. This creates a unified debugging experience where developers can see the complete execution tree for nested workflows, making it much easier to diagnose issues in complex workflow architectures.

Important Files Changed

Changed Files
Filename Score Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts 4/5 Added robust error handling utilities and normalization functions to extract execution results from nested workflow errors
apps/sim/background/webhook-execution.ts 4/5 Added trace span collection to error handling path for consistent debugging across webhook executions
apps/sim/executor/handlers/workflow/workflow-handler.ts 4/5 Implemented core nested child workflow span processing with new WorkflowTraceSpan type and span processing methods
apps/sim/app/api/schedules/execute/route.ts 4/5 Added trace span collection and logging for scheduled workflow executions
apps/sim/app/api/workflows/[id]/execute/route.ts 4/5 Enhanced error handling to extract and preserve trace spans from failed workflow executions
apps/sim/executor/index.ts 4/5 Replaced hardcoded workflow block checks with helper function and enhanced error propagation with execution results
apps/sim/app/api/workflows/[id]/log/route.ts 4/5 Moved buildTraceSpans() call to ensure trace spans available for both success and error scenarios
apps/sim/app/api/chat/utils.ts 4/5 Dramatically simplified chat execution workflow removing complex output processing in favor of trace span collection
apps/sim/executor/consts.ts 4/5 Added new WORKFLOW_INPUT block type with backwards compatibility helper function
apps/sim/background/workflow-execution.ts 4/5 Enhanced background execution error handling to capture and persist child workflow trace spans

Confidence score: 4/5

  • This PR is safe to merge with good implementation quality and comprehensive coverage across execution paths
  • Score reflects well-structured changes that maintain backwards compatibility while adding significant debugging capabilities
  • Pay attention to the unused flattenChildWorkflowSpans method in workflow-handler.ts that could be removed to reduce complexity

Sequence Diagram

sequenceDiagram
    participant User
    participant ExecutorAPI as Executor API
    participant Executor
    participant WorkflowHandler as Workflow Handler
    participant LoggingSession as Logging Session
    participant TraceSpans as Trace Spans Builder
    participant UI as Logs UI

    User->>ExecutorAPI: "Execute workflow"
    ExecutorAPI->>Executor: "Create executor instance"
    Executor->>LoggingSession: "Start logging session"
    LoggingSession->>LoggingSession: "Initialize session"
    
    Executor->>Executor: "Execute workflow blocks"
    
    alt Workflow block encountered
        Executor->>WorkflowHandler: "Execute child workflow"
        WorkflowHandler->>WorkflowHandler: "Load child workflow"
        WorkflowHandler->>Executor: "Create sub-executor"
        Executor->>Executor: "Execute child workflow"
        Executor-->>WorkflowHandler: "Return child execution result"
        WorkflowHandler->>WorkflowHandler: "Capture child trace spans"
        WorkflowHandler-->>Executor: "Return with childTraceSpans"
    end
    
    Executor->>TraceSpans: "Build trace spans from execution result"
    TraceSpans->>TraceSpans: "Process nested child workflow spans"
    TraceSpans->>TraceSpans: "Flatten synthetic wrapper spans"
    TraceSpans->>TraceSpans: "Merge child trace spans with parent"
    TraceSpans-->>Executor: "Return processed trace spans"
    
    Executor->>LoggingSession: "Complete session with trace spans"
    LoggingSession->>LoggingSession: "Persist execution logs"
    
    Executor-->>ExecutorAPI: "Return execution result"
    ExecutorAPI-->>User: "Return workflow execution result"
    
    User->>UI: "View execution logs"
    UI->>UI: "Normalize child workflow spans"
    UI->>UI: "Render nested spans hierarchy"
    UI-->>User: "Display nested workflow execution tree"
Loading

Additional Comments (1)

  1. apps/sim/app/api/schedules/execute/route.ts, line 425 (link)

    style: Type assertion to any bypasses TypeScript safety. Consider defining proper types for trace spans.

    Context Used: Context from dashboard - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used... (source)

10 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs October 7, 2025 19:27 Inactive
@icecrasher321 icecrasher321 merged commit 991a020 into staging Oct 7, 2025
4 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/nested-childworkflow-spans branch October 7, 2025 23: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