@@ -9,7 +9,6 @@ import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
99import { createLogger } from '@/lib/logs/console/logger'
1010import type { LoggingSession } from '@/lib/logs/execution/logging-session'
1111import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans'
12- import { decryptSecret } from '@/lib/utils'
1312import {
1413 loadDeployedWorkflowState ,
1514 loadWorkflowFromNormalizedTables ,
@@ -153,38 +152,37 @@ export async function executeWorkflowCore(
153152 // Merge block states
154153 const mergedStates = mergeSubblockState ( blocks )
155154
156- // Get and decrypt environment variables
157- const { personalEncrypted, workspaceEncrypted } = await getPersonalAndWorkspaceEnv (
158- userId ,
159- providedWorkspaceId
160- )
155+ const { personalEncrypted, workspaceEncrypted, personalDecrypted, workspaceDecrypted } =
156+ await getPersonalAndWorkspaceEnv ( userId , providedWorkspaceId )
157+
158+ // Use encrypted values for logging (don't log decrypted secrets)
161159 const variables = EnvVarsSchema . parse ( { ...personalEncrypted , ...workspaceEncrypted } )
162160
161+ // Use already-decrypted values for execution (no redundant decryption)
162+ const decryptedEnvVars : Record < string , string > = { ...personalDecrypted , ...workspaceDecrypted }
163+
163164 await loggingSession . safeStart ( {
164165 userId,
165166 workspaceId : providedWorkspaceId ,
166167 variables,
167168 skipLogCreation, // Skip if resuming an existing execution
168169 } )
169170
170- // Process block states with env var substitution
171- const currentBlockStates = await Object . entries ( mergedStates ) . reduce (
172- async ( accPromise , [ id , block ] ) => {
173- const acc = await accPromise
174- acc [ id ] = await Object . entries ( block . subBlocks ) . reduce (
175- async ( subAccPromise , [ key , subBlock ] ) => {
176- const subAcc = await subAccPromise
171+ // Process block states with env var substitution using pre-decrypted values
172+ const currentBlockStates = Object . entries ( mergedStates ) . reduce (
173+ ( acc , [ id , block ] ) => {
174+ acc [ id ] = Object . entries ( block . subBlocks ) . reduce (
175+ ( subAcc , [ key , subBlock ] ) => {
177176 let value = subBlock . value
178177
179178 if ( typeof value === 'string' && value . includes ( '{{' ) && value . includes ( '}}' ) ) {
180179 const matches = value . match ( / { { ( [ ^ } ] + ) } } / g)
181180 if ( matches ) {
182181 for ( const match of matches ) {
183182 const varName = match . slice ( 2 , - 2 )
184- const encryptedValue = variables [ varName ]
185- if ( encryptedValue ) {
186- const { decrypted } = await decryptSecret ( encryptedValue )
187- value = ( value as string ) . replace ( match , decrypted )
183+ const decryptedValue = decryptedEnvVars [ varName ]
184+ if ( decryptedValue !== undefined ) {
185+ value = ( value as string ) . replace ( match , decryptedValue )
188186 }
189187 }
190188 }
@@ -193,20 +191,13 @@ export async function executeWorkflowCore(
193191 subAcc [ key ] = value
194192 return subAcc
195193 } ,
196- Promise . resolve ( { } as Record < string , any > )
194+ { } as Record < string , any >
197195 )
198196 return acc
199197 } ,
200- Promise . resolve ( { } as Record < string , Record < string , any > > )
198+ { } as Record < string , Record < string , any > >
201199 )
202200
203- // Decrypt all env vars
204- const decryptedEnvVars : Record < string , string > = { }
205- for ( const [ key , encryptedValue ] of Object . entries ( variables ) ) {
206- const { decrypted } = await decryptSecret ( encryptedValue )
207- decryptedEnvVars [ key ] = decrypted
208- }
209-
210201 // Process response format
211202 const processedBlockStates = Object . entries ( currentBlockStates ) . reduce (
212203 ( acc , [ blockId , blockState ] ) => {
0 commit comments