Skip to content

Desktop: a chat can be silently re-bound to another project and its transcript physically moved, while the session header still records the original cwd #1177

Backlog

Description

@xtalia

Summary

A chat can be silently re-bound to a different project and its transcript physically moved out of the project folder it was created in. In the desktop sidebar the chat goes missing from its project (or appears under another one); opening it from the tray shows it now lives in the wrong project. The transcript's own header still records the original cwd, so the sidebar/index and the file disagree permanently.

Reproduced with file-level evidence on one real session; the code path responsible is adopt stranded transcripts (bV → JT) combined with rememberSessionRoot, which takes the project from the calling window rather than from the transcript.

Expected Behavior

  • A session's project is fixed when the session is created. Opening or sending from another window with a different project selected must not re-assign it.
  • The app must never move a transcript to a different project folder on its own, and certainly not based on which copy happens to be larger.
  • If a transcript is ever relocated, its header cwd (or an explicit project binding) must be updated so the sidebar, the index and the file agree.
  • At minimum, tell the user: "this chat was found under ; move it here?" — never do it silently.

Actual Behavior

Session 89ab9441-e151-4c75-9648-7907aa2ae1a1 ("YouTube Bot Check"):

Fact Value
Transcript header cwd C:\Users\sergsinist\.hermes\interestingthings
Where the file actually lives ~/.commandcode/projects/c-users-sergsinist-**documents**/89ab9441-….jsonl (1.69 MB, 370 records)
projectPath in app-state.json C:\Users\sergsinist\Documents
project_path in thread-index.db C:\Users\sergsinist\Documents
session-storage-roots.json projectPath: Documents, cleanupRoots: [".hermes\interestingthings", "Documents"]
thread.createdAt 2026-11-25 02:06:57
thread.locationUpdatedAt 2026-11-25 02:23:19.716
Log line at that same instant [2026-11-25 02:23:19.305] [renderer] [queue] send: starting turn {"threadId":"89ab9441-…","chars":159}

So the re-bind happened on a send, and the transcript was moved afterwards: the file now sits under documents while its first line still says cwd: C:\Users\sergsinist\.hermes\interestingthings.

The transcript contains 371 message records and exactly one session header record — there is no cwd/project/workspace change record anywhere in the file. Nothing in the transcript itself ever records the move; only the surrounding index and session-storage-roots.json do.

Scope: scanned all 135 transcripts under ~/.commandcode/projects. Exactly one has a header cwd that does not match the directory it is stored in (this session). The other apparent mismatches are 8.3 short-name artifacts (SERGSI~1 vs sergsinist), not real. The 80 other sessions of .hermes\interestingthings are still stored correctly.

Root cause (from the shipped bundle, out/main/index.js, v0.1.63)

Load path resolves the project and may "adopt" a transcript from another root:

function Rl(e, t, n = []) {
  const r = (await Promise.all([...new Set([t, ...n])].map((s) => ri(s, e)))).flat();
  const o = await wr(e, r) ?? t;
  return ol(e) || await nR(e, o).catch(...), o;
}

nR → bV picks the largest copy found under any root and moves it into the current one:

const v = p.filter(...).sort((b, D) => D.size - b.size)[0];   // biggest copy wins
if (!v || v.size <= a.size) return null;
await JT({ sessionId: e, fromDir: v.dir, toDir: s, replace: true });

JT physically renames the .jsonl (plus .meta.json, .checkpoints.jsonl, .prompts.jsonl) between project directories, replacing the target.

The project written alongside that move comes from the window, not the transcript:

rememberSessionRoot({ sessionId: a.session.id, root: c, projectPath: i?.projectPath ?? r });

and is then preferred over the thread's own project:

function zT(e) {
  const t = ti(e);                       // session-storage-roots entry
  if (t !== null) return { projectPath: t, root: ei(e) };   // wins
  const n = Yc().get(e);
  return { projectPath: n?.projectPath ?? null, root: n?.worktreePath ?? null };
}

cleanupRoots accumulates every root ever used for the session (Qz/WT union both lists), which is what lets bV find the "stranded" copy on a later load — so once this happens the session keeps being a candidate for re-adoption.

Suspected trigger: the chat was opened or a turn was sent from a window whose selected project was Documents (the tray/mini window keeps its own selection — bJ.selected, matchesSelected, selectedByOther), while the session's transcript lived under .hermes\interestingthings. The window then claimed it and moved the files.

Steps to reproduce the issue

  1. Create and use a chat inside project A, so its transcript exists under projects/<slug-A>/.
  2. From a second window (tray / mini window) that has a different project B selected, open that chat and send a turn.
  3. Watch ~/.commandcode/projects/: the session's .jsonl/.meta.json/.checkpoints.jsonl are moved from <slug-A> to <slug-B>.
  4. Check the moved file's first line — cwd is still project A, while thread-index.db.project_path, app-state.json.threads[].projectPath and session-storage-roots.json all say project B.
  5. In the sidebar the chat is no longer under A (and may not be visible under B until it reloads).

Command Code Version

0.1.63 (desktop, packaged: true; ProductVersion 0.1.63.0)

Operating System

Windows

Terminal/IDE

Command Code desktop app (Electron), launched from the Start Menu shortcut — not a terminal session.

Shell

N/A (desktop app)

Session file (optional)

The affected transcript is private (1.69 MB / 370 records) but I can share its header line, directory listing, and the relevant state entries verbatim on request.

Fix prompt (optional)

Four changes, in impact order.

  1. Never move a transcript based on which copy is bigger. In bV, drop the size comparison as the adoption criterion. A transcript belongs to the project recorded in its own session header (cwd), interpolated through the same slug function the harness uses. If the header and directory disagree, trust the header (or ask), never the newer/larger file.

  2. Do not re-bind a session from a window's selection. rememberSessionRoot should only record a root/project for sessions that have no transcript yet, or when the user explicitly picks "move this chat to project X". A window that merely has another project selected must not be able to claim an existing session — this is the same class of bug as a second window stealing a project (selectedByOther already exists for the write path).

  3. Make relocation explicit and auditable. PROJECT_RELOCATE_SESSIONS already exists and does this with collisions: "set-aside-source" and user intent. Route any automatic relocation through the same path so it is visible, and record the event somewhere inspectable (a notice or a log line with fromDir/toDir), instead of moving files silently inside a sessionLoad.

  4. Keep the header in sync if a move is legitimate. When a session is genuinely relocated, rewrite the session header's cwd (or add an explicit project record) so the file, the index and the UI cannot diverge afterwards. Consider a startup reconciliation that reports (not auto-fixes) sessions whose header cwd disagrees with their directory.

Verify by: creating a chat in project A, sending a turn from a window with project B selected, and asserting the transcript files stay under <slug-A>; and by scanning all transcripts for header.cwd != stored directory and expecting zero real mismatches.

Additional context

Filed after the same profile showed this symptom as "the project disappears and the session vanishes; open it in the tray and it has just moved to another project". Distinct from #1174 (state-write EPERM / orphaned turn), #1175 (hotkey warnings, backup schema drift) and #1176 (switch latency: full transcript re-read + inline base64). There is an existing kill switch for the adopt step — CC_DISABLE_ADOPT_STRANDED_TRANSCRIPTS=1 (CMD_ prefix also accepted) — which is a useful workaround while this is open.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions