{"record":{"id":"98e2602796300c4d","repo":"BoundaryML/baml","slug":"operation-cancelled","errorCode":null,"errorMessage":"Operation cancelled..","messagePattern":"Operation cancelled\\.\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"engine/baml-runtime/src/lib.rs","lineNumber":380,"sourceCode":"            // Only execute drop logic if we have an error (early return case)\n            let result: Result<FunctionResult> = if let Some(error) = self.error_result.take() {\n                Err(error)\n            } else {\n                // Dropped without explicit finish - likely due to cancellation/shutdown\n                // Instead of returning an error, emit a function end event for cancellation.\n                {\n                    let function_end_event = TraceEvent::new_function_end(\n                        self.call_id_stack.clone(),\n                        Err(BamlError::External {\n                            message: \"Operation cancelled\".into(),\n                        }),\n                        function_type.clone(),\n                    );\n                    BAML_TRACER\n                        .lock()\n                        .unwrap()\n                        .put(Arc::new(function_end_event));\n                    Err(anyhow::anyhow!(\"Operation cancelled..\"))\n                }\n            };\n\n            // Emit TraceEvent::new_function_end for the error case\n            let trace_event = TraceEvent::new_function_end(\n                self.call_id_stack.clone(),\n                Err(result.as_ref().err().unwrap().to_baml_error()),\n                function_type.clone(),\n            );\n            BAML_TRACER.lock().unwrap().put(Arc::new(trace_event));\n\n            // Finish the baml call\n            #[cfg(not(target_arch = \"wasm32\"))]\n            {\n                match self\n                    .tracer_wrapper\n                    .get_or_create_tracer(&self.env_vars)\n                    .finish_baml_call(call, self.ctx, &result)","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L362-L398","documentation":"A traced function's future was cancelled before completing (the tokio select on cancellation fired). The runtime still emits a function_end trace event, then returns an anyhow error 'Operation cancelled..' to signal the caller that the work was aborted mid-flight.","triggerScenarios":"Dropping/cancelling the future running a traced LLM function: task abort via tokio::select! on another branch, client disconnect, timeout, or a JoinHandle being dropped while a function call is in flight.","commonSituations":"HTTP request timeouts in web servers, user-initiated aborts (AbortController/reqwest cancellation), shutting down workers while BAML calls are pending, race conditions in streaming responses.","solutions":["Check whether the surrounding task/request was deliberately cancelled (timeout, abort, disconnect) and address that cause","Increase timeouts or move long LLM calls off paths that get aborted quickly","Handle this error as an expected cancellation in the caller rather than retrying blindly","If cancellation is unintentional, avoid dropping the JoinHandle/future prematurely and use structured cancellation"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Operation cancelled\") => {\n        // expected cancellation: cleanup, optionally retry\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Set generous timeouts on tasks wrapping BAML calls","Avoid dropping JoinHandles of in-flight LLM calls","Handle client disconnects explicitly before aborting tasks","Treat cancellation errors as control flow, not failures"],"tags":["rust","cancellation","async","tokio"],"backgroundTag":"thread-interrupted","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}