{"record":{"id":"fd16f2dd1561c0cb","repo":"BoundaryML/baml","slug":"failed-to-start-tokio-runtime-because-e","errorCode":null,"errorMessage":"Failed to start tokio runtime because:\n{e:?}","messagePattern":"Failed to start tokio runtime because:\n(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/lib.rs","lineNumber":45,"sourceCode":"impl Drop for BamlRuntimeFfi {\n    fn drop(&mut self) {\n        use baml_runtime::runtime_interface::ExperimentalTracingInterface;\n        match self.inner.flush() {\n            Ok(_) => log::trace!(\"Flushed BAML log events\"),\n            Err(e) => log::error!(\"Error while flushing BAML log events: {e:?}\"),\n        }\n    }\n}\n\nimpl BamlRuntimeFfi {\n    fn make_tokio_runtime(ruby: &Ruby) -> Result<tokio::runtime::Runtime> {\n        // NB: libruby will panic if called from a non-Ruby thread, so we stick to the current thread\n        // to avoid causing issues\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()\n            .map_err(|e| {\n                Error::new(\n                    ruby.exception_runtime_error(),\n                    format!(\"Failed to start tokio runtime because:\\n{e:?}\"),\n                )\n            })\n    }\n\n    pub fn from_directory(\n        ruby: &Ruby,\n        directory: PathBuf,\n        env_vars: HashMap<String, String>,\n    ) -> Result<BamlRuntimeFfi> {\n        let baml_runtime =\n            match BamlRuntime::from_directory(&directory, env_vars, FeatureFlags::new()) {\n                Ok(br) => br,\n                Err(e) => {\n                    return Err(Error::new(\n                        ruby.exception_runtime_error(),\n                        format!(\"{:?}\", e.context(\"Failed to initialize BAML runtime\")),","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs#L27-L63","documentation":"This error is raised by the Ruby FFI layer when the embedded tokio async runtime cannot be built. BAML's Ruby bindings use a current-thread tokio runtime (because libruby panics if called from non-Ruby threads), and any failure constructing that runtime is surfaced as a Ruby RuntimeError with the underlying tokio error attached.","triggerScenarios":"Calling any BAML Ruby API that lazily creates the runtime (e.g. Baml::Runtime.from_directory/from_files or the first call_function) when tokio's runtime Builder.build() fails — typically due to unsupported IO/driver features on the platform or resource exhaustion.","commonSituations":"Running on an exotic or unsupported platform where tokio drivers cannot initialize; constrained/embedded environments lacking resources; incompatible tokio features enabled at build time.","solutions":["Check the {:?}-formatted tokio error in the message for the root cause (e.g. IO driver unavailable).","Ensure you run on a supported platform/architecture with a normal OS environment (sockets, epoll/kqueue available).","Upgrade the baml gem / ruby_ffi native extension to the latest version.","Report the issue to BAML if it reproduces on a supported platform — this usually indicates an environment or build problem."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"raise 'unsupported platform' unless RUBY_PLATFORM =~ /linux|darwin/","typeGuard":null,"tryCatchPattern":"begin\n  runtime = Baml::Runtime.from_directory(dir, ENV.to_h)\nrescue RuntimeError => e\n  raise unless e.message.include?('Failed to start tokio runtime')\n  warn \"BAML async runtime failed to init: #{e.message}\" ; raise\nend","preventionTips":["Run on mainstream platforms (linux/macOS) with standard OS facilities.","Keep the baml gem and its native extension up to date.","Avoid embedding Ruby in environments that restrict thread/IO syscalls.","Log e.message fully — it embeds the tokio debug output needed to diagnose."],"tags":["runtime","async","tokio","ruby-ffi","init"],"backgroundTag":"module-init-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}