@@ -19,94 +19,6 @@ const BILLING_ERROR_MESSAGES = {
1919 BILLING_ERROR_GENERIC : 'Error resolving billing account' ,
2020} as const
2121
22- /**
23- * Attempts to resolve billing actor with fallback for resume contexts.
24- * Returns the resolved actor user ID or null if resolution fails and should block execution.
25- *
26- * For resume contexts, this function allows fallback to the workflow owner if workspace
27- * billing cannot be resolved, ensuring users can complete their paused workflows even
28- * if billing configuration changes mid-execution.
29- *
30- * @returns Object containing actorUserId (null if should block) and shouldBlock flag
31- */
32- async function resolveBillingActorWithFallback ( params : {
33- requestId : string
34- workflowId : string
35- workspaceId : string
36- executionId : string
37- triggerType : string
38- workflowRecord : WorkflowRecord
39- userId : string
40- isResumeContext : boolean
41- baseActorUserId : string | null
42- failureReason : 'null' | 'error'
43- error ?: unknown
44- loggingSession ?: LoggingSession
45- } ) : Promise <
46- { actorUserId : string ; shouldBlock : false } | { actorUserId : null ; shouldBlock : true }
47- > {
48- const {
49- requestId,
50- workflowId,
51- workspaceId,
52- executionId,
53- triggerType,
54- workflowRecord,
55- userId,
56- isResumeContext,
57- baseActorUserId,
58- failureReason,
59- error,
60- loggingSession,
61- } = params
62-
63- if ( baseActorUserId ) {
64- return { actorUserId : baseActorUserId , shouldBlock : false }
65- }
66-
67- const workflowOwner = workflowRecord . userId ?. trim ( )
68- if ( isResumeContext && workflowOwner ) {
69- const logMessage =
70- failureReason === 'null'
71- ? '[BILLING_FALLBACK] Workspace billing account is null. Using workflow owner for billing.'
72- : '[BILLING_FALLBACK] Exception during workspace billing resolution. Using workflow owner for billing.'
73-
74- logger . warn ( `[${ requestId } ] ${ logMessage } ` , {
75- workflowId,
76- workspaceId,
77- fallbackUserId : workflowOwner ,
78- ...( error ? { error } : { } ) ,
79- } )
80-
81- return { actorUserId : workflowOwner , shouldBlock : false }
82- }
83-
84- const fallbackUserId = workflowRecord . userId || userId || 'unknown'
85- const errorMessage =
86- failureReason === 'null'
87- ? BILLING_ERROR_MESSAGES . BILLING_REQUIRED
88- : BILLING_ERROR_MESSAGES . BILLING_ERROR_GENERIC
89-
90- logger . warn ( `[${ requestId } ] ${ errorMessage } ` , {
91- workflowId,
92- workspaceId,
93- ...( error ? { error } : { } ) ,
94- } )
95-
96- await logPreprocessingError ( {
97- workflowId,
98- executionId,
99- triggerType,
100- requestId,
101- userId : fallbackUserId ,
102- workspaceId,
103- errorMessage,
104- loggingSession,
105- } )
106-
107- return { actorUserId : null , shouldBlock : true }
108- }
109-
11022export interface PreprocessExecutionOptions {
11123 // Required fields
11224 workflowId : string
@@ -123,7 +35,7 @@ export interface PreprocessExecutionOptions {
12335 // Context information
12436 workspaceId ?: string // If known, used for billing resolution
12537 loggingSession ?: LoggingSession // If provided, will be used for error logging
126- isResumeContext ?: boolean // If true, allows fallback billing on resolution failure (for paused workflow resumes)
38+ isResumeContext ?: boolean // Deprecated: no billing fallback is allowed
12739 useAuthenticatedUserAsActor ?: boolean // If true, use the authenticated userId as actorUserId (for client-side executions and personal API keys)
12840 /** @deprecated No longer used - background/async executions always use deployed state */
12941 useDraftState ?: boolean
@@ -170,7 +82,7 @@ export async function preprocessExecution(
17082 skipUsageLimits = false ,
17183 workspaceId : providedWorkspaceId ,
17284 loggingSession : providedLoggingSession ,
173- isResumeContext = false ,
85+ isResumeContext : _isResumeContext = false ,
17486 useAuthenticatedUserAsActor = false ,
17587 } = options
17688
@@ -274,68 +186,54 @@ export async function preprocessExecution(
274186 }
275187
276188 if ( ! actorUserId ) {
277- actorUserId = workflowRecord . userId || userId
278- logger . info ( `[${ requestId } ] Using workflow owner as actor: ${ actorUserId } ` )
279- }
280-
281- if ( ! actorUserId ) {
282- const result = await resolveBillingActorWithFallback ( {
283- requestId,
189+ const fallbackUserId = userId || workflowRecord . userId || 'unknown'
190+ logger . warn ( `[${ requestId } ] ${ BILLING_ERROR_MESSAGES . BILLING_REQUIRED } ` , {
284191 workflowId,
285192 workspaceId,
193+ } )
194+
195+ await logPreprocessingError ( {
196+ workflowId,
286197 executionId,
287198 triggerType,
288- workflowRecord,
289- userId,
290- isResumeContext,
291- baseActorUserId : actorUserId ,
292- failureReason : 'null' ,
199+ requestId,
200+ userId : fallbackUserId ,
201+ workspaceId,
202+ errorMessage : BILLING_ERROR_MESSAGES . BILLING_REQUIRED ,
293203 loggingSession : providedLoggingSession ,
294204 } )
295205
296- if ( result . shouldBlock ) {
297- return {
298- success : false ,
299- error : {
300- message : 'Unable to resolve billing account' ,
301- statusCode : 500 ,
302- logCreated : true ,
303- } ,
304- }
206+ return {
207+ success : false ,
208+ error : {
209+ message : 'Unable to resolve billing account' ,
210+ statusCode : 500 ,
211+ logCreated : true ,
212+ } ,
305213 }
306-
307- actorUserId = result . actorUserId
308214 }
309215 } catch ( error ) {
310216 logger . error ( `[${ requestId } ] Error resolving billing actor` , { error, workflowId } )
311-
312- const result = await resolveBillingActorWithFallback ( {
313- requestId,
217+ const fallbackUserId = userId || workflowRecord . userId || 'unknown'
218+ await logPreprocessingError ( {
314219 workflowId,
315- workspaceId,
316220 executionId,
317221 triggerType,
318- workflowRecord,
319- userId,
320- isResumeContext,
321- baseActorUserId : null ,
322- failureReason : 'error' ,
323- error,
222+ requestId,
223+ userId : fallbackUserId ,
224+ workspaceId,
225+ errorMessage : BILLING_ERROR_MESSAGES . BILLING_ERROR_GENERIC ,
324226 loggingSession : providedLoggingSession ,
325227 } )
326228
327- if ( result . shouldBlock ) {
328- return {
329- success : false ,
330- error : {
331- message : 'Error resolving billing account' ,
332- statusCode : 500 ,
333- logCreated : true ,
334- } ,
335- }
229+ return {
230+ success : false ,
231+ error : {
232+ message : 'Error resolving billing account' ,
233+ statusCode : 500 ,
234+ logCreated : true ,
235+ } ,
336236 }
337-
338- actorUserId = result . actorUserId
339237 }
340238
341239 // ========== STEP 4: Get User Subscription ==========
0 commit comments