Skip to content

fix(sessions): keep a deleted session from being written back by a write in progress - #254

Merged
GoDiao merged 1 commit into
mainfrom
fix/deleted-session-reappears
Nov 15, 2026
Merged

GoDiao merged 1 commit into
mainfrom
fix/deleted-session-reappears

Conversation

@GoDiao

@GoDiao GoDiao commented Nov 15, 2026

Copy link
Copy Markdown
Owner

What changed

SessionService.deleteSession and deleteSessionFile now remove the session file inside the per-session write queue (enqueueSessionWrite), through one private removeSessionFile.

Why

A deleted session could come back as an empty session in the sidebar. It was seen after closing side chat tabs: each closed side chat left a session titled "btw" in the list.

Every write to a session file goes through the per-session queue; the two deletes did not. A write is "find the file, read it, append", and the append uses appendFile, which creates a missing file. A delete that landed between "find the file" and "append" was undone by the append: the file came back with one or two metadata lines and no parent, so the list showed it as an ordinary session.

The usual trigger is the title check after the CLI exits (restoreCustomTitle, called from src/server/session/persistence.ts): deleting a session stops its CLI first, the exit starts the title check, and the delete follows immediately. A side chat always has a custom title and a running CLI, so it hit this every time. Renaming a session and recording its permission mode at the same moment bring the file back the same way.

With the delete in the queue the two cannot interleave: a write that is ahead finishes and the file is then removed; a delete that is ahead leaves the write with no file to find, and it does nothing.

Not covered

Two paths that can still recreate a deleted session's file. Neither was reproduced, and neither is handled here:

  • The CLI process's own writes. A delete waits for the CLI to exit for at most 2 seconds; a CLI that exits and writes after that would create the file again.
  • clearSessionTranscript with a fallbackWorkDir creates a file for a session that has none (used for placeholder sessions). Starting a deleted session is blocked, but a /clear sent by another client at the moment of the delete is not.

Files that were already written back before this fix stay on disk; they can be deleted from the sidebar.

How it was tested

  • src/server/__tests__/sessions.test.ts: 8 new tests, 4 kinds of write (title check with an unchanged title, title written again, rename, permission mode) times the 2 delete entry points. Each holds the write at its read or append step, deletes the session, releases the write, and expects the session file and the list entry to be gone. All 8 fail on unchanged main and pass with the fix.
  • bun test: 2661 passed, 0 failed.
  • bun test --randomize --seed=1 on the touched test file: 255 passed.
  • No desktop code changed; the desktop lint and tests were not run on this branch.
  • Not verified in the running app; the tests above are the only evidence.

The session state and side chat design docs describe the delete being in the queue.

…ite in progress

Deleting a session unlinked its file without going through the per-session
write queue that every other write to the file uses. A write is "find the
file, read it, append", and the append creates a missing file, so a delete
that landed in between left a file with one or two metadata lines behind. It
showed up in the sidebar as an empty session with no parent.

The usual trigger was closing a side chat: stopping its process makes the
server write the custom title again, and the delete follows at once. It was
not limited to side chats or to the title: renaming a session or recording its
permission mode at that moment brought the file back the same way.

Both delete entry points (deleteSession and deleteSessionFile) now run in the
same queue, so a write that came first finishes before the file is removed,
and a write that comes after finds no file and does nothing.
@GoDiao
GoDiao merged commit 73f4dbd into main Nov 15, 2026
4 checks passed
@GoDiao
GoDiao deleted the fix/deleted-session-reappears branch November 15, 2026 10:42
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