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 <noreply@anthropic.com>
This commit is contained in:
krissding
2026-07-06 13:41:07 +08:00
committed by GitHub
parent f7f1be276a
commit e183d665ee
+3
View File
@@ -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;
}