Skip to content

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

Canonicalize model names at write time, keeping the provider

Claude9aee458c2b0f
diff --git a/cli/beacon-hooks/cmd/cline_event.go b/cli/beacon-hooks/cmd/cline_event.go
index 3eeb3c4c..61fee0f3 100644
--- a/cli/beacon-hooks/cmd/cline_event.go
+++ b/cli/beacon-hooks/cmd/cline_event.go
@@ -263,6 +263,12 @@ func clineTextParts(value interface{}) string {
// Provider-qualified because a bare model id is ambiguous once a runtime can reach the same model
// through more than one provider, and because opencode already writes provider/model -- one shape
// for this field across runtimes is worth more than matching each runtime's own spelling.
+//
+// The composite is the transport, not the stored shape. The logging layer splits it back apart on
+// the way out (see normalizeEventModel), writing the bare id to `model` and the prefix to
+// gen_ai.provider.name. Both facts survive, and they survive in separate fields: packing them
+// into one string is what made a Cline turn and an OTLP turn on the same model two different rows
+// in the BY MODEL rollup, since the OTLP path never built a composite.
func clineModel(input map[string]interface{}) string {
model := getFirstStr(input, "model", "modelId", "model_id")
provider := getFirstStr(input, "apiProvider", "api_provider", "provider", "providerId", "provider_id")
diff --git a/cli/beacon-hooks/cmd/cline_event_test.go b/cli/beacon-hooks/cmd/cline_event_test.go
index b418a230..babf124e 100644
--- a/cli/beacon-hooks/cmd/cline_event_test.go
+++ b/cli/beacon-hooks/cmd/cline_event_test.go
@@ -98,8 +98,14 @@ func TestClineEventTaskStartRecordsSessionAndPrompt(t *testing.T) {
if got := nested(t, event, "prompt")["text"]; got != "ship it token=[REDACTED]" {
t.Errorf("prompt.text = %q, want the redacted prompt", got)
}
- if got := event["model"]; got != "anthropic/claude-sonnet-4" {
- t.Errorf("model = %q, want the provider-qualified model", got)
+ // The mapper builds a provider/model composite; the logging layer splits it back apart so
+ // the bare id groups with the same model reported by an OTLP runtime, and the provider
+ // lands in its own field instead of being packed into a string.
+ if got := event["model"]; got != "claude-sonnet-4" {
+ t.Errorf("model = %q, want the bare canonical model id", got)
+ }
+ if got := nested(t, nested(t, event, "gen_ai"), "provider")["name"]; got != "anthropic" {
+ t.Errorf("gen_ai.provider.name = %q, want the provider the composite carried", got)
}
if got := nested(t, event, "session")["working_directory"]; got != "/tmp/project" {
t.Errorf("session.working_directory = %q, want the workspace root", got)
diff --git a/cli/beacon-hooks/cmd/omp_event_test.go b/cli/beacon-hooks/cmd/omp_event_test.go
index c0003e4d..6c928af1 100644
--- a/cli/beacon-hooks/cmd/omp_event_test.go
+++ b/cli/beacon-hooks/cmd/omp_event_test.go
@@ -377,8 +377,13 @@ func TestOmpEventNormalizesTokenUsage(t *testing.T) {
if _, ok := usage["total_tokens"]; ok {
t.Fatalf("gen_ai.usage carries a total: %v", usage)
}
- if model := event["model"]; model != "anthropic/claude-opus-4" {
- t.Fatalf("model = %v, want the responding model", model)
+ // Provider and model are recorded in separate fields; the mapper's provider/model composite
+ // is split at write time.
+ if model := event["model"]; model != "claude-opus-4" {
+ t.Fatalf("model = %v, want the bare responding model", model)
+ }
+ if got := nested(t, nested(t, event, "gen_ai"), "provider")["name"]; got != "anthropic" {
+ t.Fatalf("gen_ai.provider.name = %v, want the provider the composite carried", got)
}
}
diff --git a/cli/beacon-hooks/cmd/opencode_event_test.go b/cli/beacon-hooks/cmd/opencode_event_test.go
index 3c699add..6085c8a9 100644
--- a/cli/beacon-hooks/cmd/opencode_event_test.go
+++ b/cli/beacon-hooks/cmd/opencode_event_test.go
@@ -42,8 +42,14 @@ func TestOpenCodeEventRecordsPrompt(t *testing.T) {
if got := event["prompt"].(map[string]interface{})["text"]; got != "summarize token=[REDACTED]" {
t.Fatalf("prompt.text = %q, want redacted prompt", got)
}
- if got := event["model"]; got != "anthropic/claude-sonnet-4" {
- t.Fatalf("model = %q, want opencode model", got)
+ // opencode reports provider and model separately and the mapper joins them; the logging
+ // layer splits them back into `model` and gen_ai.provider.name so the bare id groups with
+ // the same model seen on any other runtime.
+ if got := event["model"]; got != "claude-sonnet-4" {
+ t.Fatalf("model = %q, want the bare opencode model id", got)
+ }
+ if got := nested(t, nested(t, event, "gen_ai"), "provider")["name"]; got != "anthropic" {
+ t.Fatalf("gen_ai.provider.name = %q, want the provider opencode reported", got)
}
}
diff --git a/cli/beacon-hooks/internal/logging/endpoint_event_test.go b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
index 0fc1f0cc..6e7faa12 100644
--- a/cli/beacon-hooks/internal/logging/endpoint_event_test.go
+++ b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
@@ -460,3 +460,94 @@ func TestMinimalEndpointEventKeepsProvenance(t *testing.T) {
t.Fatalf("compacted harness.collection_method = %q (present=%v), want hook", method, ok)
}
}
+
+// Model is canonicalized on the way out for the same reason harness.name is: both capture paths
+// write it, `beacon token-usage` groups its BY MODEL rollup on the raw string, and one model
+// reported under two spellings is two rows that no reader can tell apart from two models.
+func TestEndpointEventCanonicalizesModelName(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("post-tool", "test")
+ if err := logger.EndpointEvent("tool.completed", "tool", "info", "done", map[string]interface{}{
+ "model": "Anthropic/Claude-Sonnet-4-5",
+ }); err != nil {
+ t.Fatalf("EndpointEvent returned error: %v", err)
+ }
+
+ events := readEndpointEvents(t, logPath)
+ if len(events) != 1 {
+ t.Fatalf("wrote %d events, want 1", len(events))
+ }
+ if got, _ := events[0]["model"].(string); got != "claude-sonnet-4-5" {
+ t.Fatalf("model = %q, want the canonical spelling", got)
+ }
+}
+
+// The provider prefix that canonicalizing removes is kept rather than dropped: it moves to
+// gen_ai.provider.name, where a provider belongs and stays queryable.
+func TestEndpointEventKeepsTheStrippedProviderPrefix(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("post-tool", "test")
+ if err := logger.EndpointEvent("tool.completed", "tool", "info", "done", map[string]interface{}{
+ "model": "openrouter/anthropic/claude-sonnet-4-5",
+ }); err != nil {
+ t.Fatalf("EndpointEvent returned error: %v", err)
+ }
+
+ events := readEndpointEvents(t, logPath)
+ genAI, _ := events[0]["gen_ai"].(map[string]interface{})
+ provider, _ := genAI["provider"].(map[string]interface{})
+ if got, _ := provider["name"].(string); got != "openrouter/anthropic" {
+ t.Fatalf("gen_ai.provider.name = %q, want the whole stripped prefix", got)
+ }
+}
+
+// A runtime that names its own provider is the better source; a prefix parsed out of a model
+// string must never overwrite it.
+func TestEndpointEventDoesNotOverwriteAReportedProvider(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("post-tool", "test")
+ if err := logger.EndpointEvent("tool.completed", "tool", "info", "done", map[string]interface{}{
+ "model": "anthropic/claude-sonnet-4-5",
+ "gen_ai": map[string]interface{}{
+ "provider": map[string]interface{}{"name": "gateway"},
+ },
+ }); err != nil {
+ t.Fatalf("EndpointEvent returned error: %v", err)
+ }
+
+ events := readEndpointEvents(t, logPath)
+ genAI, _ := events[0]["gen_ai"].(map[string]interface{})
+ provider, _ := genAI["provider"].(map[string]interface{})
+ if got, _ := provider["name"].(string); got != "gateway" {
+ t.Fatalf("gen_ai.provider.name = %q, want the runtime's own reported provider", got)
+ }
+ if got, _ := events[0]["model"].(string); got != "claude-sonnet-4-5" {
+ t.Fatalf("model = %q, want it canonicalized regardless", got)
+ }
+}
+
+// An event with no model must not gain an empty one, and must not gain a gen_ai block it had no
+// reason to have.
+func TestEndpointEventWithoutAModelIsUntouched(t *testing.T) {
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+
+ logger := NewLoggerForPlatform("post-tool", "test")
+ if err := logger.EndpointEvent("command.executed", "command", "info", "ls", nil); err != nil {
+ t.Fatalf("EndpointEvent returned error: %v", err)
+ }
+
+ events := readEndpointEvents(t, logPath)
+ if _, ok := events[0]["model"]; ok {
+ t.Fatal("an event with no model gained one")
+ }
+ if _, ok := events[0]["gen_ai"]; ok {
+ t.Fatal("an event with no model gained a gen_ai block")
+ }
+}
diff --git a/cli/beacon-hooks/internal/logging/logging.go b/cli/beacon-hooks/internal/logging/logging.go
index 8b9bb50e..18a19a12 100644
--- a/cli/beacon-hooks/internal/logging/logging.go
+++ b/cli/beacon-hooks/internal/logging/logging.go
@@ -127,6 +127,7 @@ func (l *Logger) EndpointEventWithFidelity(action, category, severity, message,
}
event[key] = value
}
+ normalizeEventModel(event)
if err := writeEndpointJSON(path, event); err != nil {
fmt.Fprintf(os.Stderr, "logging: failed to write endpoint event to %s: %v\n", path, err)
return err
@@ -134,6 +135,45 @@ func (l *Logger) EndpointEventWithFidelity(action, category, severity, message,
return nil
}
+// normalizeEventModel canonicalizes event["model"] in place, the way the harness name is
+// canonicalized in baseEndpointEvent and for the same reason: every token report groups by this
+// field, so one model reported under two spellings is two rows in the BY MODEL rollup.
+//
+// It runs after the caller's fields are merged rather than inside each mapper because every hook
+// platform sets fields["model"] from its own payload -- Cline reads modelId, OpenCode reads a
+// nested model object, the shared path reads "model" -- and normalizing in one place is what
+// keeps a new mapper from quietly reintroducing the split.
+//
+// The provider prefix that normalizing removes is not dropped: it is recorded as
+// gen_ai.provider.name when the runtime did not already report one, so "anthropic/claude-..."
+// loses nothing by being canonicalized. An existing provider always wins, since the runtime
+// naming its own provider is a better source than a prefix parsed out of a model string.
+func normalizeEventModel(event map[string]interface{}) {
+ raw, ok := event["model"].(string)
+ if !ok || strings.TrimSpace(raw) == "" {
+ return
+ }
+ name, provider := asymptoteobserve.SplitModelProvider(raw)
+ event["model"] = name
+ if provider == "" {
+ return
+ }
+ genAI, _ := event["gen_ai"].(map[string]interface{})
+ if genAI == nil {
+ genAI = map[string]interface{}{}
+ }
+ providerBlock, _ := genAI["provider"].(map[string]interface{})
+ if providerBlock == nil {
+ providerBlock = map[string]interface{}{}
+ }
+ if existing, _ := providerBlock["name"].(string); strings.TrimSpace(existing) != "" {
+ return
+ }
+ providerBlock["name"] = provider
+ genAI["provider"] = providerBlock
+ event["gen_ai"] = genAI
+}
+
func (l *Logger) baseEndpointEvent(action, category, severity, message, fidelity string) map[string]interface{} {
hostname, _ := os.Hostname()
userName := os.Getenv("USER")
diff --git a/cli/beacon/internal/fxsession/mapper.go b/cli/beacon/internal/fxsession/mapper.go
index 76d0be42..ffe11656 100644
--- a/cli/beacon/internal/fxsession/mapper.go
+++ b/cli/beacon/internal/fxsession/mapper.go
@@ -175,7 +175,12 @@ func (m *mapper) applyPreferences(prefs *Preferences) {
return
}
if prefs.Model != "" {
- m.model = prefs.Model
+ // Canonicalized on the way in, like the harness name, so fx's spelling of a model
+ // groups with the same model reported by a hook or OTLP runtime in the BY MODEL
+ // rollup. Only the name is normalized here: fx reports its provider separately
+ // below, and a runtime naming its own provider beats one parsed out of a model
+ // string, so nothing is derived from a prefix on this path.
+ m.model = asymptoteobserve.NormalizeModelName(prefs.Model)
}
if prefs.Provider != "" {
m.provider = prefs.Provider
diff --git a/cli/beacon/internal/fxsession/mapper_test.go b/cli/beacon/internal/fxsession/mapper_test.go
index c893cd66..ffae37ef 100644
--- a/cli/beacon/internal/fxsession/mapper_test.go
+++ b/cli/beacon/internal/fxsession/mapper_test.go
@@ -299,7 +299,7 @@ func TestProviderSurvivesTheRestOfTheGenAIBlock(t *testing.T) {
if ev.GenAI == nil || ev.GenAI.Provider == nil || ev.GenAI.Provider.Name != "gateway" {
t.Errorf("%s: gen_ai.provider = %+v, want gateway", ev.Event.Action, ev.GenAI)
}
- if ev.Model != "anthropic/claude-opus-4" {
+ if ev.Model != "claude-opus-4" {
t.Errorf("%s: model = %q", ev.Event.Action, ev.Model)
}
}
@@ -508,8 +508,9 @@ func TestAlreadyCollectedEventsBuildStateWithoutBeingEmittedAgain(t *testing.T)
if got := *usage.GenAI.Usage.CostUSD; got < 0.2499 || got > 0.2501 {
t.Errorf("cost = %v, want the 0.25 delta from the checkpoint the sweep skipped", got)
}
- // The model was set by the session_started the sweep also skipped.
- if usage.Model != "anthropic/claude-opus-4" {
+ // The model was set by the session_started the sweep also skipped, canonicalized on the
+ // way in (fx reports it as "anthropic/claude-opus-4").
+ if usage.Model != "claude-opus-4" {
t.Errorf("model = %q, want the one the skipped session_started set", usage.Model)
}
}
@@ -524,7 +525,7 @@ func TestSessionStartCanBeSuppressedForAnAlreadyStartedSession(t *testing.T) {
}
// Suppressing the event must not suppress the state it carries.
prompt := find(t, mapped, "prompt.submitted")
- if prompt.Model != "anthropic/claude-opus-4" || prompt.Session.WorkingDirectory != "/repo" {
+ if prompt.Model != "claude-opus-4" || prompt.Session.WorkingDirectory != "/repo" {
t.Errorf("state from the suppressed session_started was lost: model %q dir %q",
prompt.Model, prompt.Session.WorkingDirectory)
}
@@ -739,3 +740,22 @@ func TestATurnSummaryIsPreferredOverTheCumulativeFallback(t *testing.T) {
t.Errorf("input tokens = %d, want the summary's 1200 rather than the record's 4200 total", got)
}
}
+
+// fx reports its model with a vendor prefix ("anthropic/claude-opus-4") and its provider
+// separately ("gateway"). Canonicalizing the model is what lets an fx turn group with the same
+// model reported by a hook or OTLP runtime, which spell it "claude-opus-4".
+//
+// The provider is deliberately not derived from the stripped prefix here. fx already names its
+// provider, and on this fixture the two disagree on purpose: the prefix is the model's vendor
+// while the provider is the gateway routing the call. Deriving one from the other would overwrite
+// a reported fact with a parsed guess.
+func TestFxModelIsCanonicalizedWithoutDisturbingTheReportedProvider(t *testing.T) {
+ mapped := mapFixture(t, []string{sessionStartedLine(1, "/repo"), assistantTurnLine(2)}, MapOptions{})
+ prompt := find(t, mapped, "prompt.submitted")
+ if prompt.Model != "claude-opus-4" {
+ t.Errorf("model = %q, want the vendor prefix stripped", prompt.Model)
+ }
+ if prompt.GenAI == nil || prompt.GenAI.Provider == nil || prompt.GenAI.Provider.Name != "gateway" {
+ t.Errorf("provider = %+v, want fx's own reported provider left untouched", prompt.GenAI)
+ }
+}
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
index 967d1149..a138d6b5 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
@@ -867,6 +867,32 @@ func (c Converter) EventFromMetric(resourceAttrs map[string]interface{}, metric
// datapoint values, such as Claude Code's claude_code.token.usage counter or
// the semconv gen_ai.client.token.usage histogram. Matching is deliberately
// tight so unrelated metrics keep the generic metric.observed conversion.
+// applyModel writes the canonical model name onto the event and keeps the provider prefix that
+// canonicalizing removes.
+//
+// Model is normalized here for the same reason harness.name is (see NormalizeHarnessName): both
+// capture paths write this field, every token report groups by it, and an OTLP runtime reporting
+// "anthropic/claude-sonnet-4-5" against a hook path reporting "claude-sonnet-4-5" splits one
+// model's spend across two rows in the BY MODEL rollup.
+//
+// The stripped prefix becomes gen_ai.provider.name only when the runtime did not report one
+// itself. A runtime naming its own provider is the better source; a prefix parsed out of a model
+// string is a fallback, and must never overwrite the real thing.
+func applyModel(event *Event, raw string) {
+ name, provider := asymptoteobserve.SplitModelProvider(raw)
+ event.Model = name
+ if provider == "" {
+ return
+ }
+ if event.GenAI == nil {
+ event.GenAI = &GenAIInfo{}
+ }
+ if event.GenAI.Provider != nil && strings.TrimSpace(event.GenAI.Provider.Name) != "" {
+ return
+ }
+ event.GenAI.Provider = &GenAIProviderInfo{Name: provider}
+}
+
func IsTokenUsageMetric(name string) bool {
normalized := strings.ToLower(strings.TrimSpace(name))
return normalized == "gen_ai.client.token.usage" ||
@@ -1087,7 +1113,7 @@ func (c Converter) PopulateCommon(event *Event, attrs map[string]interface{}) {
if version := FirstString(attrs, "service.version"); version != "" {
event.Harness.Version = version
}
- event.Model = FirstString(attrs, "gen_ai.request.model", "gen_ai.response.model", "model", "ai.model")
+ applyModel(event, FirstString(attrs, "gen_ai.request.model", "gen_ai.response.model", "model", "ai.model"))
event.Repository = FirstString(attrs, "vcs.repository.url", "repository", "repo.path", "workspace.repository")
event.Branch = FirstString(attrs, "vcs.branch.name", "git.branch", "branch")
if id := FirstString(attrs, "gen_ai.conversation.id", "beacon.session.id", "copilot_chat.session_id", "copilot_chat.chat_session_id", "conversation.id", "conversation_id", "session.id"); id != "" || FirstString(attrs, "cwd", "working_directory", "workspace") != "" {
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
index 185d3b45..cbc98e93 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
@@ -1657,3 +1657,69 @@ func TestInferActionMatchesWithFidelityVariant(t *testing.T) {
}
}
}
+
+// Model is canonicalized on the OTLP path for the same reason harness.name is: the hook path
+// writes the same field, `beacon token-usage` groups its BY MODEL rollup on the raw string, and a
+// runtime reporting "anthropic/claude-sonnet-4-5" against a hook path reporting
+// "claude-sonnet-4-5" splits one model's spend across two rows.
+func TestEventsFromTracesCanonicalizesModelName(t *testing.T) {
+ span, traces := newObserveSDKTraceSpan("agent.plan")
+ span.Attributes().PutStr("gen_ai.request.model", "Anthropic/Claude-Sonnet-4-5")
+
+ events := NewConverter(Options{}).EventsFromTraces(traces)
+ if len(events) != 1 {
+ t.Fatalf("expected 1 event, got %d", len(events))
+ }
+ if events[0].Model != "claude-sonnet-4-5" {
+ t.Fatalf("model = %q, want the canonical spelling", events[0].Model)
+ }
+}
+
+// The stripped prefix is kept as gen_ai.provider.name rather than discarded, so canonicalizing
+// loses nothing.
+func TestEventsFromTracesKeepsTheStrippedProviderPrefix(t *testing.T) {
+ span, traces := newObserveSDKTraceSpan("agent.plan")
+ span.Attributes().PutStr("gen_ai.request.model", "openrouter/anthropic/claude-sonnet-4-5")
+
+ events := NewConverter(Options{}).EventsFromTraces(traces)
+ event := events[0]
+ if event.GenAI == nil || event.GenAI.Provider == nil {
+ t.Fatal("no provider recorded for a prefixed model name")
+ }
+ if event.GenAI.Provider.Name != "openrouter/anthropic" {
+ t.Fatalf("provider = %q, want the whole stripped prefix", event.GenAI.Provider.Name)
+ }
+}
+
+// A provider the runtime reported itself is a better source than one parsed out of a model
+// string, and must survive.
+func TestEventsFromTracesDoesNotOverwriteAReportedProvider(t *testing.T) {
+ span, traces := newObserveSDKTraceSpan("agent.plan")
+ attrs := span.Attributes()
+ attrs.PutStr("gen_ai.provider.name", "gateway")
+ attrs.PutStr("gen_ai.request.model", "anthropic/claude-sonnet-4-5")
+
+ events := NewConverter(Options{}).EventsFromTraces(traces)
+ event := events[0]
+ if event.GenAI.Provider.Name != "gateway" {
+ t.Fatalf("provider = %q, want the runtime's own reported provider", event.GenAI.Provider.Name)
+ }
+ if event.Model != "claude-sonnet-4-5" {
+ t.Fatalf("model = %q, want it canonicalized regardless", event.Model)
+ }
+}
+
+// An event with no model must not gain a gen_ai block, which would otherwise appear on every
+// command and file event that never had one.
+func TestEventsFromTracesWithoutAModelGainsNoGenAIBlock(t *testing.T) {
+ span, traces := newObserveSDKTraceSpan("agent.plan")
+ span.Attributes().PutStr("beacon.event.action", "command.executed")
+
+ events := NewConverter(Options{}).EventsFromTraces(traces)
+ if events[0].Model != "" {
+ t.Fatalf("model = %q, want empty", events[0].Model)
+ }
+ if events[0].GenAI != nil && events[0].GenAI.Provider != nil {
+ t.Fatalf("gained a provider from nothing: %+v", events[0].GenAI.Provider)
+ }
+}
diff --git a/docs/runtimes/cline.mdx b/docs/runtimes/cline.mdx
index 4f434180..817d658f 100644
--- a/docs/runtimes/cline.mdx
+++ b/docs/runtimes/cline.mdx
@@ -50,7 +50,7 @@ beacon endpoint hooks install --harness cline
| Command telemetry | `execute_command` with command text, output, exit code, and duration |
| File telemetry | `read_file`, `list_files`, `search_files`, and `list_code_definition_names` reads; `write_to_file` and `replace_in_file` modifications with diff hash and byte count |
| MCP telemetry | `use_mcp_tool` and `access_mcp_resource` normalized as MCP tool activity |
-| Model and usage | Provider-qualified model, token counts, cache reads, and runtime-reported cost, recorded once per task |
+| Model and usage | Model and provider (recorded as `model` and `gen_ai.provider.name`), token counts, cache reads, and runtime-reported cost, recorded once per task |
| Approval telemetry | Not supported. See [Known gaps](#known-gaps) |
| Local JSONL and dashboard | Supported |
| MDM deployment | Supported for the endpoint agent. Cline plugins are installed separately in the logged-in user's context |
diff --git a/docs/telemetry-schema/normalization.mdx b/docs/telemetry-schema/normalization.mdx
index 03c1998b..7879e98b 100644
--- a/docs/telemetry-schema/normalization.mdx
+++ b/docs/telemetry-schema/normalization.mdx
@@ -7,11 +7,21 @@ description: "How Beacon maps OTLP attributes and hook payloads into normalized
Beacon normalizes [OTLP](/concepts/core-concepts#otlp) attributes and [hook](/concepts/core-concepts#hooks) payloads into the same event contract. The collector exporter looks for common runtime fields, while hook telemetry builds those fields directly from hook payloads.
+## Model names
+
+`model` is canonicalized at the point of writing, on both capture paths, the same way `harness.name` is. The value is trimmed and lowercased, and a provider prefix is removed: `Anthropic/Claude-Sonnet-4-5`, `anthropic/claude-sonnet-4-5` and `claude-sonnet-4-5` all record as `claude-sonnet-4-5`.
+
+This matters because every token report groups by this field. Before canonicalization, one model reached through two runtimes -- an OTLP runtime reporting the bare id, a plugin runtime reporting a provider-qualified one -- produced two rows in the `BY MODEL` rollup, with a reader having no way to tell that from two genuinely different models.
+
+The prefix is not discarded. It is recorded as `gen_ai.provider.name`, so a provider stays queryable in its own field rather than packed into a model string. A provider the runtime reported itself always wins: a prefix parsed out of a model name is only used when the runtime named no provider of its own.
+
+Model ids themselves are never rewritten. Date suffixes, dots and vendor spellings are preserved as the runtime reported them, because a rule that folds `claude-sonnet-4.6` into `claude-sonnet-4-6` also turns `gpt-4.1` into `gpt-4-1`, which is not a model under any name. A split row is visible to a reader; an invented id is not.
+
## Source mapping
| Source signal | Normalized field or action |
|---------------|----------------------------|
-| `gen_ai.request.model`, `gen_ai.response.model`, `model`, `ai.model` | `model` |
+| `gen_ai.request.model`, `gen_ai.response.model`, `model`, `ai.model` | `model`, canonicalized, plus `gen_ai.provider.name` from any provider prefix |
| `gen_ai.tool.name`, `tool.name`, `beacon.tool.name`, `function_name`, `tool_name` | `tool.name` and `gen_ai.tool.name` |
| `gen_ai.tool.call.arguments`, `function_args`, `arguments` | `tool.command` when command-like, plus `gen_ai.tool.call.arguments` |
| `gen_ai.tool.call.id`, `tool_use_id`, `call_id`, `tool_call_id`, `callId` | `gen_ai.tool.call.id` |
diff --git a/pkg/asymptoteobserve/model.go b/pkg/asymptoteobserve/model.go
new file mode 100644
index 00000000..ba4e1e56
--- /dev/null
+++ b/pkg/asymptoteobserve/model.go
@@ -0,0 +1,70 @@
+package asymptoteobserve
+
+import "strings"
+
+// NormalizeModelName maps whatever a runtime calls a model onto one canonical spelling, and
+// SplitModelProvider recovers the provider prefix that normalizing removes.
+//
+// This exists for the same reason NormalizeHarnessName does, one field over. `model` is what
+// every token report groups by -- `beacon token-usage` builds its BY MODEL rollup with
+// addGroup(byModel, event.Model, ...) on the raw string -- so the same model reported under two
+// spellings is two rows, and a reader comparing spend across runtimes sees a model's cost split
+// in half with no indication that it happened. The spellings genuinely differ in practice:
+// Claude Code's OTLP reports `claude-sonnet-4-5`, an OpenRouter-backed runtime reports
+// `anthropic/claude-sonnet-4-5`, and a gateway reports `Anthropic/Claude-Sonnet-4-5`. All three
+// are one model and one bill.
+//
+// Normalizing at the point of writing rather than at every point of reading is the same choice
+// the harness name made, for the same reason: the alternative pushes the inconsistency onto
+// every consumer, including the SIEM queries and dashboards Beacon does not own.
+//
+// What it does, and deliberately no more:
+//
+// - Trims surrounding whitespace and lowercases. Model ids are conventionally lowercase, and
+// the runtimes that capitalize them are the same ones that vary the prefix.
+// - Drops a provider prefix, keeping the last "/"-separated segment. The prefix is not
+// discarded by callers: SplitModelProvider returns it so it can be recorded as
+// gen_ai.provider.name, which is where a provider belongs and where it stays queryable.
+//
+// What it deliberately does NOT do is rewrite the model id itself -- no dot-to-dash folding, no
+// date-suffix stripping, no vendor alias table. It is tempting, because Copilot reports
+// `claude-sonnet-4.6` where Anthropic's own id is `claude-sonnet-4-6`, and folding the dot would
+// merge them. But the same rule applied to `gpt-4.1` produces `gpt-4-1`, which is not a model
+// that exists under any name, and a canonical field whose values do not exist anywhere is worse
+// than one that occasionally splits: a split row is visible, an invented id is not. Alias
+// mapping needs a catalog to validate against, so it belongs with the pricing work, not here.
+//
+// The empty string in, empty string out. An unrecognized model keeps its own name, as an
+// unrecognized harness does.
+func NormalizeModelName(model string) string {
+ normalized, _ := SplitModelProvider(model)
+ return normalized
+}
+
+// SplitModelProvider returns the canonical model name and the provider prefix that was removed
+// from it, both normalized. The provider is empty when the name carried no prefix.
+//
+// Only the last segment is treated as the model, so a doubly-prefixed name such as
+// `openrouter/anthropic/claude-sonnet-4-5` yields the model `claude-sonnet-4-5` and the provider
+// `openrouter/anthropic` -- the whole prefix rather than just its last component, because
+// discarding "openrouter" would claim the call went somewhere it did not.
+//
+// A trailing slash is not a provider: "anthropic/" has no model part, so the input is returned
+// unchanged rather than reduced to the empty string. Same for a leading slash, which would
+// otherwise report an empty provider as if one had been read.
+func SplitModelProvider(model string) (name string, provider string) {
+ normalized := strings.ToLower(strings.TrimSpace(model))
+ if normalized == "" {
+ return "", ""
+ }
+ idx := strings.LastIndex(normalized, "/")
+ if idx < 0 {
+ return normalized, ""
+ }
+ prefix, suffix := normalized[:idx], normalized[idx+1:]
+ if prefix == "" || suffix == "" {
+ // "/model" or "provider/" -- neither half is a usable pair, so nothing is split off.
+ return normalized, ""
+ }
+ return suffix, prefix
+}
diff --git a/pkg/asymptoteobserve/model_test.go b/pkg/asymptoteobserve/model_test.go
new file mode 100644
index 00000000..a728fc6e
--- /dev/null
+++ b/pkg/asymptoteobserve/model_test.go
@@ -0,0 +1,95 @@
+package asymptoteobserve
+
+import "testing"
+
+func TestNormalizeModelName(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ input string
+ want string
+ }{
+ {"empty", "", ""},
+ {"whitespace only", " ", ""},
+ {"already canonical", "claude-sonnet-4-5", "claude-sonnet-4-5"},
+ {"trims and lowercases", " Claude-Sonnet-4-5 ", "claude-sonnet-4-5"},
+ {"drops provider prefix", "anthropic/claude-sonnet-4-5", "claude-sonnet-4-5"},
+ {"drops mixed-case provider prefix", "Anthropic/Claude-Sonnet-4-5", "claude-sonnet-4-5"},
+ {"drops multi-segment prefix", "openrouter/anthropic/claude-sonnet-4-5", "claude-sonnet-4-5"},
+ {"unknown model keeps its own name", "some-new-model-v9", "some-new-model-v9"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := NormalizeModelName(tc.input); got != tc.want {
+ t.Fatalf("NormalizeModelName(%q) = %q, want %q", tc.input, got, tc.want)
+ }
+ })
+ }
+}
+
+// The whole point of the field: these spellings all describe one model and one bill, and before
+// normalization each was its own row in the BY MODEL rollup.
+func TestNormalizeModelNameCollapsesSpellingsOfOneModel(t *testing.T) {
+ spellings := []string{
+ "claude-sonnet-4-5",
+ "anthropic/claude-sonnet-4-5",
+ "Anthropic/Claude-Sonnet-4-5",
+ " claude-sonnet-4-5 ",
+ "openrouter/anthropic/claude-sonnet-4-5",
+ }
+ for _, spelling := range spellings {
+ if got := NormalizeModelName(spelling); got != "claude-sonnet-4-5" {
+ t.Fatalf("NormalizeModelName(%q) = %q, want all spellings to collapse to claude-sonnet-4-5", spelling, got)
+ }
+ }
+}
+
+// Model ids are not rewritten. Folding the dot in Copilot's claude-sonnet-4.6 would merge it with
+// Anthropic's claude-sonnet-4-6, but the same rule turns gpt-4.1 into gpt-4-1, which is not a
+// model under any name. A split row is visible; an invented id is not. See the doc comment.
+func TestNormalizeModelNameDoesNotInventIDs(t *testing.T) {
+ for _, model := range []string{"gpt-4.1", "claude-sonnet-4.6", "gemini-2.5-pro", "gpt-4o-2024-08-06"} {
+ if got := NormalizeModelName(model); got != model {
+ t.Fatalf("NormalizeModelName(%q) = %q, want the id left intact", model, got)
+ }
+ }
+}
+
+func TestSplitModelProvider(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ input string
+ wantModel string
+ wantProvider string
+ }{
+ {"no prefix", "claude-sonnet-4-5", "claude-sonnet-4-5", ""},
+ {"single prefix", "anthropic/claude-sonnet-4-5", "claude-sonnet-4-5", "anthropic"},
+ {"multi prefix keeps the whole path", "openrouter/anthropic/claude-sonnet-4-5", "claude-sonnet-4-5", "openrouter/anthropic"},
+ {"lowercases the provider too", "OpenRouter/Anthropic/Claude-Sonnet-4-5", "claude-sonnet-4-5", "openrouter/anthropic"},
+ {"empty", "", "", ""},
+ // Neither half of these is a usable pair, so nothing is split off rather than
+ // reporting an empty model or an empty provider that was never read.
+ {"trailing slash is not a provider", "anthropic/", "anthropic/", ""},
+ {"leading slash is not a provider", "/claude-sonnet-4-5", "/claude-sonnet-4-5", ""},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ model, provider := SplitModelProvider(tc.input)
+ if model != tc.wantModel || provider != tc.wantProvider {
+ t.Fatalf("SplitModelProvider(%q) = (%q, %q), want (%q, %q)", tc.input, model, provider, tc.wantModel, tc.wantProvider)
+ }
+ })
+ }
+}
+
+// Normalizing must be idempotent: the canonical value has to survive being normalized again, or
+// re-normalizing a stored event would keep changing it. This is the property vscode_copilot
+// failed on the harness side before it was pinned.
+func TestNormalizeModelNameIsIdempotent(t *testing.T) {
+ for _, model := range []string{
+ "anthropic/claude-sonnet-4-5", "gpt-5", "openrouter/anthropic/claude-sonnet-4-5",
+ "anthropic/", "/gpt-5", "gemini-2.5-pro",
+ } {
+ once := NormalizeModelName(model)
+ if twice := NormalizeModelName(once); twice != once {
+ t.Fatalf("NormalizeModelName(%q) = %q, but normalizing again gave %q", model, once, twice)
+ }
+ }
+}