Skip to content

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

fix(lenses): trace events carry the error type, so the MCP lens marks session-store failures

Claude5c580b4c5cb9
diff --git a/agent-skills/skills/beacon-lens-create/SKILL.md b/agent-skills/skills/beacon-lens-create/SKILL.md
index 66a880a8..7d2fe929 100644
--- a/agent-skills/skills/beacon-lens-create/SKILL.md
+++ b/agent-skills/skills/beacon-lens-create/SKILL.md
@@ -93,7 +93,8 @@ The result is `LensDataV1`; `beacon lenses spec` has the full shape. The parts y
`repository`, `model`, `token_usage`.
- `trace.events[]`, in order, each with `id`, `number`, `timestamp`, `type`, `action` and
optional `title`, `summary`, `fidelity`, `content`, `tool`, `command`, `file`, `mcp`,
- `approval`, `model`, `usage`, `tool_call_id`. `type` is one of `user_message`,
+ `approval`, `policy`, `error`, `model`, `usage`, `tool_call_id`. `error.type` is set when the
+ runtime reported the action as failed, even on an event whose `type` is not `error`. `type` is one of `user_message`,
`agent_message`, `agent_reasoning`, `tool_call`, `tool_result`, `command`, `file`, `mcp`,
`approval`, `token_usage`, `session`, `error`, `other`, and the list can grow.
- `findings`: threat-rule matches, each pointing at its evidence by `event_ids`.
diff --git a/cli/beacon/internal/endpoint/dashboard/history_store.go b/cli/beacon/internal/endpoint/dashboard/history_store.go
index 2e7b4bd5..ce798fe9 100644
--- a/cli/beacon/internal/endpoint/dashboard/history_store.go
+++ b/cli/beacon/internal/endpoint/dashboard/history_store.go
@@ -41,7 +41,7 @@ const (
// historyDerivationVersion covers everything computed from a stored line: trace keys, event
// numbers, types, summaries and search text. Bump it when that projection changes; the next
// catch-up recomputes it from the stored lines, so history survives the change.
- historyDerivationVersion = 2 // 2: trace events carry the event's policy block
+ historyDerivationVersion = 3 // 2: trace events carry the event's policy block; 3: and its error
defaultHistoryRetentionDays = 90
// maxHistoryRetentionDays is 100 years: a retention this long or longer means nothing expires.
diff --git a/cli/beacon/internal/endpoint/dashboard/history_test.go b/cli/beacon/internal/endpoint/dashboard/history_test.go
index e9d50dd9..bb26e9f2 100644
--- a/cli/beacon/internal/endpoint/dashboard/history_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/history_test.go
@@ -175,7 +175,7 @@ func parityFixture() [][]byte {
`{"timestamp":"2026-06-11T10:01:30Z","event":{"id":"e3","action":"command.executed","category":"command"},"harness":{"name":"cursor","collection_method":"otlp"},"session":{"id":"s1"},"command":{"command":"go test ./internal/endpoint/dashboard","exit_code":0}}`,
`{"timestamp":"2026-06-11T10:02:00Z","event":{"id":"e4","action":"file.modified","category":"file"},"harness":{"name":"cursor"},"session":{"id":"s1"},"file":{"path":"internal/endpoint/dashboard/traces.go","operation":"modify","language":"go","diff":"+ matchesAllTerms","diff_hash":"dh"}}`,
`{"timestamp":"2026-06-11T10:02:30Z","event":{"id":"e5","action":"approval.denied","category":"approval"},"harness":{"name":"cursor"},"session":{"id":"s1"},"approval":{"required":true,"decision":"denied","reason":"AND NEAR * not allowed"},"policy":{"id":"no-near","decision":"deny","enforcement":"enforce","reason":"provider denied"}}`,
- `{"timestamp":"2026-06-11T10:03:00Z","event":{"id":"e6","action":"mcp.tool_invoked","category":"mcp"},"harness":{"name":"cursor"},"session":{"id":"s1"},"mcp":{"server":"beacon","tool":"search_sessions","method":{"name":"tools/call"}},"gen_ai":{"tool":{"name":"mcp__beacon__search_sessions","call":{"id":"call-1","arguments":{"query":"index"},"result":"one session"}}}}`,
+ `{"timestamp":"2026-06-11T10:03:00Z","event":{"id":"e6","action":"mcp.tool_invoked","category":"mcp"},"harness":{"name":"cursor"},"session":{"id":"s1"},"mcp":{"server":"beacon","tool":"search_sessions","method":{"name":"tools/call"}},"gen_ai":{"tool":{"name":"mcp__beacon__search_sessions","call":{"id":"call-1","arguments":{"query":"index"},"result":"one session"}}},"error":{"type":"mcp_timeout"}}`,
`{"timestamp":"2026-06-11T10:04:00Z","event":{"action":"session.activity","category":"session"},"harness":{"name":"cursor"},"session":{"id":"s1"},"message":"hook with no event id"}`,
`{"timestamp":"2026-06-11T11:00:00Z","event":{"id":"o1","action":"tool.invoked","category":"tool"},"harness":{"name":"claude_code","collection_method":"otlp"},"session":{"id":"s2"},"trace":{"id":"t-abc","span_id":"span-1"},"tool":{"name":"Bash"},"message":"root span","model":"claude-opus-5"}`,
`{"timestamp":"2026-06-11T11:00:01Z","event":{"id":"o2","action":"tool.completed","category":"tool"},"harness":{"name":"claude_code","collection_method":"otlp"},"session":{"id":"s2"},"trace":{"id":"t-abc","span_id":"span-2","parent_span_id":"span-1"},"tool":{"name":"Bash"}}`,
@@ -963,6 +963,34 @@ func TestHistoryRenamesIDlessEventsWhenTheirFileRotates(t *testing.T) {
}
}
+// An event's error is part of the trace projection: a session-store MCP failure keeps its mcp
+// action and records only error.type, so without it no lens could tell the call failed.
+func TestTraceEventsCarryTheErrorType(t *testing.T) {
+ path := newTestLog(t, parityFixture())
+ for name, setup := range map[string]func(){
+ "jsonl": func() { withoutHistory(t) },
+ "history": func() { withHistory(t); optIn(t, path) },
+ } {
+ setup()
+ show, ok, err := ShowTrace(path, "session:cursor:s1", TraceQuery{Limit: 100})
+ if err != nil || !ok {
+ t.Fatalf("%s: ShowTrace = ok %v, err %v", name, ok, err)
+ }
+ for _, event := range show.Events {
+ switch {
+ case event.ID == "e6" && (event.Error == nil || event.Error.Type != "mcp_timeout"):
+ t.Fatalf("%s: e6 error = %#v, want mcp_timeout", name, event.Error)
+ case event.ID != "e6" && event.Error != nil:
+ t.Fatalf("%s: %s error = %#v, want none", name, event.ID, event.Error)
+ }
+ }
+ found, err := SearchTraces(path, TraceQuery{EventQuery: EventQuery{Q: "mcp_timeout"}, ResultLevel: "event", Limit: 10})
+ if err != nil || found.TotalMatched != 1 || found.Events[0].Event.ID != "e6" {
+ t.Fatalf("%s: search for the error type = %+v, %v", name, found, err)
+ }
+ }
+}
+
// The policy block is part of the trace projection, so both the JSONL scan and the history serve it.
func TestTraceEventsCarryThePolicyBlock(t *testing.T) {
path := newTestLog(t, parityFixture())
diff --git a/cli/beacon/internal/endpoint/dashboard/lenses/SPEC.md b/cli/beacon/internal/endpoint/dashboard/lenses/SPEC.md
index 42f7357d..f75ceed5 100644
--- a/cli/beacon/internal/endpoint/dashboard/lenses/SPEC.md
+++ b/cli/beacon/internal/endpoint/dashboard/lenses/SPEC.md
@@ -107,8 +107,10 @@ trace view uses. Its main parts:
- `trace.events[]`, in order. Each event has `id`, `number` (1-based
position), `timestamp`, `type`, `action`, and optional `category`,
`fidelity` (`observed` | `inferred`), `actor`, `title`, `summary`,
- `content`, `tool`, `command`, `file`, `mcp`, `approval`, `model`, `usage`,
- `tool_call_id` and `trace` (span IDs).
+ `content`, `tool`, `command`, `file`, `mcp`, `approval`, `policy`, `error`,
+ `model`, `usage`, `tool_call_id` and `trace` (span IDs). `error.type` is set
+ when the runtime reported the action as failed, which can happen on an event
+ whose `type` is not `error` (a failed MCP call keeps type `mcp`).
- `type` is one of `user_message`, `agent_message`, `agent_reasoning`,
`tool_call`, `tool_result`, `command`, `file`, `mcp`, `approval`,
`token_usage`, `session`, `error` or `other`. The list may grow (see
@@ -247,3 +249,4 @@ The host enforces these rules; a lens does not opt into them.
- `lenses/v1`: initial specification.
- `lenses/v1` (additive): `token_usage`, the counted usage of the trace.
+- `lenses/v1` (additive): `trace.events[].error`, the failure an event recorded.
diff --git a/cli/beacon/internal/endpoint/dashboard/lenses/mcp.lens.html b/cli/beacon/internal/endpoint/dashboard/lenses/mcp.lens.html
index a3567c81..cf07a83e 100644
--- a/cli/beacon/internal/endpoint/dashboard/lenses/mcp.lens.html
+++ b/cli/beacon/internal/endpoint/dashboard/lenses/mcp.lens.html
@@ -103,8 +103,11 @@
};
}
- // A result is a failure when the MCP response says so: isError, an error member, or an error event.
+ // A call failed when the runtime recorded an error on the event (session-store mappers keep the
+ // mcp action and set error), the event is an error, or the MCP result says isError or carries an
+ // error member.
function failed(event) {
+ if (event.error && event.error.type) return true;
if (event.type === "error" || /error|fail/i.test(String(event.action || ""))) return true;
var result = event.tool && event.tool.result;
if (!result || typeof result !== "object") return false;
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
index 64eec332..d94651d7 100644
--- a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
@@ -41,3 +41,4 @@
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "mcpish", "working_directory": "/work/app"}, "timestamp": "2026-06-15T11:00:15Z", "event": {"id": "mc-resource", "kind": "agent_runtime", "action": "mcp.tool_invoked", "category": "mcp"}, "message": "mcp.tool_invoked", "mcp": {"server": "filesystem", "tool": "read_resource", "method": {"name": "resources/read"}, "resource": {"uri": "file:///work/app/README.md"}}, "tool": {"name": "mcp__filesystem__read_resource"}, "gen_ai": {"tool": {"name": "mcp__filesystem__read_resource", "call": {"id": "call-mcp-3", "result": {"contents": [{"uri": "file:///work/app/README.md", "text": "# App"}]}}}}}
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "mcpish", "working_directory": "/work/app"}, "timestamp": "2026-06-15T11:00:20Z", "event": {"id": "mc-bare", "kind": "agent_runtime", "action": "tool.invoked", "category": "tool"}, "message": "tool.invoked", "tool": {"name": "mcp__linear__save_issue"}, "gen_ai": {"tool": {"name": "mcp__linear__save_issue", "call": {"arguments": {"title": "Flaky TestRetry"}}}}}
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "mcpish", "working_directory": "/work/app"}, "timestamp": "2026-06-15T11:00:25Z", "event": {"id": "mc-read", "kind": "agent_runtime", "action": "file.read", "category": "file"}, "message": "file.read", "file": {"path": "/work/app/main.go", "operation": "read"}}
+{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "high", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "mcpish", "working_directory": "/work/app"}, "timestamp": "2026-06-15T11:00:30Z", "event": {"id": "mc-store-fail", "kind": "agent_runtime", "action": "mcp.tool_invoked", "category": "mcp"}, "message": "mcp.tool_invoked", "mcp": {"server": "linear", "tool": "list_teams"}, "tool": {"name": "mcp__linear__list_teams"}, "gen_ai": {"tool": {"name": "mcp__linear__list_teams", "call": {"id": "call-mcp-5", "result": "connection refused"}}}, "error": {"type": "tool_execution_failed"}}
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-mcp.spec.ts b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-mcp.spec.ts
index 29daf5b4..5d998cab 100644
--- a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-mcp.spec.ts
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-mcp.spec.ts
@@ -7,13 +7,15 @@ test('mcp: calls by server and tool, with arguments, results and failures', asyn
// The pre- and post-tool events of create_issue are one call; the bare mcp__linear__ name counts;
// the file read does not.
- await expect(frame.locator('#summary')).toHaveText('4 calls to 4 tools on 3 servers · 1 failed.');
+ await expect(frame.locator('#summary')).toHaveText('5 calls to 5 tools on 3 servers · 2 failed.');
const servers = frame.locator('#list button.row');
await expect(servers).toHaveCount(3);
await expect(servers.nth(0)).toContainText('github');
await expect(servers.nth(0)).toContainText('1 failed');
- await expect(servers.nth(1)).toContainText('filesystem');
- await expect(servers.nth(2)).toContainText('linear');
+ // linear has two calls, one of them a failure recorded only as the event's error.
+ await expect(servers.nth(1)).toContainText('linear');
+ await expect(servers.nth(1)).toContainText('1 failed');
+ await expect(servers.nth(2)).toContainText('filesystem');
const detail = frame.locator('#detail');
await expect(detail.locator('h2').first()).toHaveText('github');
@@ -36,14 +38,18 @@ test('mcp: calls by server and tool, with arguments, results and failures', asyn
await expect(calls.nth(1)).toContainText('failed');
// A resource read shows its method and URI.
- await servers.nth(1).click();
+ await servers.nth(2).click();
await expect(detail.locator('h2').first()).toHaveText('filesystem');
await expect(detail.locator('.call')).toContainText('resources/read');
await expect(detail.locator('.call')).toContainText('file:///work/app/README.md');
- // A call known only by its tool name still lands under its server.
- await servers.nth(2).click();
+ // A call known only by its tool name still lands under its server, and a session-store failure
+ // that kept the mcp action and a string result is marked from its error type.
+ await servers.nth(1).click();
await expect(detail.locator('tbody')).toContainText('save_issue');
+ const failedCall = detail.locator('.call', { hasText: 'list_teams' });
+ await expect(failedCall).toContainText('failed');
+ await expect(detail.locator('.call', { hasText: 'save_issue' })).not.toContainText('failed');
});
test('mcp: a trace without MCP calls says so', async ({ page }) => {
diff --git a/cli/beacon/internal/endpoint/dashboard/traces.go b/cli/beacon/internal/endpoint/dashboard/traces.go
index 084328f9..db517eae 100644
--- a/cli/beacon/internal/endpoint/dashboard/traces.go
+++ b/cli/beacon/internal/endpoint/dashboard/traces.go
@@ -37,6 +37,7 @@ type TraceFileV1 = asymptoteobserve.TraceFileV1
type TraceMCPV1 = asymptoteobserve.TraceMCPV1
type TraceApprovalV1 = asymptoteobserve.TraceApprovalV1
type TracePolicyV1 = asymptoteobserve.TracePolicyV1
+type TraceErrorV1 = asymptoteobserve.TraceErrorV1
type TraceUsageV1 = asymptoteobserve.TraceUsageV1
type TraceSpanV1 = asymptoteobserve.TraceSpanV1
type TraceRangeV1 = asymptoteobserve.TraceRangeV1
@@ -504,6 +505,9 @@ func traceEventFromRecord(record EventRecord, number int) TraceEventV1 {
te.MCP.SessionID = event.MCP.Session.ID
}
}
+ if event.Error != nil && event.Error.Type != "" {
+ te.Error = &TraceErrorV1{Type: event.Error.Type}
+ }
if event.Approval != nil {
te.Approval = &TraceApprovalV1{Required: event.Approval.Required, Decision: event.Approval.Decision, Reason: event.Approval.Reason}
}
@@ -1056,6 +1060,7 @@ func traceEventHaystack(event TraceEventV1) string {
valueOrEmpty(event.Policy, func(p *TracePolicyV1) string {
return p.ID + " " + p.Name + " " + p.Decision + " " + p.Enforcement + " " + p.Reason
}),
+ valueOrEmpty(event.Error, func(e *TraceErrorV1) string { return e.Type }),
}, "\n")
}
diff --git a/pkg/asymptoteobserve/trace.go b/pkg/asymptoteobserve/trace.go
index 35f8c237..29492bfd 100644
--- a/pkg/asymptoteobserve/trace.go
+++ b/pkg/asymptoteobserve/trace.go
@@ -123,6 +123,7 @@ type TraceEventV1 struct {
MCP *TraceMCPV1 `json:"mcp,omitempty"`
Approval *TraceApprovalV1 `json:"approval,omitempty"`
Policy *TracePolicyV1 `json:"policy,omitempty"`
+ Error *TraceErrorV1 `json:"error,omitempty"`
Model string `json:"model,omitempty"`
Usage *TraceUsageV1 `json:"usage,omitempty"`
SourceEventID string `json:"source_event_id"`
@@ -193,6 +194,12 @@ type TracePolicyV1 struct {
Reason string `json:"reason,omitempty"`
}
+// TraceErrorV1 is the failure an event recorded, such as a tool or MCP call that a runtime
+// reported as failed while keeping the call's own action.
+type TraceErrorV1 struct {
+ Type string `json:"type,omitempty"`
+}
+
type TraceUsageV1 struct {
InputTokens int64 `json:"input_tokens,omitempty"`
OutputTokens int64 `json:"output_tokens,omitempty"`
diff --git a/spec/lenses/SPEC.md b/spec/lenses/SPEC.md
index 42f7357d..f75ceed5 100644
--- a/spec/lenses/SPEC.md
+++ b/spec/lenses/SPEC.md
@@ -107,8 +107,10 @@ trace view uses. Its main parts:
- `trace.events[]`, in order. Each event has `id`, `number` (1-based
position), `timestamp`, `type`, `action`, and optional `category`,
`fidelity` (`observed` | `inferred`), `actor`, `title`, `summary`,
- `content`, `tool`, `command`, `file`, `mcp`, `approval`, `model`, `usage`,
- `tool_call_id` and `trace` (span IDs).
+ `content`, `tool`, `command`, `file`, `mcp`, `approval`, `policy`, `error`,
+ `model`, `usage`, `tool_call_id` and `trace` (span IDs). `error.type` is set
+ when the runtime reported the action as failed, which can happen on an event
+ whose `type` is not `error` (a failed MCP call keeps type `mcp`).
- `type` is one of `user_message`, `agent_message`, `agent_reasoning`,
`tool_call`, `tool_result`, `command`, `file`, `mcp`, `approval`,
`token_usage`, `session`, `error` or `other`. The list may grow (see
@@ -247,3 +249,4 @@ The host enforces these rules; a lens does not opt into them.
- `lenses/v1`: initial specification.
- `lenses/v1` (additive): `token_usage`, the counted usage of the trace.
+- `lenses/v1` (additive): `trace.events[].error`, the failure an event recorded.