Skip to content

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

fix(endpoint): preserve updater mode across repair

shukieshah74f84fc05016
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index c162c5e4..c778c78a 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -280,6 +280,12 @@ func Uninstall(opts UninstallOptions) error {
func Repair(opts InstallOptions) (InstallResult, error) {
configPath := endpointconfig.ConfigPath(opts.UserMode)
configSnapshot := snapshotFile(configPath)
+ priorAutoUpdateMode := ""
+ if !opts.UserMode {
+ if mode, err := autoUpdateModeFromConfigFile(configPath); err == nil {
+ priorAutoUpdateMode = mode
+ }
+ }
_ = Uninstall(UninstallOptions{UserMode: opts.UserMode, LogPath: opts.LogPath, KeepLogs: true, KeepConfig: true, KeepUpdater: true})
result, err := Install(opts)
if err != nil {
@@ -287,6 +293,11 @@ func Repair(opts InstallOptions) (InstallResult, error) {
return result, err
}
if !opts.UserMode {
+ if priorAutoUpdateMode != "" {
+ if err := setAutoUpdateModeInConfigFile(configPath, priorAutoUpdateMode); err != nil {
+ return result, err
+ }
+ }
if err := reconcileUpdaterFromConfig(opts.LogPath); err != nil {
return result, err
}
@@ -329,6 +340,31 @@ func autoUpdateModeFromConfigFile(path string) (string, error) {
return partial.AutoUpdate.Mode, nil
}
+func setAutoUpdateModeInConfigFile(path, mode string) error {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return err
+ }
+ var raw map[string]json.RawMessage
+ if err := json.Unmarshal(data, &raw); err != nil {
+ return err
+ }
+ autoUpdate, err := json.Marshal(endpointconfig.AutoUpdate{Mode: mode})
+ if err != nil {
+ return err
+ }
+ raw["auto_update"] = autoUpdate
+ out, err := json.MarshalIndent(raw, "", " ")
+ if err != nil {
+ return err
+ }
+ perm := os.FileMode(0644)
+ if info, err := os.Stat(path); err == nil {
+ perm = info.Mode().Perm()
+ }
+ return os.WriteFile(path, out, perm)
+}
+
func GetStatus(userMode bool, logPath string) Status {
cfg := loadOrDefault(userMode, logPath)
runtimeLog := ResolveRuntimeLog(userMode, logPath)
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
index fc4371f6..4200c585 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
@@ -1,6 +1,7 @@
package lifecycle
import (
+ "encoding/json"
"errors"
"net"
"net/http"
@@ -318,6 +319,32 @@ func TestAutoUpdateModeFromConfigFileIgnoresDestinationValidation(t *testing.T)
if mode != "auto" {
t.Fatalf("mode = %q, want auto", mode)
}
+ if err := setAutoUpdateModeInConfigFile(path, "check-only"); err != nil {
+ t.Fatalf("setAutoUpdateModeInConfigFile: %v", err)
+ }
+ if info, err := os.Stat(path); err != nil {
+ t.Fatal(err)
+ } else if got := info.Mode().Perm(); got != 0o600 {
+ t.Fatalf("permissions = %v, want 0600", got)
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var raw map[string]json.RawMessage
+ if err := json.Unmarshal(data, &raw); err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := raw["destinations"]; !ok {
+ t.Fatalf("destinations were not preserved: %s", data)
+ }
+ mode, err = autoUpdateModeFromConfigFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if mode != "check-only" {
+ t.Fatalf("mode after set = %q, want check-only", mode)
+ }
}
func TestDiscoverAndRestoreBackups(t *testing.T) {