Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Fix Windows Save to preserve temp file when rename fails after deleting old session

Cursor Agent969fb97f0dc8
diff --git a/cli/beacon/internal/account/store.go b/cli/beacon/internal/account/store.go
index 254b709c..83e9d99b 100644
--- a/cli/beacon/internal/account/store.go
+++ b/cli/beacon/internal/account/store.go
@@ -115,7 +115,12 @@ func Save(session Session) error {
return err
}
tmpPath := tmp.Name()
- defer os.Remove(tmpPath)
+ removeTmp := true
+ defer func() {
+ if removeTmp {
+ os.Remove(tmpPath)
+ }
+ }()
if err := tmp.Chmod(0o600); err != nil {
tmp.Close()
return err
@@ -136,10 +141,14 @@ func Save(session Session) error {
if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
+ // Old session is gone; keep the temp file if rename fails so the
+ // new credential is not lost.
+ removeTmp = false
}
if err := os.Rename(tmpPath, path); err != nil {
return err
}
+ removeTmp = false
if runtime.GOOS != "windows" {
return os.Chmod(path, 0o600)
}