Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

core: agent silently stays in old directory when session_move fails ("Unable to move session to <dir>")

オープン 初心者向け
#56,038 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@1052326311 がすでに取り組んでいます。

2026年10月16日 から。

  • #56059 @1052326311 による — オープン
  • #56060 @bercedev による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
git, typescript
領域
tooling

調査の方向性

汎用的なエラーマッピングは packages/core/src/tool/plugin/opencode.ts 内、session_move ツールの Effect.mapError にあります。HTTP ハンドラ session.move の型付きエラーマッピングや、同じファイル内の worktree_remove と比較してください。Code Mode で存在しないディレクトリを指定して session_move を呼び出し、再現します。ツールの失敗が、単に 'Unable to move session to ...' と表示するのではなく、ディレクトリが存在しないといった原因を示せば完了です。

索引モデルが issue の本文から書いたものです。

説明

reproduced
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:

  1. Say why the move failed. packages/core/src/tool/plugin/opencode.ts (same on dev) maps every error to one message:
    Effect.mapError(
      (error) => new ToolFailure({ message: `Unable to move session to ${input.directory}`, error }),
    ),
    
    SessionMove already fails with typed errors (DestinationNotFoundError, DestinationNotDirectoryError, DestinationUnavailableError, NotFoundError). The session.move HTTP handler maps them to specific messages, and worktree_remove in the same file maps its own errors, so the same pattern fits here. With Directory does not exist: … the model would most likely have retried.
  2. Say when to call it. The injected hint ("When you create a worktree outside the current working directory … consider using execute to call tools.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
  1. 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", no cause)
  2. 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"}
  3. opencode.log has no entry for the failed tool call.
Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

主要言語
TypeScript
スター
215k
フォーク
28.9k
平均マージ
7時間 53分
マージ済み PR(30日)
278

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anomalyco/opencode のほかの issue

anomalyco/opencode の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。