The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Replace Windows sessions atomically
Justin D'Souza84063bb2ae77
diff --git a/cli/beacon/internal/account/replace_other.go b/cli/beacon/internal/account/replace_other.gonew file mode 100644index 00000000..03e2c1b3--- /dev/null+++ b/cli/beacon/internal/account/replace_other.go@@ -0,0 +1,9 @@+//go:build !windows++package account++import "os"++func replaceFile(source, destination string) error {+ return os.Rename(source, destination)+}diff --git a/cli/beacon/internal/account/replace_windows.go b/cli/beacon/internal/account/replace_windows.gonew file mode 100644index 00000000..2031ac8b--- /dev/null+++ b/cli/beacon/internal/account/replace_windows.go@@ -0,0 +1,21 @@+//go:build windows++package account++import "golang.org/x/sys/windows"++func replaceFile(source, destination string) error {+ sourcePtr, err := windows.UTF16PtrFromString(source)+ if err != nil {+ return err+ }+ destinationPtr, err := windows.UTF16PtrFromString(destination)+ if err != nil {+ return err+ }+ return windows.MoveFileEx(+ sourcePtr,+ destinationPtr,+ windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_WRITE_THROUGH,+ )+}diff --git a/cli/beacon/internal/account/store.go b/cli/beacon/internal/account/store.goindex 254b709c..00e76c2c 100644--- a/cli/beacon/internal/account/store.go+++ b/cli/beacon/internal/account/store.go@@ -131,13 +131,7 @@ func Save(session Session) error {if err := tmp.Close(); err != nil {return err}- // Windows does not replace an existing destination with os.Rename.- if runtime.GOOS == "windows" {- if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {- return err- }- }- if err := os.Rename(tmpPath, path); err != nil {+ if err := replaceFile(tmpPath, path); err != nil {return err}if runtime.GOOS != "windows" {