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
collector: bound `components` when a child holds its pipe; fast ci fakes
Claudeecb128b92e09
diff --git a/cli/beacon/internal/ci/healthport_test.go b/cli/beacon/internal/ci/healthport_test.goindex c5698540..8141e2b1 100644--- a/cli/beacon/internal/ci/healthport_test.go+++ b/cli/beacon/internal/ci/healthport_test.go@@ -10,7 +10,7 @@ import (// install would, rather than always 13133, so it can run beside an endpoint collector.func TestProvisionDerivesTheHealthPortFromTheOTLPPorts(t *testing.T) {t.Setenv("RUNNER_TEMP", t.TempDir())- collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"sleep 60\n")oldResolve := resolveCollectorBinaryresolveCollectorBinary = func(string) (string, error) { return collector, nil }t.Cleanup(func() { resolveCollectorBinary = oldResolve })diff --git a/cli/beacon/internal/ci/session_test.go b/cli/beacon/internal/ci/session_test.goindex 3339913f..db77bfd5 100644--- a/cli/beacon/internal/ci/session_test.go+++ b/cli/beacon/internal/ci/session_test.go@@ -20,7 +20,7 @@ import (func TestProvisionUsesRunnerTempAndWritesCollectorConfig(t *testing.T) {runnerTemp := t.TempDir()t.Setenv("RUNNER_TEMP", runnerTemp)- collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"sleep 60\n")oldResolve := resolveCollectorBinaryresolveCollectorBinary = func(configured string) (string, error) {if configured != collector {@@ -54,7 +54,7 @@ func TestProvisionUsesRunnerTempAndWritesCollectorConfig(t *testing.T) {func TestProvisionUsesLogPathDirectoryAsBaseDir(t *testing.T) {dir := t.TempDir()logPath := filepath.Join(dir, "artifacts", "runtime.jsonl")- collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"sleep 60\n")oldResolve := resolveCollectorBinaryresolveCollectorBinary = func(string) (string, error) { return collector, nil }t.Cleanup(func() { resolveCollectorBinary = oldResolve })@@ -84,7 +84,7 @@ func TestStartStopCollectorProcess(t *testing.T) {t.Setenv("RUNNER_TRACKING_ID", "github-actions-tracker")// exec so SIGTERM reaches the sleeping process directly; a trap in a `sleep 1` loop only runs// after the current sleep returns, which made every Stop wait up to a second.- collector := fakeExecutable(t, "collector", "#!/bin/sh\nenv > \"$2.env\"\nexec sleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"env > \"$2.env\"\nexec sleep 60\n")oldWait := waitCollectorReadywaitCollectorReady = func(endpointconfig.Config, time.Duration) error { return nil }t.Cleanup(func() { waitCollectorReady = oldWait })@@ -138,7 +138,7 @@ func TestStartDetachedWritesStateAndExports(t *testing.T) {t.Skip("shell fake uses POSIX signal semantics")}dir := t.TempDir()- collector := fakeExecutable(t, "collector", "#!/bin/sh\nexec sleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"exec sleep 60\n")oldWait := waitCollectorReadywaitCollectorReady = func(endpointconfig.Config, time.Duration) error { return nil }t.Cleanup(func() { waitCollectorReady = oldWait })@@ -213,7 +213,7 @@ func TestRunChildPassesTheCallersWebFetchOptIn(t *testing.T) {// bodies the job turned on reach the collector config as capture_model_context, and anything else// leaves it dropping every body.func TestProvisionCapturesModelContextWhenTheJobTurnsInlineBodiesOn(t *testing.T) {- collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"sleep 60\n")oldResolve := resolveCollectorBinaryresolveCollectorBinary = func(string) (string, error) { return collector, nil }t.Cleanup(func() { resolveCollectorBinary = oldResolve })@@ -437,7 +437,7 @@ func TestProvisionForwardWritesSecureExporterConfig(t *testing.T) {runnerTemp := t.TempDir()t.Setenv("RUNNER_TEMP", runnerTemp)t.Setenv(EnvSplunkToken, "top-secret-token")- collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ collector := fakeExecutable(t, "collector", fakeCollectorPrelude+"sleep 60\n")oldResolve := resolveCollectorBinaryresolveCollectorBinary = func(string) (string, error) { return collector, nil }t.Cleanup(func() { resolveCollectorBinary = oldResolve })@@ -561,6 +561,12 @@ func TestRunChildStripsUploadCredentialsWhenUploadConfigured(t *testing.T) {}}+// fakeCollectorPrelude starts every fake collector script. Writing the collector config runs+// `<collector> components` on macOS and Windows to decide on peer attribution; a fake that went on+// to sleep there would hold each Provision until that run timed out. Answering with an empty listing+// at once reads as a collector that cannot list its components, the same as before.+const fakeCollectorPrelude = "#!/bin/sh\n[ \"$1\" = components ] && exit 0\n"+func fakeExecutable(t *testing.T, name, script string) string {t.Helper()path := filepath.Join(t.TempDir(), name)diff --git a/cli/beacon/internal/endpoint/collector/components.go b/cli/beacon/internal/endpoint/collector/components.goindex 33e3d5fc..5cd0c630 100644--- a/cli/beacon/internal/endpoint/collector/components.go+++ b/cli/beacon/internal/endpoint/collector/components.go@@ -19,7 +19,9 @@ var requiredComponents = map[string][]string{// 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()+ cmd := exec.CommandContext(ctx, binary, "components")+ cmd.WaitDelay = componentsWaitDelay+ return cmd.Output()}type namedComponents []struct {@@ -57,7 +59,7 @@ func (l componentListing) has(kind, name string) bool {// readComponents lists binary's components. ok is false for a binary that cannot list them -- a// stand-in, or a build without the command -- or whose listing does not parse: nothing to judge it on.func readComponents(binary string) (componentListing, bool) {- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ ctx, cancel := context.WithTimeout(context.Background(), componentsTimeout)defer cancel()out, err := listComponents(ctx, binary)if err != nil {@@ -155,3 +157,13 @@ func CheckComponentsFor(binary string, extensions, processors, exporters []strin}return nil}++// componentsTimeout bounds `beacon-otelcol components`. A variable for tests.+var componentsTimeout = 10 * time.Second++// componentsWaitDelay is how long listComponents waits, after the timeout kills the binary, for its+// output pipes to close. A child the binary started keeps them open after the binary is killed (a+// shell script's commands are such children), and without a bound Output() would wait for that child+// however long it runs, so a binary that hangs on `components` would stall install, repair and every+// config render on macOS and Windows, which consult this listing to decide on peer attribution.+const componentsWaitDelay = 2 * time.Seconddiff --git a/cli/beacon/internal/endpoint/collector/components_stall_test.go b/cli/beacon/internal/endpoint/collector/components_stall_test.gonew file mode 100644index 00000000..55aa1b09--- /dev/null+++ b/cli/beacon/internal/endpoint/collector/components_stall_test.go@@ -0,0 +1,34 @@+package collector++import (+ "os"+ "path/filepath"+ "testing"+ "time"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+)++// A binary that hangs on `components` and leaves a child holding its output pipe -- a shell script+// whose sleep is a forked child, as macOS's /bin/sh runs it -- must not hold readComponents past its+// timeout: killing the shell does not close the pipe the child still has, and without WaitDelay+// Output() waits for that child. The ci tests' fake collectors did exactly this, and every+// Provision stalled a minute on macOS.+func TestReadComponentsDoesNotWaitForAChildHoldingThePipe(t *testing.T) {+ testenv.RequirePOSIXExecutableFixtures(t)+ binary := filepath.Join(t.TempDir(), "collector")+ if err := os.WriteFile(binary, []byte("#!/bin/sh\nsleep 30\necho done\n"), 0o755); err != nil {+ t.Fatal(err)+ }+ prevTimeout := componentsTimeout+ componentsTimeout = 200 * time.Millisecond+ t.Cleanup(func() { componentsTimeout = prevTimeout })++ start := time.Now()+ if _, ok := readComponents(binary); ok {+ t.Fatal("a binary that never answered listed its components")+ }+ if elapsed := time.Since(start); elapsed > componentsTimeout+componentsWaitDelay+5*time.Second {+ t.Fatalf("readComponents took %v; a child holding the pipe kept it waiting", elapsed)+ }+}