Skip to content

fix: allow deleting sessions whose parent file is missing - #659

Open
fallleave001 wants to merge 1 commit into
agegr:mainfrom
fallleave001:fix-delete-missing-parent
Open

fix: allow deleting sessions whose parent file is missing#659
fallleave001 wants to merge 1 commit into
agegr:mainfrom
fallleave001:fix-delete-missing-parent

Conversation

@fallleave001

@fallleave001 fallleave001 commented Aug 30, 2026

Copy link
Copy Markdown

Problem

Deleting a session fails with HTTP 500 when its parentSession header points to a file that no longer exists:

Error: ENOENT: no such file or directory, open '...\sessions\--C--...home-server--\2026-08-09T05-19-52-466Z_019fe4f6...jsonl'

In DELETE /api/sessions/[id] (app/api/sessions/[id]/route.ts), readSessionHeader(parentSessionPath) throws when the parent file was deleted or moved first (common when fork chains span directories and the parent is removed earlier). The whole delete then fails, leaving the session undeletable via the UI permanently.

Fix

Tolerate a missing parent header file and treat it as undefined:

const parentSessionPath = readSessionHeader(filePath)?.parentSession;
let parentSessionId: string | undefined;
if (parentSessionPath) {
  try {
    parentSessionId = readSessionHeader(parentSessionPath)?.id;
  } catch {
    parentSessionId = undefined;
  }
}

Deleting proceeds without re-parenting children when the parent is already gone (safer than failing the whole delete).

Repro

  1. Open a session (A), fork it to create child (B) in a different project/directory
  2. Delete A (or move the file manually)
  3. Try to delete B in the UI → stucks at confirmed state, refresh shows it still there; API returns 500

Deleting a session with a parentSession header whose file no longer
exists (e.g. the parent was deleted or moved first) failed with an
ENOENT from readSessionHeader, leaving the session undeletable.
Tolerate a missing parent header file and treat it as no parent.
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.

2 participants