Skip to content

Commit cb7b2eb

Browse files
committed
🤖 fix: add contextUsage fields to MuxMessageSchema
The MuxMessageSchema metadata object was missing contextUsage and contextProviderMetadata fields. When messages were serialized through oRPC/Zod, these fields were silently stripped (Zod's default behavior). This caused context usage to display cumulative usage (from the 'usage' field) instead of last-step usage (from 'contextUsage'), resulting in wildly inflated percentages (e.g., 944% instead of ~50%) after app restart. The bug only appeared after restart because during live streaming, the frontend received the fields before oRPC serialization. On reload, messages pass through the schema and lose the fields. _Generated with mux_
1 parent ca4c4bf commit cb7b2eb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/common/orpc/schemas/message.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ export const MuxMessageSchema = z.object({
7676
timestamp: z.number().optional(),
7777
model: z.string().optional(),
7878
usage: z.any().optional(),
79+
// Last step's usage only (for context window display)
80+
contextUsage: z.any().optional(),
7981
providerMetadata: z.record(z.string(), z.unknown()).optional(),
82+
// Last step's provider metadata (for context window cache display)
83+
contextProviderMetadata: z.record(z.string(), z.unknown()).optional(),
8084
duration: z.number().optional(),
8185
systemMessageTokens: z.number().optional(),
8286
muxMetadata: z.any().optional(),

0 commit comments

Comments
 (0)