Skip to content

session: unable to resume a session after its directory is removed (Session location unavailable) #55035

Open

Description

@Dif-scope

Summary

After upgrading from OpenCode 1.x to 2.0.27, sessions whose working directory no longer exists on disk cannot be opened at all: the client shows "Session location unavailable" and only offers to move the session to another directory. In V1 the same sessions could still be opened with a missing directory, so this looks like a behavior regression introduced by V2's location/worktree resolution.

Environment

  • opencode version: 2.0.27
  • OS: Windows 10.0.26200 (win32 x64)
  • Terminal: Windows Terminal + PowerShell (env vars not set)
  • Shell: PowerShell 5.1 (ComSpec = C:\Windows\system32\cmd.exe)
  • Install/channel: npm global, channel latest (major upgrade 1.19.0 → 2.0.27)
  • Active plugins: none server-side (only a CLI plugin configured)

Reproduction

  1. On OpenCode 1.x, create a session whose working directory is D:\work\proj (the session's directory = that path).
  2. Delete or move D:\work\proj.
  3. Upgrade to OpenCode 2.0.27 (the V1→V2 migration runs).
  4. Try to open/resume that session.

A V2-only reproduction (no upgrade required) should be: create a session in directory X, delete X, then reopen the session.

Expected Behavior

The session should still be openable, at minimum read-only, with a graceful fallback for a missing directory (for example, falling back to the home directory or a "read-only transcript" view). A missing directory should not make the session permanently inaccessible, or it should at least be clearly explained.

Actual Behavior

  • Opening the session shows the panel titled "Session location unavailable" with the body "Choose another directory to continue this session."
  • The client throws Error("Location unavailable") after resolving the session location; the location layer surfaces Worktree.DirectoryUnavailableError.
  • The only recovery offered is moving the session to another directory (or recreating the missing directory externally).

Additional Context

  • No data is lost: opencode session export <id> still works and the database is intact.
  • In my database, 3 sessions pointed to a directory I had deleted; recreating the directory made them openable again, which confirms the trigger is directory existence.
  • After the migration, all 76 legacy sessions have project_id = 'global' and workspace_id = NULL (i.e. not associated with their real project/directory), whereas freshly created V2 sessions appear to get a real project id. This may be relevant to which location-resolution path legacy sessions take.
  • The worktree migration (20260812213948_worktree) and clear_v1_session_permission were applied exactly at the V1→V2 upgrade.
  • Observed consistently for every session whose directory is missing.
  • Workaround: restore the missing directory, or use the client's "Choose directory" move action.

Related Issues

Activity

  1. opencode-agent commented on Oct 13, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report!

    What you're asking for: when a session's working directory has been deleted, it should still open with a sensible fallback (for example the home directory, or a clearly labelled read-only transcript) instead of requiring a move to another directory first.

    In v2, the "Session location unavailable" prompt is how a missing directory is meant to be handled. The session history should still be shown; only the message input is replaced by the prompt to move the session (see #46215 and #53268). The Location unavailable error you found comes from the session picker's search, which falls back to the local session list, so it shouldn't stop the session from opening. If you're using the TUI or desktop app and the history does not appear at all, please say which one you're using. That would be a separate bug.

    An automatic fallback directory or an explicit read-only mode would be a change to how this works, so I've marked this as a feature request for the maintainers to consider. Related issues:

    Until then, recreating the directory or using Choose directory are the ways to continue these sessions, and opencode session export <id> still gives you the full transcript.

  2. thehaven commented on Oct 14, 2026

    @thehaven

    Same failure mode, slightly different sub-case: worktree-removed sessions in
    the v2 CLI TUI (opencode2 2.0.28 on Linux, not the desktop client).

    Repro follows your steps 1-3, but the missing path is a removed
    git worktree rather than a deleted/moved project directory. The orphan
    sandboxes have a distinctive shape on this host:

    ~/.local/share/opencode/worktree/3bb416/<name>
    ~/.local/share/opencode/worktree/60843d/add-opencode-subagents-view
    ~/.local/share/opencode/worktree/a8f579/<name>
    

    The inner contents (opencode2's per-worktree data) are still on disk; it's
    the git worktree itself that's gone, and the opencode2 sqlite session DB
    still has rows whose directory field points to the now-missing path.
    opencode2 session list --format json confirms it: every row carries
    the directory of the cwd it was created in.

    Workaround that worked here: git worktree add <same-path> <branch>
    recreates the path, and opencode2 -c (or -s <id>) then resumes
    cleanly. The session is bound to the path, not to git's worktree-id
    hash, so the mismatch between the original 60843d and whatever new
    worktree-id git assigns is fine.

    Pre-emptive config that helped on the prevention side: setting
    session.new_location: "launch" in ~/.config/opencode/cli.json means
    new sessions in this CLI no longer inherit the active session's CWD; they
    stop binding to a soon-to-die worktree path. That doesn't recover
    already-orphaned sessions, just reduces the rate of new ones, and the
    underlying recovery UX you describe is the real gap.

    Pinning this here rather than filing a duplicate. Happy to file a
    separate feature request for a session.fallback_on_missing config
    (launch | home | prompt | skip) if that would help; let me know.

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