core: agent silently stays in old directory when session_move fails ("Unable to move session to <dir>")
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- git, typescript
- Domain
- tooling
Research direction
The generic error mapping is in packages/core/src/tool/plugin/opencode.ts, in the session_move tool's Effect.mapError. Compare it with the typed-error mapping in the session.move HTTP handler and with worktree_remove in the same file. Reproduce by calling session_move on a nonexistent directory in Code Mode. Done when the tool failure names the cause, such as the directory not existing, instead of only 'Unable to move session to ...'.
Written by the indexing model from the issue text.
Description
Description
After creating a worktree, the agent can end up working in the old directory without anyone noticing: session_move failed, the agent couldn't tell why, and it carried on by cd-ing into the worktree in every shell call. The session stayed in the old directory, so the worktree's AGENTS.md was never loaded and relative paths in read/edit/glob resolved against the wrong root.
How it happened (2.0.30, Sonnet 5.5): in one turn the model ran git fetch && git worktree add ../repo-x in a shell call and called tools.opencode.session_move to ../repo-x as a parallel tool call. The move ran ~100 ms after the shell started, before the fetch had finished, so the directory didn't exist yet. Rejecting the move was correct. But the tool result was only:
Unable to move session to /…/repo-x
so the model had no reason to retry. Calling session_move again once the directory existed worked.
Two things would make this recoverable:
- Say why the move failed.
packages/core/src/tool/plugin/opencode.ts(same ondev) maps every error to one message:Effect.mapError( (error) => new ToolFailure({ message: `Unable to move session to ${input.directory}`, error }), ),SessionMovealready fails with typed errors (DestinationNotFoundError,DestinationNotDirectoryError,DestinationUnavailableError,NotFoundError). Thesession.moveHTTP handler maps them to specific messages, andworktree_removein the same file maps its own errors, so the same pattern fits here. WithDirectory does not exist: …the model would most likely have retried. - Say when to call it. The injected hint ("When you create a worktree outside the current working directory … consider using
executeto calltools.opencode.session_move") and the tool description ("do not run destination-dependent tools in the same execute call") don't say the directory must exist first. Adding "call it after the command that creates the directory has finished, not in parallel with it" would likely have prevented this.
Plugins
No response
OpenCode version
2.0.30
Steps to reproduce
- In Code Mode:
await tools.opencode.session_move({ directory: "/tmp/does-not-exist" })
→Unable to move session to /tmp/does-not-exist(caught error:name: "Error", nocause) - Same move over HTTP:
opencode api post /api/session/<sessionID>/move --data '{"directory":"/tmp/does-not-exist"}'
→400 {"_tag":"InvalidRequestError","message":"Directory does not exist: /tmp/does-not-exist"} opencode.loghas no entry for the failed tool call.
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
- Dominant language
- TypeScript
- Stars
- 213k
- Forks
- 28.4k
- Avg merge
- 8h 58m
- Merged PRs (30d)
- 251
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from anomalyco/opencode
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
anomalyco/opencode#56002 · 1 comment ·
Maintainers usually reply within 1 day
-
app: keybinds match the produced character, so Ctrl+F and other letter shortcuts fail on non-Latin layoutsPossibly taken @ZXLyyds100 claimed this 1 day ago. Openreproduced
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
anomalyco/opencode#55676 · 2 comments ·
Maintainers usually reply within 1 day
-
tui: NumPad End/Home ignored under kitty keyboard protocol (Windows Terminal reports KP_END 57424)Possibly taken @argszero claimed this 1 day ago. Openreproduced
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anomalyco/opencode#55533 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
anomalyco/opencode#55383 · 3 comments ·
Maintainers usually reply within 1 day
-
web: second Firefox tab never connects to /api/event - Cache-Control: no-cache lets Firefox's HTTP cache block concurrent SSE requestsPossibly taken @zonemeen claimed this 2 days ago. Openreproduced
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
anomalyco/opencode#55369 · 2 comments ·
Maintainers usually reply within 1 day
All issues in anomalyco/opencode
Similar issues
-
Endpoint links in the tag operations list are below the 24px target sizePossibly taken @AdzerKI claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
ai-driven-qa bug Minor
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
linagora/twake-tasks#435 ·
Maintainers usually reply within 1 day
-
bug domain: database priority: p1 Stellar Wave
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
StellarState/SS-backend#632 · 1 comment ·
Maintainers usually reply within 1 day
-
A2A audit timestamps end in +00:00Z (invalid ISO 8601)Possibly taken @O1sumitkumar claimed this today. Openbug good first issue help wanted python
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
`cf complete zsh >> .zshrc` fails on vanilla zshMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
cloudflare/cf#340 ·
Maintainers usually reply within 1 day