@@ -76,6 +76,9 @@ export const callStepFile = <TData>(options: CallStepFileOptions, motia: Motia):
7676 let argvPayload = jsonData
7777 let tempDir : string | undefined
7878 let metaPath : string | undefined
79+ // This is for keeping the cleanup idempotent
80+ let isCleaned : boolean = false
81+ let isCleaning : boolean = false
7982
8083 // If payload is large, write it to a temp file and pass the path instead
8184 if ( jsonBytes >= THRESHOLD_BYTES ) {
@@ -96,16 +99,18 @@ export const callStepFile = <TData>(options: CallStepFileOptions, motia: Motia):
9699 projectRoot : motia . lockedData . baseDir ,
97100 } )
98101
99- let isCleaning = false
100- let isCleaned = false
101-
102102 const cleanupTemp = async ( ) => {
103- if ( ! tempDir ) return
103+ if ( isCleaning || isCleaned || ! tempDir ) return
104104 const dir = tempDir
105105 tempDir = undefined
106+ isCleaning = true
107+
106108 try {
107109 await fs . promises . rm ( dir , { recursive : true , force : true } )
108110 } catch { }
111+
112+ isCleaning = false
113+ isCleaned = true
109114
110115 }
111116
@@ -270,7 +275,8 @@ export const callStepFile = <TData>(options: CallStepFileOptions, motia: Motia):
270275 if ( tempDir ) {
271276 const dir = tempDir
272277 tempDir = undefined
273- void fs . promises . rm ( dir , { recursive : true , force : true } ) . catch ( ( ) => { } )
278+ void fs . promises . rm ( dir , { recursive : true , force : true } )
279+ . catch ( ( err ) => { logger . debug ( `temp cleanup: ${ dir } : ${ err . message ?? err } ` ) } )
274280 }
275281 tracer . end ( {
276282 message : error . message ,
0 commit comments