Back to blog
FILE 0x72·ONEDRIVE SYNC WAS REVERTING MY BACKEND EDITS

OneDrive sync was reverting my backend edits

May 9, 2026 · debugging, onedrive, homelab

Every few days my backend would lose a recent fix. The change would work, restart the service, work for hours, then vanish. Git showed the old code back on disk with no commit telling me why.

What was happening

The backend lives in an LXC on Proxmox. The same project also lives on my Mac inside a OneDrive folder, because I sometimes edit from the laptop. The Mac's OneDrive client was syncing the Mac copy up to the cloud. On the homelab side, the Synology was pulling the cloud copy down to a share via its Cloud Sync app. The LXC had an NFS mount of that share.

So there was a path on the LXC where an older-than-current copy of main.py was sitting in the filesystem, drifting via OneDrive whenever I touched the Mac copy.

Then I found a script in cron — written months ago and forgotten — that copied "the latest" main.py from the OneDrive-synced path into the live backend directory. It had been there the whole time, quietly reverting fixes whenever the Mac's OneDrive client overwrote the cloud copy with an older local one.

What I found

Three things had to all be true for the bug to fire:

  1. A stale main.py had to exist on the Mac (any time OneDrive conflict-resolved against me).
  2. OneDrive had to sync it up.
  3. The forgotten cron script had to run and copy it down.

Removing any one would have stopped the corruption. I removed two: the NFS mount that exposed the OneDrive copy to the LXC, and the forgotten script. Then I made the live file immutable so I'd notice if anything else tried to write it:

chattr +i /opt/assistant/backend/main.py

Any future overwrite attempt now logs a permission error instead of silently winning.

The fix

After the cleanup, the only path that can land code on the live backend is the deploy script I actually run by hand. The OneDrive-synced tree still exists for my Mac convenience, but nothing on the server reads from it anymore.

What I'd do differently

The forgotten script was the real culprit, but the OneDrive sync made it dangerous. Two-way sync of source code between dev environments and production-ish boxes is a footgun even when everything works — one network blip on the Mac and you get an older copy promoted to authoritative. I should have caught the script in a cron audit when I migrated the backend off the original host, not three months later when it started costing me fixes.

The immutable bit is now my standing pattern for any file that should only change via a deliberate deploy. If something tries to touch it, I'd rather find out from a write error than from a regression.