diff --git a/extensions/codex/src/app-server/event-projector.ts b/extensions/codex/src/app-server/event-projector.ts index 4212b1ad78c..9653d8aaf71 100644 --- a/extensions/codex/src/app-server/event-projector.ts +++ b/extensions/codex/src/app-server/event-projector.ts @@ -816,29 +816,24 @@ export class CodexAppServerEventProjector { typeof params.item.durationMs === "number" ? params.item.durationMs : undefined; const durationMs = itemDurationMs ?? (startedAt === undefined ? 0 : Math.max(0, Date.now() - startedAt)); - if (params.status === "blocked") { - emitTrustedDiagnosticEvent({ - type: "tool.execution.blocked", - ...base, - reason: "codex_native_tool_blocked", - deniedReason: "codex_native_tool_blocked", - }); - return; - } - if (params.status === "failed") { - emitTrustedDiagnosticEvent({ - type: "tool.execution.error", - ...base, - durationMs, - errorCategory: "codex_native_tool_error", - }); - return; - } - emitTrustedDiagnosticEvent({ - type: "tool.execution.completed", - ...base, - durationMs, - }); + const terminalEvent = + params.status === "blocked" + ? { + type: "tool.execution.blocked" as const, + reason: "codex_native_tool_blocked", + deniedReason: "codex_native_tool_blocked", + } + : params.status === "failed" + ? { + type: "tool.execution.error" as const, + durationMs, + errorCategory: "codex_native_tool_error", + } + : { + type: "tool.execution.completed" as const, + durationMs, + }; + emitTrustedDiagnosticEvent({ ...base, ...terminalEvent }); } private emitToolResultSummary(item: CodexThreadItem | undefined): void { diff --git a/src/logging/diagnostic-run-activity.ts b/src/logging/diagnostic-run-activity.ts index 801f08e0882..adb3758c378 100644 --- a/src/logging/diagnostic-run-activity.ts +++ b/src/logging/diagnostic-run-activity.ts @@ -21,6 +21,11 @@ type ActiveTool = { lastProgressAt: number; }; +type DiagnosticToolStartedActivityEvent = Pick< + Extract, + "runId" | "sessionId" | "sessionKey" | "toolName" | "toolCallId" +>; + export type DiagnosticSessionActivitySnapshot = { activeWorkKind?: DiagnosticSessionActiveWorkKind; activeToolName?: string; @@ -158,9 +163,7 @@ function modelCallKey(event: { runId?: string; provider?: string; model?: string return `${event.runId ?? "unknown"}:${event.provider ?? "provider"}:${event.model ?? "model"}`; } -function recordToolStarted( - event: Extract, -): void { +function recordToolStarted(event: DiagnosticToolStartedActivityEvent): void { const activity = resolveSessionActivity({ ...event, create: true }); if (!activity) { return; @@ -314,18 +317,7 @@ export function markDiagnosticToolStartedForTest(params: { toolName: string; toolCallId?: string; }): void { - const activity = resolveSessionActivity({ ...params, create: true }); - if (!activity) { - return; - } - const now = Date.now(); - activity.activeTools.set(toolKey(params), { - toolName: params.toolName, - toolCallId: params.toolCallId, - startedAt: now, - lastProgressAt: now, - }); - touchSessionActivity(activity, `tool:${params.toolName}:started`, now); + recordToolStarted(params); } export function resetDiagnosticRunActivityForTest(): void {