Skip to content

fix(opencode): recover projects moved to a new path - #38584

Open
1hirak wants to merge 2 commits into
anomalyco:devfrom
1hirak:stale-workspace-recovery
Open

fix(opencode): recover projects moved to a new path#38584
1hirak wants to merge 2 commits into
anomalyco:devfrom
1hirak:stale-workspace-recovery

Conversation

@1hirak

@1hirak 1hirak commented Jul 24, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #38578

Type of change

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

What does this PR do?

When a Git repository moved, the stored project kept the missing original path
as its primary worktree and tracked the live path as a sandbox. Desktop startup
could therefore request the deleted path first, causing Git discovery to fail
in FileSystem.realPath before the existing project record could be repaired.

This change recovers the project at both boundaries:

  • before instance creation, a missing stored worktree resolves to its single
    surviving sandbox;
  • the recovered directory is used as the instance cache key and runtime
    context, so the stale and current requests share one valid instance;
  • the in-process alias remains available for repeated stale requests after the
    database migration;
  • the live worktree is promoted to the project's primary worktree;
  • missing and duplicate sandbox paths are removed;
  • matching project and legacy-global sessions move to the recovered project
    directory, including their relative path, without changing
    time_updated; and
  • matching workspace directories are updated.

Recovery is intentionally conservative: it only redirects a missing primary
worktree when exactly one recorded sandbox still exists. Existing behavior is
unchanged when the primary worktree exists or multiple live sandboxes make the
replacement ambiguous.

How did you verify your code works?

The regression tests create a Git repository, seed project and legacy-global
sessions plus a workspace, move the repository, and then request the deleted
path. They verify:

  • the stale directory resolves to the moved repository before Git discovery;
  • instance context and caching use the live path;
  • the project ID remains stable;
  • the live worktree is promoted and sandbox state is cleaned;
  • sessions, relative paths, and workspace records are migrated; and
  • session timestamps are preserved.

Executed:

bun test test/project/project.test.ts test/project/instance.test.ts
# 47 pass, 0 fail

bun typecheck

# Required pre-push monorepo hook
bun turbo typecheck
# 30 successful, 30 total

oxlint packages/opencode/src/project/project.ts \
  packages/opencode/src/project/instance-store.ts \
  packages/opencode/test/project/project.test.ts \
  packages/opencode/test/project/instance.test.ts
# 0 errors

git diff --check

Screenshots / recordings

Not applicable; this is a project/session persistence and instance-routing fix
with no UI changes.

Checklist

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

@belisoful

belisoful commented Jul 30, 2026

Copy link
Copy Markdown

#35311 is a much better solution than this.

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.

Desktop restores a moved/deleted workspace and leaves its sessions permanently failing with FileSystem.realPath ENOENT

2 participants