Repository navigation
Description
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
- Create and use a chat inside project A, so its transcript exists under
projects/<slug-A>/. - From a second window (tray / mini window) that has a different project B selected, open that chat and send a turn.
- Watch
~/.commandcode/projects/: the session's.jsonl/.meta.json/.checkpoints.jsonlare moved from<slug-A>to<slug-B>. - Check the moved file's first line —
cwdis still project A, whilethread-index.db.project_path,app-state.json.threads[].projectPathandsession-storage-roots.jsonall say project B. - 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.
-
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 ownsessionheader (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. -
Do not re-bind a session from a window's selection.
rememberSessionRootshould 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 (selectedByOtheralready exists for the write path). -
Make relocation explicit and auditable.
PROJECT_RELOCATE_SESSIONSalready exists and does this withcollisions: "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 withfromDir/toDir), instead of moving files silently inside asessionLoad. -
Keep the header in sync if a move is legitimate. When a session is genuinely relocated, rewrite the
sessionheader'scwd(or add an explicitprojectrecord) so the file, the index and the UI cannot diverge afterwards. Consider a startup reconciliation that reports (not auto-fixes) sessions whose headercwddisagrees 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