Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/docs/content/docs/en/variables/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ To reference environment variables in your workflows, use the `{{}}` notation. W
height={350}
/>

## Variable Precedence
## How Variables are Resolved

When you have both personal and workspace variables with the same name:
**Workspace variables always take precedence** over personal variables, regardless of who runs the workflow.

1. **Workspace variables take precedence** over personal variables
2. This prevents naming conflicts and ensures consistent behavior across team workflows
3. If a workspace variable exists, the personal variable with the same name is ignored
When no workspace variable exists for a key, personal variables are used:
- **Manual runs (UI)**: Your personal variables
- **Automated runs (API, webhook, schedule, deployed chat)**: Workflow owner's personal variables

<Callout type="warning">
Choose variable names carefully to avoid unintended overrides. Consider prefixing personal variables with your initials or workspace variables with the project name.
<Callout type="info">
Personal variables are best for testing. Use workspace variables for production workflows.
</Callout>

## Security Best Practices
Expand Down
14 changes: 10 additions & 4 deletions apps/sim/app/api/workflows/[id]/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ExecuteWorkflowSchema = z.object({
stream: z.boolean().optional(),
useDraftState: z.boolean().optional(),
input: z.any().optional(),
// Optional workflow state override (for executing diff workflows)
isClientSession: z.boolean().optional(),
workflowStateOverride: z
.object({
blocks: z.record(z.any()),
Expand Down Expand Up @@ -92,16 +92,17 @@ export async function executeWorkflow(
workflowId,
workspaceId: workflow.workspaceId,
userId: actorUserId,
workflowUserId: workflow.userId,
triggerType,
useDraftState: false,
startTime: new Date().toISOString(),
isClientSession: false,
}

const snapshot = new ExecutionSnapshot(
metadata,
workflow,
input,
{},
workflow.variables || {},
streamConfig?.selectedOutputs || []
)
Expand Down Expand Up @@ -329,6 +330,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
stream: streamParam,
useDraftState,
input: validatedInput,
isClientSession = false,
workflowStateOverride,
} = validation.data

Expand Down Expand Up @@ -503,17 +505,19 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
workflowId,
workspaceId: workflow.workspaceId ?? undefined,
userId: actorUserId,
sessionUserId: isClientSession ? userId : undefined,
workflowUserId: workflow.userId,
triggerType,
useDraftState: shouldUseDraftState,
startTime: new Date().toISOString(),
isClientSession,
workflowStateOverride: effectiveWorkflowStateOverride,
}

const snapshot = new ExecutionSnapshot(
metadata,
workflow,
processedInput,
{},
workflow.variables || {},
selectedOutputs
)
Expand Down Expand Up @@ -769,17 +773,19 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
workflowId,
workspaceId: workflow.workspaceId ?? undefined,
userId: actorUserId,
sessionUserId: isClientSession ? userId : undefined,
workflowUserId: workflow.userId,
triggerType,
useDraftState: shouldUseDraftState,
startTime: new Date().toISOString(),
isClientSession,
workflowStateOverride: effectiveWorkflowStateOverride,
}

const snapshot = new ExecutionSnapshot(
metadata,
workflow,
processedInput,
{},
workflow.variables || {},
selectedOutputs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ export function useWorkflowExecution() {
selectedOutputs,
triggerType: overrideTriggerType || 'manual',
useDraftState: true,
// Pass diff workflow state if available for execution
isClientSession: true,
workflowStateOverride: executionWorkflowState
? {
blocks: executionWorkflowState.blocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export async function executeWorkflowWithFullLogging(
const executionId = options.executionId || uuidv4()
const { addConsole } = useTerminalConsoleStore.getState()

// Build request payload
const payload: any = {
input: options.workflowInput,
stream: true,
triggerType: options.overrideTriggerType || 'manual',
useDraftState: true,
isClientSession: true,
}

const response = await fetch(`/api/workflows/${activeWorkflowId}/execute`, {
Expand Down
Loading