fix(core): make worktrees read the project id from local workspace#16795
Open
fix(core): make worktrees read the project id from local workspace#16795
Conversation
jlongster
commented
Mar 9, 2026
| } | ||
| } | ||
|
|
||
| const worktree = await git(["rev-parse", "--git-common-dir"], { |
Contributor
Author
There was a problem hiding this comment.
If you look below, all I did was move this up. There shouldn't be much difference in the order of execution. Only difference will be what happens when these commands file: now we might not have an id, but that's ok. now it'll just fallback to global which is fine
jlongster
commented
Mar 9, 2026
| // same project id as the common dir, so we resolve it now | ||
| if (id == null) { | ||
| id = await readCachedId(path.join(worktree, ".git")) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
this is the main block of code I added
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.
Worktrees currently have a problem where the project id generated for them is always new. This registers them in the db as an entirely new project which is wrong: worktrees should be a workspaces that all connect back to the same project.
This is why things don't work as you expect with worktrees currently: when listing sessions for a project you don't get all the sessions across worktrees by default, you only get sessions for the local workspace. This PR will make anything like that work because those routes are scoped by project, and now worktrees will not create new projects. Everything will be related to a single project.
In a git worktree,
.gitexists but it's just a file that points to the internal git registry for that workspace inside the real.gitdirectory. We can't cache the id in there. Instead, we need to resolve the worktree and if we still don't have anidyet we then try to read the cached id from the main dir where.gitis a real directoryNote that we use
git rev-list --max-parents=0 --allto derive the "root" commit. So the way it worked before might have worked in some cases (the cached id file doesn't exist, so it always goes through that path to get the id). If all cases returned the same output and derived the same id, it would have worked. but that's not realiable:rev-listthat return multiple roots, and these can change over time, so it's really important that we cache it and always reuse whatever we generated first.