From ffd01045d01435e3c3099e7878d4e6023f9cceaf Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Tue, 21 Jul 2026 14:23:12 -0700 Subject: [PATCH] fix(ingestion): merge task usage field-wise instead of wholesale replace A payload carrying only totalTokens (e.g. terminal task_notification) no longer wipes previously known input/output/toolUses breakdowns. Co-Authored-By: Claude Fable 5 --- .../src/orchestration/Layers/ProviderRuntimeIngestion.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts index a62ffb66d4..aa4d62f828 100644 --- a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts +++ b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts @@ -186,7 +186,11 @@ export function foldTaskAgentEvent( ...((lastToolName ?? previous?.lastToolName) ? { lastToolName: lastToolName ?? previous?.lastToolName } : {}), - ...((nextUsage ?? previous?.usage) ? { usage: nextUsage ?? previous?.usage } : {}), + // Merge field-wise: a payload carrying only totalTokens (e.g. a terminal + // Claude task_notification) must not wipe previously known breakdowns. + ...(nextUsage || previous?.usage + ? { usage: { ...previous?.usage, ...nextUsage } as ThreadAgentUsage } + : {}), firstStartedAt: previous?.firstStartedAt ?? event.createdAt, lastActivityAt: event.createdAt, ...(!reactivated && (explicitEndTime ?? (terminal ? event.createdAt : previous?.endedAt))