fix(project): prefer existing sandbox project when remote URL changes#33594
fix(project): prefer existing sandbox project when remote URL changes#33594bashrusakh wants to merge 1 commit into
Conversation
|
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: Potential Related PRs Found:
The current PR (#33594) fills a specific gap in sandbox project fallback handling mentioned in the notes section, complementing the earlier worktree cache fix via |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Relates to #16995 (worktree cache lookup); not a direct fix for the per-worktree cache lookup itself, but a defense-in-depth fix that prevents the duplicate project / orphan sessions symptom whenever a directory's resolved project ID drifts (remote URL change, cache loss, worktree cache miss, etc.).
Type of change
What does this PR do?
When the resolved project ID drifts away from an existing project whose
sandboxesalready contain this directory, reuse the existing project instead of upserting a new one. This covers:projectV2.resolvecomputes a new ID from the new remote, but a worktree of the original project may already list this directory in itssandboxes..git/opencodecache is missing, the sandbox match still routes the directory back to the canonical project.Without this fix,
fromDirectoryeither migrates the existing project to a new ID (causing the TUI to display a "fork" of the same project) or creates a duplicate row at the new ID, splitting sessions and emitting spurious(fork #1)sessions.The lookup uses
json_eachon thesandboxesJSON column for a precise, case-sensitive match against the canonical git worktree path returned byprojectV2.resolve— no full table scan, noLIKEon the serialized JSON.How did you verify your code works?
bun typecheckinpackages/opencode— only pre-existing error insrc/bus/global.tsbun test test/project/project.test.ts— 37/37 pass (added one new case for the sandbox-match reuse)bun test test/project/inpackages/opencode— 85 pass, 1 skip, 4 fail (all 4 failures are pre-existing ondevininstance.test.ts/instance-bootstrap.test.ts, unrelated to this change)bun typecheckandbun test test/project.test.tsinpackages/core— cleanScreenshots / recordings
N/A (backend-only change)
Checklist