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): compare harness names canonically, and read the collector port from config
shukieshah512d00d25b0a
diff --git a/cli/beacon/cmd/endpoint_console_user_config_test.go b/cli/beacon/cmd/endpoint_console_user_config_test.goindex 1765ea41..70098dd5 100644--- a/cli/beacon/cmd/endpoint_console_user_config_test.go+++ b/cli/beacon/cmd/endpoint_console_user_config_test.go@@ -5,6 +5,7 @@ import ("path/filepath""testing"+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/diagnostics")@@ -76,6 +77,46 @@ func TestConsoleUserConfigCheckWarnsWhenNobodyIsLoggedIn(t *testing.T) {}}+// An install with --otlp-grpc-port writes that port into the user's settings. A check that only+// knew the defaults would call a correctly configured user unconfigured -- a false failure in the+// one check whose entire value is being believed when it says something is wrong.+func TestConsoleUserConfigCheckHonoursCustomOTLPPorts(t *testing.T) {+ info := userHomeWith(t, ".claude/settings.json",+ `{"env":{"OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:5317"}}`)++ cfg := endpointconfig.Config{}+ cfg.Collector.GRPCPort = 5317+ cfg.Collector.HTTPPort = 5318++ if ok, detail := consoleUserHarnessConfigured(info, cfg); !ok {+ t.Errorf("a user pointed at the configured port read as unconfigured: %s", detail)+ }++ // The same settings against an endpoint on the default ports is genuinely not configured for+ // it, and must still say so.+ def := endpointconfig.Config{}+ def.Collector.GRPCPort = endpointconfig.DefaultGRPCPort+ def.Collector.HTTPPort = endpointconfig.DefaultHTTPPort+ if ok, _ := consoleUserHarnessConfigured(info, def); ok {+ t.Error("settings pointed at :5317 matched an endpoint listening on :4317")+ }+}++// Beacon writes 127.0.0.1, but a user or an MDM profile may have written localhost against the+// same collector. Reporting that as unconfigured would be wrong.+func TestConsoleUserConfigCheckAcceptsLocalhostSpelling(t *testing.T) {+ info := userHomeWith(t, ".claude/settings.json",+ `{"env":{"OTEL_EXPORTER_OTLP_ENDPOINT":"http://localhost:4317"}}`)++ cfg := endpointconfig.Config{}+ cfg.Collector.GRPCPort = endpointconfig.DefaultGRPCPort+ cfg.Collector.HTTPPort = endpointconfig.DefaultHTTPPort++ if ok, detail := consoleUserHarnessConfigured(info, cfg); !ok {+ t.Errorf("the localhost spelling read as unconfigured: %s", detail)+ }+}+// Hook-only runtimes count as configured: the installed hook command names the hook binary, which// is what points that runtime at the endpoint.func TestConsoleUserConfigCheckAcceptsAHookOnlyRuntime(t *testing.T) {diff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.goindex c262560d..fbfc9322 100644--- a/cli/beacon/cmd/endpoint_diagnostics.go+++ b/cli/beacon/cmd/endpoint_diagnostics.go@@ -1086,7 +1086,7 @@ func consoleUserConfigCheck() diagnostics.Check {Action: "run 'beacon endpoint user-config repair-installed --system' as the user whose sessions should be captured",}}- configured, detail := consoleUserHarnessConfigured(info)+ configured, detail := consoleUserHarnessConfigured(info, loadConfigForMode(false, endpointOpts.logPath))if !configured {return diagnostics.Check{Name: name,@@ -1114,7 +1114,12 @@ func consoleUserConfigCheck() diagnostics.Check {//// At least one rather than all of them: a developer who uses only Claude Code is fully configured,// and demanding every detected runtime would produce a failure nobody should act on.-func consoleUserHarnessConfigured(info consoleUserInfo) (bool, string) {+//+// The markers come from the endpoint's own configuration rather than from constants. An install+// with --otlp-grpc-port writes that port into the user's settings, and a check that only knew the+// defaults would call a correctly configured user unconfigured -- a false failure in the one check+// whose entire value is being trusted when it says something is wrong.+func consoleUserHarnessConfigured(info consoleUserInfo, cfg endpointconfig.Config) (bool, string) {paths, err := consoleUserConfigPaths(info)if err != nil {return false, err.Error()@@ -1122,23 +1127,51 @@ func consoleUserHarnessConfigured(info consoleUserInfo) (bool, string) {if len(paths) == 0 {return false, "no agent runtime configuration found in " + info.HomeDir}+ markers := collectorEndpointMarkers(cfg)for _, p := range paths {data, err := os.ReadFile(p)if err != nil {continue}- // The endpoint marker is the collector address the install writes. Matching on it rather- // than on the file existing distinguishes "configured for this endpoint" from "the user- // happens to have a settings file", which is the difference that matters here.- if strings.Contains(string(data), "127.0.0.1:4317") ||- strings.Contains(string(data), "127.0.0.1:4318") ||- strings.Contains(string(data), embedded.BinaryStem) {+ // Matching on the collector address, or on the hook binary for hook-only runtimes, rather+ // than on the file existing: that is the difference between "configured for this endpoint"+ // and "the user happens to have used this agent before".+ text := string(data)+ if strings.Contains(text, embedded.BinaryStem) {return true, p}+ for _, marker := range markers {+ if strings.Contains(text, marker) {+ return true, p+ }+ }}return false, "found " + strconv.Itoa(len(paths)) + " runtime config file(s), none pointed at this collector"}+// collectorEndpointMarkers are the address spellings a configured runtime could contain.+//+// Both loopback spellings, because Beacon writes 127.0.0.1 but a user or an MDM profile may have+// written localhost against the same collector, and reporting that as unconfigured would be wrong.+func collectorEndpointMarkers(cfg endpointconfig.Config) []string {+ grpc := cfg.Collector.GRPCPort+ if grpc == 0 {+ grpc = endpointconfig.DefaultGRPCPort+ }+ http := cfg.Collector.HTTPPort+ if http == 0 {+ http = endpointconfig.DefaultHTTPPort+ }+ var markers []string+ for _, host := range []string{"127.0.0.1", "localhost"} {+ markers = append(markers,+ host+":"+strconv.Itoa(grpc),+ host+":"+strconv.Itoa(http),+ )+ }+ return markers+}+// consoleUserConfigPaths lists the runtime configuration files that exist in a specific user's// home directory.//diff --git a/cli/beacon/internal/endpoint/integrations/logscan.go b/cli/beacon/internal/endpoint/integrations/logscan.goindex ac1aa278..ef530c05 100644--- a/cli/beacon/internal/endpoint/integrations/logscan.go+++ b/cli/beacon/internal/endpoint/integrations/logscan.go@@ -6,6 +6,8 @@ import ("os""strings""time"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")func HasRecentHarnessEvent(logPath, harnessName string) bool {@@ -31,7 +33,17 @@ func LastHarnessEvent(logPath, harnessName string) (time.Time, bool) {}defer file.Close()- want := strings.ToLower(strings.TrimSpace(harnessName))+ // Compared canonically on both sides, because the two names come from different places and do+ // not agree on spelling. Discovery names a runtime for the CLI surface -- "vscode" is what+ // `--harness vscode` accepts -- while events carry the canonical telemetry name, which for that+ // runtime is "vscode_copilot". An exact comparison therefore asks whether two unrelated+ // vocabularies happen to coincide, and it silently answers "no" for a runtime that is working+ // perfectly: doctor's harness_observed never clears, and the operator is told to run an agent+ // they have already been running.+ //+ // This was wrong in both directions before it was normalized. Claude Code discovers as+ // "claude_code" while its hooks emitted "claude", so its observed check never cleared either.+ want := asymptoteobserve.NormalizeHarnessName(harnessName)var last time.Timefound := falsescanner := bufio.NewScanner(file)@@ -42,7 +54,7 @@ func LastHarnessEvent(logPath, harnessName string) (time.Time, bool) {continue}if harness, ok := event["harness"].(map[string]interface{}); ok {- if name, _ := harness["name"].(string); strings.ToLower(strings.TrimSpace(name)) == want {+ if name, _ := harness["name"].(string); asymptoteobserve.NormalizeHarnessName(name) == want {found = trueif ts, ok := event["timestamp"].(string); ok {if parsed, err := time.Parse(time.RFC3339Nano, ts); err == nil && parsed.After(last) {diff --git a/cli/beacon/internal/endpoint/integrations/logscan_harness_test.go b/cli/beacon/internal/endpoint/integrations/logscan_harness_test.gonew file mode 100644index 00000000..0340107e--- /dev/null+++ b/cli/beacon/internal/endpoint/integrations/logscan_harness_test.go@@ -0,0 +1,68 @@+package integrations++import (+ "os"+ "path/filepath"+ "testing"+)++func writeLog(t *testing.T, lines ...string) string {+ t.Helper()+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ var body string+ for _, l := range lines {+ body += l + "\n"+ }+ if err := os.WriteFile(path, []byte(body), 0o600); err != nil {+ t.Fatal(err)+ }+ return path+}++// Discovery and telemetry use different vocabularies for the same runtime: `--harness vscode` is+// the CLI surface, `vscode_copilot` is what its events carry. Comparing them literally asks+// whether two unrelated naming schemes happen to coincide, and answers "no" for a runtime that is+// working -- so doctor's harness_observed never clears and the operator is told to run an agent+// they have already been running.+func TestHarnessEventsMatchAcrossNamingSchemes(t *testing.T) {+ for name, tc := range map[string]struct{ discovery, event string }{+ "vscode discovery vs canonical event": {"vscode", "vscode_copilot"},+ "claude_code discovery vs raw hook event": {"claude_code", "claude"},+ "codex_cli discovery vs raw hook event": {"codex_cli", "codex"},+ "identical names still match": {"claude_code", "claude_code"},+ "case and spacing are not load-bearing": {"Claude_Code", " claude_code "},+ "antigravity discovery vs canonical event": {"antigravity", "antigravity_cli"},+ } {+ t.Run(name, func(t *testing.T) {+ log := writeLog(t, `{"timestamp":"2026-08-12T10:00:00Z","harness":{"name":"`+tc.event+`"}}`)+ if !HasRecentHarnessEvent(log, tc.discovery) {+ t.Errorf("an event from %q did not match discovery name %q, so a working runtime "++ "reads as never observed", tc.event, tc.discovery)+ }+ })+ }+}++// Normalizing must not make everything match everything. A runtime that genuinely has no events+// has to keep reporting that, or the check stops meaning anything.+func TestUnrelatedHarnessesStillDoNotMatch(t *testing.T) {+ log := writeLog(t, `{"timestamp":"2026-08-12T10:00:00Z","harness":{"name":"claude_code"}}`)+ for _, other := range []string{"vscode", "codex_cli", "gemini_cli", "cursor", "copilot_cli"} {+ if HasRecentHarnessEvent(log, other) {+ t.Errorf("a claude_code event matched %q; the check would report every runtime as observed", other)+ }+ }+}++// VS Code Copilot Chat and the Copilot CLI are different products. Collapsing them would report+// one as observed because the other ran.+func TestVSCodeAndCopilotCLIRemainDistinct(t *testing.T) {+ vscodeLog := writeLog(t, `{"timestamp":"2026-08-12T10:00:00Z","harness":{"name":"vscode_copilot"}}`)+ if HasRecentHarnessEvent(vscodeLog, "copilot_cli") {+ t.Error("a VS Code event matched the Copilot CLI, which is a different product")+ }+ cliLog := writeLog(t, `{"timestamp":"2026-08-12T10:00:00Z","harness":{"name":"copilot_cli"}}`)+ if HasRecentHarnessEvent(cliLog, "vscode") {+ t.Error("a Copilot CLI event matched VS Code, which is a different product")+ }+}