Versions
baml-py 0.223.0 and 0.226.3: both reproduce it, 3/3 runs each, within about 1 s
Python 3.11. Repro on macOS arm64; production on Linux (Cloud Run), gunicorn + uvicorn
Cause (from the source)
In BamlTracer::start_call (tracing/mod.rs), collector.track_function(call_id) runs before the FunctionStart event is put into BAML_TRACER. Between those two steps, collector.last returns a FunctionLog for that ID. Its getters call get_inner, and build_function_log returns None because there are no events yet. The code then does:
let tracer = BAML_TRACER.lock().unwrap();
build_function_log(&tracer, &self.id)
.expect("Function log expected to be present (no FunctionStart event?) ...") // panics with the lock held
That poisons the mutex, and every later BAML_TRACER.lock().unwrap() panics: tracing/mod.rs:484, lib.rs:378, storage.rs:594/723 and primitive/request.rs:144.