fix(env-vars): refactor for workspace/personal env vars to work with server side execution correctly#2197
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR refactors environment variable handling to properly distinguish between personal and workspace environment variables for different execution contexts. The changes implement a new precedence hierarchy where workspace environment variables (shared across teams, read-only) take precedence over personal environment variables (user-specific, private). For execution context determination: client-side executions (manual/chat) use the session user's personal environment variables, while server-side executions (API triggers, webhooks, schedules) use workspace variables with the workflow owner's personal variables as fallback when the caller is unknown. The refactoring introduces The ExecutionSnapshot class was simplified by removing environment variables from its constructor and serialization, moving variable resolution to execution-time rather than snapshot-creation time. The UI was enhanced to support direct creation of workspace variables (not just promotion from personal variables) with improved conflict detection and validation between the two scopes. Important Files Changed
Confidence score: 4/5
Sequence DiagramsequenceDiagram
participant User
participant NextRequest as "/api/workflows/[id]/execute"
participant Auth as "checkHybridAuth"
participant PreProcess as "preprocessExecution"
participant WorkflowLoader as "loadDeployedWorkflowState"
participant EnvUtils as "getPersonalAndWorkspaceEnv"
participant FileProcessor as "processInputFileFields"
participant ExecutionCore as "executeWorkflowCore"
participant LoggingSession as "LoggingSession"
participant PauseManager as "PauseResumeManager"
participant AsyncTasks as "tasks.trigger"
User->>NextRequest: "POST /api/workflows/[id]/execute"
NextRequest->>Auth: "checkHybridAuth(req)"
Auth-->>NextRequest: "{ success: true, userId, authType }"
NextRequest->>PreProcess: "preprocessExecution({ workflowId, userId, triggerType })"
PreProcess-->>NextRequest: "{ success: true, actorUserId, workflowRecord }"
alt isAsyncMode
NextRequest->>AsyncTasks: "tasks.trigger('workflow-execution', payload)"
AsyncTasks-->>NextRequest: "{ jobId, statusUrl }"
NextRequest-->>User: "202 Accepted { async: true, jobId }"
else Synchronous/SSE Execution
NextRequest->>WorkflowLoader: "loadDeployedWorkflowState(workflowId)"
WorkflowLoader-->>NextRequest: "{ blocks, edges, loops, parallels }"
NextRequest->>EnvUtils: "getPersonalAndWorkspaceEnv(userId, workspaceId)"
EnvUtils-->>NextRequest: "{ personalEncrypted, workspaceEncrypted }"
NextRequest->>FileProcessor: "processInputFileFields(input, blocks, context)"
FileProcessor-->>NextRequest: "processedInput"
NextRequest->>LoggingSession: "new LoggingSession(workflowId, executionId, triggerType)"
LoggingSession-->>NextRequest: "loggingSession"
NextRequest->>ExecutionCore: "executeWorkflowCore({ snapshot, callbacks, loggingSession })"
ExecutionCore->>LoggingSession: "safeStart({ userId, workspaceId, variables })"
ExecutionCore->>ExecutionCore: "Execute workflow blocks"
alt Execution Paused
ExecutionCore->>PauseManager: "persistPauseResult({ workflowId, executionId, pausePoints })"
PauseManager-->>ExecutionCore: "Pause data persisted"
else Execution Completed
ExecutionCore->>PauseManager: "processQueuedResumes(executionId)"
PauseManager-->>ExecutionCore: "Queued resumes processed"
end
ExecutionCore->>LoggingSession: "safeComplete({ finalOutput, traceSpans })"
ExecutionCore-->>NextRequest: "ExecutionResult"
alt enableSSE
NextRequest-->>User: "SSE Stream with execution events"
else Direct JSON Response
NextRequest-->>User: "200 JSON { success, output, metadata }"
end
end
|
Summary
Personal Env Vars -- used for manual / chat client side executions always. OR from workflow owner for execution triggers where caller is not known.
Workspace Env Vars -- used to share env vars across workspace [read only] take precedence over personal
UI supports adding workspace env vars directly now not only through promotion.
Type of Change
Testing
Tested manually with @Sg312 and @aadamgough
Checklist