Skip to content

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

feat(endpoint): refuse a collector too old for the config install writes

Kyle Elliott271420603c48
diff --git a/cli/beacon/internal/endpoint/collector/components.go b/cli/beacon/internal/endpoint/collector/components.go
new file mode 100644
index 00000000..95c4cb0a
--- /dev/null
+++ b/cli/beacon/internal/endpoint/collector/components.go
@@ -0,0 +1,58 @@
+package collector
+
+import (
+ "context"
+ "fmt"
+ "os/exec"
+ "time"
+
+ "gopkg.in/yaml.v3"
+)
+
+// requiredProcessors are the processors ConfigYAML puts in every pipeline that a collector older
+// than this CLI does not have. A collector refuses a whole config that names a component it does
+// not know, so one of these missing stops capture for every runtime, not just the one it serves.
+var requiredProcessors = []string{"claude_api_body"}
+
+// listComponents runs `beacon-otelcol components`, which prints what the binary was built with.
+var listComponents = func(ctx context.Context, binary string) ([]byte, error) {
+ return exec.CommandContext(ctx, binary, "components").Output()
+}
+
+// CheckComponents refuses a collector binary that is older than the config this CLI writes.
+//
+// Packages and archives ship the collector beside the CLI from the same release, so this fails only
+// when something else is picked up: an older beacon-otelcol earlier on PATH, or one passed with
+// --collector. Without it, install writes the config, the collector rejects it at start, and
+// nothing is captured until someone reads the collector's own log.
+//
+// A binary that cannot list its components -- a stand-in, or a build that does not support the
+// command -- is not refused: there is nothing to judge it on, and it fails at start as it would
+// have before.
+func CheckComponents(binary string) error {
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ out, err := listComponents(ctx, binary)
+ if err != nil {
+ return nil
+ }
+ var listed struct {
+ Processors []struct {
+ Name string `yaml:"name"`
+ } `yaml:"processors"`
+ }
+ if yaml.Unmarshal(out, &listed) != nil || len(listed.Processors) == 0 {
+ return nil
+ }
+ have := map[string]bool{}
+ for _, processor := range listed.Processors {
+ have[processor.Name] = true
+ }
+ for _, name := range requiredProcessors {
+ if !have[name] {
+ return fmt.Errorf("collector %s is older than this beacon CLI: it has no %q processor, which the collector config needs; "+
+ "use the %s from the same Beacon release, or pass --collector with one", binary, name, BinaryName)
+ }
+ }
+ return nil
+}
diff --git a/cli/beacon/internal/endpoint/collector/components_test.go b/cli/beacon/internal/endpoint/collector/components_test.go
new file mode 100644
index 00000000..3730680e
--- /dev/null
+++ b/cli/beacon/internal/endpoint/collector/components_test.go
@@ -0,0 +1,62 @@
+package collector
+
+import (
+ "context"
+ "errors"
+ "strings"
+ "testing"
+)
+
+func stubComponents(t *testing.T, out string, err error) {
+ t.Helper()
+ previous := listComponents
+ listComponents = func(context.Context, string) ([]byte, error) { return []byte(out), err }
+ t.Cleanup(func() { listComponents = previous })
+}
+
+// The v1.3.32 release collector lists only these processors, and refuses a config that names
+// claude_api_body.
+const releaseComponents = `buildinfo:
+ command: beacon-otelcol
+ version: 0.121.0
+processors:
+ - name: batch
+ module: go.opentelemetry.io/collector/processor/batchprocessor v0.121.0
+ - name: memory_limiter
+ module: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.121.0
+`
+
+func TestCheckComponentsRefusesACollectorWithoutTheBodyProcessor(t *testing.T) {
+ stubComponents(t, releaseComponents, nil)
+ err := CheckComponents("/usr/local/bin/beacon-otelcol")
+ if err == nil || !strings.Contains(err.Error(), `"claude_api_body"`) || !strings.Contains(err.Error(), "/usr/local/bin/beacon-otelcol") {
+ t.Fatalf("CheckComponents = %v, want the missing processor and the binary named", err)
+ }
+}
+
+func TestCheckComponentsAcceptsACollectorWithTheBodyProcessor(t *testing.T) {
+ stubComponents(t, releaseComponents+" - name: claude_api_body\n module: github.com/asymptote-labs/agent-beacon/collector-builder/exporter/beaconjsonexporter v0.0.0\n", nil)
+ if err := CheckComponents("beacon-otelcol"); err != nil {
+ t.Fatalf("CheckComponents = %v, want a collector that has claude_api_body accepted", err)
+ }
+}
+
+// A stand-in that cannot list its components is not judged on them.
+func TestCheckComponentsAcceptsABinaryThatCannotListComponents(t *testing.T) {
+ for name, stub := range map[string]struct {
+ out string
+ err error
+ }{
+ "command fails": {"", errors.New("exit status 1")},
+ "prints nothing": {"", nil},
+ "prints non-YAML": {"fake beacon-otelcol for smoke test\n", nil},
+ "lists processors": {"processors: []\n", nil},
+ } {
+ t.Run(name, func(t *testing.T) {
+ stubComponents(t, stub.out, stub.err)
+ if err := CheckComponents("beacon-otelcol"); err != nil {
+ t.Fatalf("CheckComponents = %v, want nil", err)
+ }
+ })
+ }
+}
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index fda10400..9d166168 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -406,6 +406,9 @@ func Install(opts InstallOptions) (InstallResult, error) {
if err != nil {
return InstallResult{}, err
}
+ if err := endpointcollector.CheckComponents(collectorBinary); err != nil {
+ return InstallResult{}, err
+ }
manifest := Manifest{
CreatedAt: time.Now().UTC().Format(time.RFC3339),