Skip to content

fix: migrate sessions when project ID changes after git init#21232

Closed
qwertist wants to merge 1 commit intoanomalyco:devfrom
qwertist:fix/migrate-sessions-on-project-id-change
Closed

fix: migrate sessions when project ID changes after git init#21232
qwertist wants to merge 1 commit intoanomalyco:devfrom
qwertist:fix/migrate-sessions-on-project-id-change

Conversation

@qwertist
Copy link
Copy Markdown

@qwertist qwertist commented Apr 6, 2026

Summary

Fixes #21230 — sessions disappear from TUI after git init in a project directory.

Problem

When git init runs in a directory that already has opencode sessions, the project ID changes (from global project to git root commit hash). A new project entry is created, but sessions linked to the old project ID are not migrated. The TUI filters by the new project ID and shows zero sessions.

Fix

Added a migration step in Project.fromDirectory() (after the existing global→project migration on line 313) that:

  1. Finds stale project entries with the same worktree but a different id
  2. Migrates all sessions from stale projects to the current project
  3. Deletes the stale project entries

This is a 12-line addition in packages/opencode/src/project/project.ts.

Testing

Manually verified on a real database with 19 orphaned sessions. After the fix, all sessions correctly appear in the TUI.

When git init runs in a directory that already has opencode sessions,
the project ID changes from the global project to the git root commit
hash. Sessions linked to the old project ID become invisible in the TUI.

This adds a migration step in fromDirectory() that detects stale project
entries with the same worktree but different IDs, moves their sessions
to the current project, and removes the stale entries.

Fixes anomalyco#21230
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, the only closely related PR found is:

PR #14287: fix(project): repair split project IDs across worktrees - #14287

This PR appears related as it also addresses project ID issues across worktrees, which is the core problem PR #21232 is fixing. However, it appears to be an older PR addressing a similar but distinct issue.

The current PR #21232 is specifically focused on migrating sessions when a project ID changes after git init, which is a more specific scenario than the broader worktree ID splitting issue.

No other directly duplicate PRs found addressing the same exact issue.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 6, 2026
@github-actions github-actions bot closed this Apr 6, 2026
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.

Project ID changes after git init — sessions disappear from TUI

1 participant