From 3022b577c6238f50d9d57f1613609a882e718786 Mon Sep 17 00:00:00 2001 From: Stephen Schoettler Date: Thu, 26 Feb 2026 12:08:28 -0800 Subject: [PATCH 1/2] fix: add null guards to usage sort comparators Prevents crash when totals is undefined in byModel/byProvider/byAgent sort comparators. Fixes 'Cannot read properties of undefined (reading totalTokens)' crash that causes context overflow in active sessions. --- src/gateway/server-methods/usage.ts | 10 +++++----- src/infra/session-cost-usage.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gateway/server-methods/usage.ts b/src/gateway/server-methods/usage.ts index e40af58f5fe..3546c25723c 100644 --- a/src/gateway/server-methods/usage.ts +++ b/src/gateway/server-methods/usage.ts @@ -844,22 +844,22 @@ export const usageHandlers: GatewayRequestHandlers = { .toSorted((a, b) => b.count - a.count), }, byModel: Array.from(byModelMap.values()).toSorted((a, b) => { - const costDiff = b.totals.totalCost - a.totals.totalCost; + const costDiff = (b.totals?.totalCost ?? 0) - (a.totals?.totalCost ?? 0); if (costDiff !== 0) { return costDiff; } - return b.totals.totalTokens - a.totals.totalTokens; + return (b.totals?.totalTokens ?? 0) - (a.totals?.totalTokens ?? 0); }), byProvider: Array.from(byProviderMap.values()).toSorted((a, b) => { - const costDiff = b.totals.totalCost - a.totals.totalCost; + const costDiff = (b.totals?.totalCost ?? 0) - (a.totals?.totalCost ?? 0); if (costDiff !== 0) { return costDiff; } - return b.totals.totalTokens - a.totals.totalTokens; + return (b.totals?.totalTokens ?? 0) - (a.totals?.totalTokens ?? 0); }), byAgent: Array.from(byAgentMap.entries()) .map(([id, totals]) => ({ agentId: id, totals })) - .toSorted((a, b) => b.totals.totalCost - a.totals.totalCost), + .toSorted((a, b) => (b.totals?.totalCost ?? 0) - (a.totals?.totalCost ?? 0)), ...tail, }; diff --git a/src/infra/session-cost-usage.ts b/src/infra/session-cost-usage.ts index 230ebd60c2e..4c021bcc72f 100644 --- a/src/infra/session-cost-usage.ts +++ b/src/infra/session-cost-usage.ts @@ -707,11 +707,11 @@ export async function loadSessionCostSummary(params: { const modelUsage = modelUsageMap.size ? Array.from(modelUsageMap.values()).toSorted((a, b) => { - const costDiff = b.totals.totalCost - a.totals.totalCost; + const costDiff = (b.totals?.totalCost ?? 0) - (a.totals?.totalCost ?? 0); if (costDiff !== 0) { return costDiff; } - return b.totals.totalTokens - a.totals.totalTokens; + return (b.totals?.totalTokens ?? 0) - (a.totals?.totalTokens ?? 0); }) : undefined; From 200f8c0f0340c12181dca28a712a53436f09588b Mon Sep 17 00:00:00 2001 From: Stephen Schoettler Date: Thu, 26 Feb 2026 12:16:28 -0800 Subject: [PATCH 2/2] fix(browser): prevent stdio buffer blocking in Docker environments --- src/browser/chrome.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/chrome.ts b/src/browser/chrome.ts index 9501d1e4d98..6e994cdcda3 100644 --- a/src/browser/chrome.ts +++ b/src/browser/chrome.ts @@ -226,7 +226,7 @@ export async function launchOpenClawChrome( args.push("about:blank"); return spawn(exe.path, args, { - stdio: "pipe", + stdio: ["ignore", "ignore", "ignore"], env: { ...process.env, // Reduce accidental sharing with the user's env.