From 6222744119e52efdbd086a07282ea8357301b571 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 1 Jul 2026 16:39:40 +0000 Subject: [PATCH] fix: surface provider decision in otel diagnostics --- .../apply-status-scripts.ts | 3 +- .../diagnose-code-agent-script.ts | 83 +++++++++++++++++++ .../platform-infra-observability/render.ts | 27 ++++++ 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/scripts/src/platform-infra-observability/apply-status-scripts.ts b/scripts/src/platform-infra-observability/apply-status-scripts.ts index 62d19c00..60e26529 100644 --- a/scripts/src/platform-infra-observability/apply-status-scripts.ts +++ b/scripts/src/platform-infra-observability/apply-status-scripts.ts @@ -90,6 +90,7 @@ export function compactDiagnoseCodeAgentResult(value: unknown): Record { const row = asPlainRecord(item) ?? {}; return [shortenEnd(textValue(row.name), 64), textValue(row.count)]; @@ -406,6 +407,9 @@ export function renderTraceTable(input: { "Identity:", formatTable(["FIELD", "VALUE"], identityRows.length > 0 ? identityRows : [["-", "-"]]), "", + "Provider decision:", + formatTable(["SERVICE", "PROFILE", "SOURCE", "DEFAULT", "MODEL", "ADAPTER", "RUNNER_NS", "SESSION"], providerRows.length > 0 ? providerRows : [["-", "-", "-", "-", "-", "-", "-", "-"]]), + "", "Key spans:", formatTable(["NAME", "SERVICE", "ROUTE", "STATUS", "DUR_MS", "RES_MS", "FETCH_REQ", "REQ_WAIT", "RESP_XFER", "PROTO", "DETAIL"], spanRows.length > 0 ? spanRows : [["-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"]]), "", @@ -483,6 +487,27 @@ function traceRunnerRows(spans: Record[]): string[][] { return dedupeRows(rows).slice(0, 12); } +function traceProviderDecisionRows(spans: Record[]): string[][] { + const rows = spans.filter((span) => { + const attrs = asPlainRecord(span.attributes); + return textValue(span.name) === "provider_decision" + || spanColumnAttr(attrs, ["agent.chat.provider_profile", "providerProfile", "defaultProviderProfile"]) !== "-"; + }).map((span) => { + const attrs = asPlainRecord(span.attributes); + return [ + shortenEnd(textValue(span.service), 20), + shortenEnd(spanColumnAttr(attrs, ["agent.chat.provider_profile", "providerProfile", "backendProfile", "defaultProviderProfile"]), 22), + shortenEnd(spanColumnAttr(attrs, ["agent.chat.provider_profile_source", "providerProfileSource"]), 12), + shortenEnd(spanColumnAttr(attrs, ["defaultProviderProfile"]), 22), + shortenEnd(spanColumnAttr(attrs, ["agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model", "model", "modelId", "providerModel"]), 28), + shortenEnd(spanColumnAttr(attrs, ["adapter"]), 16), + shortenEnd(spanColumnAttr(attrs, ["agentRunRunnerNamespace"]), 16), + shortenMiddle(spanColumnAttr(attrs, ["agent.chat.session_id", "sessionId", "workbench.session_id"]), 24), + ]; + }); + return dedupeRows(rows).slice(0, 8); +} + function traceReadWindowRows(spans: Record[]): string[][] { const rows = spans.filter((span) => textValue(span.name) === "trace_events_read").map((span) => { const attrs = asPlainRecord(span.attributes); @@ -678,6 +703,7 @@ export function renderDiagnoseCodeAgentTable(input: { const evidence = asPlainRecord(input.result.evidence); const observabilityGap = asPlainRecord(input.result.observabilityGap); const servicePath = asPlainRecord(input.result.servicePath); + const providerDecision = asPlainRecord(input.result.providerDecision); const rootCauses = asArray(input.result.rootCauseCandidates).map((item) => asPlainRecord(item) ?? {}); const http = asPlainRecord(input.result.http); const services = joinValues(input.result.services, 54); @@ -727,6 +753,7 @@ export function renderDiagnoseCodeAgentTable(input: { ` requested runId=${requestedRunId} commandId=${requestedCommandId} sessionId=${requestedSessionId} runnerJobId=${requestedRunnerJobId}`, ` observed runId=${observedRunId} commandId=${observedCommandId} sessionId=${observedSessionId} runnerJobId=${observedRunnerJobId} runnerId=${textValue(identity?.runnerId)}`, ` backendProfile=${textValue(identity?.backendProfile)} sourceCommit=${shortenMiddle(textValue(identity?.sourceCommit), 20)}`, + ` providerProfile=${textValue(providerDecision?.providerProfile)} model=${textValue(providerDecision?.model)} source=${textValue(providerDecision?.providerProfileSource)} adapter=${textValue(providerDecision?.adapter)} runnerNamespace=${textValue(providerDecision?.runnerNamespace)}`, "", "Root causes:", formatTable(["CODE", "CONF", "SUMMARY"], rootRows.length > 0 ? rootRows : [["-", "-", "-"]]),