fix: diagnose code agent by agentrun ids

This commit is contained in:
Codex
2026-06-26 22:15:12 +00:00
parent 5ddb63ef37
commit 8aae34f610
7 changed files with 191 additions and 14 deletions
@@ -39,6 +39,7 @@ export function observabilityHelp(): Record<string, unknown> {
"bun scripts/cli.ts platform-infra observability search --target D601 --grep 'no rollout found' [--lookback-minutes 360] [--candidate-limit 80] [--limit 20] [--full|--raw]",
"bun scripts/cli.ts platform-infra observability search --target D601 --path /v1/workbench/sessions --status 502 [--lookback-minutes 120] [--full|--raw]",
"bun scripts/cli.ts platform-infra observability diagnose-code-agent --target D601 --business-trace-id <trc_...> [--full|--raw]",
"bun scripts/cli.ts platform-infra observability diagnose-code-agent --target D601 --run-id <run_...> [--command-id <cmd_...>] [--runner-job-id <rjob_...>] [--full|--raw]",
],
boundary: "Prometheus remains the metrics source; this command owns only platform-infra OTel Collector, trace backend readiness, and trace lookup.",
};
@@ -217,6 +218,9 @@ export function parseDiagnoseCodeAgentOptions(args: string[]): DiagnoseCodeAgent
const commonArgs: string[] = [];
let businessTraceId: string | null = null;
let traceId: string | null = null;
let runId: string | null = null;
let commandId: string | null = null;
let runnerJobId: string | null = null;
let limit = 40;
let candidateLimit = 300;
let lookbackMinutes = 10080;
@@ -234,6 +238,24 @@ export function parseDiagnoseCodeAgentOptions(args: string[]): DiagnoseCodeAgent
if (!/^[0-9a-fA-F]{32}$/u.test(value)) throw new Error(`${arg} must be a 32-character OpenTelemetry trace id encoded as hex`);
traceId = value.toLowerCase();
index += 1;
} else if (arg === "--run-id" || arg === "--run") {
const value = args[index + 1];
if (value === undefined || value.startsWith("--")) throw new Error(`${arg} requires a value`);
if (!/^run_[A-Za-z0-9_-]+$/u.test(value)) throw new Error(`${arg} must look like run_<id>`);
runId = value;
index += 1;
} else if (arg === "--command-id" || arg === "--command") {
const value = args[index + 1];
if (value === undefined || value.startsWith("--")) throw new Error(`${arg} requires a value`);
if (!/^cmd_[A-Za-z0-9_-]+$/u.test(value)) throw new Error(`${arg} must look like cmd_<id>`);
commandId = value;
index += 1;
} else if (arg === "--runner-job-id" || arg === "--runner-job" || arg === "--runnerjob") {
const value = args[index + 1];
if (value === undefined || value.startsWith("--")) throw new Error(`${arg} requires a value`);
if (!/^rjob_[A-Za-z0-9_-]+$/u.test(value)) throw new Error(`${arg} must look like rjob_<id>`);
runnerJobId = value;
index += 1;
} else if (arg === "--limit") {
const value = args[index + 1];
if (value === undefined || value.startsWith("--")) throw new Error("--limit requires a value");
@@ -263,6 +285,8 @@ export function parseDiagnoseCodeAgentOptions(args: string[]): DiagnoseCodeAgent
}
}
}
if (businessTraceId === null && traceId === null) throw new Error("observability diagnose-code-agent requires --business-trace-id <trc_...> or --trace-id <otelTraceId>");
return { ...parseCommonOptions(commonArgs), businessTraceId, traceId, limit, candidateLimit, lookbackMinutes };
if (businessTraceId === null && traceId === null && runId === null && commandId === null && runnerJobId === null) {
throw new Error("observability diagnose-code-agent requires --business-trace-id <trc_...>, --trace-id <otelTraceId>, --run-id <run_...>, --command-id <cmd_...>, or --runner-job-id <rjob_...>");
}
return { ...parseCommonOptions(commonArgs), businessTraceId, traceId, runId, commandId, runnerJobId, limit, candidateLimit, lookbackMinutes };
}