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
Keep managed_ingest across re-installs; a failed connect is not connected
shukieshah9de07d133903
diff --git a/cli/beacon/cmd/endpoint_connect.go b/cli/beacon/cmd/endpoint_connect.goindex c76d4005..462a8076 100644--- a/cli/beacon/cmd/endpoint_connect.go+++ b/cli/beacon/cmd/endpoint_connect.go@@ -13,7 +13,6 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/auth""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/asymptote"- endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/version")@@ -234,9 +233,3 @@ func humanBytes(n int64) string {}return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp])}--// managedIngestFromConfig reports whether config.json says this endpoint is connected, for-// callers that must not touch the network or the secrets file.-func managedIngestFromConfig(cfg endpointconfig.Config) bool {- return cfg.ManagedIngest != nil && cfg.ManagedIngest.Enabled-}diff --git a/cli/beacon/internal/endpoint/asymptote/connect.go b/cli/beacon/internal/endpoint/asymptote/connect.goindex 6be0ec06..dff03e38 100644--- a/cli/beacon/internal/endpoint/asymptote/connect.go+++ b/cli/beacon/internal/endpoint/asymptote/connect.go@@ -245,8 +245,12 @@ func forwarderInstalled(userMode bool, manager Forwarder) bool {if Connected(userMode) {return true}- if _, err := os.Stat(EnrollmentPath(userMode)); err == nil {- return true+ // Either file alone is still state to clean up: a kept enrollment record, or the config+ // a connect wrote before failing at validate or load.+ for _, path := range []string{EnrollmentPath(userMode), VectorConfigPath(userMode)} {+ if _, err := os.Stat(path); err == nil {+ return true+ }}if path, err := manager.UnitPath(); err == nil && path != "" {if _, err := os.Stat(path); err == nil {diff --git a/cli/beacon/internal/endpoint/asymptote/connect_test.go b/cli/beacon/internal/endpoint/asymptote/connect_test.goindex 0e2ff958..fb86aea8 100644--- a/cli/beacon/internal/endpoint/asymptote/connect_test.go+++ b/cli/beacon/internal/endpoint/asymptote/connect_test.go@@ -249,6 +249,45 @@ func TestConnectFailsWhenVectorValidateRejectsTheConfig(t *testing.T) {if _, err := LoadEnrollment(true); !errors.Is(err, ErrNotEnrolled) {t.Fatalf("enrollment must not be recorded after a failed connect, got %v", err)}+ // The rendered config is left behind for inspection, but the machine is not connected:+ // status says so, the onboarding offer is made again, and disconnect can clean it up.+ if Connected(true) {+ t.Fatal("a connect that failed at validate must not count as connected")+ }+ if !forwarderInstalled(true, fwd) {+ t.Fatal("disconnect must see the config a failed connect left behind")+ }+ if err := Disconnect(DisconnectOptions{UserMode: true, Forwarder: fwd}); err != nil {+ t.Fatal(err)+ }+ if _, err := os.Stat(Dir(true)); !os.IsNotExist(err) {+ t.Fatal("disconnect should remove the state a failed connect left behind")+ }+}++func TestConnectedNeedsEnrollmentAndForwarderConfig(t *testing.T) {+ t.Setenv("HOME", t.TempDir())+ if Connected(true) {+ t.Fatal("fresh machine")+ }+ if err := SaveEnrollment(true, Enrollment{InstallID: "i", DeviceID: "d", OrganizationID: "o"}); err != nil {+ t.Fatal(err)+ }+ if Connected(true) {+ t.Fatal("an enrollment record alone (disconnect --keep-credentials) is not a connection")+ }+ if err := os.WriteFile(VectorConfigPath(true), []byte("# rendered"), 0o644); err != nil {+ t.Fatal(err)+ }+ if !Connected(true) {+ t.Fatal("record plus forwarder config is connected")+ }+ if err := os.Remove(EnrollmentPath(true)); err != nil {+ t.Fatal(err)+ }+ if Connected(true) {+ t.Fatal("a forwarder config alone (connect failed before recording) is not a connection")+ }}func TestDisconnectRemovesForwarderAndOptionallyKeepsCredentials(t *testing.T) {diff --git a/cli/beacon/internal/endpoint/asymptote/enrollment.go b/cli/beacon/internal/endpoint/asymptote/enrollment.goindex 2e4d386d..1326eda1 100644--- a/cli/beacon/internal/endpoint/asymptote/enrollment.go+++ b/cli/beacon/internal/endpoint/asymptote/enrollment.go@@ -53,10 +53,16 @@ func WriteInstallID(userMode bool, installID string) error {return writeFileAtomic(InstallIDPath(userMode), []byte(installID+"\n"), 0o600)}-// Connected reports whether a forwarder is installed for this endpoint: an enrollment-// record alone is not a connection, because disconnect --keep-credentials leaves it behind.+// Connected reports whether this endpoint is enrolled and has its forwarder configured: both+// enrollment.json and vector.toml exist. Either alone is not a connection. disconnect+// --keep-credentials leaves the record behind without a config, and a connect that failed at+// vector validate or at loading the service leaves the config behind without a record; a+// machine in either state must be offered connect again and reported as not connected.func Connected(userMode bool) bool {- _, err := os.Stat(VectorConfigPath(userMode))+ if _, err := os.Stat(VectorConfigPath(userMode)); err != nil {+ return false+ }+ _, err := os.Stat(EnrollmentPath(userMode))return err == nil}diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.goindex f94ca164..a9a2f331 100644--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go@@ -632,6 +632,11 @@ func buildConfig(opts InstallOptions) endpointconfig.Config {if mode, err := autoUpdateModeFromConfigFile(endpointconfig.ConfigPath(opts.UserMode)); err == nil && mode != "" {cfg.AutoUpdate = &endpointconfig.AutoUpdate{Mode: mode}}+ // A re-install (upgrades run one) must not disconnect the machine on paper: the+ // managed_ingest block is owned by connect/disconnect, so carry the existing one over.+ if existing, err := endpointconfig.Load(opts.UserMode); err == nil && existing.ManagedIngest != nil {+ cfg.ManagedIngest = existing.ManagedIngest+ }if opts.Harnesses != nil {cfg.Harnesses = opts.Harnesses}diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.goindex 6050807f..8849c545 100644--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go@@ -542,6 +542,51 @@ func TestInstallUserModeWithoutStartingService(t *testing.T) {}}+// Upgrades re-run install. The managed_ingest block belongs to connect/disconnect, so a+// re-install must carry it over instead of silently disconnecting the machine on paper.+func TestInstallPreservesManagedIngestBlock(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("install preflight is macOS-only")+ }+ home := t.TempDir()+ t.Setenv("HOME", home)+ collectorPath := filepath.Join(home, "bin", "beacon-otelcol")+ if err := os.MkdirAll(filepath.Dir(collectorPath), 0755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(collectorPath, []byte("#!/bin/sh\n"), 0755); err != nil {+ t.Fatal(err)+ }+ logPath := filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")+ opts := InstallOptions{UserMode: true, LogPath: logPath, Harnesses: []string{}, GRPCPort: freePort(t), HTTPPort: freePort(t), CollectorPath: collectorPath, StartService: false}+ if _, err := Install(opts); err != nil {+ t.Fatalf("first install: %v", err)+ }+ cfg, err := endpointconfig.Load(true)+ if err != nil {+ t.Fatal(err)+ }+ if cfg.ManagedIngest != nil {+ t.Fatalf("a fresh install must not invent a managed_ingest block: %+v", cfg.ManagedIngest)+ }+ managed := &endpointconfig.ManagedIngest{Enabled: true, IngestURL: "https://ingest.example", DeviceID: "dev-1", OrganizationID: "org-1"}+ cfg.ManagedIngest = managed+ if _, err := endpointconfig.Save(cfg); err != nil {+ t.Fatal(err)+ }++ if _, err := Install(opts); err != nil {+ t.Fatalf("re-install: %v", err)+ }+ after, err := endpointconfig.Load(true)+ if err != nil {+ t.Fatal(err)+ }+ if after.ManagedIngest == nil || *after.ManagedIngest != *managed {+ t.Fatalf("re-install dropped or changed managed_ingest: %+v", after.ManagedIngest)+ }+}+func TestInstallFailsBeforeWritingArtifactsWhenCollectorMissing(t *testing.T) {if runtime.GOOS != "darwin" {t.Skip("install preflight is macOS-only")