Skip to content

fix(project): prevent cross-repo project_id cache collisions for bare repos#18044

Closed
StevenTCramer wants to merge 2 commits intoanomalyco:devfrom
TimeWarpEngineering:fix/project-id-cache-bare-repos
Closed

fix(project): prevent cross-repo project_id cache collisions for bare repos#18044
StevenTCramer wants to merge 2 commits intoanomalyco:devfrom
TimeWarpEngineering:fix/project-id-cache-bare-repos

Conversation

@StevenTCramer
Copy link
Copy Markdown
Contributor

@StevenTCramer StevenTCramer commented Mar 18, 2026

Issue for this PR

Closes #18045

Type of change

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

What does this PR do?

Project.fromDirectory was caching the project id at worktree/.git/opencode.
For bare repos (for example .../org/repo.git), worktree was computed from path.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-dir resolves 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?

  • Ran: bun test --timeout 30000 test/project/project.test.ts
  • Result: 20 pass, 0 fail
  • Also validated regression behavior manually:
    • reverted src/project/project.ts to previous commit and reran test -> new regression test failed as expected
    • restored fixed src/project/project.ts and reran test -> all tests passed

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

N/A (non-UI change)

Checklist

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

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.
@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

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:

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

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

These PRs appear to be in the same problem domain (project ID uniqueness and collision prevention), so there may be overlap or related fixes.

@StevenTCramer StevenTCramer changed the title fix(project): isolate project ID cache per bare repo fix(project): prevent cross-repo project_id cache collisions for bare repos Mar 18, 2026
@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@StevenTCramer
Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: project_id cache collision across bare repos under shared parent directory

1 participant