Skip to content

[Bug]: Re-opening moved/renamed project fails with PlatformError: NotFound: FileSystem.realPath (stale project.worktree in opencode.db) #49817

Closed as not planned

Description

@Rafal1

Description

When a project folder on disk is moved or renamed, OpenCode continues to attempt resolving the old path. Re-opening the new directory in the UI does not refresh the project's root worktree or its active sessions in the database, resulting in a fatal FileSystem.realPath error during prompts and file operations. It only writes new path in 'project_directory' in ~/.local/share/opencode/opencode.db/opencode.db (not worktree)

Plugins

any

OpenCode version

1.18.31

Steps to reproduce

  1. Create and open a project inside a nested directory in OpenCode (e.g., ~/projects/category-a/my-app or C:/projects/old-dir/my-app).
  2. Close OpenCode.
  3. Move or rename the folder structure on disk (e.g., move my-app directly to ~/projects/my-app or C:/projects/my-app, and remove old-dir).
  4. Launch OpenCode and open the project from its new location (C:/projects/my-app).
  5. Send any prompt or trigger an operation that requires workspace access.

Actual Behavior:
OpenCode crashes with an unhandled PlatformError because it still resolves the old path:

level=ERROR message=failed ref=err_... error="PlatformError: NotFound: FileSystem.realPath (C:/projects/old-dir/my-app) (cause: Error: ENOENT: no such file or directory, lstat 'C:\\projects\\old-dir')"
...
level=ERROR message="prompt_async failed" sessionID=ses_... cause="Cause([Die(PlatformError: NotFound: FileSystem.realPath (C:\\projects\\old-dir\\my-app) (cause: Error: ENOENT: no such file or directory, lstat 'C:\\projects\\old-dir'))])"

Screenshot and/or share link

Similar issue to this: #48349

Operating System

Windows 11 (latest)

Terminal

powershell

Activity

  1. Rafal1 commented on Sep 18, 2026

    @Rafal1
    Author

    Workaround (Direct SQLite Database Fix):
    Users can manually repair their database by updating the stale paths:

    Close OpenCode.

    Back up the database

    Copy-Item "$env:USERPROFILE\.local\share\opencode\opencode.db" "$env:USERPROFILE\.local\share\opencode\opencode.db.bak"
    

    Run the following SQL updates (using Node.js built-in node:sqlite or any SQLite CLI):

    -- 1. Update project worktree and name
    UPDATE project 
    SET worktree = '<NEW_FULL_PATH>',
        name = '<PROJECT_NAME>',
        time_updated = strftime('%s', 'now') * 1000
    WHERE id = '<PROJECT_ID>';
    
    -- 2. Update existing sessions pointing to the old path
    UPDATE session 
    SET directory = REPLACE(directory, '<OLD_PATH>', '<NEW_PATH>'),
        path = REPLACE(path, '<OLD_PATH>', '<NEW_PATH>'),
        time_updated = strftime('%s', 'now') * 1000
    WHERE directory LIKE '%<OLD_PATH>%';
    
    -- 3. Update session parts and event logs
    UPDATE part SET data = REPLACE(data, '<OLD_PATH>', '<NEW_PATH>') WHERE data LIKE '%<OLD_PATH>%';
    UPDATE event SET data = REPLACE(data, '<OLD_PATH>', '<NEW_PATH>') WHERE data LIKE '%<OLD_PATH>%';
    

    Restart OpenCode and recreate the project with the right path

  2. Dante-dan commented on Sep 30, 2026

    @Dante-dan
    Contributor

    I checked the current V2 project/session paths. The project-root refresh is already implemented in #45043 and #45735: resolving a renamed repository replaces its canonical directory when the previous directory no longer exists. Existing sessions retain their own Location, so refreshing the project does not itself relocate those sessions. V2 also supports moving an idle session whose source directory is gone.

    On V2 commit df51166711, the existing renamed-project and clone-preservation regressions passed (2 tests), and the missing-source session-move regression passed (1 test). This is code-level coverage; I have not reproduced the reported Windows 1.18.31 scenario.

    For automatic recovery, I propose using the existing durable Session.Moved path to relocate inactive local sessions under the vanished project root to the new root, preserving their relative subdirectories. Keep live sessions and explicit workspace placements unchanged, and preserve historical parts/events rather than rewriting their text. Could you approve this scoped session-recovery approach?

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions