Skip to content

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

Open
benoitheinrich wants to merge 6 commits intoanomalyco:devfrom
benoitheinrich:fix-14082-sidebar-sandbox-sessions
Open

fix(project): repair split project IDs across worktrees#14287
benoitheinrich wants to merge 6 commits intoanomalyco:devfrom
benoitheinrich:fix-14082-sidebar-sandbox-sessions

Conversation

@benoitheinrich
Copy link

@benoitheinrich benoitheinrich commented Feb 19, 2026

Issue for this PR

Closes #14082

Type of change

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

What does this PR do?

When using git worktrees/sandboxes, the same repo can end up with multiple OpenCode project.id values for a single project.worktree. That splits sessions (and other project-scoped data) across IDs. In the Web UI with workspaces enabled this shows up as empty session lists for some sandboxes (/session?directory=<sandbox>&roots=true...) even though sessions exist.

This PR:

  • Stabilizes the project-id cache by storing it in the git common dir (shared by all worktrees).
  • Runs a one-time startup repair only when duplicates exist: creates a DB backup, migrates sessions from duplicate project IDs into the canonical project row, preserves metadata (sandboxes + icon/name/commands) and permissions when missing on the canonical row, then deletes duplicate project rows.
  • Guards the repair to only act on worktrees that have at least one vcs='git' project row.

How did you verify your code works?

  • cd packages/opencode && bun test test/project/project.test.ts
  • Manual verification against a local DB with duplicate project rows:
    • After starting the server, project.current resolves to the same project id for root and sandbox directories.
    • /session?directory=<sandbox>&roots=true... returns the expected sessions.

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 github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
@benoitheinrich
Copy link
Author

Updated the PR description to match the PR template sections.

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

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

@benoitheinrich
Copy link
Author

CI note: the only failing check is e2e (windows) (and the dependent test (linux) job that just asserts all upstream jobs passed).

The Windows log shows failures in prompt e2e tests with Bun reporting missing zod under .opencode/node_modules/@opencode-ai/plugin/dist/tool.js (e.g. "Cannot find package 'zod'") along with a few NotFoundError messages.

I don't see the project repair running in that job (no "Found duplicate projects" output), so this looks unrelated to the project-id/worktree changes. Would appreciate a rerun of the Windows e2e check.

@benoitheinrich
Copy link
Author

Added a test to assert returns the same when called from the repo root vs any git worktree path (: ). Commit bc711ab1b.

@benoitheinrich
Copy link
Author

Added a test to assert Project.fromDirectory() returns the same project.id when called from the repo root vs a git worktree path.

Commit: bc711ab1b

@benoitheinrich
Copy link
Author

I manually validated the one-time repair path locally.

Command:

  • bun run --conditions=browser ./src/index.ts serve --port 4097

Observed output:

Found duplicate projects. Creating DB backup...
DB backup created at: /home/benoit/.local/share/opencode/opencode.db.before-project-repair.2026-02-19T142444290Z.bak
Duplicate project repair complete. To revert: stop opencode and restore /home/benoit/.local/share/opencode/opencode.db.before-project-repair.2026-02-19T142444290Z.bak (and .bak-wal/.bak-shm if present).
Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.
opencode server listening on http://127.0.0.1:4097

Here is a screenshot of my sandboxes (worktrees) back:
image

@benoitheinrich
Copy link
Author

benoitheinrich commented Feb 19, 2026

Added coverage for the canonicalRow = canonical(data.worktree) path: if a DB project row already exists for a worktree, fromDirectory() should reuse that canonical DB id even if the git common-dir cache file contains a different id.

Commit: 17c9e1b7d

@benoitheinrich
Copy link
Author

@adamdotdevin any chance to get this PR reviewed soon ? thanks 😄

@benoitheinrich benoitheinrich force-pushed the fix-14082-sidebar-sandbox-sessions branch from d9d9dce to f930618 Compare February 23, 2026 07:23
@benoitheinrich benoitheinrich force-pushed the fix-14082-sidebar-sandbox-sessions branch from cfa9cb4 to 7d1804c Compare February 25, 2026 19:00
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.

Web: Sidebar session list hides worktree/sandbox sessions after 1.2.6 upgrade (filters to current directory only)

1 participant