Skip to content

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

Leave Claude Cowork spans and metrics unattributed under peer attribution too

Claude870efcc00465
diff --git a/CLAUDE.md b/CLAUDE.md
index e4cfafd0..524c8632 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -59,7 +59,7 @@ Supported runtime surfaces today:
- DeepSeek Harness (`dsh`) is installed through two user-level files: `$DSH_HOME/beacon-endpoint-hooks.json` and a row in `$DSH_HOME/cordis.patch.yml`; there is no project scope. The `@deepseek-ai/dsh-hooks-claude-code` bridge that row mounts is not shipped with the CLI (dev dependency only) and must be installed per profile with `@deepseek-ai/dsh-hook-protocol` at exactly the dsh version; a mount dsh cannot load is skipped at boot with only a warning. So `InstallDsh` first runs `hooks.InspectDshBridge` (`internal/endpoint/hooks/dsh_bridge.go`, read-only: the installation found from the `dsh` launcher on PATH, each `$DSH_HOME/profiles/*` resolved Node-style, and rows in any patch layer that mount a bridge by absolute path at Beacon's hooks file) and returns `*DshBridgeUnavailableError` without writing anything when nothing loads a matching bridge; explicit `--harness dsh` fails, `--all` and endpoint install skip with a warning. A healthy by-path mount (how Nix installs it; it must also resolve its declared dsh peers from its own location, because dsh's host-package interception applies only to profile plugins, else `peers_missing`) counts as installed and Beacon writes no row of its own (removing one it wrote earlier) so hooks never run twice. Beacon never installs the packages. `DshStatus.Active`/`Bridge`, discovery (misconfigured when inactive), doctor `dsh_hook_bridge`, and inventory (each profile's patch layer) surface it; tests build on-disk fixtures with `internal/endpoint/hooks/dshtest`. It also installs a Beacon-owned local skill at `$DSH_HOME/skills/beacon-endpoint/SKILL.md` and supports native session backfill from `$DSH_HOME/sessions` through `beacon endpoint dsh sync`, which fills assistant text/reasoning, tool failures, and token usage that the hook bridge does not expose. It rides the Claude-shaped envelope on the hook path, but `run_code` remains `tool.invoked` because nested commands fire their own hooks.
- fx (vercel-labs/fx) telemetry read from the session store fx commits under `~/.fx/sessions/`, covering session start, prompts, tool calls, commands with exit codes and output, file reads/creates/edits with diffs, MCP tool calls, agent messages, history compaction, and per-turn token usage plus reported cost. fx exposes no third-party hook, plugin, or OTLP surface -- its lifecycle hooks are compiled into the binary -- so collection is a read of fx's own records, run by `beacon endpoint fx sync`. Every event carries `harness.collection_method=poll`; approvals are not synthesized (fx persists permission feedback text, not a per-call decision, matching the Cline and Pi posture) and no session-end event is invented, since fx sessions are resumable. Implementation lives in `cli/beacon/internal/fxsession` and `cli/beacon/cmd/endpoint_fx.go`.
- Harness² (google-research/harness2) rollouts, read from the executor event streams Harness² records under its runs directory (`$HARNESS2_RUNS_DIR`, `~/harness2/runs`, or a `--runs-dir` an earlier sync was given and the cursor file remembers): OpenCode `run --format json` and Codex `exec --json`, recognized by their first event rather than by file name. Harness² runs Codex under its own `CODEX_HOME` with `--ephemeral` and OpenCode from a source checkout, so Beacon's Codex/OpenCode integrations do not record these sessions. Events carry `harness.name=harness2`, `harness.collection_method=poll`, the executor's own session id, and the rollout's benchmark/task/label/run/trial/attempt/harness fingerprint under `raw.harness2`. Codex `turn.completed` usage is the thread's running total and is differenced per turn; Codex exec lines carry no times, so they take the file's mtime. No prompts (an argv argument, absent from both streams) and no approvals are recorded or synthesized. `testdata/recorded` holds streams recorded from the exact OpenCode and Codex releases Harness² pins; re-record them when it bumps either. Implementation lives in `cli/beacon/internal/harness2session` and `cli/beacon/cmd/endpoint_harness2.go`.
-- Attribution of OTLP events: every account on a machine exports to the same loopback collector, and the exporter's base `user` is the collector process's own account (`asymptoteobserve.NewEvent` reads `$USER`/`$USERNAME`). On Linux the collector replaces it with the account that owns the sending socket (peer attribution): `collector.ConfigYAML` renders, only where `collector.PeerAttribution` (`runtime.GOOS == "linux"`), the `beacon_otlp_http` receiver (`collector-builder/exporter/beaconjsonexporter/otlphttpreceiver`, the upstream OTLP/HTTP protocol rebuilt on confighttp so `client.Info.Addr` keeps the client port that upstream drops; it replaces `otlp.protocols.http` on the same port) and the `beacon_peer` processor (`peerprocessor`, right after `memory_limiter` and before `batch`, which loses the connection) on Beacon's own pipelines, never the OTLP forward's, plus `peer_user: true` on beaconjson. `beacon_peer` removes `beacon.peer.uid`/`beacon.peer.user` wherever a sender put them (resource, scope, record, span, span event and link, every datapoint type), then asks `internal/peercred` for the owner of the client socket of exactly this connection: the client address from `client.Info.Addr` and the collector's end from the gRPC peer's `LocalAddr` or net/http's `LocalAddrContextKey` (no server address, no lookup). `peercred` first asks the kernel with one `NETLINK_SOCK_DIAG` exact four-tuple lookup (`diag_linux.go`, constant cost per export) and scans `/proc/net/tcp{,6}` for the same four-tuple when sock_diag itself is unavailable or, until sock_diag has once answered with a socket, when it says ENOENT (the kernel says that for a missing `tcp_diag` handler too; a socket `/proc` finds then marks sock_diag blind for good); inode 0 (TIME_WAIT/orphan, uid printed 0), no match, or two owners are unknown, never guessed, and an unrelated TIME_WAIT on the same port is skipped. The name comes from `internal/accountname` (shared with `beacon_ingest`). The converter reads the peer attributes from the resource only (`mergeSignalAttrs`), and `applyPeerUser` copies them into `user` only with `Options.PeerUser`, and with it `normalizeClaudeCoworkContext` empties `user` for `claude_cowork` (Cowork reaches a Linux collector only through a relay such as `beacon endpoint cowork --ngrok`, so the kernel names the relay's account, and the cloud identity is the sender's own claim; both stay in raw attributes; without `PeerUser` the cloud identity still replaces the collector's account); the `falcon_hec` exporter gets `peer_user: true` too, so LogScale matches the log; with `PeerUser` an unidentified sender gets an empty `user`, never the collector's root, so a recorded root always means root sent it. `CheckComponentsFor` refuses a collector without both where they are rendered. macOS and Windows have no lookup and keep the collector's account (root, or `COMPUTERNAME$` under LocalSystem). Hook and plugin events carry the person's uid or SID from `os/user.Current()` (verified by the OS in restricted mode). The person is also on the session's hook and plugin events, joined by `session.id`; the Sentinel guide carries the KQL. Never describe OTLP events on macOS or Windows as carrying the person who ran the agent.
+- Attribution of OTLP events: every account on a machine exports to the same loopback collector, and the exporter's base `user` is the collector process's own account (`asymptoteobserve.NewEvent` reads `$USER`/`$USERNAME`). On Linux the collector replaces it with the account that owns the sending socket (peer attribution): `collector.ConfigYAML` renders, only where `collector.PeerAttribution` (`runtime.GOOS == "linux"`), the `beacon_otlp_http` receiver (`collector-builder/exporter/beaconjsonexporter/otlphttpreceiver`, the upstream OTLP/HTTP protocol rebuilt on confighttp so `client.Info.Addr` keeps the client port that upstream drops; it replaces `otlp.protocols.http` on the same port) and the `beacon_peer` processor (`peerprocessor`, right after `memory_limiter` and before `batch`, which loses the connection) on Beacon's own pipelines, never the OTLP forward's, plus `peer_user: true` on beaconjson. `beacon_peer` removes `beacon.peer.uid`/`beacon.peer.user` wherever a sender put them (resource, scope, record, span, span event and link, every datapoint type), then asks `internal/peercred` for the owner of the client socket of exactly this connection: the client address from `client.Info.Addr` and the collector's end from the gRPC peer's `LocalAddr` or net/http's `LocalAddrContextKey` (no server address, no lookup). `peercred` first asks the kernel with one `NETLINK_SOCK_DIAG` exact four-tuple lookup (`diag_linux.go`, constant cost per export) and scans `/proc/net/tcp{,6}` for the same four-tuple when sock_diag itself is unavailable or, until sock_diag has once answered with a socket, when it says ENOENT (the kernel says that for a missing `tcp_diag` handler too; a socket `/proc` finds then marks sock_diag blind for good); inode 0 (TIME_WAIT/orphan, uid printed 0), no match, or two owners are unknown, never guessed, and an unrelated TIME_WAIT on the same port is skipped. The name comes from `internal/accountname` (shared with `beacon_ingest`). The converter reads the peer attributes from the resource only (`mergeSignalAttrs`), and `applyPeerUser` copies them into `user` only with `Options.PeerUser`, and with it every `claude_cowork` event, log, span or datapoint, has an empty `user` (`applyPeerUser`, which every signal passes through, and `normalizeClaudeCoworkContext` for logs; Cowork reaches a Linux collector only through a relay such as `beacon endpoint cowork --ngrok`, so the kernel names the relay's account, and the cloud identity is the sender's own claim; both stay in raw attributes; without `PeerUser` the cloud identity still replaces the collector's account); the `falcon_hec` exporter gets `peer_user: true` too, so LogScale matches the log; with `PeerUser` an unidentified sender gets an empty `user`, never the collector's root, so a recorded root always means root sent it. `CheckComponentsFor` refuses a collector without both where they are rendered. macOS and Windows have no lookup and keep the collector's account (root, or `COMPUTERNAME$` under LocalSystem). Hook and plugin events carry the person's uid or SID from `os/user.Current()` (verified by the OS in restricted mode). The person is also on the session's hook and plugin events, joined by `session.id`; the Sentinel guide carries the KQL. Never describe OTLP events on macOS or Windows as carrying the person who ran the agent.
- Claude Cowork admin-configured OpenTelemetry setup guidance and local validation.
- OpenClaw Gateway uses a Beacon-managed plugin directory plus OpenClaw's own diagnostics OTLP guidance (`beacon endpoint integrations openclaw`). The plugin's `before_tool_call` hook is fail-closed, so the handler dispatches synchronously and returns without awaiting. Conversation hooks, including `llm_output`, require `plugins.entries.beacon-endpoint.hooks.allowConversationAccess`; without it, token and agent-message coverage is partial. Beacon reads OpenClaw JSON/JSON5 config for advice but does not rewrite it.
- GitHub Copilot CLI uses MDM/customer-managed OTLP HTTP for live spans and approval-like activity, plus `beacon endpoint copilot sync` to backfill local session records from `~/.copilot/session-state`. Poll events carry assistant text, complete tool results, command/file details, and token usage with `harness.collection_method=poll`, plus the shutdown's session-wide `totalNanoAiu` differenced into `gen_ai.usage.cost_usd` once per shutdown (10^9 nano-AIU = one AI credit = US$0.01), only for sessions started on or after the 2026-06-01 AI-credit cutover (`cli/beacon/internal/copilotsession/cost.go`); approvals still come only from the live OTLP path and are not synthesized from persisted records.
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
index ed8bbaa7..cd922f86 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
@@ -2376,8 +2376,8 @@ func EventCategory(action, explicit string) string {
// beacon_peer processor resolves the sender from the kernel; this only copies what it found, and
// changes nothing when it found nobody, so an unattributed event is the collector's account as it
// always was rather than someone's guess. With it on, nothing a sender reports replaces the kernel's
-// answer; a Claude Cowork event, which arrives through a relay, gets no user instead (see
-// normalizeClaudeCoworkContext).
+// answer; a Claude Cowork event of any signal, which arrives through a relay, gets no user instead
+// (see normalizeClaudeCoworkContext).
func (c Converter) applyPeerUser(event *Event, attrs map[string]interface{}) {
if !c.opts.PeerUser {
return
@@ -2387,7 +2387,10 @@ func (c Converter) applyPeerUser(event *Event, attrs map[string]interface{}) {
// otherwise be recorded exactly like root's own, kernel-attributed exports. An event whose sender
// could not be identified carries no user at all.
uid := FirstString(attrs, PeerUIDAttribute)
- if uid == "" {
+ // Claude Cowork reaches the collector only through a relay (see normalizeClaudeCoworkContext),
+ // so the kernel's answer is the relay's account, not the person. That holds for every signal,
+ // including the spans and metric datapoints that never pass through the log normalizer.
+ if uid == "" || event.Harness.Name == "claude_cowork" {
event.User = UserInfo{}
return
}
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go
index 6f549fae..da0fb4e9 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/peer_user_test.go
@@ -172,3 +172,54 @@ func TestAnUnidentifiedSenderCarriesNoUser(t *testing.T) {
t.Fatalf("user = %+v, want none", event.User)
}
}
+
+// The same holds for Claude Cowork's spans and metric datapoints, which never pass through the log
+// normalizer: the relay's account must not become the person on any signal.
+func TestCoworkSpansAndMetricsHaveNoUserUnderThePeer(t *testing.T) {
+ t.Setenv("USER", "root")
+ conv := NewConverter(Options{PeerUser: true})
+ resource := map[string]interface{}{
+ "service.name": "claude-cowork",
+ PeerUIDAttribute: "1001",
+ PeerUserAttribute: "alice",
+ }
+
+ span := ptrace.NewSpan()
+ span.SetName("tool")
+ span.Attributes().PutStr("user.email", "root")
+ event := conv.EventFromSpan(resource, span)
+ if event.Harness.Name != "claude_cowork" {
+ t.Fatalf("span fixture did not resolve to claude_cowork (%q)", event.Harness.Name)
+ }
+ if event.User != (UserInfo{}) {
+ t.Fatalf("span user = %+v, want none: the kernel named the relay, not the person", event.User)
+ }
+
+ metrics := pmetric.NewMetrics()
+ rm := metrics.ResourceMetrics().AppendEmpty()
+ for k, v := range resource {
+ rm.Resource().Attributes().PutStr(k, v.(string))
+ }
+ sum := rm.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
+ sum.SetName("claude_code.token.usage")
+ dp := sum.SetEmptySum().DataPoints().AppendEmpty()
+ dp.SetIntValue(10)
+ dp.Attributes().PutStr("type", "input")
+ events := conv.EventsFromMetrics(metrics)
+ if len(events) == 0 {
+ t.Fatal("no events from the Cowork token usage metric")
+ }
+ for _, e := range events {
+ if e.Harness.Name != "claude_cowork" {
+ t.Fatalf("metric fixture did not resolve to claude_cowork (%q)", e.Harness.Name)
+ }
+ if e.User != (UserInfo{}) {
+ t.Fatalf("metric user = %+v, want none: the kernel named the relay, not the person", e.User)
+ }
+ }
+
+ // Without the processor (macOS, Windows) nothing changes for these signals.
+ if got := NewConverter(Options{}).EventFromSpan(resource, span).User; got == (UserInfo{}) {
+ t.Fatal("span user empty without peer_user; want the collector's account as before")
+ }
+}