@@ -163,9 +163,26 @@ type AgentTurnTimingSummary = {
|
163 | 163 | }; |
164 | 164 | |
165 | 165 | const agentTurnTimingLog = createSubsystemLogger("auto-reply/agent-turn-timing"); |
| 166 | +const agentCompactionLog = createSubsystemLogger("auto-reply/compaction"); |
| 167 | +const CODEX_APP_SERVER_COMPACTION_BACKEND = "codex-app-server"; |
166 | 168 | const AGENT_TURN_TIMING_WARN_TOTAL_MS = 1_000; |
167 | 169 | const AGENT_TURN_TIMING_WARN_STAGE_MS = 500; |
168 | 170 | |
| 171 | +function formatCompactionModelRef(provider?: string, model?: string): string { |
| 172 | +const normalizedProvider = normalizeOptionalString(provider); |
| 173 | +const normalizedModel = normalizeOptionalString(model); |
| 174 | +if (normalizedProvider && normalizedModel) { |
| 175 | +return `${sanitizeForLog(normalizedProvider)}/${sanitizeForLog(normalizedModel)}`; |
| 176 | +} |
| 177 | +if (normalizedProvider) { |
| 178 | +return sanitizeForLog(normalizedProvider); |
| 179 | +} |
| 180 | +if (normalizedModel) { |
| 181 | +return sanitizeForLog(normalizedModel); |
| 182 | +} |
| 183 | +return "unknown model"; |
| 184 | +} |
| 185 | + |
169 | 186 | function createAgentTurnTimingTracker(options: { profilerEnabled?: boolean } = {}): { |
170 | 187 | measure: <T>(name: string, run: () => Promise<T> | T) => Promise<T>; |
171 | 188 | measureSync: <T>(name: string, run: () => T) => T; |
@@ -2710,6 +2727,7 @@ export async function runAgentTurnWithFallback(params: {
|
2710 | 2727 | } |
2711 | 2728 | if (evt.stream === "compaction") { |
2712 | 2729 | const phase = readStringValue(evt.data.phase) ?? ""; |
| 2730 | +const backend = readStringValue(evt.data.backend); |
2713 | 2731 | const hookMessages = readCompactionHookMessages(evt.data.messages); |
2714 | 2732 | const sendCompactionUserNotices = async ( |
2715 | 2733 | noticePhase: "start" | "end" | "incomplete", |
@@ -2731,6 +2749,28 @@ export async function runAgentTurnWithFallback(params: {
|
2731 | 2749 | const completed = evt.data?.completed === true; |
2732 | 2750 | if (completed) { |
2733 | 2751 | attemptCompactionCount += 1; |
| 2752 | +if (backend === CODEX_APP_SERVER_COMPACTION_BACKEND) { |
| 2753 | +const modelRef = formatCompactionModelRef(provider, model); |
| 2754 | +const consoleMessage = |
| 2755 | +`codex app-server auto-compaction succeeded for ${modelRef}; ` + |
| 2756 | +"refreshed session context"; |
| 2757 | +agentCompactionLog.info( |
| 2758 | +"codex app-server auto-compaction succeeded", |
| 2759 | +{ |
| 2760 | +event: "codex_app_server_compaction_succeeded", |
| 2761 | + backend, |
| 2762 | + provider, |
| 2763 | + model, |
| 2764 | +sessionKey: params.sessionKey, |
| 2765 | +sessionId: effectiveRun.sessionId, |
| 2766 | +threadId: readStringValue(evt.data.threadId), |
| 2767 | +turnId: readStringValue(evt.data.turnId), |
| 2768 | +itemId: readStringValue(evt.data.itemId), |
| 2769 | +compactionCount: attemptCompactionCount, |
| 2770 | + consoleMessage, |
| 2771 | +}, |
| 2772 | +); |
| 2773 | +} |
2734 | 2774 | if (params.opts?.onCompactionEnd) { |
2735 | 2775 | await params.opts.onCompactionEnd(); |
2736 | 2776 | } |
|