Technical question regarding moving video file in Agent Code

I’ve been working on code for my agent that will download trailers and subtitles for a video then automatically move the video, trailer, and subtitles into an appropriately named folder using the naming convention and file structure plex recommends these extras. After digging into the existing plex code I was able to achieve this once I saw that I could call media.all_parts()[0].file in the update method of my agent to know where the file being processed for metadata is located.

My goal now is to find a way to point plex to the new location of the video file so I can avoid the refresh scan plex automatically does to find the file once it realizes the file was moved. The issue with this refresh for me is that if it often locks up mid refresh and inevitably crashes the server(this crash was already happening back when I was manually doing what I wrote the code to do). My first thought to point plex to the new video location after I moved it in code was to set media.all_parts()[0].file to the new location, but it ended up not being that simple. Can I get some input from a dev on what I would need to do to correctly move the file in code?

Seems like the crash I am seeing could be due to the database not responding soon enough. Right before the crash Plex keeps logging the Waited one whole second for a busy database warning.

Update:
I am on Server Version: 1.21.2.3943

Updating this topic with my latest findings after digging deeper into the plex code base.

It seems like plex does not write the file change I made to the MediaPart back to the database. But it does look like the title attribute in <MetadataItem> gets updated at some point after my agent is called. Seems like if I can find where in the code the update is being made to the title attribute I’ll have the info I need to make the update to the file attribute in <MediaPart>.

If a dev can save me the time and point me to the information that would also be appreciated.