fix(project): prevent cross-repo project_id cache collisions for bare repos#18044
fix(project): prevent cross-repo project_id cache collisions for bare repos#18044StevenTCramer wants to merge 2 commits intoanomalyco:devfrom
Conversation
For bare repos (e.g. opencode.git), the previous code used path.dirname(common) to get the worktree, then wrote the cache to worktree/.git/opencode. But path.dirname on 'opencode.git' gives the parent org directory, so all repos under that org shared one cache file and got the same project_id. Now we use the git common dir directly (e.g. opencode.git) for cache reads/writes, ensuring each repo gets its own cache.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Found 2 related PRs that may be duplicates or related to PR #18044:
These PRs appear to be in the same problem domain (project ID uniqueness and collision prevention), so there may be overlap or related fixes. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Closing this PR. The upstream code has been completely refactored to Effect, so this fix needs to be reimplemented against the new codebase. Will revisit when time permits. |
Issue for this PR
Closes #18045
Type of change
What does this PR do?
Project.fromDirectorywas caching the project id atworktree/.git/opencode.For bare repos (for example
.../org/repo.git),worktreewas computed frompath.dirname(git-common-dir), which resolves to the parent org directory instead of the repo git dir.That made unrelated repos under the same parent share one cache file and sometimes the same
project_id.This change reads/writes the cache directly in
git-common-dir(<common>/opencode) so each repo gets its own cache file.It also keeps the existing fallback behavior when
--git-common-dirresolves to sandbox/empty output.Added regression coverage for two different bare repos under the same parent directory to assert they do not share project ids.
How did you verify your code works?
bun test --timeout 30000 test/project/project.test.ts20 pass, 0 failsrc/project/project.tsto previous commit and reran test -> new regression test failed as expectedsrc/project/project.tsand reran test -> all tests passedScreenshots / recordings
If this is a UI change, please include a screenshot or recording.
N/A (non-UI change)
Checklist