Skip to content

fix(project): use path-aware project identity to prevent clone collisions#17943

Open
oddvalue wants to merge 1 commit intoanomalyco:devfrom
oddvalue:fix/separate-clone-project-identity
Open

fix(project): use path-aware project identity to prevent clone collisions#17943
oddvalue wants to merge 1 commit intoanomalyco:devfrom
oddvalue:fix/separate-clone-project-identity

Conversation

@oddvalue
Copy link
Copy Markdown

@oddvalue oddvalue commented Mar 17, 2026

Issue for this PR

Closes #17940

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When multiple local clones of the same git repo exist, they all get the same project ID because it's derived solely from the root commit hash. This means they share one snapshot directory and one project record — the last-opened clone overwrites the worktree path, breaking file tracking for the others.

The fix changes the project ID to Hash.fast(rootCommit + "\0" + worktree). Since git worktrees all resolve to the same common root path via --git-common-dir, they continue to share one project ID. Separate clones have different worktree paths, so they now get distinct IDs.

This works because the worktree variable already captures the right distinction: it's the common root for worktrees (shared across all worktrees of a repo) and the repo's own path for standalone clones.

The cached ID read (readCachedId) was also moved after worktree resolution so it's only called once we know whether --git-common-dir succeeded, and the worktree fallback (sandbox !== worktree) is preserved for the case where .git is a file (as in worktrees) rather than a directory.

Existing .git/opencode cache files will be invalidated on first run since the ID format changed from raw root commit to a hash. The new ID is computed and cached automatically with no user-visible impact.

How did you verify your code works?

Ran bun test in packages/opencode/ — all 19 project tests pass including the updated clone test that now asserts distinct IDs. Full suite: 1332 pass, 17 skip, 1 pre-existing failure (unrelated file permissions test).

Screenshots / recordings

N/A — no UI changes.

Checklist

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

…ions

When multiple local clones of the same git repo exist, the project ID
was derived solely from the root commit hash, causing all clones to
share one snapshot directory and project record. The last-opened clone
would overwrite the worktree path, breaking file tracking for others.

Combine the root commit with the worktree path (Hash.fast) so that
separate clones get distinct project IDs while git worktrees of the
same repo continue to share one ID via their common root.

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

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

Potential Related PRs Found:

  1. PR fix(project): repair split project IDs across worktrees #14287 — fix(project): repair split project IDs across worktrees

  2. PR fix: desktop app worktree collision - use separate ID per worktree #5647 — fix: desktop app worktree collision - use separate ID per worktree

These PRs appear to address similar concerns around project identity and worktree/clone collisions. PR #14287 specifically mentions "repair split project IDs across worktrees" and PR #5647 addresses "worktree collision" with a separate ID approach—both are conceptually related to this PR's fix of using path-aware identity to prevent clone collisions.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Multiple local clones of same repo share one project identity, breaking file change tracking

1 participant