Skip to content

Sessions become orphaned when project directory is renamed #23248

@sim590

Description

@sim590

Description

When a project directory is renamed or moved, existing sessions become invisible in the session list. The directory field stored on each session is an absolute path that is never updated when the project's worktree changes. The sessions remain in the database but are effectively orphaned — they cannot be accessed through the normal /sessions UI.

In case 1, fromDirectory() updates the project's worktree in the database, but the directory on existing sessions still points to the old path.

In case 2, the automatic migration in project.ts only matches sessions where session.directory === project.worktree exactly, which fails when the directory was renamed.

Plugins

None

OpenCode version

v1.4.7+

Steps to reproduce

Case 1: Renaming an existing Git repository (simplest)

  1. Create a Git repository with at least one commit in ~/prog/foo
  2. Open OpenCode in ~/prog/foo and create a session
  3. Close OpenCode
  4. Rename the directory: mv ~/prog/foo ~/prog/bar
  5. Open OpenCode in ~/prog/bar
  6. Open /sessions — the previous session is not visible

Case 2: Renaming a non-git directory followed by git init

  1. Open OpenCode in ~/prog/orphan-test (no Git repository)
  2. Create a session (stored under project_id = "global" with directory = ~/prog/orphan-test)
  3. Close OpenCode
  4. Rename: mv ~/prog/orphan-test ~/prog/orphan-test2
  5. Run git init && git add -A && git commit -m "init" in ~/prog/orphan-test2
  6. Open OpenCode in ~/prog/orphan-test2
  7. The session remains orphaned under project_id = "global" with the old directory path

Screenshot and/or share link

No response

Operating System

Linux

Terminal

Alacritty

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions