Skip to content

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

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.

Activity

  1. github-actions commented on Jun 4, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from the above (e.g., specifically about root-commit SHA drift after history rewrite rather than directory rename), feel free to clarify.

  2. github-actions commented on Aug 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions