Skip to content

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

Disconnect leaves the service manager alone when nothing was connected

shukieshahd794228a02f5
diff --git a/cli/beacon/internal/endpoint/asymptote/connect.go b/cli/beacon/internal/endpoint/asymptote/connect.go
index c445a072..abd45130 100644
--- a/cli/beacon/internal/endpoint/asymptote/connect.go
+++ b/cli/beacon/internal/endpoint/asymptote/connect.go
@@ -218,10 +218,16 @@ func Disconnect(opts DisconnectOptions) error {
manager = service.ForwarderManager{UserMode: opts.UserMode}
}
var problems []error
- if err := manager.Unload(); err != nil {
- problems = append(problems, fmt.Errorf("stop forwarder: %w", err))
+ // Only touch the service manager when this endpoint has managed-ingest state. Uninstall
+ // calls Disconnect unconditionally, and a bootout against the live launchd domain from
+ // an endpoint that was never connected would stop a forwarder belonging to a different
+ // install (or to the developer running the test suite).
+ if hasManagedState(opts.UserMode) {
+ if err := manager.Unload(); err != nil {
+ problems = append(problems, fmt.Errorf("stop forwarder: %w", err))
+ }
+ manager.RemoveUnits()
}
- manager.RemoveUnits()
if err := RemoveState(opts.UserMode, opts.KeepCredentials); err != nil {
problems = append(problems, fmt.Errorf("remove %s: %w", Dir(opts.UserMode), err))
}
@@ -231,6 +237,12 @@ func Disconnect(opts DisconnectOptions) error {
return errors.Join(problems...)
}
+// hasManagedState reports whether anything under the asymptote directory exists.
+func hasManagedState(userMode bool) bool {
+ _, err := os.Stat(Dir(userMode))
+ return err == nil
+}
+
// updateConfig records (or clears) the non-secret managed_ingest block in config.json. A
// missing config is created with defaults so a hook-only install can still connect.
func updateConfig(userMode bool, logPath string, managed *endpointconfig.ManagedIngest) error {
diff --git a/cli/beacon/internal/endpoint/asymptote/connect_test.go b/cli/beacon/internal/endpoint/asymptote/connect_test.go
index a5f348ce..e13c8c34 100644
--- a/cli/beacon/internal/endpoint/asymptote/connect_test.go
+++ b/cli/beacon/internal/endpoint/asymptote/connect_test.go
@@ -277,10 +277,15 @@ func TestDisconnectRemovesForwarderAndOptionallyKeepsCredentials(t *testing.T) {
if _, err := os.Stat(Dir(true)); !os.IsNotExist(err) {
t.Fatal("asymptote dir should be removed entirely")
}
- // Disconnecting an endpoint that was never connected is not an error.
+ // Disconnecting an endpoint that was never connected is not an error and must not
+ // touch the service manager: uninstall runs this on every endpoint.
+ before := fwd.unloads
if err := Disconnect(DisconnectOptions{UserMode: true, Forwarder: fwd}); err != nil {
t.Fatalf("second disconnect should be a no-op, got %v", err)
}
+ if fwd.unloads != before {
+ t.Fatal("disconnect without managed state must not unload the forwarder")
+ }
}
func TestStatusReportsCredentialState(t *testing.T) {