@@ -268,17 +268,29 @@ function normalizeUsageAttempt(raw: unknown): PersistedUsageAttempt | null {
268268 ...( typeof attempt . reasoningWireField === "string" && attempt . reasoningWireField
269269 ? { reasoningWireField : capMetadataString ( attempt . reasoningWireField ) }
270270 : { } ) ,
271- ...( typeof attempt . reasoningWireValue === "string" && attempt . reasoningWireValue
272- ? { reasoningWireValue : capMetadataString ( attempt . reasoningWireValue ) }
273- : typeof attempt . reasoningWireValue === "boolean"
274- && attempt . reasoningWireField === "reasoning.enabled"
275- ? { reasoningWireValue : attempt . reasoningWireValue }
276- : isNonNegativeFiniteNumber ( attempt . reasoningWireValue )
277- ? { reasoningWireValue : attempt . reasoningWireValue }
278- : { } ) ,
271+ ...( isValidReasoningWireValue ( attempt . reasoningWireField , attempt . reasoningWireValue )
272+ ? typeof attempt . reasoningWireValue === "string"
273+ ? { reasoningWireValue : capMetadataString ( attempt . reasoningWireValue ) }
274+ : { reasoningWireValue : attempt . reasoningWireValue }
275+ : { } ) ,
279276 } ;
280277}
281278
279+ /**
280+ * Pairing rule for reasoning diagnostics, shared with the live request-log capture path:
281+ * a non-empty string, a non-negative finite number, or a boolean only for
282+ * `reasoning.enabled`. The field name itself is validated separately at capture time;
283+ * persisted rows may carry legacy field names, so this checks only the value shape.
284+ */
285+ export function isValidReasoningWireValue (
286+ wireField : unknown ,
287+ wireValue : unknown ,
288+ ) : wireValue is string | number | boolean {
289+ return ( typeof wireValue === "string" && wireValue . length > 0 )
290+ || ( typeof wireValue === "number" && Number . isFinite ( wireValue ) && wireValue >= 0 )
291+ || ( wireField === "reasoning.enabled" && typeof wireValue === "boolean" ) ;
292+ }
293+
282294function normalizedAttempts ( raw : unknown ) : PersistedUsageAttempt [ ] {
283295 if ( ! Array . isArray ( raw ) ) return [ ] ;
284296 return raw . map ( normalizeUsageAttempt )
@@ -326,14 +338,11 @@ function normalizeUsageEntry(entry: PersistedUsageEntry): PersistedUsageEntry {
326338 ...( typeof entry . reasoningWireField === "string" && entry . reasoningWireField
327339 ? { reasoningWireField : capMetadataString ( entry . reasoningWireField ) }
328340 : { } ) ,
329- ...( typeof entry . reasoningWireValue === "string" && entry . reasoningWireValue
330- ? { reasoningWireValue : capMetadataString ( entry . reasoningWireValue ) }
331- : typeof entry . reasoningWireValue === "boolean"
332- && entry . reasoningWireField === "reasoning.enabled"
333- ? { reasoningWireValue : entry . reasoningWireValue }
334- : isNonNegativeFiniteNumber ( entry . reasoningWireValue )
335- ? { reasoningWireValue : entry . reasoningWireValue }
336- : { } ) ,
341+ ...( isValidReasoningWireValue ( entry . reasoningWireField , entry . reasoningWireValue )
342+ ? typeof entry . reasoningWireValue === "string"
343+ ? { reasoningWireValue : capMetadataString ( entry . reasoningWireValue ) }
344+ : { reasoningWireValue : entry . reasoningWireValue }
345+ : { } ) ,
337346 ...( typeof entry . requestedServiceTier === "string" && entry . requestedServiceTier
338347 ? { requestedServiceTier : capMetadataString ( entry . requestedServiceTier ) }
339348 : { } ) ,
0 commit comments