DashboardCodeLOREAI-GATEWAY-1E: resp.usage undefined…

LOREAI-GATEWAY-1E: resp.usage undefined crash in postResponse() for vLLM/OpenAI path

Category: gotcha
Confidence: 1.00
ID: 019e69f0-a05a-7d48-8e35-76baf13533c5
Project ID: ffa98226-3908-4f0c-936b-969018c62abf
Cross-project: No
Recalled in other projects: 2
Source session: (none)
Created: 2026-06-09 11:33:48
Updated: 2026-06-11 23:54:05

Cross-Project Recalls

ProjectHitsLast recalled
opencode-lore 11 13h ago
opencode 1 8d ago

Content

Trap: GatewayUsage typed as non-optional on GatewayResponse, so resp.usage.inputTokens looks safe. But resp.usage can be undefined at runtime (e.g., vLLM returning partial response). All four accumulators construct usage with ?? 0 guards on individual fields — but resp.usage itself can still be undefined if an exception produces a partial response object. Crash sites: pipeline.ts lines 2069, 2101, 2137-2140, 2150-2153, 2204-2206, 2282-2285, 2341, 2363, 2402; also buildOpenAINonStreamResponse (openai.ts:296-300). Fix: add const usage = resp.usage ?? { inputTokens: 0, outputTokens: 0, cacheReadInputTokens: 0, cacheCreationInputTokens: 0 } guard at top of postResponse() and nonStreamHttpResponse(), then use usage.* throughout.

Move to: