Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): recheck linked directory after waiting for its lock (#11224)

Danila Katalshov633c6c6a3764
diff --git a/apps/docs/content/docs/project-resources.fr.mdx b/apps/docs/content/docs/project-resources.fr.mdx
index e8b77cec02..c4b6a66098 100644
--- a/apps/docs/content/docs/project-resources.fr.mdx
+++ b/apps/docs/content/docs/project-resources.fr.mdx
@@ -98,6 +98,8 @@ Un répertoire local dispose de deux modes d'exécution, définis par ressource
L'agent travaille directement dans votre répertoire, et les exécutions ont lieu une à la fois. Lorsque deux exécutions utilisent le même répertoire réel, la seconde passe en `waiting_local_directory` et reprend une fois que la première a libéré le répertoire. Deux chemins qui mènent au même répertoire via des liens symboliques différents sont sérialisés de la même manière.
+Si le chemin lié est introuvable au démarrage d’une exécution en attente, celle-ci signale que le dossier du projet n’existe plus. Restaurez le dossier ou mettez à jour le chemin de la ressource avant de réessayer.
+
L'attente ne modifie pas le répertoire et n'occupe pas de slot d'exécution du daemon. Une exécution en attente peut être annulée ; sinon, elle reprend le démarrage lorsque le répertoire et la capacité d'exécution sont disponibles.
Un simple répertoire non git ne peut utiliser que ce mode : le mode worktree est réservé aux dépôts git.
diff --git a/apps/docs/content/docs/project-resources.ja.mdx b/apps/docs/content/docs/project-resources.ja.mdx
index 9eb76e28e3..a276266143 100644
--- a/apps/docs/content/docs/project-resources.ja.mdx
+++ b/apps/docs/content/docs/project-resources.ja.mdx
@@ -100,6 +100,8 @@ Desktop のローカルデーモンがオンラインであることを確認し
エージェントはあなたのディレクトリで直接作業し、実行は一度に 1 つずつ進みます。2 つの実行が同じ実体のディレクトリを使う場合、後から来た実行は `waiting_local_directory` に入り、先の実行がディレクトリを解放してから続行します。異なるシンボリックリンク経由で同じディレクトリに到達する 2 つのパスも、同じように直列化されます。
+待機中の実行が開始する時点でリンク先のパスが存在しない場合、プロジェクトフォルダーが存在しないことが報告されます。再試行する前に、フォルダーを復元するか、リソースのパスを更新してください。
+
待機中はディレクトリを変更せず、デーモンの実行スロットも消費しません。待機中の実行はキャンセルできます。キャンセルしなければ、ディレクトリと実行容量の両方が利用可能になってから起動を再開します。
git 管理外の通常のディレクトリはこのモードしか使えません。ワークツリーモードは git リポジトリ専用です。
diff --git a/apps/docs/content/docs/project-resources.ko.mdx b/apps/docs/content/docs/project-resources.ko.mdx
index b40054d3b9..25ddfc6c44 100644
--- a/apps/docs/content/docs/project-resources.ko.mdx
+++ b/apps/docs/content/docs/project-resources.ko.mdx
@@ -98,6 +98,8 @@ Desktop의 로컬 데몬이 온라인인지 확인합니다.
에이전트가 사용자의 디렉터리에서 직접 작업하며, 실행은 한 번에 하나씩 진행됩니다. 두 실행이 같은 실제 디렉터리를 사용하면 나중에 도착한 실행이 `waiting_local_directory` 상태로 들어가 앞선 실행이 디렉터리를 해제할 때까지 기다립니다. 서로 다른 심볼릭 링크 경로가 같은 디렉터리를 가리켜도 직렬로 실행됩니다.
+대기 중인 실행이 시작될 때 연결된 경로가 없으면 프로젝트 폴더가 더 이상 존재하지 않는다는 오류가 표시됩니다. 다시 시도하기 전에 폴더를 복원하거나 리소스 경로를 업데이트하세요.
+
기다리는 동안 디렉터리를 변경하지 않으며 데몬 실행 슬롯도 차지하지 않습니다. 대기 중인 실행은 취소할 수 있습니다. 취소하지 않으면 디렉터리와 실행 용량을 모두 사용할 수 있을 때 시작 과정을 재개합니다.
git으로 관리되지 않는 일반 디렉터리는 이 모드만 사용할 수 있습니다. 워크트리 모드는 git 저장소 전용입니다.
diff --git a/apps/docs/content/docs/project-resources.mdx b/apps/docs/content/docs/project-resources.mdx
index 32b02425cb..e7aa6d10b9 100644
--- a/apps/docs/content/docs/project-resources.mdx
+++ b/apps/docs/content/docs/project-resources.mdx
@@ -98,6 +98,8 @@ A local directory has two execution modes, set per resource with `execution_mode
The agent works directly in your directory, and runs execute one at a time. When two runs use the same real directory, the later one enters `waiting_local_directory` and continues after the earlier one releases the directory. Two paths that reach the same directory through different symlinks serialize the same way.
+If the linked path is missing when a waiting run is about to start, the run reports that the project folder no longer exists. Restore the folder or update the resource path before retrying.
+
Waiting does not modify the directory or consume a daemon execution slot. A waiting run can be cancelled; otherwise it resumes startup once both the directory and execution capacity are available.
A plain non-git directory can only use this mode: worktree mode covers git repositories.
diff --git a/apps/docs/content/docs/project-resources.zh-Hant.mdx b/apps/docs/content/docs/project-resources.zh-Hant.mdx
index ce8831ae32..6f1da6b1f2 100644
--- a/apps/docs/content/docs/project-resources.zh-Hant.mdx
+++ b/apps/docs/content/docs/project-resources.zh-Hant.mdx
@@ -99,6 +99,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
AI 代理直接在你的目錄裡工作,同一時間只進行一次執行。兩次執行使用同一個真實目錄時,後到的執行進入 `waiting_local_directory`,等前一次釋放目錄後繼續。兩個路徑經不同符號連結指向同一目錄時,同樣序列。
+如果等待中的執行即將開始時找不到連結的路徑,執行會回報專案資料夾已不存在。請先還原資料夾或更新資源路徑,再重試。
+
等待不會修改目錄,也不佔用守護程序執行槽位。等待中的執行可以取消,否則會在目錄和執行容量都可用後繼續啟動。
普通的非 git 目錄只能用這種模式:worktree 模式只面向 git 倉庫。
diff --git a/apps/docs/content/docs/project-resources.zh.mdx b/apps/docs/content/docs/project-resources.zh.mdx
index d1b2816e62..7957f25bc7 100644
--- a/apps/docs/content/docs/project-resources.zh.mdx
+++ b/apps/docs/content/docs/project-resources.zh.mdx
@@ -99,6 +99,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
智能体直接在你的目录里工作,同一时间只进行一次运行。两次运行使用同一个真实目录时,后到的运行进入 `waiting_local_directory`,等前一次释放目录后继续。两个路径经不同符号链接指向同一目录时,同样串行。
+如果等待中的运行即将开始时找不到关联的路径,运行会报告项目文件夹已不存在。请先恢复文件夹或更新资源路径,再重试。
+
等待不会修改目录,也不占用守护进程执行槽位。等待中的运行可以取消,否则会在目录和执行容量都可用后继续启动。
普通的非 git 目录只能用这种模式:worktree 模式只面向 git 仓库。
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index 43910d3d2c..369cf50b61 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -6511,7 +6511,7 @@ func (d *Daemon) acquireLocalDirectoryLockIfNeeded(ctx context.Context, task Tas
}
return nil, true
}
- if err := validateLocalPath(assignment.AbsPath); err != nil {
+ reportInvalidPath := func(err error) {
taskLog.Error("local_directory: path validation failed", "error", err)
failureReason := "local_directory_error"
if errors.Is(err, errLocalDirectoryMissing) {
@@ -6525,6 +6525,9 @@ func (d *Daemon) acquireLocalDirectoryLockIfNeeded(ctx context.Context, task Tas
}); failErr != nil {
taskLog.Error("fail task after local_directory validation error", "error", failErr)
}
+ }
+ if err := validateLocalPath(assignment.AbsPath); err != nil {
+ reportInvalidPath(err)
return nil, true
}
@@ -6697,6 +6700,15 @@ func (d *Daemon) acquireLocalDirectoryLockIfNeeded(ctx context.Context, task Tas
}
return nil, true
}
+ // The linked directory can move while this task is queued. Check again
+ // before execution setup creates context files at the old path.
+ if waitCounted {
+ if err := validateLocalPath(assignment.AbsPath); err != nil {
+ release()
+ reportInvalidPath(err)
+ return nil, true
+ }
+ }
taskLog.Info("local_directory: lock acquired")
return release, false
}
diff --git a/server/internal/daemon/local_directory_test.go b/server/internal/daemon/local_directory_test.go
index 31d868daae..160f574740 100644
--- a/server/internal/daemon/local_directory_test.go
+++ b/server/internal/daemon/local_directory_test.go
@@ -802,6 +802,93 @@ func TestAcquireLocalDirectoryLock_EarlyFailureReportsWithCancelledParent(t *tes
// run as local_directory_missing — the generic local_directory_error gave the
// user no hint that the folder itself was gone. Every other validation failure
// keeps the generic reason.
+func TestAcquireLocalDirectoryLock_ReportsDirectoryMovedDuringWait(t *testing.T) {
+ t.Parallel()
+
+ parent := t.TempDir()
+ dir := filepath.Join(parent, "project")
+ if err := os.Mkdir(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ realDir, err := filepath.EvalSymlinks(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ locker := NewLocalPathLocker()
+ releaseHolder, err := locker.Acquire(ctx, realDir, "holder", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var finishHolder sync.Once
+ defer finishHolder.Do(releaseHolder)
+
+ failures := make(chan string, 1)
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ switch {
+ case strings.HasSuffix(req.URL.Path, "/wait-local-directory"):
+ if err := os.Rename(dir, filepath.Join(parent, "moved")); err != nil {
+ t.Errorf("move linked directory while task waits: %v", err)
+ }
+ finishHolder.Do(releaseHolder)
+ case strings.HasSuffix(req.URL.Path, "/fail"):
+ var report struct {
+ FailureReason string `json:"failure_reason"`
+ }
+ if err := json.NewDecoder(req.Body).Decode(&report); err != nil {
+ t.Errorf("decode terminal report: %v", err)
+ }
+ failures <- report.FailureReason
+ default:
+ t.Errorf("unexpected daemon call: %s %s", req.Method, req.URL.Path)
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ t.Cleanup(srv.Close)
+
+ const daemonID = "d-test"
+ d := &Daemon{
+ client: NewClient(srv.URL),
+ logger: slog.Default(),
+ localPathLocks: locker,
+ cfg: Config{DaemonID: daemonID},
+ }
+ ref, err := json.Marshal(localDirectoryRef{LocalPath: dir, DaemonID: daemonID})
+ if err != nil {
+ t.Fatal(err)
+ }
+ task := Task{
+ ID: "waiter",
+ ProjectResources: []ProjectResourceData{
+ {ID: "r1", ResourceType: localDirectoryResourceType, ResourceRef: ref},
+ },
+ }
+
+ release, abort := d.acquireLocalDirectoryLockIfNeeded(ctx, task, slog.Default(), newTestTaskSlot(0))
+ if release != nil {
+ release()
+ t.Error("waiter returned a usable lock for the moved directory")
+ }
+ if !abort {
+ t.Fatal("waiter continued after its linked directory moved")
+ }
+ select {
+ case reason := <-failures:
+ if reason != "local_directory_missing" {
+ t.Errorf("failure_reason = %q, want local_directory_missing", reason)
+ }
+ default:
+ t.Error("missing terminal failure report")
+ }
+ if released, err := locker.Acquire(ctx, realDir, "next", nil); err != nil {
+ t.Errorf("waiter did not release path lock: %v", err)
+ } else {
+ released()
+ }
+}
+
func TestAcquireLocalDirectoryLock_ReportsDeletedDirectoryAsMissing(t *testing.T) {
t.Parallel()