Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

steady: a file whose folder isn't there is said gone without the wait (#1665)

yetone8173854168a9
diff --git a/internal/steady/steady.go b/internal/steady/steady.go
index ac7aff7ef..f9634799b 100644
--- a/internal/steady/steady.go
+++ b/internal/steady/steady.go
@@ -15,6 +15,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "syscall"
"time"
)
@@ -33,6 +34,10 @@ const (
gonePause = time.Millisecond
)
+// errPathNotFound is Windows' ERROR_PATH_NOT_FOUND: a folder on the way to
+// the file isn't there (ERROR_FILE_NOT_FOUND, 2, is the file alone).
+const errPathNotFound = syscall.Errno(3)
+
// windows is whether files behave as Windows' do; a test sets it.
var windows = runtime.GOOS == "windows"
@@ -51,10 +56,14 @@ func retry(f func() error) error {
return err
}
-// retryGone is retry, waiting out a moment of the file not there too.
+// retryGone is retry, waiting out a moment of the file not there too,
+// unless its folder isn't there either: nothing is being renamed into it.
+// Most agents aren't installed, and the first look at each of their files
+// waited the whole 15ms (#1665: ~22ms an agent each catalog sync, 2.6s a
+// round of 116 on Windows).
func retryGone(f func() error) error {
err := retry(f)
- for i := 0; err != nil && windows && errors.Is(err, fs.ErrNotExist) && i < goneTries; i++ {
+ for i := 0; err != nil && windows && errors.Is(err, fs.ErrNotExist) && !errors.Is(err, errPathNotFound) && i < goneTries; i++ {
time.Sleep(gonePause)
err = retry(f)
}
diff --git a/internal/steady/steady_test.go b/internal/steady/steady_test.go
index 63bd793d9..bf10baed0 100644
--- a/internal/steady/steady_test.go
+++ b/internal/steady/steady_test.go
@@ -41,3 +41,28 @@ func TestStatWaitsOutAReplace(t *testing.T) {
t.Fatalf("a file not there: %v", err)
}
}
+
+// #1665: a file whose folder isn't there is not being renamed into it, and
+// is said gone without the wait; most agents aren't installed, and each
+// one's first look waited the whole of it
+func TestStatOfAFileWithNoFolderWaitsNothing(t *testing.T) {
+ windows = true
+ defer func() { windows, stat = runtime.GOOS == "windows", os.Stat }()
+ looks := 0
+ stat = func(p string) (fs.FileInfo, error) {
+ looks++
+ return nil, &fs.PathError{Op: "stat", Path: p, Err: errors.Join(fs.ErrNotExist, errPathNotFound)}
+ }
+ if _, err := Stat("no-folder/settings.json"); !errors.Is(err, fs.ErrNotExist) || looks != 1 {
+ t.Fatalf("looked %d times: %v", looks, err)
+ }
+ // its folder there, the file not, is waited on as before
+ looks = 0
+ stat = func(p string) (fs.FileInfo, error) {
+ looks++
+ return nil, &fs.PathError{Op: "stat", Path: p, Err: fs.ErrNotExist}
+ }
+ if _, err := Stat("settings.json"); !errors.Is(err, fs.ErrNotExist) || looks < 2 {
+ t.Fatalf("looked %d times: %v", looks, err)
+ }
+}
diff --git a/internal/steady/steady_windows_test.go b/internal/steady/steady_windows_test.go
index a26b8c9e4..7f3773559 100644
--- a/internal/steady/steady_windows_test.go
+++ b/internal/steady/steady_windows_test.go
@@ -1,6 +1,8 @@
package steady
import (
+ "errors"
+ "io/fs"
"os"
"path/filepath"
"syscall"
@@ -58,3 +60,20 @@ func TestReadAFileHeldOpen(t *testing.T) {
t.Fatalf("a file not there: %v", err)
}
}
+
+// Windows itself tells a file whose folder isn't there (#1665)
+func TestNoFolderIsPathNotFound(t *testing.T) {
+ looks := 0
+ stat = func(p string) (fs.FileInfo, error) {
+ looks++
+ return os.Stat(p)
+ }
+ defer func() { stat = os.Stat }()
+ if _, err := Stat(filepath.Join(t.TempDir(), "agent", "settings.json")); !errors.Is(err, fs.ErrNotExist) || looks != 1 {
+ t.Fatalf("looked %d times: %v", looks, err)
+ }
+ looks = 0
+ if _, err := Stat(filepath.Join(t.TempDir(), "settings.json")); !errors.Is(err, fs.ErrNotExist) || looks < 2 {
+ t.Fatalf("a file alone not there looked at %d times: %v", looks, err)
+ }
+}