From e183d665eea7a9fb37834a35c5f11a079b3d94cd Mon Sep 17 00:00:00 2001 From: krissding Date: Mon, 6 Jul 2026 13:41:07 +0800 Subject: [PATCH] fix(infra): add NaN guard for unparseable timestamp in session-cost-usage (#99420) new Date(parsed.timestamp).getTime() can return NaN for unparseable strings. Without a guard, NaN silently propagates into downstream usage/cost calculations and corrupts billing data. Add Number.isNaN(timestamp) check, falling back to 0 (same default as the path when no timestamp key is present). Co-authored-by: Claude Sonnet 4.6 --- src/infra/session-cost-usage.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/infra/session-cost-usage.ts b/src/infra/session-cost-usage.ts index fe6f16fda277..e2f4d41d26a7 100644 --- a/src/infra/session-cost-usage.ts +++ b/src/infra/session-cost-usage.ts @@ -2743,6 +2743,9 @@ export async function loadSessionLogs(params: { let timestamp = 0; if (typeof parsed.timestamp === "string") { timestamp = new Date(parsed.timestamp).getTime(); + if (Number.isNaN(timestamp)) { + timestamp = 0; + } } else if (typeof message.timestamp === "number") { timestamp = message.timestamp; }