Skip to content

Bug: orphan sessions when project id drifts after git history rewrite #30683

@JochenYang

Description

@JochenYang

Bug: orphan sessions when project id drifts after git history rewrite

Describe the bug

After restarting opencode, the /sessions command sometimes does not show sessions that were created previously. They are not deleted from the database, but Session.list filters them out because their project_id no longer matches the currently-resolved project id.

To reproduce

  1. Use a git project that has no remote URL configured (so Project.resolve falls through to deriving the id from the root commit SHA1).
  2. Open opencode in the project, create some sessions, then close opencode.
  3. Rewrite the git history so the root commit SHA1 changes. This can happen in practice via:
    • git rebase --root rewriting the root commit
    • git filter-repo or git filter-branch rewriting history
    • A fresh clone / re-init that produces a different root commit
  4. Lose the <git-common-dir>/opencode cache file (e.g. AV quarantine, git clean -fd, IDE rewriting .git, WSL cross-filesystem quirks).
  5. Restart opencode in the same project directory.
  6. The sessions created in step 2 no longer appear under the new project id.

Expected behavior

Sessions created in step 2 should still be visible. They should be migrated to the new project id when opencode restarts and detects the project id has changed.

Actual behavior

The sessions are stranded under the old project_id and never appear in /sessions or any list query. They occupy storage forever and are effectively unreachable from the TUI.

Cause

Project.migrateProjectId early-returns on oldID === undefined, and fromDirectory's global->specific fallback only handled project_id = "global", so non-global orphan projects are stranded.

A fix lands in PR #30682.

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