@@ -92,6 +92,7 @@ enum StreamEvent {
9292 ToolCallFinished {
9393 tool_name : String ,
9494 result : String ,
95+ is_error : bool ,
9596 } ,
9697 AgentThought {
9798 thought : String ,
@@ -652,14 +653,16 @@ impl ApiChannel {
652653 chat_id,
653654 tool_name,
654655 result,
656+ is_error,
655657 ..
656658 } => {
657659 if let Some ( pending) = self . pending_requests . get ( & chat_id) {
658660 if let PendingRequest :: Stream ( pending) = pending. value ( ) {
659- if let Err ( e) = pending
660- . stream_tx
661- . try_send ( StreamEvent :: ToolCallFinished { tool_name, result } )
662- {
661+ if let Err ( e) = pending. stream_tx . try_send ( StreamEvent :: ToolCallFinished {
662+ tool_name,
663+ result,
664+ is_error,
665+ } ) {
663666 error ! ( "Failed to send tool_call_finished to stream: {}" , e) ;
664667 }
665668 }
@@ -2567,7 +2570,7 @@ fn log_api(logger_tx: &LoggerHandle, event: LogEvent) {
25672570mod tests {
25682571 use super :: {
25692572 bearer_token_matches, build_router, is_loopback_bind, validate_bind_security, ApiState ,
2570- PendingRequest , EMBEDDED_UI_ASSETS ,
2573+ PendingRequest , StreamEvent , EMBEDDED_UI_ASSETS ,
25712574 } ;
25722575 use crate :: bus:: { BusMessage , OutboundMessage } ;
25732576 use crate :: channels:: api_store:: ResponseStore ;
@@ -2589,6 +2592,24 @@ mod tests {
25892592 use tokio:: sync:: { mpsc, oneshot} ;
25902593 use tower:: ServiceExt ;
25912594
2595+ #[ test]
2596+ fn streamed_tool_completion_preserves_typed_error_status ( ) {
2597+ for ( result, is_error) in [
2598+ ( "Error: this is file content, not a failure" , false ) ,
2599+ ( "native failure without a text prefix" , true ) ,
2600+ ] {
2601+ let event = StreamEvent :: ToolCallFinished {
2602+ tool_name : "read_file" . to_string ( ) ,
2603+ result : result. to_string ( ) ,
2604+ is_error,
2605+ } ;
2606+ let encoded = serde_json:: to_value ( event) . expect ( "serialize stream event" ) ;
2607+
2608+ assert_eq ! ( encoded[ "type" ] , "tool_call_finished" ) ;
2609+ assert_eq ! ( encoded[ "is_error" ] , is_error) ;
2610+ }
2611+ }
2612+
25922613 struct LocalTempDir {
25932614 path : std:: path:: PathBuf ,
25942615 }
0 commit comments