You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: --config pointing into a directory that does not exist fails, because ReadWriteLock is created before _ensure_dir()#271
When the global --config PATH option points to a file whose parent directory does not exist yet, any command that reads or writes session state fails with a FileNotFoundError, for example:
FileNotFoundError: [Errno 2] No such file or directory: '/some/new/dir/sessions.json.lock'
The traceback ends in filelock, at os.open(database, flags, 0o600) in _open_lock_database.
The README and SKILL.md describe --config as the way to isolate parallel or agent runs, so pointing it at a fresh path is an expected use and should work.
Cause
Order of statements in _LockedFileStore.__init__ in colab_cli/state.py (0.8.0):
self._rwlock=filelock.ReadWriteLock(self.lock_path, is_singleton=False) # line 76self._ensure_dir() # line 77make_private(self.path)
ReadWriteLock.__init__ opens the lock database right away, so with a missing directory the constructor itself fails and the os.makedirs in the next line is never reached. The _ensure_dir() call that is meant to protect against this never gets a chance to run.
It does not depend on the filelock version
I constructed a ReadWriteLock for a lock path under a directory that does not exist, in throwaway environments:
sqlite3.OperationalError: unable to open database file
3.32.7
same
4.3.0
FileNotFoundError: [Errno 2]
Only the exception type differs; the constructor fails in every version. So a version cap on filelock would not help, and reordering the two lines does.
Reproduction
The snippet above is the smallest reproduction. With the CLI itself it should be (I did not run a colab command to confirm this one; it follows from the code and the result above):
I hit it while another application manages --config for me, one accounts/<id>/sessions.json per account. On a first-time setup the directory did not exist, and creating the first session failed. Creating the directory by hand made it work.
Suggested fix
Make sure the directory exists before the lock is created:
This does not depend on how filelock behaves, and it holds for all three versions above.
Related
I found no existing issue or PR about this one. The same ordering is still on main.
Open PR feat(sessions): track attached sessions in sessions.json #230 ("feat(sessions): track attached sessions in sessions.json") happens to move self._ensure_dir() above the ReadWriteLock(...) line in _LockedFileStore.__init__, which would also fix this, but it is part of an unrelated feature and is not merged, and its tests do not cover a missing parent directory. A small regression test for --config into a new directory would be useful whichever PR lands the reorder.
Notes
With the default path, ~/.config/colab-cli/, nobody notices, probably because that directory usually exists already (the CLI writes its log there). I did not check what SettingsStore does with its default path when that directory is missing. It shares the same __init__, so the same reordering would cover it.
Environment
google-colab-cli 0.8.0, installed with uv tool install
Python 3.14, Ubuntu 26.04 (WSL 2)
filelock 4.3.0 (what uv installed); 3.29.2 and 3.32.7 tested in throwaway environments
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
What happens
When the global
--config PATHoption points to a file whose parent directory does not exist yet, any command that reads or writes session state fails with aFileNotFoundError, for example:The traceback ends in
filelock, atos.open(database, flags, 0o600)in_open_lock_database.The README and SKILL.md describe
--configas the way to isolate parallel or agent runs, so pointing it at a fresh path is an expected use and should work.Cause
Order of statements in
_LockedFileStore.__init__incolab_cli/state.py(0.8.0):ReadWriteLock.__init__opens the lock database right away, so with a missing directory the constructor itself fails and theos.makedirsin the next line is never reached. The_ensure_dir()call that is meant to protect against this never gets a chance to run.It does not depend on the
filelockversionI constructed a
ReadWriteLockfor a lock path under a directory that does not exist, in throwaway environments:filelocksqlite3.OperationalError: unable to open database fileFileNotFoundError: [Errno 2]Only the exception type differs; the constructor fails in every version. So a version cap on
filelockwould not help, and reordering the two lines does.Reproduction
The snippet above is the smallest reproduction. With the CLI itself it should be (I did not run a
colabcommand to confirm this one; it follows from the code and the result above):I hit it while another application manages
--configfor me, oneaccounts/<id>/sessions.jsonper account. On a first-time setup the directory did not exist, and creating the first session failed. Creating the directory by hand made it work.Suggested fix
Make sure the directory exists before the lock is created:
This does not depend on how
filelockbehaves, and it holds for all three versions above.Related
main.self._ensure_dir()above theReadWriteLock(...)line in_LockedFileStore.__init__, which would also fix this, but it is part of an unrelated feature and is not merged, and its tests do not cover a missing parent directory. A small regression test for--configinto a new directory would be useful whichever PR lands the reorder.Notes
With the default path,
~/.config/colab-cli/, nobody notices, probably because that directory usually exists already (the CLI writes its log there). I did not check whatSettingsStoredoes with its default path when that directory is missing. It shares the same__init__, so the same reordering would cover it.Environment
google-colab-cli0.8.0, installed withuv tool installfilelock4.3.0 (whatuvinstalled); 3.29.2 and 3.32.7 tested in throwaway environmentsAll reactions