Skip to content

fix(project): prefer existing sandbox project when remote URL changes#33594

Draft
bashrusakh wants to merge 1 commit into
anomalyco:devfrom
bashrusakh:sandbox-lookup-fix
Draft

fix(project): prefer existing sandbox project when remote URL changes#33594
bashrusakh wants to merge 1 commit into
anomalyco:devfrom
bashrusakh:sandbox-lookup-fix

Conversation

@bashrusakh

@bashrusakh bashrusakh commented Jun 24, 2026

Copy link
Copy Markdown

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

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

What does this PR do?

When the resolved project ID drifts away from an existing project whose sandboxes already contain this directory, reuse the existing project instead of upserting a new one. This covers:

Without this fix, fromDirectory either 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_each on the sandboxes JSON column for a precise, case-sensitive match against the canonical git worktree path returned by projectV2.resolve — no full table scan, no LIKE on the serialized JSON.

How did you verify your code works?

  • bun typecheck in packages/opencode — only pre-existing error in src/bus/global.ts
  • bun test test/project/project.test.ts — 37/37 pass (added one new case for the sandbox-match reuse)
  • bun test test/project/ in packages/opencode — 85 pass, 1 skip, 4 fail (all 4 failures are pre-existing on dev in instance.test.ts / instance-bootstrap.test.ts, unrelated to this change)
  • bun typecheck and bun test test/project.test.ts in packages/core — clean

Screenshots / recordings

N/A (backend-only change)

Checklist

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

@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 github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 24, 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. fix(opencode): preserve orphan sessions on project id drift #30682 - fix(opencode): preserve orphan sessions on project id drift

    • Directly related: addresses session orphaning when project IDs change, which is the downstream impact of the remote URL change issue this PR fixes.
  2. fix(core): include git store hash in project ID to distinguish indepe… #29977 - fix(core): include git store hash in project ID to distinguish indepe...

    • Related: addresses project ID computation and distinction, which is part of the same problem space around project identity.
  3. fix(project): repair split project IDs across worktrees #14287 - fix(project): repair split project IDs across worktrees

    • Related: addresses split project IDs across worktrees, which is a similar issue to the sandbox project reuse problem.

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 --git-common-dir.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jun 24, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant