pub fn background_load_allowed() -> boolExpand description
Whether this process may load the ONNX model on a detached background thread (#519).
ONNX Runtime registers its op schemas in global C++ static state while a
model is loading. If a detached loader thread is still mid-load when the
process returns from main, it races libonnxruntime’s static-destructor
teardown — a use-after-free SIGSEGV inside onnx::OpSchema on an ORT worker
thread. The shipped lean-ctx daemon/MCP server is long-lived, so its
warmup always finishes well before exit; short-lived processes (cargo test/
bench/doctest binaries, build-time generators) can exit mid-load, so we
refuse the background spawn for them. Their semantic features simply stay
cold — blocking, on-thread loads still work and always complete before exit,
which is race-free.
Note: blocking shared_engine loads are intentionally NOT gated — they
finish on the caller’s thread before the process exits, so no worker is ever
active during teardown.