Skip to content

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

Fix inventory heartbeat forwarding edge cases

shukieshah9650565fe210
diff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.go
index d9cd17c9..4b3e73d0 100644
--- a/cli/beacon/cmd/endpoint_diagnostics.go
+++ b/cli/beacon/cmd/endpoint_diagnostics.go
@@ -325,6 +325,7 @@ func runEndpointInventory(cmd *cobra.Command, args []string) error {
func writeInventoryEvents(cfg endpointconfig.Config, result endpointinventory.Result) error {
settings := endpointconfig.InventoryConfig(cfg)
+ result = filterInventoryResult(result, settings.Runtimes)
_, err := writeInventorySnapshotEvents(cfg, settings, result, "manual", "", true, endpointinventory.State{})
return err
}
@@ -395,14 +396,16 @@ func writeInventoryHeartbeat(cfg endpointconfig.Config, settings endpointconfig.
Now: func() time.Time { return now },
}
inventoryResult := endpointinventory.Scan(scanOpts)
- writeResult, err := writeInventorySnapshotEvents(cfg, settings, inventoryResult, trigger, triggerHarness, state.LastSnapshotDigest != endpointinventory.SnapshotDigest(inventoryResult), state)
- if err != nil {
- return writeResult, err
- }
+ digest := endpointinventory.SnapshotDigest(inventoryResult)
+ writeSnapshot := state.LastSnapshotDigest != digest
if err := locked.Save(endpointinventory.State{
LastEmittedAt: now.Format(time.RFC3339),
- LastSnapshotDigest: writeResult.SnapshotDigest,
+ LastSnapshotDigest: digest,
}); err != nil {
+ return inventoryHeartbeatWriteResult{SnapshotDigest: digest, PreviousDigest: state.LastSnapshotDigest}, err
+ }
+ writeResult, err := writeInventorySnapshotEvents(cfg, settings, inventoryResult, trigger, triggerHarness, writeSnapshot, state)
+ if err != nil {
return writeResult, err
}
return writeResult, nil
@@ -497,6 +500,41 @@ func existingInventorySkills(skills []endpointinventory.Skill) []endpointinvento
return out
}
+func filterInventoryResult(result endpointinventory.Result, runtimes []string) endpointinventory.Result {
+ allowed := map[string]bool{}
+ for _, runtime := range runtimes {
+ runtime = strings.TrimSpace(runtime)
+ if runtime != "" {
+ allowed[runtime] = true
+ }
+ }
+ if len(allowed) == 0 {
+ return result
+ }
+ configs := make([]endpointinventory.Config, 0, len(result.Configs))
+ for _, config := range result.Configs {
+ if allowed[config.Runtime] {
+ configs = append(configs, config)
+ }
+ }
+ servers := make([]endpointinventory.MCPServer, 0, len(result.MCPServers))
+ for _, server := range result.MCPServers {
+ if allowed[server.Runtime] {
+ servers = append(servers, server)
+ }
+ }
+ skills := make([]endpointinventory.Skill, 0, len(result.Skills))
+ for _, skill := range result.Skills {
+ if allowed[skill.Runtime] {
+ skills = append(skills, skill)
+ }
+ }
+ result.Configs = configs
+ result.MCPServers = servers
+ result.Skills = skills
+ return result
+}
+
func runEndpointTestEvent(cmd *cobra.Command, args []string) error {
cfg := loadOrDefaultConfig()
writableStage := stageFromCheck(checkLogWritable(cfg))
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index 9e23b6dd..78fccf18 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -804,6 +804,45 @@ func TestWriteInventoryEventsAppendsInventorySnapshot(t *testing.T) {
}
}
+func TestWriteInventoryEventsHonorsConfiguredRuntimes(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ cfg := endpointconfig.Default(true, logPath)
+ cfg.Inventory = &endpointconfig.Inventory{Runtimes: []string{"cursor"}}
+ result := endpointinventory.Result{
+ Configs: []endpointinventory.Config{
+ {Runtime: "cursor", PathHash: "sha256:cursor", Exists: true, ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ {Runtime: "claude_code", PathHash: "sha256:claude", Exists: true, ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ },
+ MCPServers: []endpointinventory.MCPServer{
+ {Runtime: "cursor", ServerName: "cursor-server", SourcePathHash: "sha256:cursor", DefinitionHash: "sha256:cursor-def", ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ {Runtime: "claude_code", ServerName: "claude-server", SourcePathHash: "sha256:claude", DefinitionHash: "sha256:claude-def", ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ },
+ Skills: []endpointinventory.Skill{
+ {Runtime: "cursor", SkillName: "cursor-skill", Exists: true, ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ {Runtime: "claude_code", SkillName: "claude-skill", Exists: true, ParserStatus: endpointinventory.StatusOK, Redaction: endpointinventory.RedactionFull},
+ },
+ }
+
+ if err := writeInventoryEvents(cfg, result); err != nil {
+ t.Fatalf("writeInventoryEvents returned error: %v", err)
+ }
+ data, err := os.ReadFile(endpointinventory.LogPath(logPath, cfg.UserMode))
+ if err != nil {
+ t.Fatal(err)
+ }
+ text := string(data)
+ for _, want := range []string{"cursor-server", "cursor-skill"} {
+ if !strings.Contains(text, want) {
+ t.Fatalf("inventory log missing %q: %s", want, text)
+ }
+ }
+ for _, forbidden := range []string{"claude-server", "claude-skill"} {
+ if strings.Contains(text, forbidden) {
+ t.Fatalf("inventory log should not include filtered runtime %q: %s", forbidden, text)
+ }
+ }
+}
+
func TestInventoryHeartbeatTTLAndSnapshotDigest(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
diff --git a/cli/beacon/internal/endpoint/s3/pack/s3-upload-smoke-test.sh.tmpl b/cli/beacon/internal/endpoint/s3/pack/s3-upload-smoke-test.sh.tmpl
index 0359648a..8ea23e57 100644
--- a/cli/beacon/internal/endpoint/s3/pack/s3-upload-smoke-test.sh.tmpl
+++ b/cli/beacon/internal/endpoint/s3/pack/s3-upload-smoke-test.sh.tmpl
@@ -22,6 +22,15 @@ if [ ! -r "$BEACON_LOG" ]; then
fi
prefix="${BEACON_S3_PREFIX%/}"
+case "$prefix" in
+ */runtime)
+ prefix="${prefix%/runtime}"
+ ;;
+ */inventory)
+ prefix="${prefix%/inventory}"
+ ;;
+esac
+[ -n "$prefix" ] || prefix="beacon"
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
runtime_key="${prefix}/runtime/smoke-tests/beacon-runtime-${timestamp}.jsonl"
diff --git a/packaging/macos/jamf/claude/s3/install-forwarder.sh b/packaging/macos/jamf/claude/s3/install-forwarder.sh
index 51736084..c8d8a12f 100755
--- a/packaging/macos/jamf/claude/s3/install-forwarder.sh
+++ b/packaging/macos/jamf/claude/s3/install-forwarder.sh
@@ -19,6 +19,19 @@ VECTOR_READ_FROM="${BEACON_VECTOR_READ_FROM:-${8:-end}}"
RUNTIME_LOG_PATHS="${BEACON_RUNTIME_LOG_PATHS:-/var/log/beacon-agent/runtime.jsonl}"
NO_START="${BEACON_NO_START:-0}"
+case "$S3_PREFIX" in
+ */runtime)
+ S3_PREFIX="${S3_PREFIX%/runtime}"
+ ;;
+ */inventory)
+ S3_PREFIX="${S3_PREFIX%/inventory}"
+ ;;
+esac
+S3_PREFIX="${S3_PREFIX%/}"
+if [ -z "$S3_PREFIX" ]; then
+ S3_PREFIX="beacon"
+fi
+
if [ -z "$S3_BUCKET" ]; then
echo "S3 bucket is required (BEACON_S3_BUCKET or Jamf parameter 4)" >&2
exit 1
diff --git a/packaging/macos/test-endpoint-scripts.sh b/packaging/macos/test-endpoint-scripts.sh
index f47ea76f..d728b6d6 100644
--- a/packaging/macos/test-endpoint-scripts.sh
+++ b/packaging/macos/test-endpoint-scripts.sh
@@ -462,7 +462,7 @@ AWS_SHARED_CREDENTIALS_FILE="/tmp/test-aws-credentials" \
AWS_CONFIG_FILE="/tmp/test-aws-config" \
AWS_WEB_IDENTITY_TOKEN_FILE="/tmp/test-web-identity-token" \
AWS_ROLE_ARN="arn:aws:iam::123456789012:role/beacon-demo" \
-"$ROOT_DIR/packaging/macos/jamf/claude/s3/install-forwarder.sh" _ _ _ "beacon-test-bucket" "us-west-2" "beacon/claude" "STANDARD_IA" "end" >/dev/null
+"$ROOT_DIR/packaging/macos/jamf/claude/s3/install-forwarder.sh" _ _ _ "beacon-test-bucket" "us-west-2" "beacon/claude/runtime" "STANDARD_IA" "end" >/dev/null
if [ ! -f "$S3_FORWARDER_BASE/s3-vector.toml" ]; then
echo "S3 Vector config was not written" >&2
@@ -524,6 +524,10 @@ if ! grep -q "us-west-2" "$S3_FORWARDER_BASE/s3-vector.env"; then
echo "S3 Vector env missing region" >&2
exit 1
fi
+if ! grep -q "BEACON_S3_PREFIX='beacon/claude'" "$S3_FORWARDER_BASE/s3-vector.env"; then
+ echo "S3 Vector env should normalize old runtime suffix from prefix" >&2
+ exit 1
+fi
for expected in \
"AWS_ACCESS_KEY_ID='test-access-key'" \
"AWS_SECRET_ACCESS_KEY='test-secret-key'" \