Does Colab preserve /content files after an idle-triggered runtime recycle?
0 reputation · 21 Feb 2025, 08:31 UTC
0 reputation · 21 Feb 2025, 08:31 UTC
I need to know whether a Google Colab free-tier runtime preserves files written to /content after the backend disconnects the VM for inactivity and the user reconnects through the browser.
Colab behavior is generally described as ephemeral: hosted VMs are recycled after idle periods and local filesystem state is cleared, but Google does not publish a fixed idle timeout or an explicit resume guarantee. GPU assignment is best-effort and can be preempted. Because behavior can vary by region, account tier, and current load, a single observed reconnect is not reliable evidence.
What exactly happens to /content and mounted Drive paths after an idle disconnect? Does Colab automatically remount Drive on reconnect, and is there any supported way to detect whether the runtime reused the previous VM or provisioned a new one?
35775 reputation · 21 Feb 2025, 18:25 UTC
No. Google Colab does not preserve files written to /content after an idle-triggered runtime recycle. When the free-tier VM is disconnected for inactivity and you reconnect, Colab provisions a fresh virtual machine with an empty /content directory. Google Drive data remains intact in the cloud, but the local mount point is gone.
Confirmed: the hosted VM is ephemeral. After an idle disconnect, a reconnect receives a new backend instance. Local filesystem state—including /content—is cleared. Google Drive files survive because they live in cloud storage, not on the VM.
Inferred but not published: the exact idle timeout. Community observation suggests roughly 90 minutes for free tier and longer for paid tiers, but Google does not commit to a fixed number, and capacity, region, or account tier can shift the actual threshold.
Colab does not automatically remount Google Drive on reconnect. The mount point /content/drive disappears with the VM, so you must re-execute the mount command in the new session:
from google.colab import drive
drive.mount('/content/drive')There is no supported API to detect whether a runtime reused the previous VM or provisioned a new one. A practical heuristic is to write a unique marker file on startup and check for it after reconnect:
import os, time
marker = '/content/session_marker.txt'
if os.path.exists(marker):
print('Possible VM reuse or timeout not reached')
else:
with open(marker, 'w') as f:
f.write(str(time.time()))
print('New VM or fresh /content')Comparing hostname or /proc/self/cgroup across sessions is another informal check, but neither is guaranteed to be stable or documented.
/content as scratch space only. Move anything that must survive into /content/drive/MyDrive, GitHub, or cloud storage before the idle window closes.drive.mount() at the top of every session; do not assume the mount persists.GPU assignment is also best-effort on reconnect; the new VM may have a different accelerator or none at all.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 21 Feb 2025, 13:42 UTC
When the backend recycles a Colab VM for idle periods, the local /content directory on the temporary VM is cleared, so any files written there are lost on reconnection. Only data stored under the mounted Google Drive (/content/drive) survives because Drive is re‑mounted automatically. To verify whether a new VM was provisioned, open the console and look for a “New VM instance” line in the start‑up log, then compare file listings before and after reconnect.