Repository navigation
Description
Summary
When opencode's worktree feature rebinds an existing session to a new worktree directory, an ACP client can never load that session again. session/load requires the session's (new) directory as cwd per the documented contract, but the client only knows the original workspace root — opencode never exposes the new directory to the client: not in the error message, not in session/list, and not via any session/update. The thread shows the same error on every panel reopen/restart, forever.
Environment
- opencode version: 2.4.1 (stable, global bun install)
- OS: Windows 11 (10.0.26200, win32 x64)
- Terminal: ACP child process spawned by Zed (no TTY)
- Shell: Git Bash (paths only)
- Install/channel: stable
- Active plugins:
@slkiser/[email protected], localfast-compactionplugin — unrelated to the session-load path - ACP client: Zed, OpenCode agent via
opencode acp
Reproduction
- In an ACP client (Zed), open a workspace at the project's main worktree
<main>and start an OpenCode session. opencode binds the session todirectory = <main>(confirmed:session_v2.directory). - From within that session, have opencode create a new git worktree
<wt>(worktree feature).- Result in
~/.local/share/opencode/opencode.db: the session row'sdirectoryis rewritten to<wt>, and<wt>is registered in theworktreetable. Nothing is sent to the ACP client.
- Result in
- Close and reopen the client (or just reopen the agent panel). Zed restores the thread and calls
session/loadwithcwd = <main>. - The load fails on every attempt:
Invalid params: session ses_dec8b3b56ffeHYhCTRAHy8Weo6 does not belong to cwd: <main>: {
"sessionId": "ses_dec8b3b56ffeHYhCTRAHy8Weo6",
"cwd": "<main>"
}
session/list with cwd = <main> also does not return the session (directory-scoped), so the thread is invisible and unresumable from the client. Reproducible 100%: this fires on every panel reopen (4 failed restore attempts logged within one morning via Zed's agent-panel error telemetry).
Expected Behavior
Per the documented ACP contract ("To load, resume, or fork a session, the client must pass that session's directory as cwd"), the client needs to know the session's directory. Either:
- opencode should not silently rebind an active ACP session's directory when creating a worktree, or
- it should tell the client — e.g. a
session_info_updatewith_meta["opencode/directory"](same pattern as the existingopencode/retry/opencode/compaction_metakeys), or - minimally: expose the session's directory in
session/list_metaand in the invalid-params error, so clients can recover (re-load with the rightcwdor at least surface "session moved to ").
Actual Behavior
The client has no way to learn the session's new directory, session/load fails permanently with Invalid params ... does not belong to cwd, and the session is also hidden from session/list under the original cwd. The thread is dead from the client's perspective even though the session is intact and loadable from the worktree directory.
Additional Context
Timeline evidence from a real occurrence (opencode 2.4.1, opencode.db):
- Session created
2026-11-25 17:05:53(local) — before the worktree existed. - Worktree
<wt>registered in theworktreetable at2026-11-25 18:21:58, strategygit. session_v2.directoryfor that session now points to<wt>; the session was moved after creation.
Client side (Zed db, sidebar_threads): the thread row pins session_id to the workspace <main> with no notion of a directory change, so the client cannot comply with the contract even in principle.
Workaround confirmed: opening <wt> itself as the client workspace makes session/list (cwd = <wt>) return the session and it loads fine — which also confirms the diagnosis. The same pattern has already stranded several other sessions (session created before its worktree was registered).
Related but distinct: #60847 (worktree discovery cross-registers sibling dirs), #59371 (folder-scoped list hides sessions with duplicate project rows).
Redaction note: session title, local username and project paths are redacted; session id kept because it is required to follow the db timeline.
Activity
opencodejr commentedon Nov 26, 2026
Thanks for the detailed report. I reproduced this on 2.4.1 with a small ACP client script (attached below), and it still happens on the latest
dev(314842df).What the script does:
session/newwithcwdset to the main repo.session.moveAPI, which runs the same core move the agent'sopencode.session.movetool uses.opencode acp, the way Zed restores a thread.After the restart:
session/listwithcwdset to the main repo no longer returns the session.session/loadwith thatcwdfails every time withInvalid params: session ses_… does not belong to cwd: …/main.session/loadwith the worktree ascwdworks.While the session was moved, the ACP process sent nothing that carried the new directory; the only notification was an
available_commands_update. I couldn't find any handling of session moves in the ACP code either. I've passed this to the maintainers.Reproduction script (repro.mjs)
Run it:
bun repro.mjsLyleLiu666 commentedon Nov 26, 2026
I tested #66612 at
17c3eb1e06with Zed 1.30.2 on macOS and the ACP SDK. Live rebinding worked: Zed received the new directory and a relative file read ran in the destination worktree.After a full Zed restart, both a session moved while connected and an already-moved session sent
session/loadwith their original cwd and got-32602. The SDK loaded both sessions and replayed their history using the new cwd fromdata.directory.The patch below allows load and resume from a previous directory recorded for that session and still owned by its current project. With the same saved Zed profile and database, it reopened the original thread from the old cwd, replayed its history, and ran a follow-up file read in the new worktree. Windows remains unverified.
Patch on my fork