Skip to content

feat(state): keep attached sessions in their own store file - #230

Open
wh1ter4bb1t-js wants to merge 3 commits into
mainfrom
pm/1029-1807/g17-ssh-attach.pr1
Open

wh1ter4bb1t-js wants to merge 3 commits into
mainfrom
pm/1029-1807/g17-ssh-attach.pr1

Conversation

@wh1ter4bb1t-js

Copy link
Copy Markdown
Member

why? the coming colab ssh --attach needs its own file, since older CLIs would unassign anything in sessions.json. Adds an owner-only <stem>.attached.json, refuses a name in both files (colab stop -s NAME recovers) and an attached --config. First of a stack.

Tested: python -m pytest tests/ passes at each commit; 570 passed, 19 skipped at the tip. ruff check passes.

Drake Aiman added 3 commits November 10, 2026 17:23
A session attached to a runtime the CLI did not create must never be
unassigned by an older CLI that cannot tell it apart. StateStore now
keeps attached records in a second owner-only locked file derived from
the sessions path (sessions.attached.json by default,
<stem>.attached.json for --config), reads and lists both files and
removes from both, so existing callers work unchanged.

The file a record is read from decides its attached flag, so refreshing
a record writes it back to the file it came from and never moves it to
the other one. Records in sessions.json gain an "attached": false key,
which older versions ignore because they do not forbid extra fields.
A name can end up in both the sessions file and the attached file, for
example when `colab new -s NAME` (in this or an older version) creates
a session under a name that is already attached. StateStore now raises
DuplicateSessionError for such a name from get and list, so commands
that read the store stop before any Colab request, and the CLI prints
the error with the recovery command: colab stop -s NAME forgets the
attached record without unassigning and leaves the session the CLI
created.
Reading one store's attached file as another store's sessions file,
for example with `--config ~/.config/colab-cli/sessions.attached.json`,
would stamp its records as CLI sessions and write them back that way;
the reverse, a derived attached path that links to another store's
sessions file, would stamp CLI records as attached. StateStore now
refuses a sessions path ending in .attached.json (in any case, or a
symlink to one) and a path whose derived attached path resolves to a
file not named *.attached.json, before touching any file. The CLI runs
the same check on --config at startup, because the store opens lazily
and `colab new` or `colab run` would otherwise assign a runtime before
the refusal and record it nowhere.

Hard links and renamed copies are not detected in either direction: an
attached file linked or copied under a sessions name, or a derived
attached path hard-linked to another store's sessions file.

DuplicateSessionError and the new AttachedStorePathError share
StoreError, which the CLI reports as an error message instead of a
traceback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant