From 32d7b3b902bcc0a0be090ed783e38ffdbdd53b04 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Tue, 28 Apr 2026 11:06:57 +0800 Subject: [PATCH] fix(billing): use actual tokens in nonstreaming ReAct billing - ai_react_nonstreaming now passes real input/output tokens to billing - Was passing hardcoded 0,0 despite destructuring token data - Also fix unused variable warnings --- libs/room/src/service/ai_react_nonstreaming.rs | 14 ++++++++------ libs/room/src/service/ai_react_streaming.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/room/src/service/ai_react_nonstreaming.rs b/libs/room/src/service/ai_react_nonstreaming.rs index 881bd18..f117522 100644 --- a/libs/room/src/service/ai_react_nonstreaming.rs +++ b/libs/room/src/service/ai_react_nonstreaming.rs @@ -33,7 +33,7 @@ pub async fn process_message_ai_react_nonstreaming( .await; match final_answer { - Ok((response, input_tokens, output_tokens)) => { + Ok((response, _input_tokens, _output_tokens)) => { if let Err(e) = create_and_publish_ai_message( &db, &cache, @@ -66,15 +66,17 @@ pub async fn process_message_ai_react_nonstreaming( } // Record billing (non-fatal) - // TODO: ReAct agent does not track token counts yet; billing with 0/0 - let _ = super::billing::record_ai_usage( + if let Err(e) = super::billing::record_ai_usage( &db, project_id, model_id, - 0, - 0, + _input_tokens, + _output_tokens, ) - .await; + .await + { + tracing::warn!(error = %e, "AI billing recording failed"); + } } } Err(e) => { diff --git a/libs/room/src/service/ai_react_streaming.rs b/libs/room/src/service/ai_react_streaming.rs index 7b17d9b..3fa9e98 100644 --- a/libs/room/src/service/ai_react_streaming.rs +++ b/libs/room/src/service/ai_react_streaming.rs @@ -155,7 +155,7 @@ pub async fn process_message_ai_react_streaming( }) .await; - let (final_content, input_tokens, output_tokens, err_msg, should_log) = match result { + let (final_content, input_tokens, output_tokens, err_msg, _should_log) = match result { Ok((content, input, output)) => (content, input, output, None, false), Err(e) => { let msg = format!("[Agent error: {}]", e);