Skip to content

fix(project): use git common dir for project ID cache to prevent worktree session loss#15900

Closed
michaeldwan wants to merge 1 commit intoanomalyco:devfrom
michaeldwan:md/orphaned-project-ids
Closed

fix(project): use git common dir for project ID cache to prevent worktree session loss#15900
michaeldwan wants to merge 1 commit intoanomalyco:devfrom
michaeldwan:md/orphaned-project-ids

Conversation

@michaeldwan
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug where sessions become invisible after restarting opencode in a git worktree. The project ID cache was stored in the per-worktree .git path, which is a file (not a directory) in worktrees — so reads and writes silently failed. Each restart recomputed the ID via rev-list --all, which is unstable for repos with orphan branches (gh-pages, stash roots, subtree merges), producing a different project ID and orphaning all previous sessions.

Changes:

  • Resolve --show-toplevel and --git-common-dir before reading the cache, so the cache is read/written in the shared .git directory
  • All worktrees for the same repo now resolve the same project ID
  • Switch rev-list from --all to HEAD to exclude orphan branches from the root commit set
  • Set local git config in test fixture so tests are self-contained

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other

Issue for this PR

Fixes #12726
Fixes #12103
Fixes #13782
Fixes #5638

How did you verify your code works?

  • tsgo --noEmit passes (0 errors)
  • bun test test/project/project.test.ts — 18 pass, 0 fail
  • New test: worktree resolves the same project ID as main repo, cache lives in shared .git dir

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…tree session loss

Worktrees resolve .git to a per-worktree file, so caching the project ID
there fails silently. Each restart recomputes the ID via rev-list --all,
which is unstable for repos with orphan branches (gh-pages, stash roots).
This causes sessions to become invisible after restarting opencode in a
worktree.

- Resolve --show-toplevel and --git-common-dir before reading the cache
- Store and read the project ID cache from the shared .git directory
- Switch rev-list from --all to HEAD to exclude orphan branches
- Set local git config in test fixture for reproducible test runs
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 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 Mar 3, 2026

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

I found a potentially related PR:

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

This PR appears to address a similar issue with project IDs being split/different across worktrees. It may be addressing the same root cause (git worktree .git file handling) that PR #15900 is fixing. You should check if #14287 is still open and whether it covers the same solution or takes a different approach.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 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 Mar 3, 2026
@github-actions github-actions bot closed this Mar 3, 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

1 participant