fix(opencode): use git common dir for project ID cache to prevent worktree session loss#16389
Open
michaeldwan wants to merge 1 commit intoanomalyco:devfrom
Open
fix(opencode): use git common dir for project ID cache to prevent worktree session loss#16389michaeldwan wants to merge 1 commit intoanomalyco:devfrom
michaeldwan wants to merge 1 commit intoanomalyco:devfrom
Conversation
…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
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found a potential related PR: PR #14287: "fix(project): repair split project IDs across worktrees" Why it's related: This PR directly addresses the same issue of split/fragmented project IDs across worktrees. The current PR (16389) appears to be a more comprehensive fix that uses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #12726
Closes #12103
Closes #13782
Closes #5638
Type of change
What does this PR do?
Sessions disappear after restarting opencode in a git worktree. Two problems:
Cache location: The project ID cache (
opencodefile) was read/written inside the per-worktree.gitpath. In a worktree that's a file, not a directory, so reads and writes silently failed. Every restart recomputed the ID from scratch.Unstable ID computation:
rev-list --max-parents=0 --allincludes orphan branches (gh-pages, stash roots, subtree merges). The sorted first root commit can change depending on which orphan refs exist, producing a different project ID and orphaning all previous sessions.Fix: resolve
--show-topleveland--git-common-dirbefore touching the cache so it lives in the shared.gitdirectory. All worktrees (and independent clones) for the same repo now resolve the same project ID. Switched--alltoHEADso orphan branches can't shift the root commit set.Are you affected?
Run this to check if any of your repos have fragmented project IDs (sessions split across multiple IDs for the same repo):
No output = not affected. If you see rows,
project_idsis how many fragments exist andtotal_sessionsis how many sessions are scattered across them.How did you verify your code works?
tsgo --noEmit— 0 errorsbun test test/project/project.test.ts— 19 pass, 0 fail.gitdir; separate clone of the same repo resolves the same project IDScreenshots / recordings
No UI changes.
Checklist