fix(otel): bound code-agent full diagnosis output
This commit is contained in:
@@ -800,7 +800,13 @@ async function diagnoseCodeAgent(config: UniDeskConfig, options: DiagnoseCodeAge
|
||||
}
|
||||
const exposedResult = parsed === null
|
||||
? compactCapture(result, { full: true })
|
||||
: redactSensitiveUnknown(parsed);
|
||||
: options.raw
|
||||
? redactSensitiveUnknown(parsed)
|
||||
: {
|
||||
...compactDiagnoseCodeAgentResult(parsed),
|
||||
outputMode: "bounded-compact-json",
|
||||
rawDisclosure: "Use --raw only for Tempo/API envelope or CLI parser debugging.",
|
||||
};
|
||||
return {
|
||||
ok,
|
||||
action: "platform-infra-observability-diagnose-code-agent",
|
||||
@@ -1369,13 +1375,13 @@ function compactDiagnoseCodeAgentResult(value: unknown): Record<string, unknown>
|
||||
services: source.services ?? null,
|
||||
servicePath: source.servicePath ?? null,
|
||||
businessTraceIds: source.businessTraceIds ?? null,
|
||||
identity: source.identity ?? null,
|
||||
agentrun: compactRecord(source.agentrun, ["terminalStatus", "terminalSource", "latestSeq", "terminalEventType", "runnerProviderClassification", "authority"]),
|
||||
identity: compactDiagnoseIdentity(source.identity),
|
||||
agentrun: compactDiagnoseAgentRun(source.agentrun),
|
||||
hwlabReadModel: source.hwlabReadModel ?? null,
|
||||
http: source.http ?? null,
|
||||
http: compactDiagnoseHttp(source.http),
|
||||
projectionLag: source.projectionLag ?? null,
|
||||
summary: source.summary ?? null,
|
||||
rootCauseCandidates: asArray(source.rootCauseCandidates).slice(0, 5).map(compactRootCauseCandidate),
|
||||
rootCauseCandidates: asArray(source.rootCauseCandidates).slice(0, 3).map(compactRootCauseCandidate),
|
||||
spanNameCounts: compactNameCounts(source.spanNameCounts, 6),
|
||||
evidence: evidence === null ? null : {
|
||||
httpProblemSpanCount: evidence.httpProblemSpanCount ?? null,
|
||||
@@ -1385,17 +1391,101 @@ function compactDiagnoseCodeAgentResult(value: unknown): Record<string, unknown>
|
||||
errorSpanCount: evidence.errorSpanCount ?? null,
|
||||
errorSpanSampleNames: evidence.errorSpanSampleNames ?? null,
|
||||
idleWarningSpanCount: evidence.idleWarningSpanCount ?? null,
|
||||
idleWarningSpanTail: compactSpanList(evidence.idleWarningSpanTail, 3),
|
||||
idleWarningSpanTail: compactSpanList(evidence.idleWarningSpanTail, 1),
|
||||
},
|
||||
next: compactDiagnoseNext(source.next),
|
||||
stderrTail: source.stderrTail ?? null,
|
||||
disclosure: {
|
||||
defaultView: "compact diagnosis only; detailed span evidence is omitted to keep stdout below config/unidesk-cli.yaml output.maxStdoutBytes",
|
||||
expand: "rerun diagnose-code-agent with --full, or query a specific trace id with platform-infra observability trace --grep <span>",
|
||||
defaultView: "compact diagnosis; --full is bounded JSON, not a span dump",
|
||||
expand: "use trace --grep <span> --full for span evidence; use diagnose-code-agent --raw only for parser/envelope debugging",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function compactDiagnoseIdentity(value: unknown): Record<string, unknown> | null {
|
||||
return compactRecord(value, [
|
||||
"runId",
|
||||
"commandId",
|
||||
"sessionId",
|
||||
"turnId",
|
||||
"runnerJobId",
|
||||
"runnerId",
|
||||
"backendProfile",
|
||||
"sourceCommit",
|
||||
"jobName",
|
||||
"namespace",
|
||||
]);
|
||||
}
|
||||
|
||||
function compactDiagnoseHttp(value: unknown): Record<string, unknown> | null {
|
||||
const http = asPlainRecord(value);
|
||||
if (http === null) return null;
|
||||
return {
|
||||
problemCounts: http.problemCounts ?? null,
|
||||
problemSpanCount: http.problemSpanCount ?? null,
|
||||
statusCounts: asArray(http.statusCounts).slice(0, 4),
|
||||
};
|
||||
}
|
||||
|
||||
function compactDiagnoseAgentRun(value: unknown): Record<string, unknown> | null {
|
||||
const agentrun = asPlainRecord(value);
|
||||
if (agentrun === null) return null;
|
||||
return {
|
||||
terminalStatus: agentrun.terminalStatus ?? null,
|
||||
terminalSource: agentrun.terminalSource ?? null,
|
||||
latestSeq: agentrun.latestSeq ?? null,
|
||||
terminalEventType: agentrun.terminalEventType ?? null,
|
||||
runnerProviderClassification: agentrun.runnerProviderClassification ?? null,
|
||||
authority: compactAgentRunAuthority(agentrun.authority),
|
||||
};
|
||||
}
|
||||
|
||||
function compactAgentRunAuthority(value: unknown): Record<string, unknown> | null {
|
||||
const authority = asPlainRecord(value);
|
||||
if (authority === null) return null;
|
||||
const result: Record<string, unknown> = {
|
||||
queried: authority.queried ?? null,
|
||||
namespace: authority.namespace ?? null,
|
||||
ok: authority.ok ?? null,
|
||||
commandOk: authority.commandOk ?? null,
|
||||
resultOk: authority.resultOk ?? null,
|
||||
eventsOk: authority.eventsOk ?? null,
|
||||
commandState: authority.commandState ?? null,
|
||||
commandStatus: authority.commandStatus ?? null,
|
||||
resultTerminalStatus: authority.resultTerminalStatus ?? null,
|
||||
resultStatus: authority.resultStatus ?? null,
|
||||
terminalStatus: authority.terminalStatus ?? null,
|
||||
terminalSource: authority.terminalSource ?? null,
|
||||
terminalEventSeq: authority.terminalEventSeq ?? null,
|
||||
terminalEventType: authority.terminalEventType ?? null,
|
||||
latestSeq: authority.latestSeq ?? null,
|
||||
eventCount: authority.eventCount ?? null,
|
||||
fallback: authority.fallback ?? null,
|
||||
error: authority.error ?? null,
|
||||
warnings: limitArray(authority.warnings, 3),
|
||||
};
|
||||
const ok = authority.ok === true && authority.commandOk === true && authority.resultOk === true && authority.eventsOk === true;
|
||||
if (!ok) {
|
||||
result.attempts = compactAgentRunAuthorityAttempts(authority.attempts);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function compactAgentRunAuthorityAttempts(value: unknown): unknown[] {
|
||||
return asArray(value).slice(0, 3).map((item) => {
|
||||
const attempt = asPlainRecord(item) ?? {};
|
||||
return {
|
||||
name: attempt.name ?? attempt.section ?? attempt.kind ?? null,
|
||||
ok: attempt.ok ?? null,
|
||||
status: attempt.status ?? null,
|
||||
exitCode: attempt.exitCode ?? null,
|
||||
url: attempt.url ?? null,
|
||||
error: shortenEnd(textValue(attempt.error), 240),
|
||||
stderrTail: shortenEnd(textValue(attempt.stderrTail ?? attempt.stderr), 500),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function compactDiagnoseCandidate(value: unknown): Record<string, unknown> {
|
||||
const candidate = asPlainRecord(value) ?? {};
|
||||
return {
|
||||
@@ -1407,13 +1497,12 @@ function compactDiagnoseCandidate(value: unknown): Record<string, unknown> {
|
||||
spanCount: candidate.spanCount ?? null,
|
||||
services: candidate.services ?? null,
|
||||
servicePath: candidate.servicePath ?? null,
|
||||
identity: candidate.identity ?? null,
|
||||
identity: compactDiagnoseIdentity(candidate.identity),
|
||||
terminalStatus: candidate.terminalStatus ?? null,
|
||||
errorSpanCount: candidate.errorSpanCount ?? null,
|
||||
candidateQuality: candidate.candidateQuality ?? null,
|
||||
lowConfidence: candidate.lowConfidence ?? null,
|
||||
spanNamePreview: limitArray(candidate.spanNamePreview, 5),
|
||||
traceCommand: candidate.traceCommand ?? null,
|
||||
spanNamePreview: limitArray(candidate.spanNamePreview, 4),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user