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
security: refuse Beacon-only actions stated over OTLP (#808)
Justin D'Souzafd6d92783f06
diff --git a/cli/beacon-hooks/cmd/share_auto_test.go b/cli/beacon-hooks/cmd/share_auto_test.goindex 13f787d3..83e1d152 100644--- a/cli/beacon-hooks/cmd/share_auto_test.go+++ b/cli/beacon-hooks/cmd/share_auto_test.go@@ -6,6 +6,7 @@ import ("path/filepath""testing"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve""github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/activesession""github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/shareauto")@@ -60,7 +61,7 @@ func shareRequests(t *testing.T, logPath string) []map[string]interface{} {t.Helper()var out []map[string]interface{}for _, event := range endpointEvents(t, logPath) {- if info, _ := event["event"].(map[string]interface{}); info["action"] == shareauto.ActionShareRequested {+ if info, _ := event["event"].(map[string]interface{}); info["action"] == asymptoteobserve.ActionShareRequested {out = append(out, event)}}@@ -93,7 +94,7 @@ func TestAutoShareWritesOneRequestPerSession(t *testing.T) {}// It follows the session's first event, which is SessionStart here.events := endpointEvents(t, logPath)- if events[0]["event"].(map[string]interface{})["action"] != "session.started" || events[1]["event"].(map[string]interface{})["action"] != shareauto.ActionShareRequested {+ if events[0]["event"].(map[string]interface{})["action"] != "session.started" || events[1]["event"].(map[string]interface{})["action"] != asymptoteobserve.ActionShareRequested {t.Fatalf("order: %v then %v", events[0]["event"], events[1]["event"])}}diff --git a/cli/beacon-hooks/internal/logging/logging.go b/cli/beacon-hooks/internal/logging/logging.goindex ea46bc14..7acb6983 100644--- a/cli/beacon-hooks/internal/logging/logging.go+++ b/cli/beacon-hooks/internal/logging/logging.go@@ -159,7 +159,7 @@ func (l *Logger) EndpointEventWithFidelity(action, category, severity, message,// originated it: no runtime reported a share request.func (l *Logger) requestShareOnce(event map[string]interface{}) {info, _ := event["event"].(map[string]interface{})- if action, _ := info["action"].(string); action == shareauto.ActionShareRequested {+ if action, _ := info["action"].(string); action == asymptoteobserve.ActionShareRequested {return}session, _ := event["session"].(map[string]interface{})@@ -195,7 +195,7 @@ func (l *Logger) requestShareOnce(event map[string]interface{}) {if branch, _ := event["branch"].(string); branch != "" {fields["branch"] = branch}- if err := l.EndpointEventWithFidelity(shareauto.ActionShareRequested, "session", "info", "Auto-share requested for this session", asymptoteobserve.FidelityInferred, fields); err != nil {+ if err := l.EndpointEventWithFidelity(asymptoteobserve.ActionShareRequested, "session", "info", "Auto-share requested for this session", asymptoteobserve.FidelityInferred, fields); err != nil {// The request was not written (a read-only log, a sandbox): take the mark back so the next// hook of the session asks again, rather than leave the session marked and never requested.// Like the rest of this path it stays silent and never fails the hook.diff --git a/cli/beacon-hooks/internal/logging/share_request_test.go b/cli/beacon-hooks/internal/logging/share_request_test.goindex f437864f..0cdd8880 100644--- a/cli/beacon-hooks/internal/logging/share_request_test.go+++ b/cli/beacon-hooks/internal/logging/share_request_test.go@@ -8,6 +8,7 @@ import ("path/filepath""testing"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve""github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/activesession""github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/shareauto")@@ -30,7 +31,7 @@ func TestShareRequestMarkIsRolledBackWhenTheWriteFails(t *testing.T) {failing := trueprev := writeEndpointJSONwriteEndpointJSON = func(path string, event map[string]interface{}) error {- if info, _ := event["event"].(map[string]interface{}); failing && info["action"] == shareauto.ActionShareRequested {+ if info, _ := event["event"].(map[string]interface{}); failing && info["action"] == asymptoteobserve.ActionShareRequested {return errors.New("read-only file system")}return prev(path, event)@@ -62,13 +63,13 @@ func TestShareRequestMarkIsRolledBackWhenTheWriteFails(t *testing.T) {if len(record.Sessions) == 0 || len(record.ShareRequested) != 0 {t.Fatalf("record = %s, want the session noted and no share-request mark", data)}- if got := countActions(t, logPath, shareauto.ActionShareRequested); got != 0 {+ if got := countActions(t, logPath, asymptoteobserve.ActionShareRequested); got != 0 {t.Fatalf("share requests while failing = %d", got)}failing = falsehook()hook()- if got := countActions(t, logPath, shareauto.ActionShareRequested); got != 1 {+ if got := countActions(t, logPath, asymptoteobserve.ActionShareRequested); got != 1 {t.Fatalf("share requests = %d, want exactly one", got)}}diff --git a/cli/beacon/cmd/git_budget_test.go b/cli/beacon/cmd/git_budget_test.goindex 683e2227..4966572b 100644--- a/cli/beacon/cmd/git_budget_test.go+++ b/cli/beacon/cmd/git_budget_test.go@@ -15,6 +15,7 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/gitlink"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// The hook budget tests never wait on the wall clock (#859 exists because tests that did flaked on@@ -98,7 +99,7 @@ func budgetEventsIn(t *testing.T, logPath string) []schema.Event {var events []schema.Eventfor _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {var e schema.Event- if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == gitlink.BudgetAction {+ if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == asymptoteobserve.ActionGitHookBudgetExceeded {events = append(events, e)}}diff --git a/cli/beacon/cmd/git_hooks_test.go b/cli/beacon/cmd/git_hooks_test.goindex 5b4676e0..6055aebb 100644--- a/cli/beacon/cmd/git_hooks_test.go+++ b/cli/beacon/cmd/git_hooks_test.go@@ -12,6 +12,7 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/gitlink""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// relaxGitBudgets lifts the git hooks' wall-clock budgets for a test of what a hook writes. A hook@@ -174,7 +175,7 @@ func linkEventsIn(t *testing.T, logPath string) []schema.Event {var events []schema.Eventfor _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {var e schema.Event- if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == gitlink.LinkAction {+ if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == asymptoteobserve.ActionCommitLinked {events = append(events, e)}}diff --git a/cli/beacon/cmd/git_share_sessions.go b/cli/beacon/cmd/git_share_sessions.goindex 198081d0..8275843d 100644--- a/cli/beacon/cmd/git_share_sessions.go+++ b/cli/beacon/cmd/git_share_sessions.go@@ -133,13 +133,13 @@ func localShareURLs(logPath string) map[string]string {return urls}defer f.Close()- marker := []byte(`"` + SessionSharedAction + `"`)+ marker := []byte(`"` + asymptoteobserve.ActionSessionShared + `"`)reader := bufio.NewReaderSize(f, 256*1024)for {line, err := reader.ReadBytes('\n')if len(line) > 0 && bytes.Contains(line, marker) {var event schema.Event- if json.Unmarshal(line, &event) == nil && event.Event.Action == SessionSharedAction && event.Session != nil && event.Session.ID != "" {+ if json.Unmarshal(line, &event) == nil && event.Event.Action == asymptoteobserve.ActionSessionShared && event.Session != nil && event.Session.ID != "" {if u, _ := event.Raw["shared_url"].(string); gitlink.ValidShareURL(u) {urls[gitShareKey(event.Harness.Name, event.Session.ID)] = u}diff --git a/cli/beacon/cmd/git_share_sessions_test.go b/cli/beacon/cmd/git_share_sessions_test.goindex 52d34c99..4d0b9bd7 100644--- a/cli/beacon/cmd/git_share_sessions_test.go+++ b/cli/beacon/cmd/git_share_sessions_test.go@@ -15,11 +15,12 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/gitlink""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/handoff"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")func writeSharedEvent(t *testing.T, logPath, harness, session, url string) {t.Helper()- event := schema.NewEvent(schema.NewEventOptions{Action: SessionSharedAction, Category: "session", Harness: schema.HarnessInfo{Name: harness}})+ event := schema.NewEvent(schema.NewEventOptions{Action: asymptoteobserve.ActionSessionShared, Category: "session", Harness: schema.HarnessInfo{Name: harness}})event.Session = &schema.SessionInfo{ID: session}event.Raw = map[string]interface{}{"shared_url": url}line, _ := json.Marshal(event)diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.goindex ad70f782..6aa7521f 100644--- a/cli/beacon/cmd/share.go+++ b/cli/beacon/cmd/share.go@@ -41,9 +41,6 @@ import (// errShareNothingYet is a session with no events to share yet. --follow waits for some.var errShareNothingYet = errors.New("has nothing to share yet")-// SessionSharedAction is the runtime-log action recorded after a session is shared or refreshed.-const SessionSharedAction = "session.shared"-var (shareAccountLoad = account.LoadshareHTTPClient = &http.Client{Timeout: 60 * time.Second}@@ -1070,7 +1067,7 @@ func shareRecordEvent(session handoff.Session, result shareResult, refresh bool,verb = "refreshed"}event := schema.NewEvent(schema.NewEventOptions{- Action: SessionSharedAction,+ Action: asymptoteobserve.ActionSessionShared,Category: "session",Severity: schema.SeverityInfo,AgentVersion: version.GetVersion(),diff --git a/cli/beacon/cmd/share_follow.go b/cli/beacon/cmd/share_follow.goindex 097e2840..e6b07a4d 100644--- a/cli/beacon/cmd/share_follow.go+++ b/cli/beacon/cmd/share_follow.go@@ -17,9 +17,8 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/account""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/gitlink""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/handoff"- "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/shareauto"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// `beacon share --follow` keeps a shared trace current while its session runs: it re-reads the@@ -259,14 +258,13 @@ func shareLogRecordsEnd(session handoff.Session, storeLatest time.Time) bool {}// shareSessionEnd reports whether events, in order, end with session.ended followed by nothing but-// Beacon's bookkeeping (session.shared, session.share_requested, session.commit_linked), and the-// newest timestamp among the activity it considered (the end's, when it ended).+// Beacon's bookkeeping (asymptoteobserve.IsBeaconOnlyAction), and the newest timestamp among the+// activity it considered (the end's, when it ended).func shareSessionEnd(events []schema.Event) (bool, time.Time) {ended := falsevar latest time.Timefor _, e := range events {- switch e.Event.Action {- case SessionSharedAction, shareauto.ActionShareRequested, gitlink.LinkAction:+ if asymptoteobserve.IsBeaconOnlyAction(e.Event.Action) {continue}ended = e.Event.Action == "session.ended"diff --git a/cli/beacon/cmd/share_follow_test.go b/cli/beacon/cmd/share_follow_test.goindex a1df059f..f79c964d 100644--- a/cli/beacon/cmd/share_follow_test.go+++ b/cli/beacon/cmd/share_follow_test.go@@ -174,7 +174,7 @@ func shareEventsIn(t *testing.T, logPath string) []schema.Event {var out []schema.Eventfor _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {var e schema.Event- if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == SessionSharedAction {+ if json.Unmarshal([]byte(line), &e) == nil && e.Event.Action == asymptoteobserve.ActionSessionShared {out = append(out, e)}}diff --git a/cli/beacon/cmd/share_test.go b/cli/beacon/cmd/share_test.goindex c12158b5..490b9a07 100644--- a/cli/beacon/cmd/share_test.go+++ b/cli/beacon/cmd/share_test.go@@ -386,7 +386,7 @@ func TestShareUploadsAndRecordsTheShareLocally(t *testing.T) {if err := json.Unmarshal(bytes.TrimSpace(data), &event); err != nil {t.Fatal(err)}- if event.Event.Action != SessionSharedAction || event.Event.Fidelity != asymptoteobserve.FidelityInferred || event.Harness.CollectionMethod != "" || event.Session.ID != shareTestSession {+ if event.Event.Action != asymptoteobserve.ActionSessionShared || event.Event.Fidelity != asymptoteobserve.FidelityInferred || event.Harness.CollectionMethod != "" || event.Session.ID != shareTestSession {t.Fatalf("session.shared event = %+v", event)}diff --git a/cli/beacon/internal/gitlink/budget.go b/cli/beacon/internal/gitlink/budget.goindex 8842f5ff..52ba5c29 100644--- a/cli/beacon/internal/gitlink/budget.go+++ b/cli/beacon/internal/gitlink/budget.go@@ -16,11 +16,6 @@ import ("github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")-// BudgetAction is the event action recorded in the runtime log when one of Beacon's git hooks runs-// out of its time budget. The hooks give up quietly when that happens (a post-commit hook that runs-// out leaves the commit unlinked), so the event is the only record of it.-const BudgetAction = "git.hook_budget_exceeded"-type spawnCounterKey struct{}// countSpawn adds one to the git spawn counter ctx carries, when it carries one.@@ -136,7 +131,7 @@ func (r *HookRun) Event(repoRoot, agentVersion string) (schema.Event, bool) {outcome = "its work was cut short"}event := schema.NewEvent(schema.NewEventOptions{- Action: BudgetAction,+ Action: asymptoteobserve.ActionGitHookBudgetExceeded,Category: "system",Severity: severity,AgentVersion: agentVersion,@@ -192,13 +187,13 @@ func scanBudgetOverrunFile(path, repoRoot string, since time.Time, summary *Budgreturn}defer f.Close()- marker := []byte(`"` + BudgetAction + `"`)+ marker := []byte(`"` + asymptoteobserve.ActionGitHookBudgetExceeded + `"`)reader := bufio.NewReaderSize(f, 256*1024)for {line, err := reader.ReadBytes('\n')if len(line) > 0 && bytes.Contains(line, marker) {var event schema.Event- if json.Unmarshal(line, &event) == nil && event.Event.Action == BudgetAction && event.VCS != nil && event.VCS.Hook != nil &&+ if json.Unmarshal(line, &event) == nil && event.Event.Action == asymptoteobserve.ActionGitHookBudgetExceeded && event.VCS != nil && event.VCS.Hook != nil &&(repoRoot == "" || event.Repository == repoRoot) {if at, perr := asymptoteobserve.ParseTimestamp(event.Timestamp); perr == nil && !at.Before(since) {summary.Count++diff --git a/cli/beacon/internal/gitlink/budget_test.go b/cli/beacon/internal/gitlink/budget_test.goindex 67cddb7b..99c5289d 100644--- a/cli/beacon/internal/gitlink/budget_test.go+++ b/cli/beacon/internal/gitlink/budget_test.go@@ -177,7 +177,7 @@ func TestHookRunEvent(t *testing.T) {if err := event.Validate(); err != nil {t.Fatalf("event does not validate: %v", err)}- if event.Event.Action != BudgetAction || event.Event.Category != "system" || event.Event.Kind != "beacon_system" ||+ if event.Event.Action != asymptoteobserve.ActionGitHookBudgetExceeded || event.Event.Category != "system" || event.Event.Kind != "beacon_system" ||event.Event.Fidelity != asymptoteobserve.FidelityObserved || event.Harness.Name != "beacon" ||event.Severity != schema.SeverityLow || event.Repository != "/work/repo" || event.Endpoint.AgentVersion != "1.2.3" {t.Fatalf("event %+v", event)@@ -253,9 +253,9 @@ func TestScanBudgetOverruns(t *testing.T) {if err != nil {t.Fatal(err)}- link := schema.NewEvent(schema.NewEventOptions{Action: LinkAction, Harness: schema.HarnessInfo{Name: "cursor"}, Message: BudgetAction})+ link := schema.NewEvent(schema.NewEventOptions{Action: asymptoteobserve.ActionCommitLinked, Harness: schema.HarnessInfo{Name: "cursor"}, Message: asymptoteobserve.ActionGitHookBudgetExceeded})linkLine, _ := json.Marshal(link)- _, _ = f.Write([]byte(`not json "` + BudgetAction + `"` + "\n" + string(linkLine) + "\n"))+ _, _ = f.Write([]byte(`not json "` + asymptoteobserve.ActionGitHookBudgetExceeded + `"` + "\n" + string(linkLine) + "\n"))f.Close()all := ScanBudgetOverruns(logPath, "", since)diff --git a/cli/beacon/internal/gitlink/events.go b/cli/beacon/internal/gitlink/events.goindex 8d20d9b6..e3652519 100644--- a/cli/beacon/internal/gitlink/events.go+++ b/cli/beacon/internal/gitlink/events.go@@ -10,9 +10,6 @@ import ("github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")-// LinkAction is the event action recorded in the runtime log when a commit is linked to a session.-const LinkAction = "session.commit_linked"-// AttributionFileOverlap is the only attribution method today: the session wrote files the commit// changes.const AttributionFileOverlap = "file_overlap"@@ -97,7 +94,7 @@ func LinkEvents(result Result, cc CommitContext, agentVersion string) []schema.Efor _, link := range result.Added {c := candidates[link.Key()]event := schema.NewEvent(schema.NewEventOptions{- Action: LinkAction,+ Action: asymptoteobserve.ActionCommitLinked,Category: "session",Severity: schema.SeverityInfo,AgentVersion: agentVersion,diff --git a/cli/beacon/internal/gitlink/events_test.go b/cli/beacon/internal/gitlink/events_test.goindex d8f8638f..954b5713 100644--- a/cli/beacon/internal/gitlink/events_test.go+++ b/cli/beacon/internal/gitlink/events_test.go@@ -10,6 +10,7 @@ import ("time""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")func TestSanitizeRemoteURL(t *testing.T) {@@ -57,7 +58,7 @@ func TestLinkEventsShape(t *testing.T) {if err := e.Validate(); err != nil {t.Fatal(err)}- if e.Event.Action != LinkAction || e.Event.Fidelity != "inferred" || e.Harness.Name != "claude_code" || e.Harness.CollectionMethod != "" {+ if e.Event.Action != asymptoteobserve.ActionCommitLinked || e.Event.Fidelity != "inferred" || e.Harness.Name != "claude_code" || e.Harness.CollectionMethod != "" {t.Fatalf("event info %+v harness %+v", e.Event, e.Harness)}if e.Session == nil || e.Session.ID != "s1" || e.Session.WorkingDirectory != "/work/repo" || e.Repository != "/work/repo" || e.Branch != "main" {diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex 48daad1f..7859552f 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -313,6 +313,18 @@ func shouldDropCopilotMetric(resourceAttrs map[string]interface{}, name string,return true}+// statedAction is the first action the attributes state, unless it is one only Beacon itself+// writes (asymptoteobserve.IsBeaconOnlyAction). Anything that can reach the loopback OTLP+// receiver can state an action, so one of those arriving over OTLP is not believed and the action+// is inferred as if none were stated.+func statedAction(attrs map[string]interface{}, keys ...string) string {+ action := FirstString(attrs, keys...)+ if asymptoteobserve.IsBeaconOnlyAction(action) {+ return ""+ }+ return action+}+func (c Converter) EventFromLog(resourceAttrs map[string]interface{}, record plog.LogRecord) Event {event, _, _ := c.eventFromLog(resourceAttrs, record)return event@@ -329,7 +341,7 @@ func (c Converter) eventFromLog(resourceAttrs map[string]interface{}, record plots := Timestamp(record.Timestamp().AsTime())// An action the record states outright is observed by definition; only the fallback has to// account for how it got there.- action := FirstString(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action")+ action := statedAction(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action")fidelity := asymptoteobserve.FidelityObservedif action == "" {action, fidelity = InferActionWithFidelity(attrs, body)@@ -362,7 +374,7 @@ func (c Converter) eventFromLog(resourceAttrs map[string]interface{}, record plofunc (c Converter) EventFromSpan(resourceAttrs map[string]interface{}, span ptrace.Span) Event {attrs := MergeMaps(resourceAttrs, AttrsToMap(span.Attributes()))codexTurnUsage := IsCodexTurnUsageSpan(attrs, span.Name())- action := FirstString(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action")+ action := statedAction(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action")fidelity := asymptoteobserve.FidelityObservedif action == "" {action, fidelity = InferActionWithFidelity(attrs, span.Name())@@ -620,7 +632,7 @@ func (c Converter) NormalizeClaudeLogEvent(event *Event, attrs map[string]interfnormalizeClaudeCoworkContext(event, attrs)originalAction := event.Event.ActionoriginalCategory := event.Event.Category- preserveAction := FirstString(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action") != ""+ preserveAction := statedAction(attrs, "beacon.event.action", "event.action", "gen_ai.agent.action", "ai.agent.action") != ""preserveCategory := preserveAction || FirstString(attrs, "beacon.event.category", "event.category", "category") != ""originalFidelity := event.Event.Fidelity@@ -876,7 +888,7 @@ func JSONMapAttr(attrs map[string]interface{}, key string) map[string]interface{func (c Converter) EventFromMetric(resourceAttrs map[string]interface{}, metric pmetric.Metric) Event {attrs := MergeMaps(resourceAttrs, map[string]interface{}{})- action := FirstString(attrs, "beacon.event.action", "event.action")+ action := statedAction(attrs, "beacon.event.action", "event.action")if action == "" {action = "metric.observed"}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/reserved_action_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/reserved_action_test.gonew file mode 100644index 00000000..1f0c9b59--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/reserved_action_test.go@@ -0,0 +1,53 @@+package beaconevent++import (+ "testing"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"+ "go.opentelemetry.io/collector/pdata/plog"+ "go.opentelemetry.io/collector/pdata/ptrace"+)++// Anything that reaches the loopback OTLP receiver can state an action, so the actions only Beacon+// itself writes (a share record, an auto-share request Beacon Cloud publishes on, a commit link, a+// git hook overrun) must not be taken from OTLP attributes.+func TestOTLPCannotStateBeaconOnlyActions(t *testing.T) {+ for _, action := range []string{+ asymptoteobserve.ActionSessionShared, asymptoteobserve.ActionShareRequested, "Session.Share_Requested",+ asymptoteobserve.ActionCommitLinked, asymptoteobserve.ActionGitHookBudgetExceeded,+ } {+ for _, key := range []string{"beacon.event.action", "event.action", "gen_ai.agent.action"} {+ logs := plog.NewLogs()+ record := logs.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()+ record.Body().SetStr("forged")+ record.Attributes().PutStr(key, action)+ record.Attributes().PutStr("session.id", "s1")+ for _, event := range NewConverter(Options{}).EventsFromLogs(logs) {+ if asymptoteobserve.IsBeaconOnlyAction(event.Event.Action) {+ t.Fatalf("log %s=%q produced action %q", key, action, event.Event.Action)+ }+ }++ traces := ptrace.NewTraces()+ span := traces.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()+ span.SetName("forged")+ span.Attributes().PutStr(key, action)+ for _, event := range NewConverter(Options{}).EventsFromTraces(traces) {+ if asymptoteobserve.IsBeaconOnlyAction(event.Event.Action) {+ t.Fatalf("span %s=%q produced action %q", key, action, event.Event.Action)+ }+ }+ }+ }+}++func TestOTLPStillStatesOrdinaryActions(t *testing.T) {+ logs := plog.NewLogs()+ record := logs.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()+ record.Body().SetStr("ran")+ record.Attributes().PutStr("beacon.event.action", "command.executed")+ events := NewConverter(Options{}).EventsFromLogs(logs)+ if len(events) != 1 || events[0].Event.Action != "command.executed" {+ t.Fatalf("events = %#v, want command.executed", events)+ }+}diff --git a/pkg/asymptoteobserve/beacon_actions.go b/pkg/asymptoteobserve/beacon_actions.gonew file mode 100644index 00000000..d7c174ef--- /dev/null+++ b/pkg/asymptoteobserve/beacon_actions.go@@ -0,0 +1,29 @@+package asymptoteobserve++import "strings"++// Actions only Beacon itself writes to the runtime log: its bookkeeping about a session or a+// repository rather than anything a runtime did.+const (+ // ActionSessionShared records that a session was shared or a share refreshed.+ ActionSessionShared = "session.shared"+ // ActionShareRequested is the event the hook adapter writes once per session when auto-share+ // applies to it. Beacon Cloud publishes a trace on it.+ ActionShareRequested = "session.share_requested"+ // ActionCommitLinked records that a commit was linked to a session.+ ActionCommitLinked = "session.commit_linked"+ // ActionGitHookBudgetExceeded records that one of Beacon's git hooks ran out of its time budget.+ ActionGitHookBudgetExceeded = "git.hook_budget_exceeded"+)++// IsBeaconOnlyAction reports whether action is one only Beacon itself writes. Telemetry that+// arrives from outside -- anything that can reach the loopback OTLP receiver -- must not be+// believed when it states one, and a session's own activity is told apart from Beacon's+// bookkeeping about it with the same test.+func IsBeaconOnlyAction(action string) bool {+ switch strings.ToLower(strings.TrimSpace(action)) {+ case ActionSessionShared, ActionShareRequested, ActionCommitLinked, ActionGitHookBudgetExceeded:+ return true+ }+ return false+}diff --git a/pkg/asymptoteobserve/shareauto/shareauto.go b/pkg/asymptoteobserve/shareauto/shareauto.goindex 3c151705..f4c9c92c 100644--- a/pkg/asymptoteobserve/shareauto/shareauto.go+++ b/pkg/asymptoteobserve/shareauto/shareauto.go@@ -36,10 +36,6 @@ const (// SchemaVersion is written into both files.SchemaVersion = "beacon.share_settings.v1"- // ActionShareRequested is the event the hook adapter writes once per session when auto-share- // applies to it.- ActionShareRequested = "session.share_requested"-// maxWalk bounds how many directories are searched above a working directory for a project.maxWalk = 64)