What happens to my 401(k) loan when I file bankruptcy?

Hopefully nothing.

Your 401(k) (generally) is protected in bankruptcy as an exempt piece of property.

Utah Code 78B-5-505. Property exempt from execution.

(xiv) except as provided in Subsection (1)(b), any money or other assets held for or payable to the individual as a participant or beneficiary from or an interest of the individual as a participant or beneficiary in a retirement plan or arrangement that is described in Section 401(a), 401(h), 401(k), 403(a), 403(b), 408, 408A, 409, 414(d), 414(e), or 457, Internal Revenue Code;

Your 401(k) loan is simply a loan you have taken out from the 401(k) (your own retirement money) for some immediate purpose.  Bankruptcy doesn’t discharge this debt, because it is a debt that you owe to yourself.  You simply keep making payments back to yourself (401k) after filing.