Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Need to pass in right context extensions in workflow handler.

Type of Change

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

Testing

Tested manually.

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 Jan 6, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 6, 2026 1:35am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 6, 2026

Greptile Summary

Fixed hosted API key resolution for child workflow executions by passing workspaceId, userId, and executionId through context extensions. Previously, child workflows couldn't access workspace-specific BYOK (Bring Your Own Key) configurations because these critical context fields weren't propagated.

Key changes:

  • Added workspaceId - enables workspace-specific BYOK key lookup in database
  • Added userId - provides user context for authorization and tracking
  • Added executionId - maintains execution lineage for proper request tracking

This ensures child workflows use the same API key resolution logic as parent workflows, supporting multi-tenancy and proper cost attribution.

Confidence Score: 5/5

  • This PR is safe to merge - it's a simple, targeted bug fix with no side effects
  • The change is minimal (3 lines), addresses a clear bug, follows established patterns in the codebase (contextExtensions usage in execution-core.ts), and has no breaking changes or side effects
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/executor/handlers/workflow/workflow-handler.ts Added three critical context fields (workspaceId, userId, executionId) to child workflow execution context to enable proper hosted API key resolution

Sequence Diagram

sequenceDiagram
    participant Parent as Parent Workflow
    participant WH as WorkflowBlockHandler
    participant Executor as Child Executor
    participant DAG as DAGExecutor
    participant Agent as AgentBlockHandler
    participant Provider as Provider System
    participant BYOK as BYOK Resolver

    Parent->>WH: execute(ctx, block, inputs)
    Note over Parent,WH: ctx has workspaceId, userId, executionId
    
    WH->>WH: loadChildWorkflow(workflowId)
    
    WH->>Executor: new Executor({<br/>contextExtensions: {<br/>  workspaceId: ctx.workspaceId,<br/>  userId: ctx.userId,<br/>  executionId: ctx.executionId<br/>}})
    Note over WH,Executor: FIX: Now passing context fields
    
    Executor->>DAG: create execution context
    Note over DAG: Maps contextExtensions to<br/>ExecutionContext
    
    DAG->>Agent: execute LLM block
    Note over Agent: Child workflow executes<br/>agent/LLM blocks
    
    Agent->>Provider: executeProviderRequest({<br/>workspaceId: ctx.workspaceId<br/>})
    Note over Provider: workspaceId now available
    
    Provider->>BYOK: getApiKeyWithBYOK(provider, model, workspaceId)
    
    BYOK->>BYOK: Query database for<br/>workspace BYOK key
    
    alt BYOK key found
        BYOK-->>Provider: Return workspace API key
    else No BYOK, hosted model
        BYOK-->>Provider: Return rotating hosted key
    end
    
    Provider-->>Agent: Execute with resolved API key
    Agent-->>DAG: Return block output
    DAG-->>WH: Return execution result
    WH-->>Parent: Return child workflow output
Loading

@icecrasher321 icecrasher321 merged commit d25084e into staging Jan 6, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/child-workflow-agent branch January 6, 2026 22:39
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