Skip to content

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

Scheduled inventory: skip service accounts, keep one digest per console user

shukieshah3ce2f7e679e5
diff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.go
index 1b98d97d..4e38dbaa 100644
--- a/cli/beacon/cmd/endpoint_diagnostics.go
+++ b/cli/beacon/cmd/endpoint_diagnostics.go
@@ -423,7 +423,7 @@ func inventoryConfigIncluded(config endpointinventory.Config) bool {
func writeInventoryEvents(cfg endpointconfig.Config, result endpointinventory.Result) error {
settings := endpointconfig.InventoryConfig(cfg)
result = filterInventoryResult(result, settings.Runtimes)
- _, err := writeInventorySnapshotEvents(cfg, settings, result, "manual", endpointinventory.SnapshotDigest(result), true, endpointinventory.State{})
+ _, err := writeInventorySnapshotEvents(cfg, settings, result, "manual", endpointinventory.SnapshotDigest(result), "", true)
return err
}
@@ -483,12 +483,29 @@ func systemHeartbeatScope() heartbeatScope {
if err != nil {
fmt.Fprintf(os.Stderr, "warning: could not resolve the console user for inventory: %v\n", err)
}
- if !ok || strings.TrimSpace(info.HomeDir) == "" {
+ if !ok || !isInventoriableUser(info) {
return heartbeatScope{NoConsoleUser: true}
}
return heartbeatScope{HomeDir: info.HomeDir}
}
+// isInventoriableUser rejects the accounts that can own /dev/console without being a person:
+// macOS service accounts (underscore-prefixed, home /var/empty) hold it at the login window and
+// during setup, and root holds it on a headless box. Inventorying their homes yields an empty
+// snapshot that then flips the digest back and forth with the real user's.
+func isInventoriableUser(info consoleUserInfo) bool {
+ home := strings.TrimSpace(info.HomeDir)
+ name := strings.TrimSpace(info.Username)
+ if home == "" || name == "root" || name == "loginwindow" || strings.HasPrefix(name, "_") {
+ return false
+ }
+ switch home {
+ case "/", "/var/empty", "/var/root", "/nonexistent":
+ return false
+ }
+ return true
+}
+
func loadInventoryHeartbeatConfig(userMode bool, logPath, configPath string) (endpointconfig.Config, error) {
if configPath == "" {
return loadConfigForMode(userMode, logPath), nil
@@ -531,7 +548,9 @@ func writeInventoryHeartbeat(cfg endpointconfig.Config, settings endpointconfig.
var inventoryResult endpointinventory.Result
digest := state.LastSnapshotDigest
+ previous := state.LastSnapshotDigest
writeSnapshot := false
+ next := state
if scope.NoConsoleUser {
inventoryResult = endpointinventory.Result{
GeneratedAt: now.Format(time.RFC3339),
@@ -547,23 +566,24 @@ func writeInventoryHeartbeat(cfg endpointconfig.Config, settings endpointconfig.
MaxContentBytes: settings.MaxContentBytes,
})
digest = endpointinventory.SnapshotDigest(inventoryResult)
- writeSnapshot = state.LastSnapshotDigest != digest
+ // Compare against the last digest for *this* home: a multi-user machine alternates
+ // console users, and a switch is not a change in anyone's inventory.
+ previous = state.DigestFor(inventoryResult.UserScope.HomeHash)
+ writeSnapshot = previous != digest
+ next = state.WithDigest(inventoryResult.UserScope.HomeHash, digest)
}
- writeResult, err := writeInventorySnapshotEvents(cfg, settings, inventoryResult, trigger, digest, writeSnapshot, state)
+ writeResult, err := writeInventorySnapshotEvents(cfg, settings, inventoryResult, trigger, digest, previous, writeSnapshot)
if err != nil {
return writeResult, err
}
- if err := locked.Save(endpointinventory.State{
- LastEmittedAt: now.Format(time.RFC3339),
- LastSnapshotDigest: digest,
- }); err != nil {
- return inventoryHeartbeatWriteResult{SnapshotDigest: digest, PreviousDigest: state.LastSnapshotDigest}, err
+ next.LastEmittedAt = now.Format(time.RFC3339)
+ if err := locked.Save(next); err != nil {
+ return inventoryHeartbeatWriteResult{SnapshotDigest: digest, PreviousDigest: previous}, err
}
return writeResult, nil
}
-func writeInventorySnapshotEvents(cfg endpointconfig.Config, settings endpointconfig.InventorySettings, result endpointinventory.Result, trigger, digest string, writeSnapshot bool, state endpointinventory.State) (inventoryHeartbeatWriteResult, error) {
- previousDigest := state.LastSnapshotDigest
+func writeInventorySnapshotEvents(cfg endpointconfig.Config, settings endpointconfig.InventorySettings, result endpointinventory.Result, trigger, digest, previousDigest string, writeSnapshot bool) (inventoryHeartbeatWriteResult, error) {
counts := endpointinventory.CountsFor(result)
inventoryMeta := map[string]interface{}{
"generated_at": result.GeneratedAt,
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index 5a730a63..2cdefd9a 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -2219,3 +2219,69 @@ func captureStdout(t *testing.T, fn func() error) (string, error) {
}
return string(output), runErr
}
+
+// A shared Mac alternates console users. Switching between them is not a change in anyone's
+// inventory, so the second visit to each home must write a heartbeat and no snapshot.
+func TestScheduledHeartbeatKeepsOneDigestPerConsoleUser(t *testing.T) {
+ alice, bob := t.TempDir(), t.TempDir()
+ writeTestFile(t, filepath.Join(alice, ".cursor", "mcp.json"), `{"mcpServers":{"alice-one":{"command":"npx"}}}`)
+ writeTestFile(t, filepath.Join(bob, ".cursor", "mcp.json"), `{"mcpServers":{"bob-one":{"command":"npx"},"bob-two":{"command":"uvx"}}}`)
+ t.Setenv("HOME", t.TempDir())
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ cfg := endpointconfig.Default(false, logPath)
+ settings := endpointconfig.InventoryConfig(cfg)
+
+ run := func(home string) inventoryHeartbeatWriteResult {
+ t.Helper()
+ r, err := writeInventoryHeartbeat(cfg, settings, false, inventoryTriggerScheduled, heartbeatScope{HomeDir: home})
+ if err != nil {
+ t.Fatal(err)
+ }
+ return r
+ }
+ if r := run(alice); !r.SnapshotWritten {
+ t.Fatalf("first visit to alice must snapshot: %+v", r)
+ }
+ if r := run(bob); !r.SnapshotWritten {
+ t.Fatalf("first visit to bob must snapshot: %+v", r)
+ }
+ if r := run(alice); r.SnapshotWritten || !r.Written {
+ t.Fatalf("returning to alice with nothing changed must be heartbeat only: %+v", r)
+ }
+ if r := run(bob); r.SnapshotWritten {
+ t.Fatalf("returning to bob with nothing changed must be heartbeat only: %+v", r)
+ }
+ writeTestFile(t, filepath.Join(alice, ".cursor", "mcp.json"), `{"mcpServers":{"alice-one":{"command":"npx"},"alice-two":{"command":"uvx"}}}`)
+ if r := run(alice); !r.SnapshotWritten {
+ t.Fatalf("a real change for alice must snapshot: %+v", r)
+ }
+ state, err := endpointinventory.ReadState(endpointinventory.StatePathForLog(logPath, false))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(state.LastSnapshotDigests) != 2 {
+ t.Fatalf("state should remember one digest per home: %+v", state)
+ }
+}
+
+func TestSystemHeartbeatScopeIgnoresServiceAccountsAtTheConsole(t *testing.T) {
+ oldResolver := activeConsoleUser
+ t.Cleanup(func() { activeConsoleUser = oldResolver })
+ for _, tc := range []struct {
+ name string
+ info consoleUserInfo
+ want bool // NoConsoleUser
+ }{
+ {"setup assistant", consoleUserInfo{Username: "_mbsetupuser", HomeDir: "/var/empty"}, true},
+ {"root", consoleUserInfo{Username: "root", HomeDir: "/var/root"}, true},
+ {"loginwindow", consoleUserInfo{Username: "loginwindow", HomeDir: "/"}, true},
+ {"empty home", consoleUserInfo{Username: "someone", HomeDir: ""}, true},
+ {"real user", consoleUserInfo{Username: "zac", HomeDir: t.TempDir()}, false},
+ } {
+ info := tc.info
+ activeConsoleUser = func() (consoleUserInfo, bool, error) { return info, true, nil }
+ if got := systemHeartbeatScope().NoConsoleUser; got != tc.want {
+ t.Errorf("%s: NoConsoleUser = %t, want %t", tc.name, got, tc.want)
+ }
+ }
+}
diff --git a/cli/beacon/internal/endpoint/inventory/heartbeat.go b/cli/beacon/internal/endpoint/inventory/heartbeat.go
index 7d29cf7c..327b8ba1 100644
--- a/cli/beacon/internal/endpoint/inventory/heartbeat.go
+++ b/cli/beacon/internal/endpoint/inventory/heartbeat.go
@@ -26,6 +26,38 @@ type Counts struct {
type State struct {
LastEmittedAt string `json:"last_emitted_at,omitempty"`
LastSnapshotDigest string `json:"last_snapshot_digest,omitempty"`
+ // LastSnapshotDigests remembers the last digest per scanned home (keyed by UserScope.HomeHash).
+ // Inventory is per user but the state file is per endpoint: on a Mac where the console user
+ // changes between runs, a single digest would flip on every switch and write a snapshot each
+ // time although nobody's inventory changed. LastSnapshotDigest keeps the most recent value
+ // for status and for state files written before this map existed.
+ LastSnapshotDigests map[string]string `json:"last_snapshot_digests,omitempty"`
+}
+
+// DigestFor returns the last digest recorded for a home, falling back to the endpoint-wide value
+// when no per-home record exists yet (a state file from an older version).
+func (s State) DigestFor(homeHash string) string {
+ if d, ok := s.LastSnapshotDigests[homeHash]; ok && homeHash != "" {
+ return d
+ }
+ if len(s.LastSnapshotDigests) == 0 {
+ return s.LastSnapshotDigest
+ }
+ return ""
+}
+
+// WithDigest returns a copy of the state recording digest for a home and as the latest overall.
+func (s State) WithDigest(homeHash, digest string) State {
+ out := s
+ out.LastSnapshotDigest = digest
+ out.LastSnapshotDigests = make(map[string]string, len(s.LastSnapshotDigests)+1)
+ for k, v := range s.LastSnapshotDigests {
+ out.LastSnapshotDigests[k] = v
+ }
+ if homeHash != "" {
+ out.LastSnapshotDigests[homeHash] = digest
+ }
+ return out
}
type LockedState struct {
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index 19553d04..9acbeb25 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -673,7 +673,7 @@ func TestReadStateTreatsEmptyFileAsFreshState(t *testing.T) {
if err != nil {
t.Fatalf("ReadState returned error for empty state file: %v", err)
}
- if state != (State{}) {
+ if state.LastEmittedAt != "" || state.LastSnapshotDigest != "" || len(state.LastSnapshotDigests) != 0 {
t.Fatalf("state = %#v, want empty", state)
}
}
@@ -1081,3 +1081,20 @@ func hasScope(result Result, scope string) bool {
}
return false
}
+
+func TestStateDigestFallsBackToTheLegacyFieldThenTracksPerHome(t *testing.T) {
+ legacy := State{LastSnapshotDigest: "sha256:old"}
+ if legacy.DigestFor("home-a") != "sha256:old" {
+ t.Fatal("a pre-map state must answer with the endpoint-wide digest for any home")
+ }
+ next := legacy.WithDigest("home-a", "sha256:a")
+ if next.DigestFor("home-a") != "sha256:a" || next.LastSnapshotDigest != "sha256:a" {
+ t.Fatalf("WithDigest should record per home and overall: %+v", next)
+ }
+ if next.DigestFor("home-b") != "" {
+ t.Fatal("once per-home digests exist, an unknown home has no previous digest")
+ }
+ if legacy.LastSnapshotDigests != nil {
+ t.Fatal("WithDigest must not mutate its receiver")
+ }
+}
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index e4cfad16..78438c95 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -11,6 +11,15 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
## September 2026
+### Unreleased
+
+- **Scheduled inventory on shared Macs** · A system-mode heartbeat inventories whoever owns the
+ console. macOS service accounts (`_mbsetupuser` at the login window, home `/var/empty`) passed
+ that check and produced an empty snapshot, and on a Mac where two people alternate at the
+ console every switch wrote a "changed" snapshot although nobody's inventory changed. Service
+ accounts are now treated as no console user (heartbeat only, no snapshot), and the state file
+ remembers the last digest per home, so returning to an unchanged user writes a heartbeat only.
+
### v1.3.12 · September 15, 2026
- **User-mode inventory job starts beside a system install** · On a Mac that also ran the
diff --git a/docs/cli/endpoint-inventory.mdx b/docs/cli/endpoint-inventory.mdx
index 5cbb804f..960caab1 100644
--- a/docs/cli/endpoint-inventory.mdx
+++ b/docs/cli/endpoint-inventory.mdx
@@ -65,7 +65,7 @@ A scheduled local job appends inventory telemetry to a separate `inventory_state
- `inventory.heartbeat` records that Beacon checked local agent configuration inventory, including counts and a snapshot digest. Every run writes one; it is the endpoint's liveness signal.
- `inventory.snapshot` records the current metadata-only inventory. It is written only when the snapshot digest changed since the last run.
-A system-mode job runs as root and inventories the active console user's home. When nobody is logged in it still writes the heartbeat, with `user_scope.mode` set to `no_console_user`, and no snapshot. The scheduled scan covers user-level configuration only; project-scoped files (`.cursor/mcp.json`, `.claude/settings.json` in a repository) are reported by `beacon endpoint inventory` run from that directory, not by the job.
+A system-mode job runs as root and inventories the active console user's home. When nobody is logged in, or the console is held by a macOS service account such as `_mbsetupuser` at the login window, it still writes the heartbeat, with `user_scope.mode` set to `no_console_user`, and no snapshot. On a Mac where several people share the console, the job keeps the last digest per home, so a switch between users is not reported as a change; each user's snapshot is written only when that user's inventory changed. The scheduled scan covers user-level configuration only; project-scoped files (`.cursor/mcp.json`, `.claude/settings.json` in a repository) are reported by `beacon endpoint inventory` run from that directory, not by the job.
By default, inventory snapshots include config file metadata, MCP server metadata, skill metadata, and hook config metadata across supported local runtimes. They do not include skill instruction bodies, MCP secret values, full environment values, full command arguments, or unrelated config content.