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
fix(endpoint): wait for updater exit before deferred reload
shukieshah6a90832051fc
diff --git a/cli/beacon/internal/endpoint/service/updater.go b/cli/beacon/internal/endpoint/service/updater.goindex 8944cebf..3083ca97 100644--- a/cli/beacon/internal/endpoint/service/updater.go+++ b/cli/beacon/internal/endpoint/service/updater.go@@ -17,16 +17,21 @@ const UpdaterLabel = "com.beacon.endpoint.updater"type UpdaterManager struct{}var startDeferredUpdaterReload = func(path string) error {- cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf(- "sleep 75; /bin/launchctl bootout system/%s >/dev/null 2>&1 || true; /bin/launchctl bootstrap system %s >/dev/null 2>&1",- UpdaterLabel,- shellQuote(path),- ))+ cmd := exec.Command("/bin/sh", "-c", deferredUpdaterReloadScript(os.Getpid(), path))cmd.Stdout = nilcmd.Stderr = nilreturn cmd.Start()}+func deferredUpdaterReloadScript(pid int, path string) string {+ return fmt.Sprintf(+ "deadline=$((SECONDS+600)); while /bin/kill -0 %d >/dev/null 2>&1 && [ \"$SECONDS\" -lt \"$deadline\" ]; do sleep 2; done; /bin/launchctl bootout system/%s >/dev/null 2>&1 || true; /bin/launchctl bootstrap system %s >/dev/null 2>&1",+ pid,+ UpdaterLabel,+ shellQuote(path),+ )+}+// PlistPath returns the LaunchDaemon plist path for the updater job.func (UpdaterManager) PlistPath() string {return filepath.Join("/Library/LaunchDaemons", UpdaterLabel+".plist")diff --git a/cli/beacon/internal/endpoint/service/updater_test.go b/cli/beacon/internal/endpoint/service/updater_test.goindex 2fcb413d..725e64a1 100644--- a/cli/beacon/internal/endpoint/service/updater_test.go+++ b/cli/beacon/internal/endpoint/service/updater_test.go@@ -84,3 +84,18 @@ func TestUpdaterLoadDefersReloadForRunningUpdater(t *testing.T) {t.Fatalf("deferred reload path = %q, want updater plist", deferredPath)}}++func TestDeferredUpdaterReloadScriptWaitsForParentExit(t *testing.T) {+ script := deferredUpdaterReloadScript(12345, "/Library/LaunchDaemons/com.beacon.endpoint.updater.plist")+ for _, want := range []string{+ "/bin/kill -0 12345",+ "SECONDS+600",+ "do sleep 2; done",+ "/bin/launchctl bootout system/" + UpdaterLabel,+ "/bin/launchctl bootstrap system '/Library/LaunchDaemons/com.beacon.endpoint.updater.plist'",+ } {+ if !strings.Contains(script, want) {+ t.Fatalf("deferred reload script missing %q:\n%s", want, script)+ }+ }+}