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
fix(codex): one originator-to-surface mapping for live capture, import and usage (#1141)
kyle-elliott-asymptote30f7c2950c65
diff --git a/cli/beacon/internal/codexsession/codexsession_test.go b/cli/beacon/internal/codexsession/codexsession_test.goindex 74326d56..1080288f 100644--- a/cli/beacon/internal/codexsession/codexsession_test.go+++ b/cli/beacon/internal/codexsession/codexsession_test.go@@ -98,6 +98,32 @@ func TestMapCodexShellCommandIsACommand(t *testing.T) {}}+// The desktop app writes its rollouts to the same store, with its client name verbatim in+// session_meta. Its events are codex_desktop, as the live collector names the same conversation,+// including on a later sweep that starts past the session_meta line.+func TestMapCodexDesktopRolloutIsCodexDesktop(t *testing.T) {+ ref := SessionRef{ID: "sess-d", Path: "/tmp/codex.jsonl", Workspace: "/tmp/repo"}+ meta := strings.Replace(strings.Replace(sessionMetaLine("sess-d", "/tmp/repo"),+ `"originator":"codex-tui"`, `"originator":"Codex Desktop"`, 1), `"source":"cli"`, `"source":"vscode"`, 1)+ records := decodeFixture(t, []string{+ meta,+ turnContextLine("turn-1", "gpt-6-astra"),+ messageLine("user", "msg-user", "add a health endpoint"),+ tokenUsageLine("sess-d", "turn-1", 120, 90, 10, 8, 2),+ })+ for _, opts := range []MapOptions{{}, {MinLine: 1, SkipSessionStarted: true}} {+ mapped := MapSession(ref, records, opts)+ if len(mapped) == 0 {+ t.Fatalf("MinLine %d: nothing mapped", opts.MinLine)+ }+ for _, item := range mapped {+ if item.Event.Harness.Name != "codex_desktop" {+ t.Fatalf("MinLine %d: %s harness = %q, want codex_desktop", opts.MinLine, item.Event.Event.Action, item.Event.Harness.Name)+ }+ }+ }+}+func TestCollectOnceUsesCursor(t *testing.T) {dir := t.TempDir()codexDir := filepath.Join(dir, ".codex")diff --git a/cli/beacon/internal/codexsession/mapper.go b/cli/beacon/internal/codexsession/mapper.goindex da2708af..cf6a7e8a 100644--- a/cli/beacon/internal/codexsession/mapper.go+++ b/cli/beacon/internal/codexsession/mapper.go@@ -37,6 +37,8 @@ type mapper struct {out []MappedEventtools map[string]codexToolCallsessionID string+ // harness is the Codex surface the rollout's session_meta names, codex_cli until it does.+ harness stringworkspace stringmodel stringturnID string@@ -62,6 +64,7 @@ func MapSession(ref SessionRef, records []Record, opts MapOptions) []MappedEventopts: opts,tools: map[string]codexToolCall{},sessionID: ref.ID,+ harness: asymptoteobserve.CodexSurface(""),workspace: ref.Workspace,tokenRecordTurns: tokenRecordTurns,}@@ -97,6 +100,9 @@ func (m *mapper) consumeSessionMeta(record Record, emit bool) {if meta.CWD != "" {m.workspace = meta.CWD}+ if meta.Originator != "" {+ m.harness = asymptoteobserve.CodexSurface(meta.Originator)+ }if emit && !m.opts.SkipSessionStarted && !m.started {ev := m.base(record, "session.started", "session", schema.SeverityInfo, schema.FidelityObserved, "Codex session started")ev.Raw = map[string]interface{}{"codex_session": m.raw(record)}@@ -411,7 +417,7 @@ func (m *mapper) base(record Record, action, category string, severity schema.SeFidelity: fidelity,Message: message,Origin: schema.OriginLocal,- Harness: schema.HarnessInfo{Name: Harness, CollectionMethod: schema.CollectionMethodPoll},+ Harness: schema.HarnessInfo{Name: m.harness, CollectionMethod: schema.CollectionMethodPoll},})if ts := eventTimestamp(record.Entry); ts != "" {ev.Timestamp = tsdiff --git a/cli/beacon/internal/codexsession/types.go b/cli/beacon/internal/codexsession/types.goindex 7e087ede..ca7c1a53 100644--- a/cli/beacon/internal/codexsession/types.go+++ b/cli/beacon/internal/codexsession/types.go@@ -12,6 +12,9 @@ import ("fmt")+// Harness is Codex's runtime name. The desktop app writes its rollouts to the same store, and+// each rollout's events are named by the originator in its session_meta (codex_desktop for the+// desktop app), the same mapping the live collector uses.const Harness = "codex_cli"type Entry struct {diff --git a/cli/beacon/internal/tokens/tokens.go b/cli/beacon/internal/tokens/tokens.goindex 37d973eb..ae2c18ae 100644--- a/cli/beacon/internal/tokens/tokens.go+++ b/cli/beacon/internal/tokens/tokens.go@@ -191,14 +191,10 @@ type usageEvent struct {contextLimit int64cumulative boolmetricName string- // codexAppServer marks usage exported by Codex's app-server, which the CLI and the desktop app- // share. A legacy turn metric from it names no conversation, so its harness is the exporter's- // default rather than its surface.- codexAppServer bool- rawSource string- sourceStart time.Time- seriesField string- seriesValue float64+ rawSource string+ sourceStart time.Time+ seriesField string+ seriesValue float64// collectionMethod is harness.collection_method, lowercased: whether this usage came from// live capture or from a poll of the runtime's own session store. requestScoped (cost.go)@@ -613,10 +609,6 @@ func collectUsageEvents(events []schema.Event, sessionUsers sessionUserIndex) []ue.cumulative = true}ue.metricName, _ = event.Raw["metric_name"].(string)- if attrs, ok := event.Raw["attributes"].(map[string]interface{}); ok {- service, _ := attrs["service.name"].(string)- ue.codexAppServer = strings.EqualFold(strings.TrimSpace(service), "codex-app-server")- }ue.rawSource, _ = event.Raw["source"].(string)ue.tokenSource, _ = event.Raw["token_source"].(string)if codex, ok := event.Raw["codex_session"].(map[string]interface{}); ok {@@ -635,11 +627,6 @@ func collectUsageEvents(events []schema.Event, sessionUsers sessionUserIndex) []// the first time it appears for an endpoint/model. Legacy aggregate metrics// before that cutover remain reportable, while a manually configured// trace+metric overlap after it cannot double-count the same turns.-//-// A legacy metric from Codex's app-server names no conversation, so the exporter can't tell-// whether the CLI or the desktop app sent it and records it as codex_cli. Both surfaces read one-// ~/.codex/config.toml and so export the same signals; a turn span from either covers it. Metrics-// from an older CLI (codex_cli_rs) keep to their own harness.func preferCodexTurnSpans(events []*usageEvent) []*usageEvent {type sourceKey struct {endpoint string@@ -672,16 +659,7 @@ func preferCodexTurnSpans(events []*usageEvent) []*usageEvent {}out := events[:0]for _, event := range events {- key := keyFor(event)- cutover, ok := cutovers[key]- if event.codexAppServer && usageHarnessKey(key.harness) == "codex_cli" {- for _, surface := range []string{"codex_cli", "codex_desktop"} {- key.harness = surface- if other, found := cutovers[key]; found && (!ok || other.Before(cutover)) {- cutover, ok = other, true- }- }- }+ cutover, ok := cutovers[keyFor(event)]if ok &&strings.EqualFold(event.metricName, "codex.turn.token_usage") &&!event.ts.IsZero() &&@@ -718,9 +696,10 @@ func liveScopeFor(endpoint, harness, session string) (liveScope, bool) {}// usageHarnessKey is the harness a session's live/poll check groups by. Codex's CLI and desktop app-// are one runtime with one session store and one set of conversation ids, and `codex sync` reads-// both surfaces' rollouts and names them codex_cli. So within one session the two names are one-// key, or a Desktop session's backfill would be counted again beside its live capture.+// are one runtime with one session store, and a conversation id belongs to one of them, so folding+// the two names never merges two sessions. Logs written before the collector and `codex sync` both+// went by the originator hold one session under both names -- the collector named every app-server+// session codex_desktop, `codex sync` every rollout codex_cli -- and the fold counts it once.func usageHarnessKey(harness string) string {normalized := asymptoteobserve.NormalizeHarnessName(harness)if normalized == "codex_desktop" {diff --git a/cli/beacon/internal/tokens/tokens_test.go b/cli/beacon/internal/tokens/tokens_test.goindex 3cd58aa3..9ab2217e 100644--- a/cli/beacon/internal/tokens/tokens_test.go+++ b/cli/beacon/internal/tokens/tokens_test.go@@ -847,14 +847,14 @@ func TestAggregatePrefersLiveCaptureOverPollBackfill(t *testing.T) {suppressed: 1,},{- // The app-server's legacy metric names no conversation, so the exporter can't place it- // and it is codex_cli; the Desktop turn span over the same turns must still drop it.- name: "codex desktop turn span and an app-server legacy metric",+ // Codex tags its legacy metric with the session's originator, so the exporter names it+ // codex_desktop like the Desktop turn span over the same turns, which drops it.+ name: "codex desktop turn span and the desktop's legacy metric",events: []schema.Event{- event("2026-06-11T10:00:30Z", "codex_cli", otlp, "", "token.usage", &tokens{input: 20}, func(e *schema.Event) {+ event("2026-06-11T10:00:30Z", "codex_desktop", otlp, "", "token.usage", &tokens{input: 20}, func(e *schema.Event) {e.Model = "gpt-5.6-sol"e.Raw = map[string]interface{}{"metric_name": "codex.turn.token_usage", "metric_temporality": "Delta",- "attributes": map[string]interface{}{"service.name": "codex-app-server"}}+ "attributes": map[string]interface{}{"service.name": "codex-app-server", "originator": "Codex_Desktop", "session_source": "vscode"}}}),event("2026-06-11T10:00:30Z", "codex_desktop", otlp, "019a-desktop", "token.usage", &tokens{input: 20}, func(e *schema.Event) {e.Model = "gpt-5.6-sol"@@ -885,9 +885,26 @@ func TestAggregatePrefersLiveCaptureOverPollBackfill(t *testing.T) {suppressed: 0,},{- // `codex sync` reads Desktop rollouts too and names them codex_cli; live capture of- // the same conversation is codex_desktop. One session, so the backfill goes.+ // `codex sync` reads the same conversation from its rollout. Here both name it+ // codex_desktop, from the originator; one session, so the backfill goes.name: "codex desktop live capture and codex sync",+ events: []schema.Event{+ event("2026-06-11T10:00:00Z", "codex_desktop", otlp, "019a-desktop", "session.started", nil, nil),+ event("2026-06-11T10:00:20Z", "codex_desktop", poll, "019a-desktop", "token.usage", &tokens{input: 500, output: 40}, model("gpt-5.6-sol")),+ event("2026-06-11T10:00:30Z", "codex_desktop", otlp, "019a-desktop", "token.usage", &tokens{input: 500, output: 40}, func(e *schema.Event) {+ e.Model = "gpt-5.6-sol"+ e.Raw = map[string]interface{}{"source": "codex_turn_span", "turn_start_timestamp": "2026-06-11T10:00:01Z"}+ }),+ },+ want: tokens{input: 500, output: 40},+ wantEvents: 1,+ suppressed: 1,+ },+ {+ // Logs written before the originator decided name one session twice: `codex sync`+ // wrote Desktop rollouts as codex_cli, and the collector wrote every app-server+ // session, CLI ones too, as codex_desktop.+ name: "codex live capture and codex sync under the names logs already hold",events: []schema.Event{event("2026-06-11T10:00:00Z", "codex_desktop", otlp, "019a-desktop", "session.started", nil, nil),event("2026-06-11T10:00:20Z", "codex_cli", poll, "019a-desktop", "token.usage", &tokens{input: 500, output: 40}, model("gpt-5.6-sol")),diff --git a/collector-builder/exporter/beaconjsonexporter/codex_surface_e2e_test.go b/collector-builder/exporter/beaconjsonexporter/codex_surface_e2e_test.goindex dd3f5258..568dadc3 100644--- a/collector-builder/exporter/beaconjsonexporter/codex_surface_e2e_test.go+++ b/collector-builder/exporter/beaconjsonexporter/codex_surface_e2e_test.go@@ -2,6 +2,8 @@ package beaconjsonexporterimport ("context"+ "encoding/json"+ "os""path/filepath""sync/atomic""testing"@@ -10,6 +12,7 @@ import ("go.opentelemetry.io/collector/component""go.opentelemetry.io/collector/exporter""go.opentelemetry.io/collector/pdata/plog"+ "go.opentelemetry.io/collector/pdata/pmetric""go.opentelemetry.io/collector/pdata/ptrace""go.opentelemetry.io/collector/processor/processortest")@@ -18,10 +21,49 @@ type nopHost struct{}func (nopHost) GetExtensions() map[component.ID]component.Component { return nil }+// codexAppServerExport is one Codex app-server process's OTLP export of one turn, as OTLP/JSON:+// the conversation's start and prompt logs, the turn span and the legacy token metric. The+// fixtures follow openai/codex's own emitters field for field (otel/src/events/shared.rs,+// core/src/tasks/mod.rs, core/src/state/turn_token_usage.rs) and the tracing bridges' defaults,+// which put the worker's OS thread id on the span under the same thread.id key Codex uses for the+// conversation.+type codexAppServerExport struct {+ Originator string `json:"originator"`+ Conversation string `json:"conversation"`+ Logs json.RawMessage `json:"logs"`+ Traces json.RawMessage `json:"traces"`+ Metrics json.RawMessage `json:"metrics"`+}++func loadCodexAppServerExport(t *testing.T, name string) (codexAppServerExport, plog.Logs, ptrace.Traces, pmetric.Metrics) {+ t.Helper()+ data, err := os.ReadFile(filepath.Join("internal", "beaconevent", "testdata", name))+ if err != nil {+ t.Fatal(err)+ }+ var export codexAppServerExport+ if err := json.Unmarshal(data, &export); err != nil {+ t.Fatal(err)+ }+ logs, err := (&plog.JSONUnmarshaler{}).UnmarshalLogs(export.Logs)+ if err != nil {+ t.Fatal(err)+ }+ traces, err := (&ptrace.JSONUnmarshaler{}).UnmarshalTraces(export.Traces)+ if err != nil {+ t.Fatal(err)+ }+ metrics, err := (&pmetric.JSONUnmarshaler{}).UnmarshalMetrics(export.Metrics)+ if err != nil {+ t.Fatal(err)+ }+ return export, logs, traces, metrics+}+// The CLI and the desktop app both export as codex-app-server. The collector builds a separate// exporter per pipeline from one config, as here: each conversation's logs name its surface on the-// logs exporter, and its usage span, which reaches the traces exporter later without an-// originator, lands under the same harness.+// logs exporter, its usage span, which reaches the traces exporter without an originator, lands+// under the same harness, and the legacy token metric is named by the originator it carries.func TestCollectorNamesCodexAppServerSessionsByOriginator(t *testing.T) {ctx := context.Background()cfg := &Config{@@ -41,92 +83,67 @@ func TestCollectorNamesCodexAppServerSessionsByOriginator(t *testing.T) {if err != nil {t.Fatalf("CreateTraces: %v", err)}- for _, exp := range []component.Component{logsExporter, tracesExporter} {+ metricsExporter, err := factory.CreateMetrics(ctx, set, cfg)+ if err != nil {+ t.Fatalf("CreateMetrics: %v", err)+ }+ for _, exp := range []component.Component{logsExporter, tracesExporter, metricsExporter} {if err := exp.Start(ctx, nopHost{}); err != nil {t.Fatalf("Start: %v", err)}t.Cleanup(func() { _ = exp.Shutdown(ctx) })}- logs := plog.NewLogs()- rl := logs.ResourceLogs().AppendEmpty()- rl.Resource().Attributes().PutStr("service.name", "codex-app-server")- sl := rl.ScopeLogs().AppendEmpty()- for _, conv := range []struct{ id, originator string }{{"cli-conv", "codex-tui"}, {"desktop-conv", "Codex_Desktop"}} {- for _, eventName := range []string{"codex.conversation_starts", "codex.user_prompt"} {- rec := sl.LogRecords().AppendEmpty()- rec.Attributes().PutStr("event.name", eventName)- rec.Attributes().PutStr("conversation.id", conv.id)- rec.Attributes().PutStr("originator", conv.originator)- rec.Attributes().PutStr("model", "gpt-5.5")- if eventName == "codex.user_prompt" {- rec.Attributes().PutStr("prompt", "list the files")+ written := 0+ for _, tc := range []struct {+ fixture, want string+ spanFirst bool+ }{+ {"codex-app-server-cli-0.164.0.json", "codex_cli", false},+ // A short turn's span can beat its prompt log across the two pipelines: the traces+ // exporter holds it, and the logs exporter writes it once the log names the conversation.+ {"codex-app-server-desktop-0.164.0.json", "codex_desktop", true},+ } {+ export, logs, traces, metrics := loadCodexAppServerExport(t, tc.fixture)+ if tc.spanFirst {+ if err := tracesExporter.ConsumeTraces(ctx, traces); err != nil {+ t.Fatalf("ConsumeTraces: %v", err)+ }+ if events := readEvents(t, cfg.Path); len(events) != written {+ t.Fatalf("%s: span written before its conversation was named: %+v", export.Originator, events[written:])}}- }- if err := logsExporter.ConsumeLogs(ctx, logs); err != nil {- t.Fatalf("ConsumeLogs: %v", err)- }-- traces := ptrace.NewTraces()- rs := traces.ResourceSpans().AppendEmpty()- rs.Resource().Attributes().PutStr("service.name", "codex-app-server")- ss := rs.ScopeSpans().AppendEmpty()- for _, thread := range []string{"cli-conv", "desktop-conv"} {- span := ss.Spans().AppendEmpty()- span.SetName("session_task.turn")- span.Attributes().PutStr("thread.id", thread)- span.Attributes().PutInt("codex.turn.token_usage.input_tokens", 1200)- span.Attributes().PutInt("codex.turn.token_usage.output_tokens", 80)- }- if err := tracesExporter.ConsumeTraces(ctx, traces); err != nil {- t.Fatalf("ConsumeTraces: %v", err)- }-- // A short turn's span can beat its prompt log across the two pipelines: the traces exporter- // holds it, and the logs exporter writes it once the log names the conversation.- early := ptrace.NewTraces()- ers := early.ResourceSpans().AppendEmpty()- ers.Resource().Attributes().PutStr("service.name", "codex-app-server")- earlySpan := ers.ScopeSpans().AppendEmpty().Spans().AppendEmpty()- earlySpan.SetName("session_task.turn")- earlySpan.Attributes().PutStr("thread.id", "quick-desktop-conv")- earlySpan.Attributes().PutInt("codex.turn.token_usage.input_tokens", 300)- if err := tracesExporter.ConsumeTraces(ctx, early); err != nil {- t.Fatalf("ConsumeTraces: %v", err)- }- for _, event := range readEvents(t, cfg.Path) {- if event.Session != nil && event.Session.ID == "quick-desktop-conv" {- t.Fatalf("span written before its conversation was named: %+v", event)+ if err := logsExporter.ConsumeLogs(ctx, logs); err != nil {+ t.Fatalf("ConsumeLogs: %v", err)}- }- quick := plog.NewLogs()- qrl := quick.ResourceLogs().AppendEmpty()- qrl.Resource().Attributes().PutStr("service.name", "codex-app-server")- qrec := qrl.ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()- qrec.Attributes().PutStr("event.name", "codex.user_prompt")- qrec.Attributes().PutStr("conversation.id", "quick-desktop-conv")- qrec.Attributes().PutStr("originator", "Codex_Desktop")- qrec.Attributes().PutStr("prompt", "hi")- if err := logsExporter.ConsumeLogs(ctx, quick); err != nil {- t.Fatalf("ConsumeLogs: %v", err)- }-- want := map[string]string{"cli-conv": "codex_cli", "desktop-conv": "codex_desktop", "quick-desktop-conv": "codex_desktop"}- usage := 0- for _, event := range readEvents(t, cfg.Path) {- if event.Session == nil {- t.Fatalf("event without a session: %#v", event)+ if !tc.spanFirst {+ if err := tracesExporter.ConsumeTraces(ctx, traces); err != nil {+ t.Fatalf("ConsumeTraces: %v", err)+ }}- if got := event.Harness.Name; got != want[event.Session.ID] {- t.Errorf("%s in %s recorded as %q, want %q", event.Event.Action, event.Session.ID, got, want[event.Session.ID])+ if err := metricsExporter.ConsumeMetrics(ctx, metrics); err != nil {+ t.Fatalf("ConsumeMetrics: %v", err)}- if event.Event.Action == "token.usage" {- usage++++ events := readEvents(t, cfg.Path)[written:]+ written += len(events)+ var span, metric int+ for _, event := range events {+ if got := event.Harness.Name; got != tc.want {+ t.Errorf("%s: %s recorded as %q, want %q", export.Originator, event.Event.Action, got, tc.want)+ }+ if event.Event.Action != "token.usage" {+ continue+ }+ if event.Session != nil && event.Session.ID == export.Conversation {+ span+++ } else {+ metric+++ }+ }+ if span != 1 || metric == 0 {+ t.Fatalf("%s: wrote %d usage span(s) in the conversation and %d metric usage event(s), want 1 and some", export.Originator, span, metric)}- }- if usage != 3 {- t.Fatalf("wrote %d token.usage events, want 3", usage)}}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface.goindex e321fa9d..9d74305a 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface.go@@ -5,27 +5,26 @@ import ("strings""sync""time"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// Codex runs on one set of app-server internals in the desktop app and, since about CLI 0.158, in the// terminal too, and both export OTLP as service.name=codex-app-server. The service name alone// therefore can't tell the Codex desktop app from the CLI. What does is the `originator` attribute-// Codex puts on its semantic log events: "Codex_Desktop" for the desktop app, "codex-tui" for the-// terminal, "codex_exec" for `codex exec`.+// Codex puts on its semantic log events and its metrics: "Codex_Desktop" for the desktop app,+// "codex-tui" for the terminal, "codex_exec" for `codex exec` (asymptoteobserve.CodexSurface).//-// Not every record carries it: the per-turn usage span has only the conversation (thread) id, and-// the legacy token metric not even that. So the surface an originator names is remembered per-// conversation, and a conversation's records without one get the same name. A record with neither-// stays codex_cli, the name Codex's hooks use on every surface.+// Not every record carries it: the per-turn usage span has only the conversation (thread) id. So+// the surface an originator names is remembered per conversation, and a conversation's records+// without one get the same name. A record with neither stays codex_cli, the name Codex's hooks use+// on every surface.//// The logs and traces pipelines flush on their own timers, so a short turn's usage span can reach// the exporter before the prompt log that names its conversation. Sort holds such a record until// its conversation is named or codexHoldWindow runs out.-const (- codexCLIHarness = "codex_cli"- codexDesktopHarness = "codex_desktop"-)+const codexCLIHarness = "codex_cli"// maxCodexConversations bounds the conversations remembered, least recently used first out. A// Codex conversation's records arrive within its own lifetime, so a few thousand recent@@ -100,26 +99,6 @@ func AcquireCodexSurfaces(config any) (*CodexSurfaces, func()) {}}-// codexSurfaceFromOriginator is the harness an originator names, or "" when there is none.-func codexSurfaceFromOriginator(originator string) string {- normalized := strings.ToLower(strings.TrimSpace(originator))- switch {- case normalized == "":- return ""- case strings.Contains(normalized, "desktop"):- return codexDesktopHarness- default:- return codexCLIHarness- }-}--// isCodexAppServerName is true for the service name both the desktop app and the CLI's app-server-// report, the one name that needs an originator to place.-func isCodexAppServerName(name string) bool {- normalized := strings.NewReplacer("-", "", "_", "", " ", "").Replace(strings.ToLower(strings.TrimSpace(name)))- return normalized == "codexappserver"-}-// settle sets a Codex event's harness to the surface it ran in. It only touches events whose name// came from the shared app-server service name; a name stated outright (beacon.harness.name,// harness.name) or a CLI-only service (codex_cli_rs, codex_exec) is already exact.@@ -130,7 +109,7 @@ func (s *CodexSurfaces) settle(event *Event, attrs map[string]interface{}) {if FirstString(attrs, "beacon.harness.name", "harness.name") != "" {return}- if !isCodexAppServerName(FirstString(attrs, "service.name")) {+ if !asymptoteobserve.IsCodexAppServer(FirstString(attrs, "service.name")) {return}conversation := ""@@ -140,11 +119,11 @@ func (s *CodexSurfaces) settle(event *Event, attrs map[string]interface{}) {if conversation == "" {conversation = FirstString(attrs, "conversation.id", "thread.id", "conversation_id", "thread_id")}- surface := codexSurfaceFromOriginator(FirstString(attrs, "originator"))- switch {- case surface != "":+ surface := ""+ if originator := strings.TrimSpace(FirstString(attrs, "originator")); originator != "" {+ surface = asymptoteobserve.CodexSurface(originator)s.remember(conversation, surface)- default:+ } else {surface = s.recall(conversation)}if surface == "" {diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface_test.goindex 86ae00eb..441f99e1 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface_test.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/codex_surface_test.go@@ -43,13 +43,17 @@ func codexTurnSpan(thread string) ptrace.Span {return span}-// codexUsageMetric is the legacy token metric. Codex exports it with no conversation id.-func codexUsageMetric() pmetric.Metric {+// codexUsageMetric is the legacy token metric. Codex tags it with the session's originator but no+// conversation id; an empty originator leaves the tag off.+func codexUsageMetric(originator string) pmetric.Metric {metric := pmetric.NewMetric()metric.SetName("codex.turn.token_usage")dp := metric.SetEmptySum().DataPoints().AppendEmpty()dp.SetDoubleValue(80)dp.Attributes().PutStr("token_type", "output")+ if originator != "" {+ dp.Attributes().PutStr("originator", originator)+ }return metric}@@ -126,11 +130,13 @@ func TestCodexConversationKeepsItsSurfaceOnRecordsWithoutOriginator(t *testing.Tif got := converter.EventFromLog(appServer(), codexLog("codex.tool_result", "desktop-conv", "")).Harness.Name; got != "codex_desktop" {t.Fatalf("desktop log without originator = %q, want codex_desktop", got)}- // The legacy metric names no conversation, so nothing places it; the token report folds the- // two Codex names together where it matters (cli/beacon/internal/tokens usageHarnessKey).- for _, event := range converter.EventsFromMetric(appServer(), codexUsageMetric()) {- if event.Harness.Name != "codex_cli" {- t.Fatalf("usage metric without a conversation = %q, want codex_cli", event.Harness.Name)+ // The legacy metric names no conversation; its own originator places it, and without one it+ // takes the default.+ for originator, want := range map[string]string{"Codex_Desktop": "codex_desktop", "codex-tui": "codex_cli", "": "codex_cli"} {+ for _, event := range converter.EventsFromMetric(appServer(), codexUsageMetric(originator)) {+ if event.Harness.Name != want {+ t.Fatalf("usage metric with originator %q = %q, want %q", originator, event.Harness.Name, want)+ }}}if got := converter.EventFromSpan(appServer(), codexTurnSpan("unknown-conv")).Harness.Name; got != "codex_cli" {@@ -209,8 +215,8 @@ func TestAcquireCodexSurfacesSharesOnePerConfig(t *testing.T) {if logs == other {t.Fatal("exporters built from different configs share a memory")}- logs.remember("desktop-conv", codexDesktopHarness)- if got := traces.recall("desktop-conv"); got != codexDesktopHarness {+ logs.remember("desktop-conv", "codex_desktop")+ if got := traces.recall("desktop-conv"); got != "codex_desktop" {t.Fatalf("traces exporter recalls %q, want codex_desktop", got)}@@ -288,7 +294,7 @@ func TestCodexSurfacesDrainOnShutdown(t *testing.T) {converter.EventFromSpan(appServer(), codexTurnSpan("unnamed")),converter.EventFromSpan(appServer(), codexTurnSpan("named-late")),}, now)- surfaces.remember("named-late", codexDesktopHarness)+ surfaces.remember("named-late", "codex_desktop")drained := surfaces.Drain()if len(drained) != 2 || drained[0].Harness.Name != "codex_cli" || drained[1].Harness.Name != "codex_desktop" {diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-cli-0.164.0.json b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-cli-0.164.0.jsonnew file mode 100644index 00000000..75322f4a--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-cli-0.164.0.json@@ -0,0 +1,277 @@+{+ "runtime": "Codex app-server (terminal CLI)",+ "version": "0.164.0",+ "originator": "codex-tui",+ "conversation": "019a17e0-efe2-7ae3-b558-d333b8e7ce96",+ "logs": {+ "resourceLogs": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "host.name", "value": {"stringValue": "mac-studio.local"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeLogs": [+ {+ "scope": {+ "name": "codex_otel.log_only"+ },+ "logRecords": [+ {+ "timeUnixNano": "1793286245102000000",+ "observedTimeUnixNano": "1793286245102000000",+ "severityNumber": 9,+ "severityText": "INFO",+ "eventName": "event otel/src/events/session_telemetry.rs:690",+ "attributes": [+ {"key": "event.name", "value": {"stringValue": "codex.conversation_starts"}},+ {"key": "provider_name", "value": {"stringValue": "OpenAI"}},+ {"key": "auth.env_openai_api_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_codex_api_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_codex_api_key_enabled", "value": {"boolValue": false}},+ {"key": "auth.env_provider_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_refresh_token_url_override_present", "value": {"boolValue": false}},+ {"key": "reasoning_effort", "value": {"stringValue": "medium"}},+ {"key": "reasoning_summary", "value": {"stringValue": "auto"}},+ {"key": "context_window", "value": {"intValue": "272000"}},+ {"key": "auto_compact_token_limit", "value": {"intValue": "244800"}},+ {"key": "approval_policy", "value": {"stringValue": "on-request"}},+ {"key": "sandbox_policy", "value": {"stringValue": "workspace-write"}},+ {"key": "mcp_servers", "value": {"stringValue": ""}},+ {"key": "event.timestamp", "value": {"stringValue": "2026-10-29T15:04:05.102Z"}},+ {"key": "conversation.id", "value": {"stringValue": "019a17e0-efe2-7ae3-b558-d333b8e7ce96"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "user.account_id", "value": {"stringValue": "8f1c2a6e-3b7d-4f0a-9c5e-2d4b6a8e0f13"}},+ {"key": "user.email", "value": {"stringValue": "[email protected]"}},+ {"key": "terminal.type", "value": {"stringValue": "codex-tui/0.164.0 (Mac OS 15.6.1; arm64) iTerm.app/3.6.5"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "slug", "value": {"stringValue": "gpt-5.5"}}+ ]+ },+ {+ "timeUnixNano": "1793286247417000000",+ "observedTimeUnixNano": "1793286247417000000",+ "severityNumber": 9,+ "severityText": "INFO",+ "eventName": "event otel/src/events/session_telemetry.rs:1179",+ "attributes": [+ {"key": "event.name", "value": {"stringValue": "codex.user_prompt"}},+ {"key": "prompt_length", "value": {"stringValue": "27"}},+ {"key": "prompt", "value": {"stringValue": "list the files in this repo"}},+ {"key": "event.timestamp", "value": {"stringValue": "2026-10-29T15:04:07.417Z"}},+ {"key": "conversation.id", "value": {"stringValue": "019a17e0-efe2-7ae3-b558-d333b8e7ce96"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "user.account_id", "value": {"stringValue": "8f1c2a6e-3b7d-4f0a-9c5e-2d4b6a8e0f13"}},+ {"key": "user.email", "value": {"stringValue": "[email protected]"}},+ {"key": "terminal.type", "value": {"stringValue": "codex-tui/0.164.0 (Mac OS 15.6.1; arm64) iTerm.app/3.6.5"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "slug", "value": {"stringValue": "gpt-5.5"}}+ ]+ }+ ]+ }+ ]+ }+ ]+ },+ "traces": {+ "resourceSpans": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeSpans": [+ {+ "scope": {+ "name": "codex-app-server"+ },+ "spans": [+ {+ "traceId": "4bf92f3577b34da6a3ce929d0e0e4736",+ "spanId": "00f067aa0ba902b7",+ "name": "session_task.turn",+ "kind": 1,+ "startTimeUnixNano": "1793286247417000000",+ "endTimeUnixNano": "1793286255837000000",+ "attributes": [+ {"key": "code.file.path", "value": {"stringValue": "core/src/tasks/mod.rs"}},+ {"key": "code.module.name", "value": {"stringValue": "codex_core::tasks"}},+ {"key": "code.line.number", "value": {"intValue": "369"}},+ {"key": "thread.id", "value": {"intValue": "23"}},+ {"key": "thread.name", "value": {"stringValue": "tokio-runtime-worker"}},+ {"key": "target", "value": {"stringValue": "codex_core::tasks"}},+ {"key": "thread.id", "value": {"stringValue": "019a17e0-efe2-7ae3-b558-d333b8e7ce96"}},+ {"key": "turn.id", "value": {"stringValue": "1"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "codex.turn.reasoning_effort", "value": {"stringValue": "medium"}},+ {"key": "codex.turn.token_usage.input_tokens", "value": {"intValue": "13347"}},+ {"key": "codex.turn.token_usage.cached_input_tokens", "value": {"intValue": "9984"}},+ {"key": "codex.turn.token_usage.cache_write_input_tokens", "value": {"intValue": "0"}},+ {"key": "codex.turn.token_usage.non_cached_input_tokens", "value": {"intValue": "3363"}},+ {"key": "codex.turn.token_usage.output_tokens", "value": {"intValue": "512"}},+ {"key": "codex.turn.token_usage.reasoning_output_tokens", "value": {"intValue": "64"}},+ {"key": "codex.turn.token_usage.total_tokens", "value": {"intValue": "13859"}},+ {"key": "busy_ns", "value": {"intValue": "41250000"}},+ {"key": "idle_ns", "value": {"intValue": "8378750000"}}+ ],+ "status": {}+ }+ ]+ }+ ]+ }+ ]+ },+ "metrics": {+ "resourceMetrics": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeMetrics": [+ {+ "scope": {+ "name": "codex"+ },+ "metrics": [+ {+ "name": "codex.turn.token_usage",+ "histogram": {+ "aggregationTemporality": 1,+ "dataPoints": [+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "total"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 13859.0,+ "min": 13859.0,+ "max": 13859.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 13347.0,+ "min": 13347.0,+ "max": 13347.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "cached_input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 9984.0,+ "min": 9984.0,+ "max": 9984.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "cache_write_input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 0.0,+ "min": 0.0,+ "max": 0.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "output"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 512.0,+ "min": 512.0,+ "max": 512.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "reasoning_output"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "cli"}},+ {"key": "originator", "value": {"stringValue": "codex-tui"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286247417000000",+ "timeUnixNano": "1793286257417000000",+ "count": "1",+ "sum": 64.0,+ "min": 64.0,+ "max": 64.0+ }+ ]+ }+ }+ ]+ }+ ]+ }+ ]+ }+}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-desktop-0.164.0.json b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-desktop-0.164.0.jsonnew file mode 100644index 00000000..e14dc17a--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/testdata/codex-app-server-desktop-0.164.0.json@@ -0,0 +1,277 @@+{+ "runtime": "Codex app-server (desktop app)",+ "version": "0.164.0",+ "originator": "Codex_Desktop",+ "conversation": "019a1802-4c1b-7d40-9e2f-6a0d3c5b7e21",+ "logs": {+ "resourceLogs": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "host.name", "value": {"stringValue": "mac-studio.local"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeLogs": [+ {+ "scope": {+ "name": "codex_otel.log_only"+ },+ "logRecords": [+ {+ "timeUnixNano": "1793286607102000000",+ "observedTimeUnixNano": "1793286607102000000",+ "severityNumber": 9,+ "severityText": "INFO",+ "eventName": "event otel/src/events/session_telemetry.rs:690",+ "attributes": [+ {"key": "event.name", "value": {"stringValue": "codex.conversation_starts"}},+ {"key": "provider_name", "value": {"stringValue": "OpenAI"}},+ {"key": "auth.env_openai_api_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_codex_api_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_codex_api_key_enabled", "value": {"boolValue": false}},+ {"key": "auth.env_provider_key_present", "value": {"boolValue": false}},+ {"key": "auth.env_refresh_token_url_override_present", "value": {"boolValue": false}},+ {"key": "reasoning_effort", "value": {"stringValue": "medium"}},+ {"key": "reasoning_summary", "value": {"stringValue": "auto"}},+ {"key": "context_window", "value": {"intValue": "272000"}},+ {"key": "auto_compact_token_limit", "value": {"intValue": "244800"}},+ {"key": "approval_policy", "value": {"stringValue": "on-request"}},+ {"key": "sandbox_policy", "value": {"stringValue": "workspace-write"}},+ {"key": "mcp_servers", "value": {"stringValue": ""}},+ {"key": "event.timestamp", "value": {"stringValue": "2026-10-29T15:10:07.102Z"}},+ {"key": "conversation.id", "value": {"stringValue": "019a1802-4c1b-7d40-9e2f-6a0d3c5b7e21"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "user.account_id", "value": {"stringValue": "8f1c2a6e-3b7d-4f0a-9c5e-2d4b6a8e0f13"}},+ {"key": "user.email", "value": {"stringValue": "[email protected]"}},+ {"key": "terminal.type", "value": {"stringValue": "Codex Desktop/0.164.0 (Mac OS 15.6.1; arm64) unknown"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "slug", "value": {"stringValue": "gpt-5.5"}}+ ]+ },+ {+ "timeUnixNano": "1793286609417000000",+ "observedTimeUnixNano": "1793286609417000000",+ "severityNumber": 9,+ "severityText": "INFO",+ "eventName": "event otel/src/events/session_telemetry.rs:1179",+ "attributes": [+ {"key": "event.name", "value": {"stringValue": "codex.user_prompt"}},+ {"key": "prompt_length", "value": {"stringValue": "27"}},+ {"key": "prompt", "value": {"stringValue": "list the files in this repo"}},+ {"key": "event.timestamp", "value": {"stringValue": "2026-10-29T15:10:09.417Z"}},+ {"key": "conversation.id", "value": {"stringValue": "019a1802-4c1b-7d40-9e2f-6a0d3c5b7e21"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "user.account_id", "value": {"stringValue": "8f1c2a6e-3b7d-4f0a-9c5e-2d4b6a8e0f13"}},+ {"key": "user.email", "value": {"stringValue": "[email protected]"}},+ {"key": "terminal.type", "value": {"stringValue": "Codex Desktop/0.164.0 (Mac OS 15.6.1; arm64) unknown"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "slug", "value": {"stringValue": "gpt-5.5"}}+ ]+ }+ ]+ }+ ]+ }+ ]+ },+ "traces": {+ "resourceSpans": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeSpans": [+ {+ "scope": {+ "name": "codex-app-server"+ },+ "spans": [+ {+ "traceId": "0af7651916cd43dd8448eb211c80319c",+ "spanId": "b7ad6b7169203331",+ "name": "session_task.turn",+ "kind": 1,+ "startTimeUnixNano": "1793286609417000000",+ "endTimeUnixNano": "1793286617837000000",+ "attributes": [+ {"key": "code.file.path", "value": {"stringValue": "core/src/tasks/mod.rs"}},+ {"key": "code.module.name", "value": {"stringValue": "codex_core::tasks"}},+ {"key": "code.line.number", "value": {"intValue": "369"}},+ {"key": "thread.id", "value": {"intValue": "23"}},+ {"key": "thread.name", "value": {"stringValue": "tokio-runtime-worker"}},+ {"key": "target", "value": {"stringValue": "codex_core::tasks"}},+ {"key": "thread.id", "value": {"stringValue": "019a1802-4c1b-7d40-9e2f-6a0d3c5b7e21"}},+ {"key": "turn.id", "value": {"stringValue": "1"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "codex.turn.reasoning_effort", "value": {"stringValue": "medium"}},+ {"key": "codex.turn.token_usage.input_tokens", "value": {"intValue": "13347"}},+ {"key": "codex.turn.token_usage.cached_input_tokens", "value": {"intValue": "9984"}},+ {"key": "codex.turn.token_usage.cache_write_input_tokens", "value": {"intValue": "0"}},+ {"key": "codex.turn.token_usage.non_cached_input_tokens", "value": {"intValue": "3363"}},+ {"key": "codex.turn.token_usage.output_tokens", "value": {"intValue": "512"}},+ {"key": "codex.turn.token_usage.reasoning_output_tokens", "value": {"intValue": "64"}},+ {"key": "codex.turn.token_usage.total_tokens", "value": {"intValue": "13859"}},+ {"key": "busy_ns", "value": {"intValue": "41250000"}},+ {"key": "idle_ns", "value": {"intValue": "8378750000"}}+ ],+ "status": {}+ }+ ]+ }+ ]+ }+ ]+ },+ "metrics": {+ "resourceMetrics": [+ {+ "resource": {+ "attributes": [+ {"key": "service.name", "value": {"stringValue": "codex-app-server"}},+ {"key": "service.version", "value": {"stringValue": "0.164.0"}},+ {"key": "env", "value": {"stringValue": "dev"}},+ {"key": "telemetry.sdk.language", "value": {"stringValue": "rust"}},+ {"key": "telemetry.sdk.name", "value": {"stringValue": "opentelemetry"}},+ {"key": "telemetry.sdk.version", "value": {"stringValue": "0.31.0"}}+ ]+ },+ "scopeMetrics": [+ {+ "scope": {+ "name": "codex"+ },+ "metrics": [+ {+ "name": "codex.turn.token_usage",+ "histogram": {+ "aggregationTemporality": 1,+ "dataPoints": [+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "total"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 13859.0,+ "min": 13859.0,+ "max": 13859.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 13347.0,+ "min": 13347.0,+ "max": 13347.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "cached_input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 9984.0,+ "min": 9984.0,+ "max": 9984.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "cache_write_input"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 0.0,+ "min": 0.0,+ "max": 0.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "output"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 512.0,+ "min": 512.0,+ "max": 512.0+ },+ {+ "attributes": [+ {"key": "token_type", "value": {"stringValue": "reasoning_output"}},+ {"key": "tmp_mem_enabled", "value": {"stringValue": "false"}},+ {"key": "auth_mode", "value": {"stringValue": "Chatgpt"}},+ {"key": "session_source", "value": {"stringValue": "vscode"}},+ {"key": "originator", "value": {"stringValue": "Codex_Desktop"}},+ {"key": "model", "value": {"stringValue": "gpt-5.5"}},+ {"key": "app.version", "value": {"stringValue": "0.164.0"}}+ ],+ "startTimeUnixNano": "1793286609417000000",+ "timeUnixNano": "1793286619417000000",+ "count": "1",+ "sum": 64.0,+ "min": 64.0,+ "max": 64.0+ }+ ]+ }+ }+ ]+ }+ ]+ }+ ]+ }+}diff --git a/docs/runtimes/codex-cli.mdx b/docs/runtimes/codex-cli.mdxindex bb340fd9..cf0e52d3 100644--- a/docs/runtimes/codex-cli.mdx+++ b/docs/runtimes/codex-cli.mdx@@ -26,7 +26,7 @@ Use `--include-codex-spans` during install or repair only when you need every ra### Codex CLI or Desktop-Codex CLI 0.158 and newer run on the same app-server as the desktop app, so both report the service name `codex-app-server`, and that name alone does not say which one a session ran in. Beacon goes by the `originator` attribute on Codex's log events instead: `Codex_Desktop` is recorded as `codex_desktop`, and `codex-tui` (the terminal), `codex_exec` (`codex exec`) and any other value as `codex_cli`. The usage span carries no originator, so it takes the surface its conversation's logs named; if it reaches the collector before those logs, Beacon waits up to ten seconds for them before writing it. A record that names neither, such as Codex's legacy token metric (which has no conversation id) or a usage span from a conversation whose logs never arrived, is recorded as `codex_cli`. Token reports still drop usage a Desktop session reports twice, through a turn span and a legacy metric or through live capture and `codex sync`. Events already in the log keep the name they were written with, so CLI 0.158+ sessions recorded before Beacon v1.3.48 still show as `codex_desktop`.+Codex CLI 0.158 and newer run on the same app-server as the desktop app, so both report the service name `codex-app-server`, and that name alone does not say which one a session ran in. Beacon goes by the `originator` Codex reports instead: `Codex_Desktop` is recorded as `codex_desktop`, and `codex-tui` (the terminal), `codex_exec` (`codex exec`), `codex_vscode` (the IDE extension) and any other value as `codex_cli`. Codex's log events and its legacy token metric carry the originator. The usage span does not, so it takes the surface its conversation's logs named; if it reaches the collector before those logs, Beacon waits up to ten seconds for them before writing it, and a usage span whose logs never arrive is recorded as `codex_cli`. `beacon endpoint codex sync` names each rollout the same way, from the originator in its `session_meta` line (`Codex Desktop` for the desktop app). Token reports still drop usage a Desktop session reports twice, through a turn span and a legacy metric or through live capture and `codex sync`. Events already in the log keep the name they were written with, so CLI 0.158+ sessions recorded before Beacon v1.3.48 still show as `codex_desktop`, and Desktop rollouts `codex sync` read before it went by the originator still show as `codex_cli`.### Session-file recoverydiff --git a/pkg/asymptoteobserve/harness.go b/pkg/asymptoteobserve/harness.goindex 6005780c..8bd97c80 100644--- a/pkg/asymptoteobserve/harness.go+++ b/pkg/asymptoteobserve/harness.go@@ -48,9 +48,8 @@ func NormalizeHarnessName(name string) string {return "antigravity_cli"// codex-app-server is not a Desktop name. The desktop app and, since about CLI 0.158, the terminal// CLI both run Codex's app-server and export OTLP under that one service name, so it falls- // through to codex_cli here. The collector exporter tells the two apart by the `originator`- // Codex reports on each conversation (beaconevent.CodexSurfaces) and names Desktop sessions- // codex_desktop there.+ // through to codex_cli here. What tells them apart is the `originator` Codex reports for each+ // conversation; CodexSurface maps it.case lower == "codex_desktop" || lower == "codex-desktop" || lower == "codex desktop":return "codex_desktop"case strings.Contains(lower, "codex"):@@ -419,3 +418,29 @@ func NormalizeHarnessName(name string) string {return ""}}++// CodexSurface is the harness a Codex originator names. Every Codex client (the terminal CLI,+// `codex exec`, the IDE extension, the desktop app) runs on Codex's app-server and reports its+// client name as `originator`: on OTLP records sanitized to a metric tag ("codex-tui",+// "codex_exec", "Codex_Desktop"), and verbatim in a rollout's session_meta ("Codex Desktop"). The+// live collector and `codex sync` both name a conversation from it, so one conversation gets one+// name on both paths. Only the desktop app is codex_desktop.+func CodexSurface(originator string) string {+ lower := strings.ToLower(strings.TrimSpace(originator))+ switch {+ case strings.Contains(lower, "desktop"):+ return "codex_desktop"+ // The IDE extension is the CLI's agent in an editor panel, with no harness of its own.+ case lower == "codex_vscode":+ return "codex_cli"+ default:+ return "codex_cli"+ }+}++// IsCodexAppServer reports whether a service name is Codex's app-server, the one the CLI and the+// desktop app share and that therefore needs an originator to place.+func IsCodexAppServer(serviceName string) bool {+ normalized := strings.NewReplacer("-", "", "_", "", " ", "").Replace(strings.ToLower(strings.TrimSpace(serviceName)))+ return normalized == "codexappserver"+}diff --git a/pkg/asymptoteobserve/harness_test.go b/pkg/asymptoteobserve/harness_test.goindex 46839728..bf5bc0d4 100644--- a/pkg/asymptoteobserve/harness_test.go+++ b/pkg/asymptoteobserve/harness_test.go@@ -58,6 +58,30 @@ func TestHarnessSpellingsConvergeOnCanonicalNames(t *testing.T) {}}+// Each originator Codex's clients report (openai/codex otel/src/metrics/tags.rs), in the spelling+// OTLP carries and, for the desktop app, the raw one a rollout's session_meta carries.+func TestCodexSurfaceNamesOnlyTheDesktopAppDesktop(t *testing.T) {+ for want, originators := range map[string][]string{+ "codex_desktop": {"Codex_Desktop", "Codex Desktop", "codex_desktop", "codex-desktop"},+ "codex_cli": {"codex-tui", "codex_exec", "codex_cli_rs", "codex-cli", "codex_vscode", "codex_sdk_ts",+ "codex_mcp_server", "codex-app-server-sdk", "other", ""},+ } {+ for _, originator := range originators {+ if got := CodexSurface(originator); got != want {+ t.Errorf("CodexSurface(%q) = %q, want %q", originator, got, want)+ }+ }+ }+ for name, want := range map[string]bool{+ "codex-app-server": true, "codex_app_server": true, "Codex App Server": true,+ "codex_cli_rs": false, "codex_exec": false, "codex-app-server-sdk": false, "": false,+ } {+ if got := IsCodexAppServer(name); got != want {+ t.Errorf("IsCodexAppServer(%q) = %t, want %t", name, got, want)+ }+ }+}+// Normalizing an already-canonical name must return it unchanged. vscode_copilot once collapsed// into copilot_cli, a different product, so anything that re-read and re-wrote an event silently// reassigned VS Code activity to the CLI.